2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1997--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
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.
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.
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/>.
21 #include "dispatcher.hh"
22 #include "engraver-group.hh"
23 #include "global-context.hh"
25 #include "grob-properties.hh"
26 #include "paper-score.hh"
27 #include "translator-dispatch-list.hh"
31 Engraver_group::override (SCM sev)
33 Stream_event *ev = unsmob<Stream_event> (sev);
34 SCM sym = ev->get_property ("symbol");
35 Grob_property_info gpi (context (), sym);
37 if (to_boolean (ev->get_property ("once")))
39 SCM token = gpi.temporary_override (ev->get_property ("property-path"),
40 ev->get_property ("value"));
41 if (scm_is_pair (token))
42 if (Global_context *g = context ()->get_global_context ())
44 g->add_finalization (scm_list_4 (ly_context_matched_pop_property_proc,
45 context ()->self_scm (),
51 gpi.push (ev->get_property ("property-path"),
52 ev->get_property ("value"));
56 Engraver_group::revert (SCM sev)
58 Stream_event *ev = unsmob<Stream_event> (sev);
59 SCM sym = ev->get_property ("symbol");
60 Grob_property_info gpi (context (), sym);
62 if (to_boolean (ev->get_property ("once")))
64 SCM token = gpi.temporary_revert (ev->get_property ("property-path"));
65 if (scm_is_pair (token))
66 if (Global_context *g = context ()->get_global_context ())
68 g->add_finalization (scm_list_4 (ly_context_matched_pop_property_proc,
69 context ()->self_scm (),
75 gpi.pop (ev->get_property ("property-path"));
79 Engraver_group::connect_to_context (Context *c)
81 Translator_group::connect_to_context (c);
82 c->event_source ()->add_listener (GET_LISTENER (Engraver_group, override), ly_symbol2scm ("Override"));
83 c->event_source ()->add_listener (GET_LISTENER (Engraver_group, revert), ly_symbol2scm ("Revert"));
87 Engraver_group::disconnect_from_context ()
89 context ()->event_source ()->remove_listener (GET_LISTENER (Engraver_group, override), ly_symbol2scm ("Override"));
90 context ()->event_source ()->remove_listener (GET_LISTENER (Engraver_group, revert), ly_symbol2scm ("Revert"));
91 Translator_group::disconnect_from_context ();
95 Engraver_group::announce_grob (Grob_info info)
97 announce_infos_.push_back (info);
99 Context *dad_con = context_->get_parent_context ();
100 if (info.rerouting_daddy_context_)
102 dad_con = info.rerouting_daddy_context_;
103 info.rerouting_daddy_context_ = 0;
106 Engraver_group *dad_eng
108 ? dynamic_cast<Engraver_group *> (dad_con->implementation ())
112 dad_eng->announce_grob (info);
116 Engraver_group::acknowledge_grobs ()
118 if (!announce_infos_.size ())
121 SCM name_sym = ly_symbol2scm ("name");
123 for (vsize j = 0; j < announce_infos_.size (); j++)
125 Grob_info info = announce_infos_[j];
127 SCM meta = info.grob ()->get_property ("meta");
128 SCM nm = scm_assoc (name_sym, meta);
129 if (scm_is_pair (nm))
134 SCM ackhandle = scm_hashq_create_handle_x (acknowledge_hash_table_drul_[info.start_end ()],
137 SCM acklist = scm_cdr (ackhandle);
139 if (scm_is_false (acklist))
142 = scm_cdr (scm_assoc (ly_symbol2scm ("interfaces"), meta));
143 acklist = Engraver_dispatch_list::create (get_simple_trans_list (),
144 ifaces, info.start_end ());
146 scm_set_cdr_x (ackhandle, acklist);
149 Engraver_dispatch_list *dispatch
150 = unsmob<Engraver_dispatch_list> (acklist);
153 dispatch->apply (info);
158 Ugh. This is slightly expensive. We could/should cache the value of
162 Engraver_group::pending_grobs () const
164 if (!announce_infos_.empty ())
166 for (SCM s = context_->children_contexts ();
167 scm_is_pair (s); s = scm_cdr (s))
169 Context *c = unsmob<Context> (scm_car (s));
170 Engraver_group *group
171 = dynamic_cast<Engraver_group *> (c->implementation ());
173 if (group && group->pending_grobs ())
180 Engraver_group::do_announces ()
185 DOCME: why is this inside the loop?
187 for (SCM s = context ()->children_contexts ();
188 scm_is_pair (s); s = scm_cdr (s))
190 Context *c = unsmob<Context> (scm_car (s));
191 Engraver_group *group
192 = dynamic_cast<Engraver_group *> (c->implementation ());
194 group->do_announces ();
199 precomputed_translator_foreach (PROCESS_ACKNOWLEDGED);
200 if (announce_infos_.size () == 0)
203 acknowledge_grobs ();
204 announce_infos_.clear ();
207 while (pending_grobs ());
210 Engraver_group::Engraver_group ()
212 acknowledge_hash_table_drul_[LEFT]
213 = acknowledge_hash_table_drul_[RIGHT]
216 acknowledge_hash_table_drul_[LEFT] = scm_c_make_hash_table (61);
217 acknowledge_hash_table_drul_[RIGHT] = scm_c_make_hash_table (61);
220 #include "translator.icc"
222 ADD_TRANSLATOR_GROUP (Engraver_group,
224 "A group of engravers taken together.",
237 Engraver_group::derived_mark () const
239 scm_gc_mark (acknowledge_hash_table_drul_[LEFT]);
240 scm_gc_mark (acknowledge_hash_table_drul_[RIGHT]);