2 property-iterator.cc -- implement Property_iterator
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
9 #include "property-iterator.hh"
12 #include "context-def.hh"
13 #include "global-context.hh"
15 bool check_grob (Music *mus, SCM sym);
18 There is no real processing to a property: just lookup the
19 translation unit, and set the property.
22 Property_iterator::process (Moment m)
24 SCM sym = get_music ()->get_property ("symbol");
25 if (scm_is_symbol (sym))
27 SCM val = get_music ()->get_property ("value");
30 ok = type_check_assignment (sym, val, ly_symbol2scm ("translation-type?"));
32 get_outlet ()->internal_set_property (sym, val);
34 Simple_music_iterator::process (m);
38 Property_unset_iterator::process (Moment m)
40 SCM sym = get_music ()->get_property ("symbol");
41 type_check_assignment (sym, SCM_EOL, ly_symbol2scm ("translation-type?"));
42 get_outlet ()->unset_property (sym);
44 Simple_music_iterator::process (m);
47 MAKE_SCHEME_CALLBACK (Property_iterator, once_finalization, 2);
49 Property_iterator::once_finalization (SCM translator, SCM music)
51 Music *m = unsmob_music (music);
53 = dynamic_cast<Context *> (unsmob_context (translator));
54 SCM sym = m->get_property ("symbol");
56 tg->unset_property (sym);
57 return SCM_UNSPECIFIED;
61 Property_iterator::do_quit ()
63 if (to_boolean (get_music ()->get_property ("once")))
65 SCM trans = get_outlet ()->self_scm ();
66 SCM music = get_music ()->self_scm ();
68 Global_context *tg = get_outlet ()->get_global_context ();
69 tg->add_finalization (scm_list_n (once_finalization_proc,
70 trans, music, SCM_UNDEFINED));
75 check_grob (Music *mus, SCM sym)
77 bool g = to_boolean (scm_object_property (sym, ly_symbol2scm ("is-grob?")));
80 mus->origin ()->warning (_f ("not a grob name, `%s'",
81 ly_symbol2string (sym)));
87 get_property_path (Music *m)
89 SCM grob_property_path = m->get_property ("grob-property-path");
91 SCM eprop = m->get_property ("grob-property");
92 if (scm_is_symbol (eprop))
94 grob_property_path = scm_list_1 (eprop);
97 return grob_property_path;
101 Push_property_iterator::process (Moment m)
103 SCM sym = get_music ()->get_property ("symbol");
104 if (check_grob (get_music (), sym))
106 SCM grob_property_path = get_property_path (get_music ());
107 SCM val = get_music ()->get_property ("grob-value");
109 if (to_boolean (get_music ()->get_property ("pop-first"))
110 && !to_boolean (get_music ()->get_property ("once")))
112 execute_general_pushpop_property (get_outlet (), sym, grob_property_path, SCM_UNDEFINED);
114 execute_general_pushpop_property (get_outlet (), sym, grob_property_path, val);
116 Simple_music_iterator::process (m);
119 MAKE_SCHEME_CALLBACK (Push_property_iterator, once_finalization, 2);
121 Push_property_iterator::once_finalization (SCM trans, SCM music)
123 Music *mus = unsmob_music (music);
124 Context *tg = dynamic_cast<Context *> (unsmob_context (trans));
126 SCM sym = mus->get_property ("symbol");
127 if (check_grob (mus, sym))
129 SCM grob_property_path = get_property_path (mus);
131 execute_general_pushpop_property (tg, sym, grob_property_path, SCM_UNDEFINED);
133 return SCM_UNSPECIFIED;
137 Push_property_iterator::do_quit ()
139 if (to_boolean (get_music ()->get_property ("once")))
141 SCM trans = get_outlet ()->self_scm ();
142 SCM music = get_music ()->self_scm ();
144 Global_context *tg = get_outlet ()->get_global_context ();
145 tg->add_finalization (scm_list_n (once_finalization_proc,
146 trans, music, SCM_UNDEFINED));
151 Pop_property_iterator::process (Moment m)
153 SCM sym = get_music ()->get_property ("symbol");
155 if (check_grob (get_music (), sym))
157 SCM grob_property_path = get_property_path (get_music ());
158 execute_general_pushpop_property (get_outlet (), sym, grob_property_path, SCM_UNDEFINED);
160 Simple_music_iterator::process (m);
163 IMPLEMENT_CTOR_CALLBACK (Pop_property_iterator);
164 IMPLEMENT_CTOR_CALLBACK (Push_property_iterator);
165 IMPLEMENT_CTOR_CALLBACK (Property_iterator);
166 IMPLEMENT_CTOR_CALLBACK (Property_unset_iterator);