2 music-output-def.cc -- implement Music_output_def
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
12 #include "music-output-def.hh"
13 #include "global-context.hh"
14 #include "context-def.hh"
16 #include "file-path.hh"
17 #include "lily-guile.hh"
18 #include "ly-module.hh"
20 #include "ly-smobs.icc"
22 Music_output_def::Music_output_def ()
24 translator_tab_
= new Scheme_hash_table
;
28 scm_gc_unprotect_object (translator_tab_
->self_scm ());
29 scope_
= ly_make_anonymous_module ();
32 Music_output_def::~Music_output_def ()
36 Music_output_def::Music_output_def (Music_output_def
const &s
)
42 translator_tab_
= new Scheme_hash_table (*s
.translator_tab_
);
43 scm_gc_unprotect_object (translator_tab_
->self_scm ());
45 scope_
= ly_make_anonymous_module ();
46 if (ly_module_p (s
.scope_
))
47 ly_import_module (scope_
, s
.scope_
);
51 IMPLEMENT_SMOBS (Music_output_def
);
52 IMPLEMENT_DEFAULT_EQUAL_P (Music_output_def
);
55 Music_output_def::mark_smob (SCM m
)
57 Music_output_def
* mo
= (Music_output_def
*) SCM_CELL_WORD_1 (m
);
58 if (mo
->translator_tab_
)
59 scm_gc_mark (mo
->translator_tab_
->self_scm ());
67 Music_output_def::derived_mark ()
73 Music_output_def::assign_context_def (SCM transdef
)
75 Context_def
*tp
= unsmob_context_def (transdef
);
78 translator_tab_
->set (tp
->get_context_name (), transdef
);
80 String nm
= ly_symbol2string (tp
->get_context_name ()) + "Context";
83 scm_module_define (scope_
, ly_symbol2scm (nm
.to_str0 ()), transdef
);
87 find the translator for NAME. NAME must be a symbol.
90 Music_output_def::find_context_def (SCM name
) const
93 translator_tab_
->try_retrieve (name
, &val
);
98 Music_output_def::print_smob (SCM s
, SCM p
, scm_print_state
*)
100 Music_output_def
* def
= unsmob_music_output_def (s
);
102 scm_puts (classname (def
), p
);
110 Music_output_def::get_scmvar (String s
) const
112 return lookup_variable (ly_symbol2scm (s
.to_str0 ()));
116 Music_output_def::set_variable (SCM sym
, SCM val
)
118 scm_module_define (scope_
, sym
, val
);
122 Music_output_def::lookup_variable (SCM sym
) const
124 SCM var
= ly_module_lookup (scope_
, sym
);
126 return scm_variable_ref (var
);
129 LY_DEFINE (ly_paper_lookup
, "ly:paper-lookup",
130 2, 0,0, (SCM pap
, SCM sym
),
131 "Lookup @var{sym} in @var{pap}. "
132 "Return the value or @code{'()} if undefined.")
134 Music_output_def
*op
= unsmob_music_output_def (pap
);
135 SCM_ASSERT_TYPE (op
, pap
, SCM_ARG1
, __FUNCTION__
, "Paper");
136 SCM_ASSERT_TYPE (ly_symbol_p (sym
), sym
, SCM_ARG2
, __FUNCTION__
, "symbol");
138 SCM var
= ly_module_lookup (op
->scope_
, sym
);
139 if (SCM_VARIABLEP (var
))
140 return SCM_VARIABLE_REF (var
);
145 LY_DEFINE (ly_output_def_scope
, "ly:output-def-scope",
147 "Get the variable scope inside @var{def}.")
149 Music_output_def
*op
= unsmob_music_output_def (def
);
150 SCM_ASSERT_TYPE (op
, def
, SCM_ARG1
, __FUNCTION__
, "Output definition");
154 LY_DEFINE (ly_output_def_clone
, "ly:output-def-clone",
158 Music_output_def
*op
= unsmob_music_output_def (def
);
159 SCM_ASSERT_TYPE (op
, def
, SCM_ARG1
, __FUNCTION__
, "Output definition");
160 SCM s
= op
->clone ()->self_scm ();
161 scm_gc_unprotect_object (s
);