2 property-iterator.cc -- implement Property_iterator
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 #include "property-iterator.hh"
11 #include "translator-def.hh"
12 #include "translator-group.hh"
13 #include "global-translator.hh"
16 bool check_grob(Music *mus, SCM sym);
19 There is no real processing to a property: just lookup the
20 translation unit, and set the property.
23 Property_iterator::process (Moment m)
25 SCM sym = get_music ()->get_mus_property ("symbol");
26 if (gh_symbol_p (sym))
28 SCM val = get_music ()->get_mus_property ("value");
31 ok = type_check_assignment (sym, val, ly_symbol2scm ("translation-type?"));
33 report_to ()->internal_set_property (sym, val);
35 Simple_music_iterator::process (m);
39 Property_unset_iterator::process (Moment m)
41 SCM sym = get_music ()->get_mus_property ("symbol");
42 type_check_assignment (sym, SCM_EOL, ly_symbol2scm ("translation-type?"));
43 report_to ()->unset_property (sym);
45 Simple_music_iterator::process (m);
48 MAKE_SCHEME_CALLBACK(Property_iterator,once_finalization, 2);
50 Property_iterator::once_finalization(SCM translator, SCM music )
52 Music * m = unsmob_music (music);
54 = dynamic_cast<Translator_group*> (unsmob_translator (translator));
55 SCM sym = m->get_mus_property ("symbol");
57 tg->unset_property (sym);
58 return SCM_UNSPECIFIED;
62 Property_iterator::do_quit ()
64 if (to_boolean (get_music ()->get_mus_property ("once")))
66 SCM trans = report_to()->self_scm();
67 SCM music = get_music()->self_scm();
69 Global_translator * tg= report_to()->top_translator ();
71 tg->add_finalization (scm_list_n (once_finalization_proc,
72 trans, music, SCM_UNDEFINED));
80 This is a rather crude check: we merely check if the translator
84 check_grob(Music *mus, SCM sym)
88 list_p = gh_eval_str ("list?");
92 SCM type = scm_object_property (sym, ly_symbol2scm ("translation-type?"));
93 bool ok = type == list_p;
97 mus->origin()->warning (_f("Not a grob name, `%s'." , ly_symbol2string (sym)));
103 Push_property_iterator::process (Moment m)
105 SCM sym = get_music ()->get_mus_property ("symbol");
106 if (check_grob (get_music (), sym))
108 SCM eprop = get_music ()->get_mus_property ("grob-property");
109 SCM val = get_music ()->get_mus_property ("grob-value");
111 if (to_boolean (get_music ()->get_mus_property ("pop-first"))
112 && !to_boolean (get_music ()->get_mus_property ("once"))
114 Translator_def::apply_pushpop_property (report_to (),
115 sym, eprop, SCM_UNDEFINED);
117 Translator_def::apply_pushpop_property (report_to (), sym, eprop, val);
119 Simple_music_iterator::process (m);
122 MAKE_SCHEME_CALLBACK(Push_property_iterator,once_finalization, 2);
124 Push_property_iterator::once_finalization (SCM trans, SCM music)
126 Music * mus = unsmob_music (music);
128 = dynamic_cast<Translator_group*> (unsmob_translator (trans));
130 SCM sym = mus->get_mus_property ("symbol");
131 if (check_grob (mus, sym))
133 SCM eprop = mus->get_mus_property ("grob-property");
135 Translator_def::apply_pushpop_property (tg, sym, eprop, SCM_UNDEFINED);
137 return SCM_UNSPECIFIED;
141 Push_property_iterator::do_quit ()
143 if (to_boolean (get_music ()->get_mus_property ("once")))
145 SCM trans = report_to()->self_scm();
146 SCM music = get_music ()->self_scm();
148 Global_translator * tg= report_to()->top_translator ();
149 tg->add_finalization (scm_list_n (once_finalization_proc,
150 trans, music, SCM_UNDEFINED));
155 Pop_property_iterator::process (Moment m)
157 SCM sym = get_music ()->get_mus_property ("symbol");
158 if (check_grob (get_music (), sym))
160 SCM eprop = get_music ()->get_mus_property ("grob-property");
161 Translator_def::apply_pushpop_property (report_to (), sym, eprop, SCM_UNDEFINED);
163 Simple_music_iterator::process (m);
168 IMPLEMENT_CTOR_CALLBACK (Pop_property_iterator);
169 IMPLEMENT_CTOR_CALLBACK (Push_property_iterator);
170 IMPLEMENT_CTOR_CALLBACK (Property_iterator);
171 IMPLEMENT_CTOR_CALLBACK (Property_unset_iterator);