X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fpart-combine-engraver.cc;h=9646d7a355a6a46bdf6c6bcb12b36614d9f904b8;hb=4d405ef96a8a62771d7d9a283ff5369a772e89d8;hp=bbc0d059e5a7ccd432cbdc78879d0f208f12fc95;hpb=a82dc4a0cca57f285e818f6c227c8428a3c02a71;p=lilypond.git diff --git a/lily/part-combine-engraver.cc b/lily/part-combine-engraver.cc index bbc0d059e5..9646d7a355 100644 --- a/lily/part-combine-engraver.cc +++ b/lily/part-combine-engraver.cc @@ -1,7 +1,7 @@ /* This file is part of LilyPond, the GNU music typesetter. - Copyright (C) 2000--2010 Jan Nieuwenhuizen + Copyright (C) 2000--2015 Jan Nieuwenhuizen Han-Wen Nienhuys @@ -34,50 +34,77 @@ class Part_combine_engraver : public Engraver TRANSLATOR_DECLARATIONS (Part_combine_engraver); protected: - DECLARE_ACKNOWLEDGER (note_head); - DECLARE_ACKNOWLEDGER (stem); + void acknowledge_note_head (Grob_info); + void acknowledge_stem (Grob_info); - DECLARE_TRANSLATOR_LISTENER (part_combine); + void listen_part_combine (Stream_event *); + void listen_note (Stream_event *); void process_music (); void stop_translation_timestep (); + void create_item (Stream_event *ev); + private: Item *text_; - Stream_event *event_; + Stream_event *new_event_; // Event happened at this moment + bool note_found_; + // Event possibly from an earlier moment waiting to create a text: + Stream_event *waiting_event_; }; -IMPLEMENT_TRANSLATOR_LISTENER (Part_combine_engraver, part_combine); void Part_combine_engraver::listen_part_combine (Stream_event *ev) { - ASSIGN_EVENT_ONCE (event_, ev); + ASSIGN_EVENT_ONCE (new_event_, ev); + // If two events occur at the same moment, discard the second as the + // warning indicates: + waiting_event_ = new_event_; +} + +void +Part_combine_engraver::listen_note (Stream_event *) +{ + note_found_ = true; } -Part_combine_engraver::Part_combine_engraver () +Part_combine_engraver::Part_combine_engraver (Context *c) + : Engraver (c) { text_ = 0; - event_ = 0; + new_event_ = 0; + waiting_event_ = 0; + note_found_ = false; +} + +void +Part_combine_engraver::create_item (Stream_event *ev) +{ + SCM what = scm_car (ev->get_property ("class")); + SCM text = SCM_EOL; + if (scm_is_eq (what, ly_symbol2scm ("solo-one-event"))) + text = get_property ("soloText"); + else if (scm_is_eq (what, ly_symbol2scm ("solo-two-event"))) + text = get_property ("soloIIText"); + else if (scm_is_eq (what, ly_symbol2scm ("unisono-event"))) + text = get_property ("aDueText"); + + if (Text_interface::is_markup (text)) + { + text_ = make_item ("CombineTextScript", ev->self_scm ()); + text_->set_property ("text", text); + } } void Part_combine_engraver::process_music () { - if (event_ + if (waiting_event_ && to_boolean (get_property ("printPartCombineTexts"))) { - SCM what = event_->get_property ("class"); - SCM text = SCM_EOL; - if (what == ly_symbol2scm ("solo-one-event")) - text = get_property ("soloText"); - else if (what == ly_symbol2scm ("solo-two-event")) - text = get_property ("soloIIText"); - else if (what == ly_symbol2scm ("unisono-event")) - text = get_property ("aDueText"); - - if (Text_interface::is_markup (text)) - { - text_ = make_item ("CombineTextScript", event_->self_scm ()); - text_->set_property ("text", text); - } + if (note_found_ || !to_boolean (get_property ("partCombineTextsOnNote"))) + { + create_item (waiting_event_); + waiting_event_ = 0; + } } } @@ -89,8 +116,8 @@ Part_combine_engraver::acknowledge_note_head (Grob_info i) Grob *t = text_; Side_position_interface::add_support (t, i.grob ()); if (Side_position_interface::get_axis (t) == X_AXIS - && !t->get_parent (Y_AXIS)) - t->set_parent (i.grob (), Y_AXIS); + && !t->get_parent (Y_AXIS)) + t->set_parent (i.grob (), Y_AXIS); } } @@ -105,25 +132,34 @@ void Part_combine_engraver::stop_translation_timestep () { text_ = 0; - event_ = 0; + new_event_ = 0; + note_found_ = false; +} + +void +Part_combine_engraver::boot () +{ + ADD_LISTENER (Part_combine_engraver, part_combine); + ADD_LISTENER (Part_combine_engraver, note); + ADD_ACKNOWLEDGER (Part_combine_engraver, note_head); + ADD_ACKNOWLEDGER (Part_combine_engraver, stem); } -ADD_ACKNOWLEDGER (Part_combine_engraver, note_head); -ADD_ACKNOWLEDGER (Part_combine_engraver, stem); ADD_TRANSLATOR (Part_combine_engraver, - /* doc */ - "Part combine engraver for orchestral scores: Print markings" - " @q{a2}, @q{Solo}, @q{Solo II}, and @q{unisono}.", - - /* create */ - "CombineTextScript ", - - /* read */ - "printPartCombineTexts " - "soloText " - "soloIIText " - "aDueText ", - - /* write */ - "" - ); + /* doc */ + "Part combine engraver for orchestral scores: Print markings" + " @q{a2}, @q{Solo}, @q{Solo II}, and @q{unisono}.", + + /* create */ + "CombineTextScript ", + + /* read */ + "printPartCombineTexts " + "partCombineTextsOnNote " + "soloText " + "soloIIText " + "aDueText ", + + /* write */ + "" + );