2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1997--2010 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 m)
36 send_stream_event (get_outlet (), "SetProperty", get_music ()->origin (),
37 ly_symbol2scm ("symbol"), get_music ()->get_property ("symbol"),
38 ly_symbol2scm ("value"), get_music ()->get_property ("value"));
40 Simple_music_iterator::process (m);
44 Property_unset_iterator::process (Moment m)
46 SCM sym = get_music ()->get_property ("symbol");
47 send_stream_event (get_outlet (), "UnsetProperty", get_music ()->origin (),
48 ly_symbol2scm ("symbol"), sym);
50 Simple_music_iterator::process (m);
53 MAKE_SCHEME_CALLBACK (Property_iterator, once_finalization, 2);
55 Property_iterator::once_finalization (SCM ctx, SCM music)
57 Music *m = unsmob_music (music);
58 Context *c = unsmob_context (ctx);
60 send_stream_event (c, "UnsetProperty", m->origin (),
61 ly_symbol2scm ("symbol"), m->get_property ("symbol"));
62 return SCM_UNSPECIFIED;
66 Property_iterator::do_quit ()
68 if (to_boolean (get_music ()->get_property ("once")))
70 SCM trans = get_outlet ()->self_scm ();
71 SCM music = get_music ()->self_scm ();
73 Global_context *tg = get_outlet ()->get_global_context ();
74 tg->add_finalization (scm_list_n (once_finalization_proc,
75 trans, music, SCM_UNDEFINED));
80 check_grob (Music *mus, SCM sym)
82 bool g = to_boolean (scm_object_property (sym, ly_symbol2scm ("is-grob?")));
85 mus->origin ()->warning (_f ("not a grob name, `%s'",
86 ly_symbol2string (sym)));
92 get_property_path (Music *m)
94 SCM grob_property_path = m->get_property ("grob-property-path");
96 SCM eprop = m->get_property ("grob-property");
97 if (scm_is_symbol (eprop))
99 grob_property_path = scm_list_1 (eprop);
102 return grob_property_path;
106 Push_property_iterator::process (Moment m)
108 SCM sym = get_music ()->get_property ("symbol");
109 if (check_grob (get_music (), sym))
111 SCM grob_property_path = get_property_path (get_music ());
112 SCM val = get_music ()->get_property ("grob-value");
114 if (to_boolean (get_music ()->get_property ("pop-first"))
115 && !to_boolean (get_music ()->get_property ("once")))
116 send_stream_event (get_outlet (), "Revert", get_music ()->origin (),
117 ly_symbol2scm ("symbol"), sym,
118 ly_symbol2scm ("property-path"), grob_property_path);
120 send_stream_event (get_outlet (), "Override", get_music ()->origin (),
121 ly_symbol2scm ("symbol"), sym,
122 ly_symbol2scm ("property-path"), grob_property_path,
123 ly_symbol2scm ("value"), val);
125 Simple_music_iterator::process (m);
128 MAKE_SCHEME_CALLBACK (Push_property_iterator, once_finalization, 2);
130 Push_property_iterator::once_finalization (SCM ctx, SCM music)
132 Music *mus = unsmob_music (music);
133 Context *c = unsmob_context (ctx);
135 SCM sym = mus->get_property ("symbol");
136 if (check_grob (mus, sym))
138 SCM grob_property_path = get_property_path (mus);
140 send_stream_event (c, "Revert", mus->origin (),
141 ly_symbol2scm ("symbol"), sym,
142 ly_symbol2scm ("property-path"), grob_property_path);
144 return SCM_UNSPECIFIED;
148 Push_property_iterator::do_quit ()
150 if (to_boolean (get_music ()->get_property ("once")))
152 SCM trans = get_outlet ()->self_scm ();
153 SCM music = get_music ()->self_scm ();
155 Global_context *tg = get_outlet ()->get_global_context ();
156 tg->add_finalization (scm_list_n (once_finalization_proc,
157 trans, music, SCM_UNDEFINED));
162 Pop_property_iterator::process (Moment m)
164 SCM sym = get_music ()->get_property ("symbol");
166 if (check_grob (get_music (), sym))
168 SCM grob_property_path = get_property_path (get_music ());
170 send_stream_event (get_outlet (), "Revert", get_music ()->origin (),
171 ly_symbol2scm ("symbol"), sym,
172 ly_symbol2scm ("property-path"), grob_property_path);
174 Simple_music_iterator::process (m);
177 IMPLEMENT_CTOR_CALLBACK (Pop_property_iterator);
178 IMPLEMENT_CTOR_CALLBACK (Push_property_iterator);
179 IMPLEMENT_CTOR_CALLBACK (Property_iterator);
180 IMPLEMENT_CTOR_CALLBACK (Property_unset_iterator);