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>
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 input_origin_
= s
.input_origin_
;
43 scope_
= ly_make_anonymous_module (false);
44 if (ly_c_module_p (s
.scope_
))
45 ly_import_module (scope_
, s
.scope_
);
49 IMPLEMENT_SMOBS (Output_def
);
50 IMPLEMENT_DEFAULT_EQUAL_P (Output_def
);
54 Output_def::mark_smob (SCM m
)
56 Output_def
* mo
= (Output_def
*) SCM_CELL_WORD_1 (m
);
59 FIXME: why is this necessary?
60 all bookpaper_ should be protected by themselves.
63 scm_gc_mark (mo
->parent_
->self_scm ());
71 Output_def::derived_mark () {}
74 assign_context_def (Output_def
* m
, SCM transdef
)
76 Context_def
*tp
= unsmob_context_def (transdef
);
81 SCM sym
= tp
->get_context_name ();
82 scm_module_define (m
->scope_
, sym
, transdef
);
87 find the translator for NAME. NAME must be a symbol.
90 find_context_def (Output_def
const *m
, SCM name
)
92 Context_def
*cd
= unsmob_context_def (m
->lookup_variable (name
));
93 return cd
? cd
->self_scm () : SCM_EOL
;
97 Output_def::print_smob (SCM s
, SCM p
, scm_print_state
*)
99 Output_def
* def
= unsmob_output_def (s
);
101 scm_puts (classname (def
), p
);
109 Output_def::get_dimension (SCM s
) const
111 SCM val
= lookup_variable (s
);
112 return ly_scm2double (val
);
117 Output_def::lookup_variable (SCM sym
) const
119 SCM var
= ly_module_lookup (scope_
, sym
);
120 if (SCM_VARIABLEP (var
) && SCM_VARIABLE_REF(var
) != SCM_UNDEFINED
)
121 return SCM_VARIABLE_REF (var
);
124 return parent_
->lookup_variable (sym
);
130 Output_def::c_variable (String s
) const
132 return lookup_variable (ly_symbol2scm (s
.to_str0 ()));
136 Output_def::set_variable (SCM sym
, SCM val
)
138 scm_module_define (scope_
, sym
, val
);
141 LY_DEFINE (ly_paper_lookup
, "ly:output-def-lookup",
142 2, 0, 0, (SCM pap
, SCM sym
),
143 "Lookup @var{sym} in @var{pap}. "
144 "Return the value or @code{'()} if undefined.")
146 Output_def
*op
= unsmob_output_def (pap
);
147 SCM_ASSERT_TYPE (op
, pap
, SCM_ARG1
, __FUNCTION__
, "Output_def");
148 SCM_ASSERT_TYPE (ly_c_symbol_p (sym
), sym
, SCM_ARG2
, __FUNCTION__
, "symbol");
150 return op
->lookup_variable (sym
);
153 LY_DEFINE (ly_output_def_scope
, "ly:output-def-scope",
155 "Get the variable scope inside @var{def}.")
157 Output_def
*op
= unsmob_output_def (def
);
158 SCM_ASSERT_TYPE (op
, def
, SCM_ARG1
, __FUNCTION__
, "Output definition");
163 LY_DEFINE (ly_output_def_parent
, "ly:output-def-parent",
165 "Get the parent output-def of @var{def}.")
167 Output_def
*op
= unsmob_output_def (def
);
168 SCM_ASSERT_TYPE (op
, def
, SCM_ARG1
, __FUNCTION__
, "Output definition");
169 return op
->parent_
? op
->parent_
->self_scm () : SCM_EOL
;
173 LY_DEFINE (ly_output_def_clone
, "ly:output-def-clone",
177 Output_def
*op
= unsmob_output_def (def
);
178 SCM_ASSERT_TYPE (op
, def
, SCM_ARG1
, __FUNCTION__
, "Output definition");
179 SCM s
= op
->clone ()->self_scm ();
180 scm_gc_unprotect_object (s
);
184 LY_DEFINE(ly_output_description
, "ly:output-description",
187 "Return the description of translators in @var{output-def}.")
189 Output_def
*id
= unsmob_output_def (output_def
);
191 SCM al
=ly_module_to_alist (id
->scope_
);
194 for (SCM s
= al
; ly_c_pair_p (s
); s
= ly_cdr (s
))
196 Context_def
* td
= unsmob_context_def (ly_cdar (s
));
197 SCM key
= ly_caar (s
);
198 if (td
&& key
== td
->get_context_name ())
201 l
= scm_cons (scm_cons (key
, td
->to_alist ()), l
);
209 #include "interval.hh"
211 /* FIXME. This is broken until we have a generic way of
212 putting lists inside the \paper block. */
214 line_dimensions_int (Output_def
*def
, int n
)
216 Real lw
= def
->get_dimension (ly_symbol2scm ("linewidth"));
217 Real ind
= n
? 0.0 : def
->get_dimension (ly_symbol2scm ("indent"));
219 return Interval (ind
, lw
);
222 LY_DEFINE (ly_paper_def_p
, "ly:paper-def?",
224 "Is @var{def} a paper definition?")
226 return ly_bool2scm (unsmob_output_def (def
));
231 LY_DEFINE (ly_bookpaper_outputscale
, "ly:bookpaper-outputscale",
234 "Get outputscale for BP.")
236 Output_def
*b
= unsmob_output_def (bp
);
237 SCM_ASSERT_TYPE (b
, bp
, SCM_ARG1
, __FUNCTION__
, "bookpaper");
238 return scm_make_real (output_scale (b
));
243 LY_DEFINE (ly_make_output_def
, "ly:make-output-def",
245 "Make a output def.")
247 Output_def
*bp
= new Output_def
;
248 return scm_gc_unprotect_object (bp
->self_scm ());