2 music-output-def.cc -- implement Output_def
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 #include "book-paper-def.hh"
10 #include "context-def.hh"
11 #include "file-path.hh"
12 #include "global-context.hh"
13 #include "lily-guile.hh"
14 #include "ly-module.hh"
16 #include "output-def.hh"
17 #include "output-def.hh"
18 #include "scm-hash.hh"
21 #include "ly-smobs.icc"
23 Output_def::Output_def ()
29 scope_ = ly_make_anonymous_module (false);
32 Output_def::~Output_def ()
36 Output_def::Output_def (Output_def const &s)
42 scope_= ly_make_anonymous_module (false);
43 if (is_module (s.scope_))
44 ly_import_module (scope_, s.scope_);
48 IMPLEMENT_SMOBS (Output_def);
49 IMPLEMENT_DEFAULT_EQUAL_P (Output_def);
53 Output_def::mark_smob (SCM m)
55 Output_def * mo = (Output_def*) SCM_CELL_WORD_1 (m);
58 FIXME: why is this necessary?
59 all bookpaper_ should be protected by themselves.
62 scm_gc_mark (mo->parent_->self_scm ());
70 Output_def::derived_mark () {}
73 assign_context_def (Output_def * m, SCM transdef)
75 Context_def *tp = unsmob_context_def (transdef);
80 SCM sym = tp->get_context_name ();
81 scm_module_define (m->scope_, sym, transdef);
86 find the translator for NAME. NAME must be a symbol.
89 find_context_def (Output_def const *m, SCM name)
91 Context_def *cd = unsmob_context_def (m->lookup_variable (name));
92 return cd ? cd->self_scm () : SCM_EOL;
96 Output_def::print_smob (SCM s, SCM p, scm_print_state *)
98 Output_def * def = unsmob_output_def (s);
100 scm_puts (classname (def), p);
108 Output_def::get_dimension (SCM s) const
110 SCM val = lookup_variable (s);
111 return ly_scm2double (val);
116 Output_def::lookup_variable (SCM sym) const
118 SCM var = ly_module_lookup (scope_, sym);
119 if (SCM_VARIABLEP (var))
120 return SCM_VARIABLE_REF (var);
123 return parent_->lookup_variable (sym);
129 Output_def::c_variable (String s) const
131 return lookup_variable (ly_symbol2scm (s.to_str0 ()));
135 Output_def::set_variable (SCM sym, SCM val)
137 scm_module_define (scope_, sym, val);
140 LY_DEFINE (ly_paper_lookup, "ly:output-def-lookup",
141 2, 0, 0, (SCM pap, SCM sym),
142 "Lookup @var{sym} in @var{pap}. "
143 "Return the value or @code{'()} if undefined.")
145 Output_def *op = unsmob_output_def (pap);
146 SCM_ASSERT_TYPE (op, pap, SCM_ARG1, __FUNCTION__, "Output_def");
147 SCM_ASSERT_TYPE (ly_c_symbol_p (sym), sym, SCM_ARG2, __FUNCTION__, "symbol");
149 return op->lookup_variable (sym);
152 LY_DEFINE (ly_output_def_scope, "ly:output-def-scope",
154 "Get the variable scope inside @var{def}.")
156 Output_def *op = unsmob_output_def (def);
157 SCM_ASSERT_TYPE (op, def, SCM_ARG1, __FUNCTION__, "Output definition");
162 LY_DEFINE (ly_output_def_parent, "ly:output-def-parent",
164 "Get the parent output-def of @var{def}.")
166 Output_def *op = unsmob_output_def (def);
167 SCM_ASSERT_TYPE (op, def, SCM_ARG1, __FUNCTION__, "Output definition");
168 return op->parent_ ? op->parent_->self_scm () : SCM_EOL;
172 LY_DEFINE (ly_output_def_clone, "ly:output-def-clone",
176 Output_def *op = unsmob_output_def (def);
177 SCM_ASSERT_TYPE (op, def, SCM_ARG1, __FUNCTION__, "Output definition");
178 SCM s = op->clone ()->self_scm ();
179 scm_gc_unprotect_object (s);
183 LY_DEFINE(ly_output_description, "ly:output-description",
186 "Return the description of translators in @var{output-def}.")
188 Output_def *id = unsmob_output_def (output_def);
190 SCM al =ly_module_to_alist (id->scope_);
193 for (SCM s = al ; ly_c_pair_p (s); s = ly_cdr (s))
195 Context_def * td = unsmob_context_def (ly_cdar (s));
196 SCM key = ly_caar (s);
197 if (td && key == td->get_context_name ())
200 l = scm_cons (scm_cons (key, td->to_alist ()), l);
208 #include "interval.hh"
210 /* FIXME. This is broken until we have a generic way of
211 putting lists inside the \paper block. */
213 line_dimensions_int (Output_def *def, int n)
215 Real lw = def->get_dimension (ly_symbol2scm ("linewidth"));
216 Real ind = n ? 0.0 : def->get_dimension (ly_symbol2scm ("indent"));
218 return Interval (ind, lw);
221 LY_DEFINE (ly_paper_def_p, "ly:paper-def?",
223 "Is @var{def} a paper definition?")
225 return ly_bool2scm (unsmob_output_def (def));