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 "context-def.hh"
10 #include "file-path.hh"
11 #include "global-context.hh"
12 #include "interval.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 Output_def::Output_def ()
27 scope_ = ly_make_anonymous_module (false);
30 Output_def::Output_def (Output_def const &s)
36 input_origin_ = s.input_origin_;
37 scope_= ly_make_anonymous_module (false);
38 if (ly_c_module_p (s.scope_))
39 ly_import_module (scope_, s.scope_);
42 Output_def::~Output_def ()
46 #include "ly-smobs.icc"
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 bookpaper_ 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);
128 LY_DEFINE (ly_paper_lookup, "ly:output-def-lookup",
129 2, 0, 0, (SCM pap, SCM sym),
130 "Lookup @var{sym} in @var{pap}. "
131 "Return the value or @code{'()} if undefined.")
133 Output_def *op = unsmob_output_def (pap);
134 SCM_ASSERT_TYPE (op, pap, SCM_ARG1, __FUNCTION__, "Output_def");
135 SCM_ASSERT_TYPE (scm_is_symbol (sym), sym, SCM_ARG2, __FUNCTION__, "symbol");
137 return op->lookup_variable (sym);
140 LY_DEFINE (ly_output_def_scope, "ly:output-def-scope",
142 "Get the variable scope inside @var{def}.")
144 Output_def *op = unsmob_output_def (def);
145 SCM_ASSERT_TYPE (op, def, SCM_ARG1, __FUNCTION__, "Output definition");
149 LY_DEFINE (ly_output_def_parent, "ly:output-def-parent",
151 "Get the parent output-def of @var{def}.")
153 Output_def *op = unsmob_output_def (def);
154 SCM_ASSERT_TYPE (op, def, SCM_ARG1, __FUNCTION__, "Output definition");
155 return op->parent_ ? op->parent_->self_scm () : SCM_EOL;
158 LY_DEFINE (ly_output_def_clone, "ly:output-def-clone",
162 Output_def *op = unsmob_output_def (def);
163 SCM_ASSERT_TYPE (op, def, SCM_ARG1, __FUNCTION__, "Output definition");
164 SCM s = op->clone ()->self_scm ();
165 scm_gc_unprotect_object (s);
169 LY_DEFINE (ly_output_description, "ly:output-description",
170 1, 0, 0, (SCM output_def),
171 "Return the description of translators in @var{output-def}.")
173 Output_def *id = unsmob_output_def (output_def);
175 SCM al = ly_module2alist (id->scope_);
178 for (SCM s = al; ly_c_pair_p (s); s = ly_cdr (s))
180 Context_def * td = unsmob_context_def (ly_cdar (s));
181 SCM key = ly_caar (s);
182 if (td && key == td->get_context_name ())
183 ell = scm_cons (scm_cons (key, td->to_alist ()), ell);
188 /* FIXME. This is broken until we have a generic way of
189 putting lists inside the \paper block. */
191 line_dimensions_int (Output_def *def, int n)
193 Real lw = def->get_dimension (ly_symbol2scm ("linewidth"));
194 Real ind = n ? 0.0 : def->get_dimension (ly_symbol2scm ("indent"));
195 return Interval (ind, lw);
198 LY_DEFINE (ly_paper_def_p, "ly:paper-def?",
200 "Is @var{def} a paper definition?")
202 return ly_bool2scm (unsmob_output_def (def));
205 LY_DEFINE (ly_bookpaper_outputscale, "ly:bookpaper-outputscale",
207 "Get outputscale for BP.")
209 Output_def *b = unsmob_output_def (bp);
210 SCM_ASSERT_TYPE (b, bp, SCM_ARG1, __FUNCTION__, "bookpaper");
211 return scm_make_real (output_scale (b));
214 LY_DEFINE (ly_make_output_def, "ly:make-output-def",
216 "Make a output def.")
218 Output_def *bp = new Output_def ;
219 return scm_gc_unprotect_object (bp->self_scm ());