X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fhyphen-engraver.cc;h=fb83dc407fbe809c412ba69a9c567b38ed30a023;hb=5d7a663ab5450018118c99fc48263c18f2df52dc;hp=cb276bcf4e6096ab25ad6a7d34fc20177ef2926a;hpb=0af2486a28f1c60b9de929a9101964d880927e54;p=lilypond.git diff --git a/lily/hyphen-engraver.cc b/lily/hyphen-engraver.cc index cb276bcf4e..fb83dc407f 100644 --- a/lily/hyphen-engraver.cc +++ b/lily/hyphen-engraver.cc @@ -1,136 +1,154 @@ /* hyphen-engraver.cc -- implement Hyphen_engraver - (c) 1999 Glen Prideaux + source file of the GNU LilyPond music typesetter + + (c) 1999--2003 Glen Prideaux , + Han-Wen Nienhuys , + Jan Nieuwenhuizen */ -#include "proto.hh" -#include "musical-request.hh" +#include "warn.hh" #include "hyphen-spanner.hh" -#include "paper-column.hh" #include "item.hh" #include "engraver.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 { - Score_element *last_lyric_l_; - Score_element *current_lyric_l_; - Hyphen_req* req_l_; - Spanner* hyphen_p_; + Music* ev_; + Spanner* hyphen_; + Spanner * finished_hyphen_; public: - Hyphen_engraver (); - VIRTUAL_COPY_CONS (Translator); + TRANSLATOR_DECLARATIONS(Hyphen_engraver); protected: - virtual void acknowledge_element (Score_element_info); - virtual void do_removal_processing(); - virtual void do_process_music(); - virtual bool do_try_music (Music*); - virtual void do_pre_move_processing(); - virtual void do_post_move_processing (); + virtual void acknowledge_grob (Grob_info); + virtual void finalize (); + virtual bool try_music (Music*); + virtual void stop_translation_timestep (); + virtual void process_music (); private: }; -ADD_THIS_TRANSLATOR (Hyphen_engraver); + + Hyphen_engraver::Hyphen_engraver () { - current_lyric_l_ = 0; - last_lyric_l_ = 0; - hyphen_p_ = 0; - req_l_ = 0; + hyphen_ = 0; + finished_hyphen_ = 0; + ev_ = 0; } void -Hyphen_engraver::acknowledge_element (Score_element_info i) +Hyphen_engraver::acknowledge_grob (Grob_info i) { - // -> text-item - if (i.elem_l_->has_interface (ly_symbol2scm ("text-item-interface"))) + Item * item = dynamic_cast (i.grob_); + // -> text_item + if (item && item->internal_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_); - } + if (hyphen_) + hyphen_->set_bound (LEFT, item); + + if (finished_hyphen_) + finished_hyphen_->set_bound (RIGHT, item); } } bool -Hyphen_engraver::do_try_music (Music* r) +Hyphen_engraver::try_music (Music* r) { - if (Hyphen_req* p = dynamic_cast (r)) - { - if (req_l_) - return false; + if (ev_) + return false; + + ev_ = r; + return true; +} - req_l_ = p; - return true; +void +completize_hyphen (Spanner* sp) +{ + if (!sp->get_bound (RIGHT)) + { + SCM heads = sp->get_grob_property ("heads"); + if (gh_pair_p (heads)) + { + Item* it = dynamic_cast (unsmob_grob (gh_car (heads))); + if (it) + sp->set_bound (RIGHT, it); + } } - return false; } + + void -Hyphen_engraver::do_removal_processing () +Hyphen_engraver::finalize () { - if (hyphen_p_) + if (hyphen_) { - req_l_->warning (_ ("unterminated hyphen")); - hyphen_p_->set_bound(RIGHT, unsmob_element (get_property ("currentCommandColumn"))); + completize_hyphen (hyphen_); + + if (!hyphen_->get_bound (RIGHT)) + hyphen_->warning (_ ("unterminated hyphen")); + typeset_grob (hyphen_); + hyphen_ = 0; + } + + if (finished_hyphen_) + { + completize_hyphen (finished_hyphen_); + + if (!finished_hyphen_->get_bound (RIGHT)) + finished_hyphen_->warning (_("unterminated hyphen")); + typeset_grob (finished_hyphen_); + finished_hyphen_ =0; } } void -Hyphen_engraver::do_process_music () +Hyphen_engraver::process_music () { - if (req_l_) + if (ev_) { - if (!last_lyric_l_) - { - req_l_->warning (_ ("Nothing to connect hyphen to on the left. Ignoring hyphen request.")); - return; - } - - hyphen_p_ = new Spanner (get_property ("basicHyphenSpannerProperties")); - hyphen_p_->set_extent_callback (Score_element::point_dimension_callback,Y_AXIS); - Hyphen_spanner (hyphen_p_).set_textitem (LEFT, last_lyric_l_); - announce_element (Score_element_info (hyphen_p_, req_l_)); + hyphen_ = make_spanner ("LyricHyphen"); + announce_grob (hyphen_, ev_->self_scm()); } } void -Hyphen_engraver::do_pre_move_processing () +Hyphen_engraver::stop_translation_timestep () { - if (hyphen_p_) + if (finished_hyphen_ && finished_hyphen_->get_bound (RIGHT)) { - typeset_element (hyphen_p_); - hyphen_p_ = 0; + typeset_grob (finished_hyphen_); + finished_hyphen_ = 0; } - if (current_lyric_l_) + if (finished_hyphen_ && hyphen_) { - last_lyric_l_ = current_lyric_l_; - current_lyric_l_ =0; + programming_error ("Haven't finished hyphen yet."); + typeset_grob (finished_hyphen_); + finished_hyphen_ =0; } -} + + if (hyphen_) + finished_hyphen_ = hyphen_; + hyphen_ = 0; -void -Hyphen_engraver::do_post_move_processing () -{ - req_l_ = 0; + ev_ = 0; } + + +ENTER_DESCRIPTION(Hyphen_engraver, +/* descr */ "Create lyric hyphens", +/* creats*/ "LyricHyphen", +/* accepts */ "hyphen-event", +/* acks */ "lyric-syllable-interface", +/* reads */ "", +/* write */ "");