X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fhyphen-engraver.cc;h=19ff388963d2273934eb9a5356b1da005557aefe;hb=17378a326b64ebeaeb6f9454cde414923785a470;hp=013c9620b6b3e79292d23a44e32ea63383a916f2;hpb=3370901a4dcec5826728dda9bcbe02efb2d77b5e;p=lilypond.git diff --git a/lily/hyphen-engraver.cc b/lily/hyphen-engraver.cc index 013c9620b6..19ff388963 100644 --- a/lily/hyphen-engraver.cc +++ b/lily/hyphen-engraver.cc @@ -1,121 +1,178 @@ /* - hyphen-engraver.cc -- implement Hyphen_engraver + This file is part of LilyPond, the GNU music typesetter. - (c) 1999 Glen Prideaux + Copyright (C) 1999--2015 Glen Prideaux , + Han-Wen Nienhuys , + Jan Nieuwenhuizen + + 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 "proto.hh" -#include "musical-request.hh" -#include "hyphen-engraver.hh" -#include "hyphen-spanner.hh" -#include "score-column.hh" -#include "text-item.hh" -#include "extender-engraver.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" + +#include "translator.icc" + +class Hyphen_engraver : public Engraver +{ + Stream_event *ev_; + Stream_event *finished_ev_; + + Spanner *hyphen_; + Spanner *finished_hyphen_; + +public: + TRANSLATOR_DECLARATIONS (Hyphen_engraver); + +protected: -ADD_THIS_TRANSLATOR (Hyphen_engraver); + void acknowledge_lyric_syllable (Grob_info); + void listen_hyphen (Stream_event *); + + virtual void finalize (); + + void stop_translation_timestep (); + void process_music (); +}; Hyphen_engraver::Hyphen_engraver () { - hyphen_spanner_p_ = 0; - req_l_ = 0; + hyphen_ = 0; + finished_hyphen_ = 0; + finished_ev_ = 0; + ev_ = 0; } void -Hyphen_engraver::acknowledge_element (Score_element_info i) +Hyphen_engraver::acknowledge_lyric_syllable (Grob_info i) { - if (Text_item* t = dynamic_cast (i.elem_l_)) - { - Rhythmic_req * rh = dynamic_cast (i.req_l_); - if (!rh) - return; - - now_lyrics_.push (Text_lyric_tuple (t, rh, now_mom () + rh->length_mom ())); - /* - UGH. What do we do in case of multiple alternatives? - */ - if (hyphen_spanner_p_ - && !hyphen_spanner_p_->spanned_drul_[RIGHT] - ) - { - hyphen_spanner_p_->set_textitem (RIGHT, t); - } - } -} + Item *item = i.item (); + if (!hyphen_) + hyphen_ = make_spanner ("LyricSpace", item->self_scm ()); -bool -Hyphen_engraver::do_try_music (Music* r) -{ - if (Hyphen_req* p = dynamic_cast (r)) - { - if (req_l_) - return false; + if (hyphen_) + hyphen_->set_bound (LEFT, item); - req_l_ = p; - return true; - } - return false; + if (finished_hyphen_) + finished_hyphen_->set_bound (RIGHT, item); +} + +void +Hyphen_engraver::listen_hyphen (Stream_event *ev) +{ + ASSIGN_EVENT_ONCE (ev_, ev); } void -Hyphen_engraver::do_removal_processing () +completize_hyphen (Spanner *sp) { - if (hyphen_spanner_p_) + if (!sp->get_bound (RIGHT)) { - req_l_->warning (_ ("unterminated hyphen")); - hyphen_spanner_p_->set_bounds(RIGHT, get_staff_info ().command_pcol_l ()); + extract_item_set (sp, "heads", heads); + if (heads.size ()) + sp->set_bound (RIGHT, heads.back ()); } } void -Hyphen_engraver::do_process_requests () +Hyphen_engraver::finalize () { - Array stopped_texts; - Moment now = now_mom (); + if (hyphen_) + { + completize_hyphen (hyphen_); - stopped_texts.clear (); - while (past_lyrics_pq_.size () - && past_lyrics_pq_.front ().end_ == now) - stopped_texts.push (past_lyrics_pq_.get ()); + if (!hyphen_->get_bound (RIGHT)) + { + hyphen_->warning (_ ("removing unterminated hyphen")); + hyphen_->suicide (); + } - if (req_l_) + hyphen_ = 0; + } + + if (finished_hyphen_) { - if (!stopped_texts.size ()) - { - req_l_->warning ("Nothing to connect hyphen to on the left. Ignoring hyphen request"); - return; - } - - hyphen_spanner_p_ = new Hyphen_spanner; - hyphen_spanner_p_->set_textitem (LEFT, stopped_texts[0].text_l_); - announce_element (Score_element_info (hyphen_spanner_p_, req_l_)); + 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::do_pre_move_processing () +Hyphen_engraver::stop_translation_timestep () { - for (int i=0; i < now_lyrics_.size (); i++) + if (finished_hyphen_ && finished_hyphen_->get_bound (RIGHT)) { - past_lyrics_pq_.insert (now_lyrics_[i]); + finished_hyphen_ = 0; + finished_ev_ = 0; } - now_lyrics_.clear (); - if (hyphen_spanner_p_) + if (finished_hyphen_ && hyphen_) { - typeset_element (hyphen_spanner_p_); - hyphen_spanner_p_ = 0; + programming_error ("hyphen not finished yet"); + finished_hyphen_ = 0; + finished_ev_ = 0; } + + if (hyphen_) + { + finished_hyphen_ = hyphen_; + finished_ev_ = ev_; + } + + hyphen_ = 0; + ev_ = 0; } + + void -Hyphen_engraver::do_post_move_processing () +Hyphen_engraver::boot () { - Moment now = now_mom (); - while (past_lyrics_pq_.size () && past_lyrics_pq_.front ().end_ < now) - past_lyrics_pq_.delmin (); - - req_l_ =0; + ADD_LISTENER (Hyphen_engraver, hyphen); + ADD_ACKNOWLEDGER (Hyphen_engraver, lyric_syllable); } +ADD_TRANSLATOR (Hyphen_engraver, + /* doc */ + "Create lyric hyphens and distance constraints between words.", + + /* create */ + "LyricHyphen " + "LyricSpace ", + + /* read */ + "", + /* write */ + "" + );