]> git.donarmstrong.com Git - lilypond.git/blob - lily/property-iterator.cc
* lily/include/lily-guile.hh: many new ly_ functions. Thanks to
[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_property ("symbol");
24   if (ly_symbol_p (sym))
25     {
26       SCM val = get_music ()->get_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_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_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_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 = scm_c_eval_string ("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_property ("symbol");
103   if (check_grob (get_music (), sym))
104     {
105       SCM eprop = get_music ()->get_property ("grob-property");
106       SCM val = get_music ()->get_property ("grob-value");
107
108       if (to_boolean (get_music ()->get_property ("pop-first"))
109           && !to_boolean (get_music ()->get_property ("once")))
110         execute_pushpop_property (get_outlet (), sym, eprop, SCM_UNDEFINED);
111
112       execute_pushpop_property (get_outlet (), sym, eprop, 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 trans, SCM music)
120 {
121   Music * mus = unsmob_music (music);
122   Context * tg = dynamic_cast<Context *> (unsmob_context (trans));
123     
124   SCM sym = mus->get_property ("symbol");
125   if (check_grob (mus, sym))
126     {
127       SCM eprop = mus->get_property ("grob-property");
128   
129       execute_pushpop_property (tg, sym, eprop, SCM_UNDEFINED);
130     }
131   return SCM_UNSPECIFIED;
132 }
133
134 void
135 Push_property_iterator::do_quit ()
136 {
137   if (to_boolean (get_music ()->get_property  ("once")))
138     {
139       SCM trans = get_outlet ()->self_scm ();
140       SCM music = get_music ()->self_scm ();
141
142       Global_context * tg=  get_outlet ()->get_global_context ();
143       tg->add_finalization (scm_list_n (once_finalization_proc,
144                                         trans, music, SCM_UNDEFINED));
145     }
146 }
147
148 void
149 Pop_property_iterator::process (Moment m)
150 {
151   SCM sym = get_music ()->get_property ("symbol");
152   
153   if (check_grob (get_music (), sym))
154     {
155       SCM eprop = get_music ()->get_property ("grob-property");
156 execute_pushpop_property (get_outlet (), sym, eprop, SCM_UNDEFINED);
157     }
158   Simple_music_iterator::process (m);
159 }
160
161
162
163 IMPLEMENT_CTOR_CALLBACK (Pop_property_iterator);
164 IMPLEMENT_CTOR_CALLBACK (Push_property_iterator);
165 IMPLEMENT_CTOR_CALLBACK (Property_iterator);
166 IMPLEMENT_CTOR_CALLBACK (Property_unset_iterator);
167