]> git.donarmstrong.com Git - lilypond.git/blob - lily/property-iterator.cc
f067a6628212b29ec6d2d9350676fb7483adbd03
[lilypond.git] / lily / property-iterator.cc
1 /*
2   property-iterator.cc -- implement Property_iterator
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #include "property-iterator.hh"
10
11 #include "context-def.hh"
12 #include "global-context.hh"
13 #include "international.hh"
14 #include "music.hh"
15
16 bool check_grob (Music *mus, SCM sym);
17
18 /**
19    There is no real processing to a property: just lookup the
20    translation unit, and set the property.
21 */
22 void
23 Property_iterator::process (Moment m)
24 {
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"));
28   
29   Simple_music_iterator::process (m);
30 }
31
32 void
33 Property_unset_iterator::process (Moment m)
34 {
35   SCM sym = get_music ()->get_property ("symbol");
36   send_stream_event (get_outlet (), "UnsetProperty", get_music ()->origin (),
37                      ly_symbol2scm ("symbol"), sym);
38
39   Simple_music_iterator::process (m);
40 }
41
42 MAKE_SCHEME_CALLBACK (Property_iterator, once_finalization, 2);
43 SCM
44 Property_iterator::once_finalization (SCM ctx, SCM music)
45 {
46   Music *m = unsmob_music (music);
47   Context *c = unsmob_context (ctx);
48
49   send_stream_event (c, "UnsetProperty", m->origin (),
50                      ly_symbol2scm ("symbol"), m->get_property ("symbol"));
51   return SCM_UNSPECIFIED;
52 }
53
54 void
55 Property_iterator::do_quit ()
56 {
57   if (to_boolean (get_music ()->get_property ("once")))
58     {
59       SCM trans = get_outlet ()->self_scm ();
60       SCM music = get_music ()->self_scm ();
61
62       Global_context *tg = get_outlet ()->get_global_context ();
63       tg->add_finalization (scm_list_n (once_finalization_proc,
64                                         trans, music, SCM_UNDEFINED));
65     }
66 }
67
68 bool
69 check_grob (Music *mus, SCM sym)
70 {
71   bool g = to_boolean (scm_object_property (sym, ly_symbol2scm ("is-grob?")));
72
73   if (!g)
74     mus->origin ()->warning (_f ("not a grob name, `%s'",
75                                  ly_symbol2string (sym)));
76
77   return g;
78 }
79
80 SCM
81 get_property_path (Music *m)
82 {
83   SCM grob_property_path = m->get_property ("grob-property-path");
84
85   SCM eprop = m->get_property ("grob-property");
86   if (scm_is_symbol (eprop))
87     {
88       grob_property_path = scm_list_1 (eprop);
89     }
90
91   return grob_property_path;
92 }
93
94 void
95 Push_property_iterator::process (Moment m)
96 {
97   SCM sym = get_music ()->get_property ("symbol");
98   if (check_grob (get_music (), sym))
99     {
100       SCM grob_property_path = get_property_path (get_music ());
101       SCM val = get_music ()->get_property ("grob-value");
102
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);
108                         
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);
113     }
114   Simple_music_iterator::process (m);
115 }
116
117 MAKE_SCHEME_CALLBACK (Push_property_iterator, once_finalization, 2);
118 SCM
119 Push_property_iterator::once_finalization (SCM ctx, SCM music)
120 {
121   Music *mus = unsmob_music (music);
122   Context *c = unsmob_context (ctx);
123
124   SCM sym = mus->get_property ("symbol");
125   if (check_grob (mus, sym))
126     {
127       SCM grob_property_path = get_property_path (mus);
128
129       send_stream_event (c, "Revert", mus->origin (),
130                          ly_symbol2scm ("symbol"), sym,
131                          ly_symbol2scm ("property-path"), grob_property_path);
132     }
133   return SCM_UNSPECIFIED;
134 }
135
136 void
137 Push_property_iterator::do_quit ()
138 {
139   if (to_boolean (get_music ()->get_property ("once")))
140     {
141       SCM trans = get_outlet ()->self_scm ();
142       SCM music = get_music ()->self_scm ();
143
144       Global_context *tg = get_outlet ()->get_global_context ();
145       tg->add_finalization (scm_list_n (once_finalization_proc,
146                                         trans, music, SCM_UNDEFINED));
147     }
148 }
149
150 void
151 Pop_property_iterator::process (Moment m)
152 {
153   SCM sym = get_music ()->get_property ("symbol");
154
155   if (check_grob (get_music (), sym))
156     {
157       SCM grob_property_path = get_property_path (get_music ());
158
159       send_stream_event (get_outlet (), "Revert", get_music ()->origin (),
160                          ly_symbol2scm ("symbol"), sym,
161                          ly_symbol2scm ("property-path"), grob_property_path);
162     }
163   Simple_music_iterator::process (m);
164 }
165
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);