2 property-iterator.cc -- implement Property_iterator
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
9 #include "property-iterator.hh"
11 #include "context-def.hh"
12 #include "global-context.hh"
13 #include "international.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 send_stream_event (get_outlet (), "SetProperty", get_music ()->origin (),
26 ly_symbol2scm ("symbol"), get_music ()->get_property ("symbol"),
27 ly_symbol2scm ("value"), get_music ()->get_property ("value"));
29 Simple_music_iterator::process (m);
33 Property_unset_iterator::process (Moment m)
35 SCM sym = get_music ()->get_property ("symbol");
36 send_stream_event (get_outlet (), "UnsetProperty", get_music ()->origin (),
37 ly_symbol2scm ("symbol"), sym);
39 Simple_music_iterator::process (m);
42 MAKE_SCHEME_CALLBACK (Property_iterator, once_finalization, 2);
44 Property_iterator::once_finalization (SCM ctx, SCM music)
46 Music *m = unsmob_music (music);
47 Context *c = unsmob_context (ctx);
49 send_stream_event (c, "UnsetProperty", m->origin (),
50 ly_symbol2scm ("symbol"), m->get_property ("symbol"));
51 return SCM_UNSPECIFIED;
55 Property_iterator::do_quit ()
57 if (to_boolean (get_music ()->get_property ("once")))
59 SCM trans = get_outlet ()->self_scm ();
60 SCM music = get_music ()->self_scm ();
62 Global_context *tg = get_outlet ()->get_global_context ();
63 tg->add_finalization (scm_list_n (once_finalization_proc,
64 trans, music, SCM_UNDEFINED));
69 check_grob (Music *mus, SCM sym)
71 bool g = to_boolean (scm_object_property (sym, ly_symbol2scm ("is-grob?")));
74 mus->origin ()->warning (_f ("not a grob name, `%s'",
75 ly_symbol2string (sym)));
81 get_property_path (Music *m)
83 SCM grob_property_path = m->get_property ("grob-property-path");
85 SCM eprop = m->get_property ("grob-property");
86 if (scm_is_symbol (eprop))
88 grob_property_path = scm_list_1 (eprop);
91 return grob_property_path;
95 Push_property_iterator::process (Moment m)
97 SCM sym = get_music ()->get_property ("symbol");
98 if (check_grob (get_music (), sym))
100 SCM grob_property_path = get_property_path (get_music ());
101 SCM val = get_music ()->get_property ("grob-value");
103 if (to_boolean (get_music ()->get_property ("pop-first"))
104 && !to_boolean (get_music ()->get_property ("once")))
105 send_stream_event (get_outlet (), "Revert", get_music ()->origin (),
106 ly_symbol2scm ("symbol"), sym,
107 ly_symbol2scm ("property-path"), grob_property_path);
109 send_stream_event (get_outlet (), "Override", get_music ()->origin (),
110 ly_symbol2scm ("symbol"), sym,
111 ly_symbol2scm ("property-path"), grob_property_path,
112 ly_symbol2scm ("value"), val);
114 Simple_music_iterator::process (m);
117 MAKE_SCHEME_CALLBACK (Push_property_iterator, once_finalization, 2);
119 Push_property_iterator::once_finalization (SCM ctx, SCM music)
121 Music *mus = unsmob_music (music);
122 Context *c = unsmob_context (ctx);
124 SCM sym = mus->get_property ("symbol");
125 if (check_grob (mus, sym))
127 SCM grob_property_path = get_property_path (mus);
129 send_stream_event (c, "Revert", mus->origin (),
130 ly_symbol2scm ("symbol"), sym,
131 ly_symbol2scm ("property-path"), grob_property_path);
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 ());
159 send_stream_event (get_outlet (), "Revert", get_music ()->origin (),
160 ly_symbol2scm ("symbol"), sym,
161 ly_symbol2scm ("property-path"), grob_property_path);
163 Simple_music_iterator::process (m);
166 IMPLEMENT_CTOR_CALLBACK (Pop_property_iterator);
167 IMPLEMENT_CTOR_CALLBACK (Push_property_iterator);
168 IMPLEMENT_CTOR_CALLBACK (Property_iterator);
169 IMPLEMENT_CTOR_CALLBACK (Property_unset_iterator);