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 "output-def.hh"
11 #include "context-def.hh"
12 #include "file-path.hh"
13 #include "global-context.hh"
14 #include "interval.hh"
15 #include "ly-module.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 (Output_def const &s)
38 input_origin_ = s.input_origin_;
39 scope_ = ly_make_anonymous_module (false);
40 if (ly_c_module_p (s.scope_))
41 ly_module_copy (scope_, s.scope_);
44 Output_def::~Output_def ()
48 IMPLEMENT_SMOBS (Output_def);
49 IMPLEMENT_DEFAULT_EQUAL_P (Output_def);
52 Output_def::mark_smob (SCM m)
54 Output_def *mo = (Output_def*) SCM_CELL_WORD_1 (m);
56 /* FIXME: why is this necessary?
57 all paper_ should be protected by themselves. */
59 scm_gc_mark (mo->parent_->self_scm ());
65 assign_context_def (Output_def * m, SCM transdef)
67 Context_def *tp = unsmob_context_def (transdef);
72 SCM sym = tp->get_context_name ();
73 m->set_variable (sym, transdef);
77 /* find the translator for NAME. NAME must be a symbol. */
79 find_context_def (Output_def const *m, SCM name)
81 Context_def *cd = unsmob_context_def (m->lookup_variable (name));
82 return cd ? cd->self_scm () : SCM_EOL;
86 Output_def::print_smob (SCM s, SCM p, scm_print_state *)
88 Output_def * def = unsmob_output_def (s);
90 scm_puts (classname (def), p);
98 Output_def::get_dimension (SCM s) const
100 SCM val = lookup_variable (s);
101 return scm_to_double (val);
105 Output_def::lookup_variable (SCM sym) const
107 SCM var = ly_module_lookup (scope_, sym);
108 if (SCM_VARIABLEP (var) && SCM_VARIABLE_REF(var) != SCM_UNDEFINED)
109 return SCM_VARIABLE_REF (var);
112 return parent_->lookup_variable (sym);
118 Output_def::c_variable (String s) const
120 return lookup_variable (ly_symbol2scm (s.to_str0 ()));
124 Output_def::set_variable (SCM sym, SCM val)
126 scm_module_define (scope_, sym, val);
130 /* FIXME. This is broken until we have a generic way of
131 putting lists inside the \layout block. */
133 line_dimensions_int (Output_def *def, int n)
135 Real lw = def->get_dimension (ly_symbol2scm ("linewidth"));
136 Real ind = n ? 0.0 : def->get_dimension (ly_symbol2scm ("indent"));
137 return Interval (ind, lw);