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