]> git.donarmstrong.com Git - lilypond.git/blob - lily/property-iterator.cc
``slikken kreng''
[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
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_mus_property ("symbol");
25   if (gh_symbol_p (sym))
26     {
27       SCM val = get_music ()->get_mus_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         report_to ()->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_mus_property ("symbol");
41   type_check_assignment (sym, SCM_EOL, ly_symbol2scm ("translation-type?"));  
42   report_to ()->unset_property (sym);
43
44   Simple_music_iterator::process (m);
45 }
46
47
48 SCM list_p = 0;
49
50 bool
51 check_grob(Music *mus, SCM sym)
52 {
53   if (!list_p)
54     {
55       list_p = gh_eval_str ("list?");
56     }
57   
58   
59   SCM type = scm_object_property (sym, ly_symbol2scm ("translation-type?"));
60   bool ok = type == list_p;
61
62   if (!ok)
63     {
64       mus->origin()->warning (_f("Not a grob name, `%s'." , ly_symbol2string (sym)));
65     }
66   return  ok;
67 }
68
69 void
70 Push_property_iterator::process (Moment m)
71 {
72   SCM sym = get_music ()->get_mus_property ("symbol");
73   if (check_grob (get_music (), sym))
74     {
75       SCM eprop = get_music ()->get_mus_property ("grob-property");
76       SCM val = get_music ()->get_mus_property ("grob-value");
77
78       if (to_boolean (get_music ()->get_mus_property ("pop-first")))
79         Translator_def::apply_pushpop_property (report_to (),
80                                                 sym, eprop, SCM_UNDEFINED);
81
82       Translator_def::apply_pushpop_property (report_to (), sym, eprop, val);
83     }
84   Simple_music_iterator::process (m);
85 }
86
87 void
88 Pop_property_iterator::process (Moment m)
89 {
90   SCM sym = get_music ()->get_mus_property ("symbol");
91   if (check_grob (get_music (), sym))
92     {
93       SCM eprop = get_music ()->get_mus_property ("grob-property");
94       Translator_def::apply_pushpop_property (report_to (), sym, eprop, SCM_UNDEFINED);
95     }  
96   Simple_music_iterator::process (m);
97 }
98
99
100 IMPLEMENT_CTOR_CALLBACK (Pop_property_iterator);
101 IMPLEMENT_CTOR_CALLBACK (Push_property_iterator);
102 IMPLEMENT_CTOR_CALLBACK (Property_iterator);
103 IMPLEMENT_CTOR_CALLBACK (Property_unset_iterator);