]> git.donarmstrong.com Git - lilypond.git/blob - lily/property-iterator.cc
56ec9998874ec397427f0236719b7eb6516dda0b
[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--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "property-iterator.hh"
10
11 #include "music.hh"
12 #include "context-def.hh"
13 #include "global-context.hh"
14
15 bool check_grob (Music *mus, SCM sym);
16
17 /**
18    There is no real processing to a property: just lookup the
19    translation unit, and set the property.
20 */
21 void
22 Property_iterator::process (Moment m)
23 {
24   SCM sym = get_music ()->get_property ("symbol");
25   if (scm_is_symbol (sym))
26     {
27       SCM val = get_music ()->get_property ("value");
28       bool ok = true;
29       if (val != SCM_EOL)
30         ok = type_check_assignment (sym, val, ly_symbol2scm ("translation-type?"));
31       if (ok)
32         get_outlet ()->internal_set_property (sym, val);
33     }
34   Simple_music_iterator::process (m);
35 }
36
37 void
38 Property_unset_iterator::process (Moment m)
39 {
40   SCM sym = get_music ()->get_property ("symbol");
41   type_check_assignment (sym, SCM_EOL, ly_symbol2scm ("translation-type?"));  
42   get_outlet ()->unset_property (sym);
43
44   Simple_music_iterator::process (m);
45 }
46
47 MAKE_SCHEME_CALLBACK (Property_iterator, once_finalization, 2);
48 SCM
49 Property_iterator::once_finalization (SCM translator, SCM music )
50 {
51   Music * m = unsmob_music (music);
52   Context * tg
53     = dynamic_cast<Context *> (unsmob_context (translator));
54   SCM sym = m->get_property ("symbol");
55
56   tg->unset_property (sym);
57   return SCM_UNSPECIFIED;
58 }
59
60 void
61 Property_iterator::do_quit ()
62 {
63   if (to_boolean (get_music ()->get_property  ("once")))
64     {
65       SCM trans = get_outlet ()->self_scm ();
66       SCM music = get_music ()->self_scm ();
67
68       Global_context * tg = get_outlet ()->get_global_context ();
69       tg->add_finalization (scm_list_n (once_finalization_proc,
70                                         trans, music, SCM_UNDEFINED));
71     }
72 }
73
74
75 SCM list_p = 0;
76
77 /*
78   This is a rather crude check: we merely check if the translator
79   property is a list.
80  */
81 bool
82 check_grob (Music *mus, SCM sym)
83 {
84   if (!list_p)
85     {
86       list_p = scm_c_eval_string ("list?");
87     }
88   
89   
90   SCM type = scm_object_property (sym, ly_symbol2scm ("translation-type?"));
91   bool ok = type == list_p;
92
93   if (!ok)
94     {
95       mus->origin ()->warning (_f ("Not a grob name, `%s'." , ly_symbol2string (sym)));
96     }
97   return  ok;
98 }
99
100 void
101 Push_property_iterator::process (Moment m)
102 {
103   SCM sym = get_music ()->get_property ("symbol");
104   if (check_grob (get_music (), sym))
105     {
106       SCM eprop = get_music ()->get_property ("grob-property");
107       SCM val = get_music ()->get_property ("grob-value");
108
109       if (to_boolean (get_music ()->get_property ("pop-first"))
110           && !to_boolean (get_music ()->get_property ("once")))
111         execute_pushpop_property (get_outlet (), sym, eprop, SCM_UNDEFINED);
112
113       execute_pushpop_property (get_outlet (), 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   Context * tg = dynamic_cast<Context *> (unsmob_context (trans));
124     
125   SCM sym = mus->get_property ("symbol");
126   if (check_grob (mus, sym))
127     {
128       SCM eprop = mus->get_property ("grob-property");
129   
130       execute_pushpop_property (tg, sym, eprop, SCM_UNDEFINED);
131     }
132   return SCM_UNSPECIFIED;
133 }
134
135 void
136 Push_property_iterator::do_quit ()
137 {
138   if (to_boolean (get_music ()->get_property  ("once")))
139     {
140       SCM trans = get_outlet ()->self_scm ();
141       SCM music = get_music ()->self_scm ();
142
143       Global_context * tg =  get_outlet ()->get_global_context ();
144       tg->add_finalization (scm_list_n (once_finalization_proc,
145                                         trans, music, SCM_UNDEFINED));
146     }
147 }
148
149 void
150 Pop_property_iterator::process (Moment m)
151 {
152   SCM sym = get_music ()->get_property ("symbol");
153   
154   if (check_grob (get_music (), sym))
155     {
156       SCM eprop = get_music ()->get_property ("grob-property");
157 execute_pushpop_property (get_outlet (), 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