]> git.donarmstrong.com Git - lilypond.git/blob - lily/property-iterator.cc
* VERSION (MY_PATCH_LEVEL): make 1.7.0
[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--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "property-iterator.hh"
10 #include "music.hh"
11 #include "translator-def.hh"
12 #include "translator-group.hh"
13 #include "global-translator.hh"
14
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_mus_property ("symbol");
26   if (gh_symbol_p (sym))
27     {
28       SCM val = get_music ()->get_mus_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         report_to ()->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_mus_property ("symbol");
42   type_check_assignment (sym, SCM_EOL, ly_symbol2scm ("translation-type?"));  
43   report_to ()->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   Translator_group * tg
54     = dynamic_cast<Translator_group*> (unsmob_translator (translator));
55   SCM sym = m->get_mus_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_mus_property  ("once")))
65     {
66       SCM trans = report_to()->self_scm();
67       SCM music = get_music()->self_scm();
68
69       Global_translator * tg=  report_to()->top_translator ();
70
71       tg->add_finalization (scm_list_n (once_finalization_proc,
72                                         trans, music, SCM_UNDEFINED));
73     }
74 }
75
76
77 SCM list_p = 0;
78
79 bool
80 check_grob(Music *mus, SCM sym)
81 {
82   if (!list_p)
83     {
84       list_p = gh_eval_str ("list?");
85     }
86   
87   
88   SCM type = scm_object_property (sym, ly_symbol2scm ("translation-type?"));
89   bool ok = type == list_p;
90
91   if (!ok)
92     {
93       mus->origin()->warning (_f("Not a grob name, `%s'." , ly_symbol2string (sym)));
94     }
95   return  ok;
96 }
97
98 void
99 Push_property_iterator::process (Moment m)
100 {
101   SCM sym = get_music ()->get_mus_property ("symbol");
102   if (check_grob (get_music (), sym))
103     {
104       SCM eprop = get_music ()->get_mus_property ("grob-property");
105       SCM val = get_music ()->get_mus_property ("grob-value");
106
107       if (to_boolean (get_music ()->get_mus_property ("pop-first"))
108           && !to_boolean (get_music ()->get_mus_property ("once"))
109           )
110         Translator_def::apply_pushpop_property (report_to (),
111                                                 sym, eprop, SCM_UNDEFINED);
112
113       Translator_def::apply_pushpop_property (report_to (), sym, eprop, val);
114     }
115   Simple_music_iterator::process (m);
116 }
117
118 MAKE_SCHEME_CALLBACK(Push_property_iterator,once_finalization, 2);
119 SCM
120 Push_property_iterator::once_finalization (SCM trans, SCM music)
121 {
122   Music * mus = unsmob_music (music);
123   Translator_group *tg
124     = dynamic_cast<Translator_group*> (unsmob_translator (trans));
125
126   SCM sym = mus->get_mus_property ("symbol");
127   if (check_grob (mus, sym))
128     {
129       SCM eprop = mus->get_mus_property ("grob-property");
130   
131       Translator_def::apply_pushpop_property (tg, sym, eprop, SCM_UNDEFINED);
132     }
133   return SCM_UNSPECIFIED;
134 }
135
136 void
137 Push_property_iterator::do_quit ()
138 {
139   if (to_boolean (get_music ()->get_mus_property  ("once")))
140     {
141       SCM trans = report_to()->self_scm();
142       SCM music = get_music ()->self_scm();
143
144       Global_translator * tg=  report_to()->top_translator ();
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_mus_property ("symbol");
154   if (check_grob (get_music (), sym))
155     {
156       SCM eprop = get_music ()->get_mus_property ("grob-property");
157       Translator_def::apply_pushpop_property (report_to (), sym, eprop, SCM_UNDEFINED);
158     }  
159   Simple_music_iterator::process (m);
160 }
161
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