2 engravergroup.cc -- implement Engraver_group_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 #include "flower-proto.hh"
10 #include "engraver-group-engraver.hh"
11 #include "engraver.hh"
13 #include "paper-score.hh"
17 Engraver_group_engraver::announce_grob (Grob_info info)
19 announce_info_arr_.push (info);
20 Engraver::announce_grob (info);
25 Engraver_group_engraver::create_grobs_in_simple_children ()
27 for (SCM p = simple_trans_list_; gh_pair_p (p); p = ly_cdr (p))
29 Translator * t = unsmob_translator (ly_car (p));
30 Engraver * eng = dynamic_cast<Engraver*> (t);
38 Done: eliminating useless broadcast/acknowledge
41 One cause for translation slowness: grob broadcasted/acknowledges
42 (b/a): every grob is b/a-ed to all peer-engravers and all
43 parent-engravers. This means that lots of (often) useless b/a is done
44 for large scores (the top-level engravers gets to know every detail of
45 every voice, thread, etc. Measurements indicate this is 10% of the
50 old: (pre 1.5.13) 10.28
61 The cost of this B/A is # of useless engravers * cost of one ack,
62 which is rather low, since cost of one ack is only an interface check.
63 The cost of precomputing engraver lists has two elts: computing the
64 list itself, GC for the structure, looking up the list during the
68 SCM find_acknowledge_engravers (SCM gravlist, SCM meta);
70 Engraver_group_engraver::acknowledge_grobs ()
72 if (!announce_info_arr_.size ())
75 SCM tab = get_property ("acknowledgeHashTable");
76 SCM name_sym = ly_symbol2scm ("name");
77 SCM meta_sym = ly_symbol2scm ("meta");
80 for (int j =0; j < announce_info_arr_.size (); j++)
82 Grob_info info = announce_info_arr_[j];
84 SCM meta = info.grob_l_->internal_get_grob_property (meta_sym);
85 SCM nm = scm_assoc (name_sym, meta);
91 it's tempting to put an assert for
92 immutable_property_alist_ == '(), but in fact, some
93 engravers (clef-engraver) add some more information to the
94 immutable_property_alist_ (after it has been '()-ed).
96 We ignore the grob anyway. He who has no name, shall not
102 SCM acklist = scm_hashq_ref (tab, nm, SCM_UNDEFINED);
103 if (acklist == SCM_BOOL_F)
105 acklist= find_acknowledge_engravers (gh_cons (self_scm (), simple_trans_list_), meta);
106 scm_hashq_set_x (tab, nm, acklist);
109 for (SCM p = acklist; gh_pair_p (p); p = ly_cdr (p))
111 Translator * t = unsmob_translator (ly_car (p));
112 Engraver * eng = dynamic_cast<Engraver*> (t);
113 if (eng && eng!= info.origin_trans_l_)
114 eng->acknowledge_grob (info);
120 Engraver_group_engraver::do_announces ()
122 for (SCM p = trans_group_list_; gh_pair_p (p); p =ly_cdr (p))
124 Translator * t = unsmob_translator (ly_car (p));
125 dynamic_cast<Engraver_group_engraver*> (t)->do_announces ();
128 create_grobs_in_simple_children ();
130 while (announce_info_arr_.size ())
132 acknowledge_grobs ();
133 announce_info_arr_.clear ();
134 create_grobs_in_simple_children ();
141 order is : top to bottom (as opposed to do_announces)
144 Engraver_group_engraver::process_music ()
146 for (SCM p = simple_trans_list_; gh_pair_p (p); p =ly_cdr (p))
148 Translator * t = unsmob_translator (ly_car (p));
149 Engraver * eng = dynamic_cast<Engraver*> (t);
152 eng->process_music ();
154 for (SCM p = trans_group_list_; gh_pair_p (p); p =ly_cdr (p))
156 Translator * t = unsmob_translator (ly_car (p));
157 Engraver*eng = dynamic_cast<Engraver*> (t);
159 eng->process_music ();
164 Engraver_group_engraver::initialize ()
166 SCM tab = scm_make_vector (gh_int2scm (61), SCM_BOOL_F); // magic ->
167 set_property ("acknowledgeHashTable", tab);
169 Translator_group::initialize ();
172 Engraver_group_engraver::Engraver_group_engraver() {}
174 ENTER_DESCRIPTION(Engraver_group_engraver,
175 /* descr */ "A group of engravers taken together",
186 bool engraver_valid (Translator*tr, SCM ifaces)
188 SCM ack_ifs = scm_assoc (ly_symbol2scm ("interfaces-acked"), tr->translator_description());
189 ack_ifs = gh_cdr (ack_ifs);
190 for (SCM s = ifaces; ly_pair_p (s); s = ly_cdr (s))
191 if (scm_memq (ly_car (s), ack_ifs) != SCM_BOOL_F)
198 find_acknowledge_engravers (SCM gravlist, SCM meta_alist)
200 SCM ifaces = gh_cdr (scm_assoc (ly_symbol2scm ("interfaces"), meta_alist));
203 for (SCM s = gravlist; ly_pair_p (s); s = ly_cdr (s))
205 Translator* tr = unsmob_translator (ly_car (s));
206 if (engraver_valid (tr, ifaces))
207 l = scm_cons (tr->self_scm (), l);
209 l = scm_reverse_x (l, SCM_EOL);