X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fhyphen-engraver.cc;h=78470bf2fb1184cf28ac7361b093fa6da2cf201e;hb=9e781b7dc83b60a543ce218aa1a5f139f74c760f;hp=db20eb02b69b8d7bd9dee8828a0655bb2b69afb6;hpb=2745cbd907f8216a4cc1fc5f488ae19efdfdbd10;p=lilypond.git diff --git a/lily/hyphen-engraver.cc b/lily/hyphen-engraver.cc index db20eb02b6..78470bf2fb 100644 --- a/lily/hyphen-engraver.cc +++ b/lily/hyphen-engraver.cc @@ -1,140 +1,173 @@ /* - hyphen-engraver.cc -- implement Hyphen_engraver + This file is part of LilyPond, the GNU music typesetter. - source file of the GNU LilyPond music typesetter + Copyright (C) 1999--2014 Glen Prideaux , + Han-Wen Nienhuys , + Jan Nieuwenhuizen - (c) 1999--2003 Glen Prideaux + LilyPond is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + LilyPond is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LilyPond. If not, see . */ -#include "flower-proto.hh" -#include "event.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 - event, 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_; - Music* req_; - Spanner* hyphen_; + Stream_event *ev_; + Stream_event *finished_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 (); -private: -}; + DECLARE_ACKNOWLEDGER (lyric_syllable); + DECLARE_TRANSLATOR_LISTENER (hyphen); + virtual void finalize (); + void stop_translation_timestep (); + void process_music (); +}; Hyphen_engraver::Hyphen_engraver () { - current_lyric_ = 0; - last_lyric_ = 0; hyphen_ = 0; - req_ = 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.grob_->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_); - } - } -} + Item *item = i.item (); + if (!hyphen_) + hyphen_ = make_spanner ("LyricSpace", item->self_scm ()); -bool -Hyphen_engraver::try_music (Music* r) -{ - if (req_) - return false; + if (hyphen_) + hyphen_->set_bound (LEFT, item); - req_ = r; - return true; + if (finished_hyphen_) + finished_hyphen_->set_bound (RIGHT, item); } +IMPLEMENT_TRANSLATOR_LISTENER (Hyphen_engraver, hyphen); void -Hyphen_engraver::finalize () +Hyphen_engraver::listen_hyphen (Stream_event *ev) { - if (hyphen_) - { - req_->origin ()->warning (_ ("unterminated hyphen")); - hyphen_->set_bound (RIGHT, unsmob_grob (get_property ("currentCommandColumn"))); - } + ASSIGN_EVENT_ONCE (ev_, ev); } void -Hyphen_engraver::process_acknowledged_grobs () +completize_hyphen (Spanner *sp) { - if (req_ &&! hyphen_) + if (!sp->get_bound (RIGHT)) { - if (!last_lyric_) - { - req_->origin ()->warning (_ ("Nothing to connect hyphen to on the left. Ignoring hyphen event.")); - return; - } - - hyphen_ = new Spanner (get_property ("LyricHyphen")); - - Hyphen_spanner (hyphen_).set_textitem (LEFT, last_lyric_); - announce_grob(hyphen_, req_->self_scm()); + extract_item_set (sp, "heads", heads); + if (heads.size ()) + sp->set_bound (RIGHT, heads.back ()); } } - void -Hyphen_engraver::stop_translation_timestep () +Hyphen_engraver::finalize () { if (hyphen_) { - typeset_grob (hyphen_); + completize_hyphen (hyphen_); + + if (!hyphen_->get_bound (RIGHT)) + { + hyphen_->warning (_ ("removing unterminated hyphen")); + hyphen_->suicide (); + } + hyphen_ = 0; } - if (current_lyric_) + if (finished_hyphen_) { - last_lyric_ = current_lyric_; - current_lyric_ =0; + 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::start_translation_timestep () +Hyphen_engraver::process_music () { - req_ = 0; + if (ev_) + hyphen_ = make_spanner ("LyricHyphen", ev_->self_scm ()); } +void +Hyphen_engraver::stop_translation_timestep () +{ + if (finished_hyphen_ && finished_hyphen_->get_bound (RIGHT)) + { + finished_hyphen_ = 0; + finished_ev_ = 0; + } + + if (finished_hyphen_ && hyphen_) + { + programming_error ("hyphen not finished yet"); + finished_hyphen_ = 0; + finished_ev_ = 0; + } + + if (hyphen_) + { + finished_hyphen_ = hyphen_; + finished_ev_ = ev_; + } + + hyphen_ = 0; + ev_ = 0; +} + +ADD_ACKNOWLEDGER (Hyphen_engraver, lyric_syllable); + +ADD_TRANSLATOR (Hyphen_engraver, + /* doc */ + "Create lyric hyphens and distance constraints between words.", + + /* create */ + "LyricHyphen " + "LyricSpace ", + + /* read */ + "", -ENTER_DESCRIPTION(Hyphen_engraver, -/* descr */ "Create lyric hyphens", -/* creats*/ "LyricHyphen", -/* accepts */ "hyphen-event", -/* acks */ "lyric-syllable-interface", -/* reads */ "", -/* write */ ""); + /* write */ + "" + );