]> git.donarmstrong.com Git - lilypond.git/blob - lily/property-iterator.cc
Fix some bugs in the dynamic engraver and PostScript backend
[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--2006 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   SCM sym = get_music ()->get_property ("symbol");
26   if (scm_is_symbol (sym))
27     {
28       SCM val = get_music ()->get_property ("value");
29       bool ok = true;
30       if (val != SCM_EOL)
31         ok = type_check_assignment (sym, val, ly_symbol2scm ("translation-type?"));
32       if (ok)
33         get_outlet ()->internal_set_property (sym, val);
34     }
35   Simple_music_iterator::process (m);
36 }
37
38 void
39 Property_unset_iterator::process (Moment m)
40 {
41   SCM sym = get_music ()->get_property ("symbol");
42   type_check_assignment (sym, SCM_EOL, ly_symbol2scm ("translation-type?"));
43   get_outlet ()->unset_property (sym);
44
45   Simple_music_iterator::process (m);
46 }
47
48 MAKE_SCHEME_CALLBACK (Property_iterator, once_finalization, 2);
49 SCM
50 Property_iterator::once_finalization (SCM translator, SCM music)
51 {
52   Music *m = unsmob_music (music);
53   Context *tg
54     = dynamic_cast<Context *> (unsmob_context (translator));
55   SCM sym = m->get_property ("symbol");
56
57   tg->unset_property (sym);
58   return SCM_UNSPECIFIED;
59 }
60
61 void
62 Property_iterator::do_quit ()
63 {
64   if (to_boolean (get_music ()->get_property ("once")))
65     {
66       SCM trans = get_outlet ()->self_scm ();
67       SCM music = get_music ()->self_scm ();
68
69       Global_context *tg = get_outlet ()->get_global_context ();
70       tg->add_finalization (scm_list_n (once_finalization_proc,
71                                         trans, music, SCM_UNDEFINED));
72     }
73 }
74
75 bool
76 check_grob (Music *mus, SCM sym)
77 {
78   bool g = to_boolean (scm_object_property (sym, ly_symbol2scm ("is-grob?")));
79
80   if (!g)
81     mus->origin ()->warning (_f ("not a grob name, `%s'",
82                                  ly_symbol2string (sym)));
83
84   return g;
85 }
86
87 SCM
88 get_property_path (Music *m)
89 {
90   SCM grob_property_path = m->get_property ("grob-property-path");
91
92   SCM eprop = m->get_property ("grob-property");
93   if (scm_is_symbol (eprop))
94     {
95       grob_property_path = scm_list_1 (eprop);
96     }
97
98   return grob_property_path;
99 }
100
101 void
102 Push_property_iterator::process (Moment m)
103 {
104   SCM sym = get_music ()->get_property ("symbol");
105   if (check_grob (get_music (), sym))
106     {
107       SCM grob_property_path = get_property_path (get_music ());
108       SCM val = get_music ()->get_property ("grob-value");
109
110       if (to_boolean (get_music ()->get_property ("pop-first"))
111           && !to_boolean (get_music ()->get_property ("once")))
112         
113         execute_general_pushpop_property (get_outlet (), sym, grob_property_path, SCM_UNDEFINED);
114
115       execute_general_pushpop_property (get_outlet (), sym, grob_property_path, val);
116     }
117   Simple_music_iterator::process (m);
118 }
119
120 MAKE_SCHEME_CALLBACK (Push_property_iterator, once_finalization, 2);
121 SCM
122 Push_property_iterator::once_finalization (SCM trans, SCM music)
123 {
124   Music *mus = unsmob_music (music);
125   Context *tg = dynamic_cast<Context *> (unsmob_context (trans));
126
127   SCM sym = mus->get_property ("symbol");
128   if (check_grob (mus, sym))
129     {
130       SCM grob_property_path = get_property_path (mus);
131
132       execute_general_pushpop_property (tg, sym, grob_property_path, SCM_UNDEFINED);
133     }
134   return SCM_UNSPECIFIED;
135 }
136
137 void
138 Push_property_iterator::do_quit ()
139 {
140   if (to_boolean (get_music ()->get_property ("once")))
141     {
142       SCM trans = get_outlet ()->self_scm ();
143       SCM music = get_music ()->self_scm ();
144
145       Global_context *tg = get_outlet ()->get_global_context ();
146       tg->add_finalization (scm_list_n (once_finalization_proc,
147                                         trans, music, SCM_UNDEFINED));
148     }
149 }
150
151 void
152 Pop_property_iterator::process (Moment m)
153 {
154   SCM sym = get_music ()->get_property ("symbol");
155
156   if (check_grob (get_music (), sym))
157     {
158       SCM grob_property_path = get_property_path (get_music ());
159       execute_general_pushpop_property (get_outlet (), sym, grob_property_path, SCM_UNDEFINED);
160     }
161   Simple_music_iterator::process (m);
162 }
163
164 IMPLEMENT_CTOR_CALLBACK (Pop_property_iterator);
165 IMPLEMENT_CTOR_CALLBACK (Push_property_iterator);
166 IMPLEMENT_CTOR_CALLBACK (Property_iterator);
167 IMPLEMENT_CTOR_CALLBACK (Property_unset_iterator);
168