]> git.donarmstrong.com Git - lilypond.git/blob - lily/property-iterator.cc
Web-ja: update introduction
[lilypond.git] / lily / property-iterator.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1997--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
5
6   LilyPond is free software: you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10
11   LilyPond is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "property-iterator.hh"
21
22 #include "context-def.hh"
23 #include "global-context.hh"
24 #include "international.hh"
25 #include "music.hh"
26
27 bool check_grob (Music *mus, SCM sym);
28
29 /**
30    There is no real processing to a property: just lookup the
31    translation unit, and set the property.
32 */
33 void
34 Property_iterator::process (Moment mom)
35 {
36   Context *o = get_outlet ();
37   Music *m = get_music ();
38
39   send_stream_event (o, "SetProperty", m->origin (),
40                      ly_symbol2scm ("symbol"), m->get_property ("symbol"),
41                      ly_symbol2scm ("value"), m->get_property ("value"),
42                      ly_symbol2scm ("once"), m->get_property ("once"));
43
44   Simple_music_iterator::process (mom);
45 }
46
47 void
48 Property_unset_iterator::process (Moment mom)
49 {
50   Context *o = get_outlet ();
51   Music *m = get_music ();
52
53   send_stream_event (o, "UnsetProperty", m->origin (),
54                      ly_symbol2scm ("symbol"), m->get_property ("symbol"),
55                      ly_symbol2scm ("once"), m->get_property ("once"));
56
57   Simple_music_iterator::process (mom);
58 }
59
60 bool
61 check_grob (Music *mus, SCM sym)
62 {
63   bool g = to_boolean (scm_object_property (sym, ly_symbol2scm ("is-grob?")));
64
65   if (!g)
66     mus->origin ()->warning (_f ("not a grob name, `%s'",
67                                  ly_symbol2string (sym)));
68
69   return g;
70 }
71
72 SCM
73 get_property_path (Music *m)
74 {
75   SCM grob_property_path = m->get_property ("grob-property-path");
76
77   SCM eprop = m->get_property ("grob-property");
78   if (scm_is_symbol (eprop))
79     {
80       grob_property_path = scm_list_1 (eprop);
81     }
82
83   return grob_property_path;
84 }
85
86 void
87 Push_property_iterator::process (Moment m)
88 {
89   SCM sym = get_music ()->get_property ("symbol");
90   if (check_grob (get_music (), sym))
91     {
92       SCM grob_property_path = get_property_path (get_music ());
93       SCM val = get_music ()->get_property ("grob-value");
94       SCM once = get_music ()->get_property ("once");
95
96       if (to_boolean (get_music ()->get_property ("pop-first"))
97           && !to_boolean (once))
98         send_stream_event (get_outlet (), "Revert", get_music ()->origin (),
99                            ly_symbol2scm ("symbol"), sym,
100                            ly_symbol2scm ("property-path"), grob_property_path);
101
102       send_stream_event (get_outlet (), "Override", get_music ()->origin (),
103                          ly_symbol2scm ("symbol"), sym,
104                          ly_symbol2scm ("property-path"), grob_property_path,
105                          ly_symbol2scm ("once"), once,
106                          ly_symbol2scm ("value"), val);
107     }
108   Simple_music_iterator::process (m);
109 }
110
111 void
112 Pop_property_iterator::process (Moment mom)
113 {
114   Music *m = get_music ();
115   SCM sym = m->get_property ("symbol");
116
117   if (check_grob (m, sym))
118     {
119       SCM grob_property_path = get_property_path (m);
120
121       send_stream_event (get_outlet (), "Revert", m->origin (),
122                          ly_symbol2scm ("symbol"), sym,
123                          ly_symbol2scm ("once"), m->get_property ("once"),
124                          ly_symbol2scm ("property-path"), grob_property_path);
125     }
126   Simple_music_iterator::process (mom);
127 }
128
129 IMPLEMENT_CTOR_CALLBACK (Pop_property_iterator);
130 IMPLEMENT_CTOR_CALLBACK (Push_property_iterator);
131 IMPLEMENT_CTOR_CALLBACK (Property_iterator);
132 IMPLEMENT_CTOR_CALLBACK (Property_unset_iterator);