2 music-output-def.cc -- implement Output_def
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 #include "output-def.hh"
11 #include "context-def.hh"
12 #include "file-path.hh"
13 #include "global-context.hh"
14 #include "interval.hh"
16 #include "output-def.hh"
17 #include "scm-hash.hh"
20 #include "ly-smobs.icc"
22 Output_def::Output_def ()
28 scope_ = ly_make_anonymous_module (false);
31 Output_def::Output_def (Output_def const &s)
37 input_origin_ = s.input_origin_;
38 scope_ = ly_make_anonymous_module (false);
39 if (ly_c_module_p (s.scope_))
40 ly_module_copy (scope_, s.scope_);
43 Output_def::~Output_def ()
47 IMPLEMENT_SMOBS (Output_def);
48 IMPLEMENT_DEFAULT_EQUAL_P (Output_def);
51 Output_def::mark_smob (SCM m)
53 Output_def *mo = (Output_def*) SCM_CELL_WORD_1 (m);
55 /* FIXME: why is this necessary?
56 all paper_ should be protected by themselves. */
58 scm_gc_mark (mo->parent_->self_scm ());
64 assign_context_def (Output_def * m, SCM transdef)
66 Context_def *tp = unsmob_context_def (transdef);
71 SCM sym = tp->get_context_name ();
72 m->set_variable (sym, transdef);
76 /* find the translator for NAME. NAME must be a symbol. */
78 find_context_def (Output_def const *m, SCM name)
80 Context_def *cd = unsmob_context_def (m->lookup_variable (name));
81 return cd ? cd->self_scm () : SCM_EOL;
85 Output_def::print_smob (SCM s, SCM p, scm_print_state *)
87 Output_def * def = unsmob_output_def (s);
89 scm_puts (classname (def), p);
97 Output_def::get_dimension (SCM s) const
99 SCM val = lookup_variable (s);
100 return scm_to_double (val);
104 Output_def::lookup_variable (SCM sym) const
106 SCM var = ly_module_lookup (scope_, sym);
107 if (SCM_VARIABLEP (var) && SCM_VARIABLE_REF(var) != SCM_UNDEFINED)
108 return SCM_VARIABLE_REF (var);
111 return parent_->lookup_variable (sym);
117 Output_def::c_variable (String s) const
119 return lookup_variable (ly_symbol2scm (s.to_str0 ()));
123 Output_def::set_variable (SCM sym, SCM val)
125 scm_module_define (scope_, sym, val);
129 /* FIXME. This is broken until we have a generic way of
130 putting lists inside the \layout block. */
132 line_dimensions_int (Output_def *def, int n)
134 Real lw = def->get_dimension (ly_symbol2scm ("linewidth"));
135 Real ind = n ? 0.0 : def->get_dimension (ly_symbol2scm ("indent"));
136 return Interval (ind, lw);