X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fhyphen-engraver.cc;h=b4dbcefc8cdcbd557b3994438bd729cd1f0919d3;hb=5b4b0d6e9a197e8f9eb085b7c2ad78b8be3e5cfc;hp=224a517b6ee31dca46ee8190b18839f2d85659b8;hpb=38fa6a3720e1187ec51514ab2a209c67ce19e14c;p=lilypond.git diff --git a/lily/hyphen-engraver.cc b/lily/hyphen-engraver.cc index 224a517b6e..b4dbcefc8c 100644 --- a/lily/hyphen-engraver.cc +++ b/lily/hyphen-engraver.cc @@ -1,136 +1,162 @@ /* hyphen-engraver.cc -- implement Hyphen_engraver - (c) 1999 Glen Prideaux + source file of the GNU LilyPond music typesetter + + (c) 1999--2008 Glen Prideaux , + Han-Wen Nienhuys , + Jan Nieuwenhuizen */ -#include "flower-proto.hh" -#include "musical-request.hh" -#include "hyphen-spanner.hh" -#include "paper-column.hh" -#include "item.hh" #include "engraver.hh" +#include "international.hh" +#include "item.hh" +#include "pointer-group-interface.hh" +#include "spanner.hh" +#include "stream-event.hh" +#include "warn.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. +#include "translator.icc" - 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_l_; - Grob *current_lyric_l_; - Hyphen_req* req_l_; - Spanner* hyphen_p_; + Stream_event *ev_; + Stream_event *finished_ev_; + + Spanner *hyphen_; + Spanner *finished_hyphen_; + public: - Hyphen_engraver (); - VIRTUAL_COPY_CONS (Translator); + TRANSLATOR_DECLARATIONS (Hyphen_engraver); protected: - virtual void acknowledge_grob (Grob_info); - virtual void do_removal_processing(); - virtual bool try_music (Music*); - virtual void stop_translation_timestep(); - virtual void start_translation_timestep (); - virtual void create_grobs (); -private: -}; + DECLARE_ACKNOWLEDGER (lyric_syllable); + DECLARE_TRANSLATOR_LISTENER (hyphen); + + virtual void finalize (); -ADD_THIS_TRANSLATOR (Hyphen_engraver); + void stop_translation_timestep (); + void process_music (); +}; Hyphen_engraver::Hyphen_engraver () { - current_lyric_l_ = 0; - last_lyric_l_ = 0; - hyphen_p_ = 0; - req_l_ = 0; + hyphen_ = 0; + finished_hyphen_ = 0; + finished_ev_ = 0; + ev_ = 0; } void -Hyphen_engraver::acknowledge_grob (Grob_info i) +Hyphen_engraver::acknowledge_lyric_syllable (Grob_info i) { - // -> text-item - if (i.elem_l_->has_interface (ly_symbol2scm ("lyric-syllable-interface"))) - { - current_lyric_l_ = i.elem_l_; - if (hyphen_p_ - && !hyphen_p_->get_bound (RIGHT) - ) - { - Hyphen_spanner (hyphen_p_).set_textitem (RIGHT, i.elem_l_); - } - } -} + Item *item = i.item (); + + if (!hyphen_) + hyphen_ = make_spanner ("LyricSpace", item->self_scm ()); + if (hyphen_) + hyphen_->set_bound (LEFT, item); + + if (finished_hyphen_) + finished_hyphen_->set_bound (RIGHT, item); +} -bool -Hyphen_engraver::try_music (Music* r) +IMPLEMENT_TRANSLATOR_LISTENER (Hyphen_engraver, hyphen); +void +Hyphen_engraver::listen_hyphen (Stream_event *ev) { - if (Hyphen_req* p = dynamic_cast (r)) - { - if (req_l_) - return false; - - req_l_ = p; - return true; - } - return false; + ASSIGN_EVENT_ONCE (ev_, ev); } void -Hyphen_engraver::do_removal_processing () +completize_hyphen (Spanner *sp) { - if (hyphen_p_) + if (!sp->get_bound (RIGHT)) { - req_l_->origin ()->warning (_ ("unterminated hyphen")); - hyphen_p_->set_bound(RIGHT, unsmob_element (get_property ("currentCommandColumn"))); + extract_item_set (sp, "heads", heads); + if (heads.size ()) + sp->set_bound (RIGHT, heads.back ()); } } void -Hyphen_engraver::create_grobs () +Hyphen_engraver::finalize () { - if (req_l_ &&! hyphen_p_) + if (hyphen_) { - if (!last_lyric_l_) + completize_hyphen (hyphen_); + + if (!hyphen_->get_bound (RIGHT)) { - req_l_->origin ()->warning (_ ("Nothing to connect hyphen to on the left. Ignoring hyphen request.")); - return; + hyphen_->warning (_ ("removing unterminated hyphen")); + hyphen_->suicide (); } - - hyphen_p_ = new Spanner (get_property ("LyricHyphen")); - Hyphen_spanner (hyphen_p_).set_textitem (LEFT, last_lyric_l_); - announce_grob (hyphen_p_, req_l_); + hyphen_ = 0; + } + + if (finished_hyphen_) + { + completize_hyphen (finished_hyphen_); + + if (!finished_hyphen_->get_bound (RIGHT)) + { + if (finished_ev_) + 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 ()); +} void Hyphen_engraver::stop_translation_timestep () { - if (hyphen_p_) + if (finished_hyphen_ && finished_hyphen_->get_bound (RIGHT)) + { + finished_hyphen_ = 0; + finished_ev_ = 0; + } + + if (finished_hyphen_ && hyphen_) { - typeset_grob (hyphen_p_); - hyphen_p_ = 0; + programming_error ("hyphen not finished yet"); + finished_hyphen_ = 0; + finished_ev_ = 0; } - if (current_lyric_l_) + if (hyphen_) { - last_lyric_l_ = current_lyric_l_; - current_lyric_l_ =0; + finished_hyphen_ = hyphen_; + finished_ev_ = ev_; } + + hyphen_ = 0; + ev_ = 0; } -void -Hyphen_engraver::start_translation_timestep () -{ - req_l_ = 0; -} +ADD_ACKNOWLEDGER (Hyphen_engraver, lyric_syllable); + +ADD_TRANSLATOR (Hyphen_engraver, + /* doc */ + "Create lyric hyphens and distance constraints between words.", + + /* create */ + "LyricHyphen " + "LyricSpace ", + /* read */ + "", + /* write */ + "" + );