2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1997--2012 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
20 #include "property-iterator.hh"
22 #include "context-def.hh"
23 #include "global-context.hh"
24 #include "international.hh"
27 bool check_grob (Music *mus, SCM sym);
30 There is no real processing to a property: just lookup the
31 translation unit, and set the property.
34 Property_iterator::process (Moment mom)
36 Context *o = get_outlet ();
37 Music *m = get_music ();
38 SCM previous_value = o->get_property (m->get_property ("symbol"));
39 send_stream_event (o, "SetProperty", m->origin (),
40 ly_symbol2scm ("symbol"), m->get_property ("symbol"),
41 ly_symbol2scm ("value"), m->get_property ("value"));
43 /* For \once \set install a finalization hook to reset the property to the
44 * previous value after the timestep */
45 if (to_boolean (m->get_property ("once")))
47 Global_context *tg = get_outlet ()->get_global_context ();
48 tg->add_finalization (scm_list_n (once_finalization_proc,
49 o->self_scm (), m->self_scm (),
50 ly_quote_scm (previous_value), SCM_UNDEFINED));
53 Simple_music_iterator::process (mom);
57 Property_unset_iterator::process (Moment m)
59 SCM sym = get_music ()->get_property ("symbol");
60 send_stream_event (get_outlet (), "UnsetProperty", get_music ()->origin (),
61 ly_symbol2scm ("symbol"), sym);
63 Simple_music_iterator::process (m);
66 MAKE_SCHEME_CALLBACK (Property_iterator, once_finalization, 3);
68 Property_iterator::once_finalization (SCM ctx, SCM music, SCM previous_value)
70 Music *m = unsmob_music (music);
71 Context *c = unsmob_context (ctx);
73 // Do not use UnsetProperty, which sets the default, but rather
74 // cache the value before the \once \set command and restore it now
75 send_stream_event (c, "SetProperty", m->origin (),
76 ly_symbol2scm ("symbol"), m->get_property ("symbol"),
77 ly_symbol2scm ("value"), previous_value);
79 return SCM_UNSPECIFIED;
83 Property_iterator::do_quit ()
88 check_grob (Music *mus, SCM sym)
90 bool g = to_boolean (scm_object_property (sym, ly_symbol2scm ("is-grob?")));
93 mus->origin ()->warning (_f ("not a grob name, `%s'",
94 ly_symbol2string (sym)));
100 get_property_path (Music *m)
102 SCM grob_property_path = m->get_property ("grob-property-path");
104 SCM eprop = m->get_property ("grob-property");
105 if (scm_is_symbol (eprop))
107 grob_property_path = scm_list_1 (eprop);
110 return grob_property_path;
114 Push_property_iterator::process (Moment m)
116 SCM sym = get_music ()->get_property ("symbol");
117 if (check_grob (get_music (), sym))
119 SCM grob_property_path = get_property_path (get_music ());
120 SCM val = get_music ()->get_property ("grob-value");
122 if (to_boolean (get_music ()->get_property ("pop-first"))
123 && !to_boolean (get_music ()->get_property ("once")))
124 send_stream_event (get_outlet (), "Revert", get_music ()->origin (),
125 ly_symbol2scm ("symbol"), sym,
126 ly_symbol2scm ("property-path"), grob_property_path);
128 send_stream_event (get_outlet (), "Override", get_music ()->origin (),
129 ly_symbol2scm ("symbol"), sym,
130 ly_symbol2scm ("property-path"), grob_property_path,
131 ly_symbol2scm ("value"), val);
133 Simple_music_iterator::process (m);
136 MAKE_SCHEME_CALLBACK (Push_property_iterator, once_finalization, 2);
138 Push_property_iterator::once_finalization (SCM ctx, SCM music)
140 Music *mus = unsmob_music (music);
141 Context *c = unsmob_context (ctx);
143 SCM sym = mus->get_property ("symbol");
144 if (check_grob (mus, sym))
146 SCM grob_property_path = get_property_path (mus);
148 send_stream_event (c, "Revert", mus->origin (),
149 ly_symbol2scm ("symbol"), sym,
150 ly_symbol2scm ("property-path"), grob_property_path);
152 return SCM_UNSPECIFIED;
156 Push_property_iterator::do_quit ()
158 if (to_boolean (get_music ()->get_property ("once")))
160 SCM trans = get_outlet ()->self_scm ();
161 SCM music = get_music ()->self_scm ();
163 Global_context *tg = get_outlet ()->get_global_context ();
164 tg->add_finalization (scm_list_n (once_finalization_proc,
165 trans, music, SCM_UNDEFINED));
170 Pop_property_iterator::process (Moment m)
172 SCM sym = get_music ()->get_property ("symbol");
174 if (check_grob (get_music (), sym))
176 SCM grob_property_path = get_property_path (get_music ());
178 send_stream_event (get_outlet (), "Revert", get_music ()->origin (),
179 ly_symbol2scm ("symbol"), sym,
180 ly_symbol2scm ("property-path"), grob_property_path);
182 Simple_music_iterator::process (m);
185 IMPLEMENT_CTOR_CALLBACK (Pop_property_iterator);
186 IMPLEMENT_CTOR_CALLBACK (Push_property_iterator);
187 IMPLEMENT_CTOR_CALLBACK (Property_iterator);
188 IMPLEMENT_CTOR_CALLBACK (Property_unset_iterator);