2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1997--2014 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"
24 #include "grob-properties.hh"
25 #include "paper-score.hh"
26 #include "translator-dispatch-list.hh"
29 IMPLEMENT_LISTENER (Engraver_group, override);
31 Engraver_group::override (SCM sev)
33 Stream_event *ev = Stream_event::unsmob (sev);
35 Grob_property_info (context (), ev->get_property ("symbol"))
36 .push (ev->get_property ("property-path"),
37 ev->get_property ("value"));
40 IMPLEMENT_LISTENER (Engraver_group, revert);
42 Engraver_group::revert (SCM sev)
44 Stream_event *ev = Stream_event::unsmob (sev);
46 Grob_property_info (context (), ev->get_property ("symbol"))
47 .pop (ev->get_property ("property-path"));
51 Engraver_group::connect_to_context (Context *c)
53 Translator_group::connect_to_context (c);
54 c->event_source ()->add_listener (GET_LISTENER (override), ly_symbol2scm ("Override"));
55 c->event_source ()->add_listener (GET_LISTENER (revert), ly_symbol2scm ("Revert"));
59 Engraver_group::disconnect_from_context ()
61 context ()->event_source ()->remove_listener (GET_LISTENER (override), ly_symbol2scm ("Override"));
62 context ()->event_source ()->remove_listener (GET_LISTENER (revert), ly_symbol2scm ("Revert"));
63 Translator_group::disconnect_from_context ();
67 Engraver_group::announce_grob (Grob_info info)
69 announce_infos_.push_back (info);
71 Context *dad_con = context_->get_parent_context ();
72 if (info.rerouting_daddy_context_)
74 dad_con = info.rerouting_daddy_context_;
75 info.rerouting_daddy_context_ = 0;
78 Engraver_group *dad_eng
80 ? dynamic_cast<Engraver_group *> (dad_con->implementation ())
84 dad_eng->announce_grob (info);
88 Engraver_group::acknowledge_grobs ()
90 if (!announce_infos_.size ())
93 SCM name_sym = ly_symbol2scm ("name");
94 SCM meta_sym = ly_symbol2scm ("meta");
96 for (vsize j = 0; j < announce_infos_.size (); j++)
98 Grob_info info = announce_infos_[j];
100 SCM meta = info.grob ()->internal_get_property (meta_sym);
101 SCM nm = scm_assoc (name_sym, meta);
102 if (scm_is_pair (nm))
107 SCM acklist = scm_hashq_ref (acknowledge_hash_table_drul_[info.start_end ()],
110 Engraver_dispatch_list *dispatch
111 = Engraver_dispatch_list::unsmob (acklist);
113 if (acklist == SCM_BOOL_F)
116 = scm_cdr (scm_assoc (ly_symbol2scm ("interfaces"), meta));
117 acklist = Engraver_dispatch_list::create (get_simple_trans_list (),
118 ifaces, info.start_end ());
121 = Engraver_dispatch_list::unsmob (acklist);
123 scm_hashq_set_x (acknowledge_hash_table_drul_[info.start_end ()], nm, acklist);
127 dispatch->apply (info);
132 Ugh. This is slightly expensive. We could/should cache the value of
136 Engraver_group::pending_grob_count () const
138 int count = announce_infos_.size ();
139 for (SCM s = context_->children_contexts ();
140 scm_is_pair (s); s = scm_cdr (s))
142 Context *c = Context::unsmob (scm_car (s));
143 Engraver_group *group
144 = dynamic_cast<Engraver_group *> (c->implementation ());
147 count += group->pending_grob_count ();
153 Engraver_group::do_announces ()
158 DOCME: why is this inside the loop?
160 for (SCM s = context ()->children_contexts ();
161 scm_is_pair (s); s = scm_cdr (s))
163 Context *c = Context::unsmob (scm_car (s));
164 Engraver_group *group
165 = dynamic_cast<Engraver_group *> (c->implementation ());
167 group->do_announces ();
172 precomputed_translator_foreach (PROCESS_ACKNOWLEDGED);
173 if (announce_infos_.size () == 0)
176 acknowledge_grobs ();
177 announce_infos_.clear ();
180 while (pending_grob_count () > 0);
183 Engraver_group::Engraver_group ()
185 acknowledge_hash_table_drul_[LEFT]
186 = acknowledge_hash_table_drul_[RIGHT]
189 acknowledge_hash_table_drul_[LEFT] = scm_c_make_hash_table (61);
190 acknowledge_hash_table_drul_[RIGHT] = scm_c_make_hash_table (61);
193 #include "translator.icc"
195 ADD_TRANSLATOR_GROUP (Engraver_group,
197 "A group of engravers taken together.",
210 Engraver_group::derived_mark () const
212 scm_gc_mark (acknowledge_hash_table_drul_[LEFT]);
213 scm_gc_mark (acknowledge_hash_table_drul_[RIGHT]);