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, Direction dir,
96 Context *reroute_context)
98 announce_infos_.push_back (Announce_grob_info (info, dir));
100 Context *dad_con = reroute_context ? reroute_context
101 : context_->get_parent_context ();
103 Engraver_group *dad_eng
105 ? dynamic_cast<Engraver_group *> (dad_con->implementation ())
109 dad_eng->announce_grob (info, dir);
113 Engraver_group::acknowledge_grobs ()
115 if (!announce_infos_.size ())
118 SCM name_sym = ly_symbol2scm ("name");
120 for (vsize j = 0; j < announce_infos_.size (); j++)
122 Announce_grob_info info = announce_infos_[j];
124 SCM meta = info.grob ()->get_property ("meta");
125 SCM nm = scm_assoc (name_sym, meta);
126 if (scm_is_pair (nm))
131 SCM ackhandle = scm_hashq_create_handle_x (acknowledge_hash_table_drul_[info.start_end ()],
134 SCM acklist = scm_cdr (ackhandle);
136 if (scm_is_false (acklist))
139 = scm_cdr (scm_assoc (ly_symbol2scm ("interfaces"), meta));
140 acklist = Engraver_dispatch_list::create (get_simple_trans_list (),
141 ifaces, info.start_end ());
143 scm_set_cdr_x (ackhandle, acklist);
146 Engraver_dispatch_list *dispatch
147 = unsmob<Engraver_dispatch_list> (acklist);
150 dispatch->apply (info);
155 Ugh. This is slightly expensive. We could/should cache the value of
159 Engraver_group::pending_grobs () const
161 if (!announce_infos_.empty ())
163 for (SCM s = context_->children_contexts ();
164 scm_is_pair (s); s = scm_cdr (s))
166 Context *c = unsmob<Context> (scm_car (s));
167 Engraver_group *group
168 = dynamic_cast<Engraver_group *> (c->implementation ());
170 if (group && group->pending_grobs ())
177 Engraver_group::do_announces ()
182 DOCME: why is this inside the loop?
184 for (SCM s = context ()->children_contexts ();
185 scm_is_pair (s); s = scm_cdr (s))
187 Context *c = unsmob<Context> (scm_car (s));
188 Engraver_group *group
189 = dynamic_cast<Engraver_group *> (c->implementation ());
191 group->do_announces ();
196 precomputed_translator_foreach (PROCESS_ACKNOWLEDGED);
197 if (announce_infos_.size () == 0)
200 acknowledge_grobs ();
201 announce_infos_.clear ();
204 while (pending_grobs ());
207 Engraver_group::Engraver_group ()
209 acknowledge_hash_table_drul_[LEFT]
210 = acknowledge_hash_table_drul_[RIGHT]
213 acknowledge_hash_table_drul_[LEFT] = scm_c_make_hash_table (61);
214 acknowledge_hash_table_drul_[RIGHT] = scm_c_make_hash_table (61);
217 #include "translator.icc"
219 ADD_TRANSLATOR_GROUP (Engraver_group,
221 "A group of engravers taken together.",
234 Engraver_group::derived_mark () const
236 scm_gc_mark (acknowledge_hash_table_drul_[LEFT]);
237 scm_gc_mark (acknowledge_hash_table_drul_[RIGHT]);