]> git.donarmstrong.com Git - lilypond.git/blob - lily/engraver-group.cc
Doc: NR - 3.4.2 - update eg. Score.skipTypesetting
[lilypond.git] / lily / engraver-group.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 "context.hh"
21 #include "dispatcher.hh"
22 #include "engraver-group.hh"
23 #include "grob.hh"
24 #include "grob-properties.hh"
25 #include "paper-score.hh"
26 #include "translator-dispatch-list.hh"
27 #include "warn.hh"
28
29 void
30 Engraver_group::override (SCM sev)
31 {
32   Stream_event *ev = unsmob<Stream_event> (sev);
33
34   Grob_property_info (context (), ev->get_property ("symbol"))
35     .push (ev->get_property ("property-path"),
36            ev->get_property ("value"));
37 }
38
39 void
40 Engraver_group::revert (SCM sev)
41 {
42   Stream_event *ev = unsmob<Stream_event> (sev);
43
44   Grob_property_info (context (), ev->get_property ("symbol"))
45     .pop (ev->get_property ("property-path"));
46 }
47
48 void
49 Engraver_group::connect_to_context (Context *c)
50 {
51   Translator_group::connect_to_context (c);
52   c->event_source ()->add_listener (GET_LISTENER (Engraver_group, override), ly_symbol2scm ("Override"));
53   c->event_source ()->add_listener (GET_LISTENER (Engraver_group, revert), ly_symbol2scm ("Revert"));
54 }
55
56 void
57 Engraver_group::disconnect_from_context ()
58 {
59   context ()->event_source ()->remove_listener (GET_LISTENER (Engraver_group, override), ly_symbol2scm ("Override"));
60   context ()->event_source ()->remove_listener (GET_LISTENER (Engraver_group, revert), ly_symbol2scm ("Revert"));
61   Translator_group::disconnect_from_context ();
62 }
63
64 void
65 Engraver_group::announce_grob (Grob_info info)
66 {
67   announce_infos_.push_back (info);
68
69   Context *dad_con = context_->get_parent_context ();
70   if (info.rerouting_daddy_context_)
71     {
72       dad_con = info.rerouting_daddy_context_;
73       info.rerouting_daddy_context_ = 0;
74     }
75
76   Engraver_group *dad_eng
77     = dad_con
78       ? dynamic_cast<Engraver_group *> (dad_con->implementation ())
79       : 0;
80
81   if (dad_eng)
82     dad_eng->announce_grob (info);
83 }
84
85 void
86 Engraver_group::acknowledge_grobs ()
87 {
88   if (!announce_infos_.size ())
89     return;
90
91   SCM name_sym = ly_symbol2scm ("name");
92
93   for (vsize j = 0; j < announce_infos_.size (); j++)
94     {
95       Grob_info info = announce_infos_[j];
96
97       SCM meta = info.grob ()->get_property ("meta");
98       SCM nm = scm_assoc (name_sym, meta);
99       if (scm_is_pair (nm))
100         nm = scm_cdr (nm);
101       else
102         continue;
103
104       SCM ackhandle = scm_hashq_create_handle_x (acknowledge_hash_table_drul_[info.start_end ()],
105                                                  nm, SCM_BOOL_F);
106
107       SCM acklist = scm_cdr (ackhandle);
108
109       if (scm_is_false (acklist))
110         {
111           SCM ifaces
112             = scm_cdr (scm_assoc (ly_symbol2scm ("interfaces"), meta));
113           acklist = Engraver_dispatch_list::create (get_simple_trans_list (),
114                                                     ifaces, info.start_end ());
115
116           scm_set_cdr_x (ackhandle, acklist);
117         }
118
119       Engraver_dispatch_list *dispatch
120         = unsmob<Engraver_dispatch_list> (acklist);
121
122       if (dispatch)
123         dispatch->apply (info);
124     }
125 }
126
127 /*
128   Ugh. This is slightly expensive. We could/should cache the value of
129   the group count?
130 */
131 bool
132 Engraver_group::pending_grobs () const
133 {
134   if (!announce_infos_.empty ())
135     return true;
136   for (SCM s = context_->children_contexts ();
137        scm_is_pair (s); s = scm_cdr (s))
138     {
139       Context *c = unsmob<Context> (scm_car (s));
140       Engraver_group *group
141         = dynamic_cast<Engraver_group *> (c->implementation ());
142
143       if (group && group->pending_grobs ())
144         return true;
145     }
146   return false;
147 }
148
149 void
150 Engraver_group::do_announces ()
151 {
152   do
153     {
154       /*
155         DOCME: why is this inside the loop?
156        */
157       for (SCM s = context ()->children_contexts ();
158            scm_is_pair (s); s = scm_cdr (s))
159         {
160           Context *c = unsmob<Context> (scm_car (s));
161           Engraver_group *group
162             = dynamic_cast<Engraver_group *> (c->implementation ());
163           if (group)
164             group->do_announces ();
165         }
166
167       while (1)
168         {
169           precomputed_translator_foreach (PROCESS_ACKNOWLEDGED);
170           if (announce_infos_.size () == 0)
171             break;
172
173           acknowledge_grobs ();
174           announce_infos_.clear ();
175         }
176     }
177   while (pending_grobs ());
178 }
179
180 Engraver_group::Engraver_group ()
181 {
182   acknowledge_hash_table_drul_[LEFT]
183     = acknowledge_hash_table_drul_[RIGHT]
184       = SCM_EOL;
185
186   acknowledge_hash_table_drul_[LEFT] = scm_c_make_hash_table (61);
187   acknowledge_hash_table_drul_[RIGHT] = scm_c_make_hash_table (61);
188 }
189
190 #include "translator.icc"
191
192 ADD_TRANSLATOR_GROUP (Engraver_group,
193                       /* doc */
194                       "A group of engravers taken together.",
195
196                       /* create */
197                       "",
198
199                       /* read */
200                       "",
201
202                       /* write */
203                       ""
204                      );
205
206 void
207 Engraver_group::derived_mark () const
208 {
209   scm_gc_mark (acknowledge_hash_table_drul_[LEFT]);
210   scm_gc_mark (acknowledge_hash_table_drul_[RIGHT]);
211 }