X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fengraver-group.cc;h=3fc8cf2f85c11f7d324d3261cd3c722e900bca7e;hb=47db9a3883d726ca53e2133a3b2298f78dd6a32e;hp=2c1b3d2d863502a5f705a997a5ad94f44659f5f1;hpb=9efbad2d9487a05b04423e7e9f062968e8f8eaf4;p=lilypond.git diff --git a/lily/engraver-group.cc b/lily/engraver-group.cc index 2c1b3d2d86..3fc8cf2f85 100644 --- a/lily/engraver-group.cc +++ b/lily/engraver-group.cc @@ -1,95 +1,213 @@ /* - engravergroup.cc -- implement Engraver_group_engraver + This file is part of LilyPond, the GNU music typesetter. - source file of the GNU LilyPond music typesetter + Copyright (C) 1997--2015 Han-Wen Nienhuys - (c) 1997--1998 Han-Wen Nienhuys + LilyPond is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + LilyPond is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LilyPond. If not, see . */ -#include "proto.hh" -#include "plist.hh" +#include "context.hh" +#include "dispatcher.hh" #include "engraver-group.hh" -#include "engraver.hh" -#include "debug.hh" -#include "p-score.hh" -#include "score-element.hh" +#include "grob.hh" +#include "grob-properties.hh" +#include "paper-score.hh" +#include "translator-dispatch-list.hh" +#include "warn.hh" + +IMPLEMENT_LISTENER (Engraver_group, override); +void +Engraver_group::override (SCM sev) +{ + Stream_event *ev = Stream_event::unsmob (sev); + + Grob_property_info (context (), ev->get_property ("symbol")) + .push (ev->get_property ("property-path"), + ev->get_property ("value")); +} + +IMPLEMENT_LISTENER (Engraver_group, revert); +void +Engraver_group::revert (SCM sev) +{ + Stream_event *ev = Stream_event::unsmob (sev); + + Grob_property_info (context (), ev->get_property ("symbol")) + .pop (ev->get_property ("property-path")); +} -IMPLEMENT_IS_TYPE_B2(Engraver_group_engraver,Engraver, Translator_group); -ADD_THIS_TRANSLATOR(Engraver_group_engraver); +void +Engraver_group::connect_to_context (Context *c) +{ + Translator_group::connect_to_context (c); + c->event_source ()->add_listener (GET_LISTENER (override), ly_symbol2scm ("Override")); + c->event_source ()->add_listener (GET_LISTENER (revert), ly_symbol2scm ("Revert")); +} void -Engraver_group_engraver::announce_element (Score_element_info info) +Engraver_group::disconnect_from_context () { - announce_info_arr_.push (info); - Engraver::announce_element (info); + context ()->event_source ()->remove_listener (GET_LISTENER (override), ly_symbol2scm ("Override")); + context ()->event_source ()->remove_listener (GET_LISTENER (revert), ly_symbol2scm ("Revert")); + Translator_group::disconnect_from_context (); } void -Engraver_group_engraver::do_announces() +Engraver_group::announce_grob (Grob_info info) { - Link_array groups = group_l_arr (); - for (int i=0; i < groups.size(); i++) + announce_infos_.push_back (info); + + Context *dad_con = context_->get_parent_context (); + if (info.rerouting_daddy_context_) { - Engraver * eng = dynamic_cast (groups[i]); - if (eng) - { - Engraver_group_engraver * group = - (Engraver_group_engraver*) eng; - group->do_announces(); - } + dad_con = info.rerouting_daddy_context_; + info.rerouting_daddy_context_ = 0; } - - Request dummy_req; - Link_array nongroups = nongroup_l_arr (); - while (announce_info_arr_.size ()) + Engraver_group *dad_eng + = dad_con + ? dynamic_cast (dad_con->implementation ()) + : 0; + + if (dad_eng) + dad_eng->announce_grob (info); +} + +void +Engraver_group::acknowledge_grobs () +{ + if (!announce_infos_.size ()) + return; + + SCM name_sym = ly_symbol2scm ("name"); + + for (vsize j = 0; j < announce_infos_.size (); j++) { - for (int j =0; j < announce_info_arr_.size(); j++) - { - Score_element_info info = announce_info_arr_[j]; - - if (!info.req_l_) - info.req_l_ = &dummy_req; - for (int i=0; i < nongroups.size(); i++) - { // Is this good enough? - Engraver * eng = dynamic_cast (nongroups[i]); - if (eng && eng!= info.origin_grav_l_arr_[0]) - eng->acknowledge_element (info); - } - } - announce_info_arr_.clear (); - for (int i=0; i < nongroups.size(); i++) - { - Engraver * eng = dynamic_cast (nongroups[i]); - if (eng) - eng->process_acknowledged (); - } + Grob_info info = announce_infos_[j]; + + SCM meta = info.grob ()->get_property ("meta"); + SCM nm = scm_assoc (name_sym, meta); + if (scm_is_pair (nm)) + nm = scm_cdr (nm); + else + continue; + SCM acklist = scm_hashq_ref (acknowledge_hash_table_drul_[info.start_end ()], + nm, SCM_BOOL_F); + + Engraver_dispatch_list *dispatch + = Engraver_dispatch_list::unsmob (acklist); + + if (acklist == SCM_BOOL_F) + { + SCM ifaces + = scm_cdr (scm_assoc (ly_symbol2scm ("interfaces"), meta)); + acklist = Engraver_dispatch_list::create (get_simple_trans_list (), + ifaces, info.start_end ()); + + dispatch + = Engraver_dispatch_list::unsmob (acklist); + + scm_hashq_set_x (acknowledge_hash_table_drul_[info.start_end ()], nm, acklist); + } + + if (dispatch) + dispatch->apply (info); } } - -Staff_info -Engraver_group_engraver::get_staff_info() const +/* + Ugh. This is slightly expensive. We could/should cache the value of + the group count? +*/ +int +Engraver_group::pending_grob_count () const { - Staff_info inf = Engraver::get_staff_info(); - - Link_array simple_translators = nongroup_l_arr (); - for (int i=0; i < simple_translators.size(); i++) + int count = announce_infos_.size (); + for (SCM s = context_->children_contexts (); + scm_is_pair (s); s = scm_cdr (s)) { - Engraver * eng = dynamic_cast (simple_translators[i]); - if (eng) - eng->fill_staff_info (inf); + Context *c = Context::unsmob (scm_car (s)); + Engraver_group *group + = dynamic_cast (c->implementation ()); + + if (group) + count += group->pending_grob_count (); } - return inf; + return count; } +void +Engraver_group::do_announces () +{ + do + { + /* + DOCME: why is this inside the loop? + */ + for (SCM s = context ()->children_contexts (); + scm_is_pair (s); s = scm_cdr (s)) + { + Context *c = Context::unsmob (scm_car (s)); + Engraver_group *group + = dynamic_cast (c->implementation ()); + if (group) + group->do_announces (); + } + + while (1) + { + precomputed_translator_foreach (PROCESS_ACKNOWLEDGED); + if (announce_infos_.size () == 0) + break; + acknowledge_grobs (); + announce_infos_.clear (); + } + } + while (pending_grob_count () > 0); +} -Engraver_group_engraver::~Engraver_group_engraver () +Engraver_group::Engraver_group () { + acknowledge_hash_table_drul_[LEFT] + = acknowledge_hash_table_drul_[RIGHT] + = SCM_EOL; + + acknowledge_hash_table_drul_[LEFT] = scm_c_make_hash_table (61); + acknowledge_hash_table_drul_[RIGHT] = scm_c_make_hash_table (61); } -Engraver_group_engraver::Engraver_group_engraver () +#include "translator.icc" + +ADD_TRANSLATOR_GROUP (Engraver_group, + /* doc */ + "A group of engravers taken together.", + + /* create */ + "", + + /* read */ + "", + + /* write */ + "" + ); + +void +Engraver_group::derived_mark () const { + scm_gc_mark (acknowledge_hash_table_drul_[LEFT]); + scm_gc_mark (acknowledge_hash_table_drul_[RIGHT]); }