X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fstaff-symbol-engraver.cc;h=5d70855273e152e87b134a8fd2f72f0e5694ff24;hb=8cab78caa0db1ba14f2e52e4c1ddbb541ea0e5cb;hp=95c8ee9ab092e6a083704bab11fb224255c57dee;hpb=8a37f4d25a58780a966ac364d580e98b58d7162f;p=lilypond.git diff --git a/lily/staff-symbol-engraver.cc b/lily/staff-symbol-engraver.cc index 95c8ee9ab0..5d70855273 100644 --- a/lily/staff-symbol-engraver.cc +++ b/lily/staff-symbol-engraver.cc @@ -3,11 +3,39 @@ source file of the GNU LilyPond music typesetter - (c) 1997--2005 Han-Wen Nienhuys + (c) 1997--2009 Han-Wen Nienhuys */ -#include "staff-symbol-engraver.hh" +#include "engraver.hh" +#include "international.hh" #include "spanner.hh" +#include "stream-event.hh" +#include "warn.hh" + +#include "translator.icc" + +class Staff_symbol_engraver : public Engraver +{ +public: + TRANSLATOR_DECLARATIONS (Staff_symbol_engraver); + +protected: + Drul_array span_events_; + Spanner *span_; + Spanner *finished_span_; + bool first_start_; + +protected: + virtual void start_spanner (); + virtual void stop_spanner (); + + void stop_translation_timestep (); + virtual ~Staff_symbol_engraver (); + DECLARE_ACKNOWLEDGER (grob); + DECLARE_TRANSLATOR_LISTENER (staff_span); + virtual void finalize (); + void process_music (); +}; Staff_symbol_engraver::~Staff_symbol_engraver () { @@ -16,23 +44,22 @@ Staff_symbol_engraver::~Staff_symbol_engraver () Staff_symbol_engraver::Staff_symbol_engraver () { - first_start_ = true; + finished_span_ = 0; + first_start_ = true; span_ = 0; span_events_[LEFT] = 0; span_events_[RIGHT] = 0; } -bool -Staff_symbol_engraver::try_music (Music *music) +IMPLEMENT_TRANSLATOR_LISTENER (Staff_symbol_engraver, staff_span); +void +Staff_symbol_engraver::listen_staff_span (Stream_event *ev) { - Direction d = to_dir (music->get_property ("span-direction")); + Direction d = to_dir (ev->get_property ("span-direction")); if (d) - { - span_events_[d] = music; - return true; - } - - return false; + ASSIGN_EVENT_ONCE (span_events_[d], ev); + else + programming_error (_ ("staff-span event has no direction")); } void @@ -42,35 +69,40 @@ Staff_symbol_engraver::process_music () { finished_span_ = span_; span_ = 0; + if (first_start_) + first_start_ = false; } - if (span_events_[START]) + if (span_events_[START] + || (first_start_ && !span_events_[STOP])) start_spanner (); } - -void -Staff_symbol_engraver::initialize () -{ - start_spanner (); -} - void Staff_symbol_engraver::start_spanner () { if (!span_) { span_ = make_spanner ("StaffSymbol", SCM_EOL); + span_->set_bound (LEFT, + unsmob_grob (get_property ("currentCommandColumn"))); } } void Staff_symbol_engraver::stop_spanner () { - if (finished_span_ && !finished_span_->get_bound (RIGHT)) - { - finished_span_->set_bound (RIGHT, unsmob_grob (get_property ("currentCommandColumn"))); - } + if (!finished_span_) + return; + + if (!finished_span_->get_bound (RIGHT)) + finished_span_->set_bound (RIGHT, unsmob_grob (get_property ("currentCommandColumn"))); + + announce_end_grob (finished_span_, + span_events_[STOP] + ? span_events_[STOP]->self_scm () + : SCM_EOL); + finished_span_ = 0; } @@ -78,10 +110,8 @@ void Staff_symbol_engraver::stop_translation_timestep () { if ((span_events_[START] || first_start_) - && span_ - && !span_->get_bound (LEFT)) + && span_) { - span_->set_bound (LEFT, unsmob_grob (get_property ("currentCommandColumn"))); first_start_ = false; } @@ -98,23 +128,35 @@ Staff_symbol_engraver::finalize () stop_spanner (); } +/* + Todo: staff-symbol-referencer iface. +*/ void Staff_symbol_engraver::acknowledge_grob (Grob_info s) { - /* Perhaps should try to take SeparationItem as bound of the staff symbol? - */ - if (span_) - s.grob_->set_property ("staff-symbol", span_->self_scm ()); + */ + if (span_ || finished_span_) + { + Spanner *my = span_ ? span_ : finished_span_; + s.grob ()->set_object ("staff-symbol", my->self_scm ()); + } } +ADD_ACKNOWLEDGER (Staff_symbol_engraver, grob); + ADD_TRANSLATOR (Staff_symbol_engraver, - /* descr */ "Create the constellation of five (default) " - "staff lines.", - /* creats*/ "StaffSymbol", - /* accepts */ "staff-span-event", - /* acks */ "grob-interface", - /* reads */ "", - /* write */ ""); + /* doc */ + "Create the constellation of five (default) staff lines.", + + /* create */ + "StaffSymbol ", + + /* read */ + "", + + /* write */ + "" + );