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 ());
65 Output_def::derived_mark ()
70 assign_context_def (Output_def
* m
, SCM transdef
)
72 Context_def
*tp
= unsmob_context_def (transdef
);
77 SCM sym
= tp
->get_context_name ();
78 scm_module_define (m
->scope_
, sym
, transdef
);
82 /* find the translator for NAME. NAME must be a symbol. */
84 find_context_def (Output_def
const *m
, SCM name
)
86 Context_def
*cd
= unsmob_context_def (m
->lookup_variable (name
));
87 return cd
? cd
->self_scm () : SCM_EOL
;
91 Output_def::print_smob (SCM s
, SCM p
, scm_print_state
*)
93 Output_def
* def
= unsmob_output_def (s
);
95 scm_puts (classname (def
), p
);
103 Output_def::get_dimension (SCM s
) const
105 SCM val
= lookup_variable (s
);
106 return ly_scm2double (val
);
110 Output_def::lookup_variable (SCM sym
) const
112 SCM var
= ly_module_lookup (scope_
, sym
);
113 if (SCM_VARIABLEP (var
) && SCM_VARIABLE_REF(var
) != SCM_UNDEFINED
)
114 return SCM_VARIABLE_REF (var
);
117 return parent_
->lookup_variable (sym
);
123 Output_def::c_variable (String s
) const
125 return lookup_variable (ly_symbol2scm (s
.to_str0 ()));
129 Output_def::set_variable (SCM sym
, SCM val
)
131 scm_module_define (scope_
, sym
, val
);
134 LY_DEFINE (ly_paper_lookup
, "ly:output-def-lookup",
135 2, 0, 0, (SCM pap
, SCM sym
),
136 "Lookup @var{sym} in @var{pap}. "
137 "Return the value or @code{'()} if undefined.")
139 Output_def
*op
= unsmob_output_def (pap
);
140 SCM_ASSERT_TYPE (op
, pap
, SCM_ARG1
, __FUNCTION__
, "Output_def");
141 SCM_ASSERT_TYPE (ly_c_symbol_p (sym
), sym
, SCM_ARG2
, __FUNCTION__
, "symbol");
143 return op
->lookup_variable (sym
);
146 LY_DEFINE (ly_output_def_scope
, "ly:output-def-scope",
148 "Get the variable scope inside @var{def}.")
150 Output_def
*op
= unsmob_output_def (def
);
151 SCM_ASSERT_TYPE (op
, def
, SCM_ARG1
, __FUNCTION__
, "Output definition");
155 LY_DEFINE (ly_output_def_parent
, "ly:output-def-parent",
157 "Get the parent output-def of @var{def}.")
159 Output_def
*op
= unsmob_output_def (def
);
160 SCM_ASSERT_TYPE (op
, def
, SCM_ARG1
, __FUNCTION__
, "Output definition");
161 return op
->parent_
? op
->parent_
->self_scm () : SCM_EOL
;
164 LY_DEFINE (ly_output_def_clone
, "ly:output-def-clone",
168 Output_def
*op
= unsmob_output_def (def
);
169 SCM_ASSERT_TYPE (op
, def
, SCM_ARG1
, __FUNCTION__
, "Output definition");
170 SCM s
= op
->clone ()->self_scm ();
171 scm_gc_unprotect_object (s
);
175 LY_DEFINE (ly_output_description
, "ly:output-description",
176 1, 0, 0, (SCM output_def
),
177 "Return the description of translators in @var{output-def}.")
179 Output_def
*id
= unsmob_output_def (output_def
);
181 SCM al
= ly_module2alist (id
->scope_
);
184 for (SCM s
= al
; ly_c_pair_p (s
); s
= ly_cdr (s
))
186 Context_def
* td
= unsmob_context_def (ly_cdar (s
));
187 SCM key
= ly_caar (s
);
188 if (td
&& key
== td
->get_context_name ())
189 ell
= scm_cons (scm_cons (key
, td
->to_alist ()), ell
);
194 /* FIXME. This is broken until we have a generic way of
195 putting lists inside the \paper block. */
197 line_dimensions_int (Output_def
*def
, int n
)
199 Real lw
= def
->get_dimension (ly_symbol2scm ("linewidth"));
200 Real ind
= n
? 0.0 : def
->get_dimension (ly_symbol2scm ("indent"));
201 return Interval (ind
, lw
);
204 LY_DEFINE (ly_paper_def_p
, "ly:paper-def?",
206 "Is @var{def} a paper definition?")
208 return ly_bool2scm (unsmob_output_def (def
));
211 LY_DEFINE (ly_bookpaper_outputscale
, "ly:bookpaper-outputscale",
213 "Get outputscale for BP.")
215 Output_def
*b
= unsmob_output_def (bp
);
216 SCM_ASSERT_TYPE (b
, bp
, SCM_ARG1
, __FUNCTION__
, "bookpaper");
217 return scm_make_real (output_scale (b
));
220 LY_DEFINE (ly_make_output_def
, "ly:make-output-def",
222 "Make a output def.")
224 Output_def
*bp
= new Output_def
;
225 return scm_gc_unprotect_object (bp
->self_scm ());