X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fhyphen-engraver.cc;h=8f7193fad165216a7652d21f9d99534ef0a693dc;hb=db4dd36b622417b5fe4c4a4660402e0ac7b5beb1;hp=6d5fd573f7edf49b65a885dc638e1d4209d8d8ba;hpb=a6ee9dcd388111e842064a8d46ab06c4897a00d2;p=lilypond.git diff --git a/lily/hyphen-engraver.cc b/lily/hyphen-engraver.cc index 6d5fd573f7..8f7193fad1 100644 --- a/lily/hyphen-engraver.cc +++ b/lily/hyphen-engraver.cc @@ -1,68 +1,58 @@ /* hyphen-engraver.cc -- implement Hyphen_engraver - (c) 1999 Glen Prideaux + source file of the GNU LilyPond music typesetter + + (c) 1999--2004 Glen Prideaux , + Han-Wen Nienhuys , + Jan Nieuwenhuizen */ -#include "flower-proto.hh" -#include "musical-request.hh" -#include "hyphen-spanner.hh" -#include "paper-column.hh" +#include "warn.hh" #include "item.hh" #include "engraver.hh" +#include "spanner.hh" -/** - Generate an centred hyphen. Should make a Hyphen_spanner that - typesets a nice centred hyphen of varying length depending on the - gap between syllables. - - We remember the last Item that come across. When we get a - request, we create the spanner, and attach the left point to the - last lyrics, and the right point to any lyrics we receive by - then. */ class Hyphen_engraver : public Engraver { - Grob *last_lyric_; - Grob *current_lyric_; - Hyphen_req* req_; - Spanner* hyphen_; + Music *ev_; + Spanner *hyphen_; + Spanner *finished_hyphen_; public: - TRANSLATOR_DECLARATIONS(Hyphen_engraver); + TRANSLATOR_DECLARATIONS (Hyphen_engraver); protected: virtual void acknowledge_grob (Grob_info); virtual void finalize (); virtual bool try_music (Music*); virtual void stop_translation_timestep (); - virtual void start_translation_timestep (); - virtual void process_acknowledged_grobs (); + virtual void process_music (); private: }; + Hyphen_engraver::Hyphen_engraver () { - current_lyric_ = 0; - last_lyric_ = 0; hyphen_ = 0; - req_ = 0; + finished_hyphen_ = 0; + ev_ = 0; } void Hyphen_engraver::acknowledge_grob (Grob_info i) { - // -> text-item - if (i.grob_->internal_has_interface (ly_symbol2scm ("lyric-syllable-interface"))) + Item * item = dynamic_cast (i.grob_); + // -> Text_item + if (item && item->internal_has_interface (ly_symbol2scm ("lyric-syllable-interface"))) { - current_lyric_ = i.grob_; - if (hyphen_ - && !hyphen_->get_bound (RIGHT) - ) - { - Hyphen_spanner (hyphen_).set_textitem (RIGHT, i.grob_); - } + if (hyphen_) + hyphen_->set_bound (LEFT, item); + + if (finished_hyphen_) + finished_hyphen_->set_bound (RIGHT, item); } } @@ -70,42 +60,66 @@ Hyphen_engraver::acknowledge_grob (Grob_info i) bool Hyphen_engraver::try_music (Music* r) { - if (Hyphen_req* p = dynamic_cast (r)) - { - if (req_) - return false; + if (ev_) + return false; - req_ = p; - return true; - } - return false; + ev_ = r; + return true; } void -Hyphen_engraver::finalize () +completize_hyphen (Spanner* sp) { - if (hyphen_) + if (!sp->get_bound (RIGHT)) { - req_->origin ()->warning (_ ("unterminated hyphen")); - hyphen_->set_bound (RIGHT, unsmob_grob (get_property ("currentCommandColumn"))); + SCM heads = sp->get_property ("heads"); + if (scm_is_pair (heads)) + { + Item* it = dynamic_cast (unsmob_grob (scm_car (heads))); + if (it) + sp->set_bound (RIGHT, it); + } } } + + void -Hyphen_engraver::process_acknowledged_grobs () +Hyphen_engraver::finalize () { - if (req_ &&! hyphen_) + if (hyphen_) { - if (!last_lyric_) + completize_hyphen (hyphen_); + + if (!hyphen_->get_bound (RIGHT)) { - req_->origin ()->warning (_ ("Nothing to connect hyphen to on the left. Ignoring hyphen request.")); - return; + hyphen_->warning (_ ("removing unterminated hyphen")); + hyphen_->suicide (); } - - hyphen_ = new Spanner (get_property ("LyricHyphen")); - Hyphen_spanner (hyphen_).set_textitem (LEFT, last_lyric_); - announce_grob(hyphen_, req_->self_scm()); + hyphen_ = 0; + } + + if (finished_hyphen_) + { + completize_hyphen (finished_hyphen_); + + if (!finished_hyphen_->get_bound (RIGHT)) + { + finished_hyphen_->warning (_("unterminated hyphen; removing")); + finished_hyphen_->suicide (); + } + finished_hyphen_ =0; + } +} + +void +Hyphen_engraver::process_music () +{ + if (ev_) + { + hyphen_ = make_spanner ("LyricHyphen", ev_->self_scm () +); } } @@ -113,29 +127,31 @@ Hyphen_engraver::process_acknowledged_grobs () void Hyphen_engraver::stop_translation_timestep () { - if (hyphen_) + if (finished_hyphen_ && finished_hyphen_->get_bound (RIGHT)) { - typeset_grob (hyphen_); - hyphen_ = 0; + finished_hyphen_ = 0; } - if (current_lyric_) + if (finished_hyphen_ && hyphen_) { - last_lyric_ = current_lyric_; - current_lyric_ =0; + programming_error ("Haven't finished hyphen yet."); + finished_hyphen_ =0; } -} + + if (hyphen_) + finished_hyphen_ = hyphen_; + hyphen_ = 0; -void -Hyphen_engraver::start_translation_timestep () -{ - req_ = 0; + ev_ = 0; } -ENTER_DESCRIPTION(Hyphen_engraver, + + +ENTER_DESCRIPTION (Hyphen_engraver, /* descr */ "Create lyric hyphens", /* creats*/ "LyricHyphen", -/* acks */ "lyric-syllable-interface", +/* accepts */ "hyphen-event", +/* acks */ "lyric-syllable-interface", /* reads */ "", /* write */ "");