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 #include "program-option.hh"
24 #include "string-convert.hh"
26 Output_def::Output_def ()
32 scope_ = ly_make_anonymous_module (false);
35 Output_def::Output_def (Output_def const &s)
41 input_origin_ = s.input_origin_;
42 scope_ = ly_make_anonymous_module (false);
43 if (ly_is_module (s.scope_))
44 ly_module_copy (scope_, s.scope_);
47 Output_def::~Output_def ()
51 IMPLEMENT_SMOBS (Output_def);
52 IMPLEMENT_DEFAULT_EQUAL_P (Output_def);
55 Output_def::mark_smob (SCM m)
57 Output_def *mo = (Output_def*) SCM_CELL_WORD_1 (m);
59 /* FIXME: why is this necessary?
60 all paper_ should be protected by themselves. */
62 scm_gc_mark (mo->parent_->self_scm ());
68 assign_context_def (Output_def * m, SCM transdef)
70 Context_def *tp = unsmob_context_def (transdef);
75 SCM sym = tp->get_context_name ();
76 m->set_variable (sym, transdef);
80 /* find the translator for NAME. NAME must be a symbol. */
82 find_context_def (Output_def const *m, SCM name)
84 Context_def *cd = unsmob_context_def (m->lookup_variable (name));
85 return cd ? cd->self_scm () : SCM_EOL;
89 Output_def::print_smob (SCM s, SCM p, scm_print_state *)
91 Output_def * def = unsmob_output_def (s);
93 scm_puts (classname (def), p);
101 Output_def::get_dimension (SCM s) const
103 SCM val = lookup_variable (s);
104 return scm_to_double (val);
108 Output_def::lookup_variable (SCM sym) const
110 SCM var = ly_module_lookup (scope_, sym);
111 if (SCM_VARIABLEP (var) && SCM_VARIABLE_REF(var) != SCM_UNDEFINED)
112 return SCM_VARIABLE_REF (var);
115 return parent_->lookup_variable (sym);
117 return SCM_UNDEFINED;
121 Output_def::c_variable (String s) const
123 return lookup_variable (ly_symbol2scm (s.to_str0 ()));
127 Output_def::set_variable (SCM sym, SCM val)
129 scm_module_define (scope_, sym, val);
133 /* FIXME. This is broken until we have a generic way of
134 putting lists inside the \layout block. */
136 line_dimensions_int (Output_def *def, int n)
138 Real lw = def->get_dimension (ly_symbol2scm ("linewidth"));
139 Real ind = n ? 0.0 : def->get_dimension (ly_symbol2scm ("indent"));
140 return Interval (ind, lw);