Use scalar instead of embedded_scm for context mod overrides.
[lilypond/mpolesky.git] / lily / property-iterator.cc
blobd4fa5749c6af03fd3ae03f3762eb9d0d1e1b6b3c
1 /*
2 property-iterator.cc -- implement Property_iterator
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2009 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
9 #include "property-iterator.hh"
11 #include "context-def.hh"
12 #include "global-context.hh"
13 #include "international.hh"
14 #include "music.hh"
16 bool check_grob (Music *mus, SCM sym);
18 /**
19 There is no real processing to a property: just lookup the
20 translation unit, and set the property.
22 void
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);
32 void
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);
43 SCM
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;
54 void
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));
68 bool
69 check_grob (Music *mus, SCM sym)
71 bool g = to_boolean (scm_object_property (sym, ly_symbol2scm ("is-grob?")));
73 if (!g)
74 mus->origin ()->warning (_f ("not a grob name, `%s'",
75 ly_symbol2string (sym)));
77 return g;
80 SCM
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;
94 void
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;
136 void
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));
150 void
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);