2 property-iterator.cc -- implement Property_iterator
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 #include "property-iterator.hh"
11 #include "context-def.hh"
12 #include "global-context.hh"
14 bool check_grob (Music
*mus
, SCM sym
);
17 There is no real processing to a property: just lookup the
18 translation unit, and set the property.
21 Property_iterator::process (Moment m
)
23 SCM sym
= get_music ()->get_property ("symbol");
24 if (gh_symbol_p (sym
))
26 SCM val
= get_music ()->get_property ("value");
29 ok
= type_check_assignment (sym
, val
, ly_symbol2scm ("translation-type?"));
31 get_outlet ()->internal_set_property (sym
, val
);
33 Simple_music_iterator::process (m
);
37 Property_unset_iterator::process (Moment m
)
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
);
43 Simple_music_iterator::process (m
);
46 MAKE_SCHEME_CALLBACK (Property_iterator
,once_finalization
, 2);
48 Property_iterator::once_finalization (SCM translator
, SCM music
)
50 Music
* m
= unsmob_music (music
);
52 = dynamic_cast<Context
*> (unsmob_context (translator
));
53 SCM sym
= m
->get_property ("symbol");
55 tg
->unset_property (sym
);
56 return SCM_UNSPECIFIED
;
60 Property_iterator::do_quit ()
62 if (to_boolean (get_music ()->get_property ("once")))
64 SCM trans
= get_outlet ()->self_scm ();
65 SCM music
= get_music ()->self_scm ();
67 Global_context
* tg
= get_outlet ()->get_global_context ();
68 tg
->add_finalization (scm_list_n (once_finalization_proc
,
69 trans
, music
, SCM_UNDEFINED
));
77 This is a rather crude check: we merely check if the translator
81 check_grob (Music
*mus
, SCM sym
)
85 list_p
= gh_eval_str ("list?");
89 SCM type
= scm_object_property (sym
, ly_symbol2scm ("translation-type?"));
90 bool ok
= type
== list_p
;
94 mus
->origin ()->warning (_f ("Not a grob name, `%s'." , ly_symbol2string (sym
)));
100 Push_property_iterator::process (Moment m
)
102 SCM sym
= get_music ()->get_property ("symbol");
103 if (check_grob (get_music (), sym
))
105 SCM eprop
= get_music ()->get_property ("grob-property");
106 SCM val
= get_music ()->get_property ("grob-value");
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
);
112 execute_pushpop_property (get_outlet (), sym
, eprop
, val
);
114 Simple_music_iterator::process (m
);
117 MAKE_SCHEME_CALLBACK (Push_property_iterator
,once_finalization
, 2);
119 Push_property_iterator::once_finalization (SCM trans
, SCM music
)
121 Music
* mus
= unsmob_music (music
);
122 Context
* tg
= dynamic_cast<Context
*> (unsmob_context (trans
));
124 SCM sym
= mus
->get_property ("symbol");
125 if (check_grob (mus
, sym
))
127 SCM eprop
= mus
->get_property ("grob-property");
129 execute_pushpop_property (tg
, sym
, eprop
, SCM_UNDEFINED
);
131 return SCM_UNSPECIFIED
;
135 Push_property_iterator::do_quit ()
137 if (to_boolean (get_music ()->get_property ("once")))
139 SCM trans
= get_outlet ()->self_scm ();
140 SCM music
= get_music ()->self_scm ();
142 Global_context
* tg
= get_outlet ()->get_global_context ();
143 tg
->add_finalization (scm_list_n (once_finalization_proc
,
144 trans
, music
, SCM_UNDEFINED
));
149 Pop_property_iterator::process (Moment m
)
151 SCM sym
= get_music ()->get_property ("symbol");
153 if (check_grob (get_music (), sym
))
155 SCM eprop
= get_music ()->get_property ("grob-property");
156 execute_pushpop_property (get_outlet (), sym
, eprop
, SCM_UNDEFINED
);
158 Simple_music_iterator::process (m
);
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
);