X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Flyric-engraver.cc;h=75556716ec83cd3057ec78af55d873c656fff4f0;hb=44eef75fc924487b8d322d7f4c7a4d9d73d204b1;hp=b244fe95832b3a2e4fa199e149073f514580b991;hpb=91821bd59959b1289f2d711509017a4dacebecd2;p=lilypond.git diff --git a/lily/lyric-engraver.cc b/lily/lyric-engraver.cc index b244fe9583..75556716ec 100644 --- a/lily/lyric-engraver.cc +++ b/lily/lyric-engraver.cc @@ -3,7 +3,7 @@ source file of the GNU LilyPond music typesetter - (c) 1997--2005 Han-Wen Nienhuys + (c) 1997--2006 Han-Wen Nienhuys Jan Nieuwenhuizen */ @@ -14,6 +14,9 @@ #include "multi-measure-rest.hh" #include "note-head.hh" #include "rest.hh" +#include "stream-event.hh" + +#include "translator.icc" /** Generate texts for lyric syllables. We only do one lyric at a time. @@ -23,17 +26,17 @@ class Lyric_engraver : public Engraver { protected: void stop_translation_timestep (); - virtual bool try_music (Music *); void process_music (); + DECLARE_TRANSLATOR_LISTENER (lyric); public: TRANSLATOR_DECLARATIONS (Lyric_engraver); private: - Music *event_; + Stream_event *event_; Item *text_; Item *last_text_; - + Context *get_voice_context (); }; @@ -44,15 +47,11 @@ Lyric_engraver::Lyric_engraver () event_ = 0; } -bool -Lyric_engraver::try_music (Music *r) +IMPLEMENT_TRANSLATOR_LISTENER (Lyric_engraver, lyric); +void +Lyric_engraver::listen_lyric (Stream_event *ev) { - if (!event_) - { - event_ = r; - return true; - } - return false; + ASSIGN_EVENT_ONCE (event_, ev); } void @@ -61,7 +60,7 @@ Lyric_engraver::process_music () if (event_) { SCM text = event_->get_property ("text"); - + if (ly_is_equal (text, scm_makfrom0str (" "))) { if (last_text_) @@ -70,7 +69,6 @@ Lyric_engraver::process_music () else { text_ = make_item ("LyricText", event_->self_scm ()); - text_->set_property ("text", text); } } } @@ -83,15 +81,15 @@ get_voice_to_lyrics (Context *lyrics) return c; SCM voice_name = lyrics->get_property ("associatedVoice"); - String nm = lyrics->id_string (); + string nm = lyrics->id_string (); if (scm_is_string (voice_name)) nm = ly_scm2string (voice_name); else { - int idx = nm.index_last ('-'); - if (idx >= 0) - nm = nm.left_string (idx); + ssize idx = nm.rfind ('-'); + if (idx != NPOS) + nm = nm.substr (0, idx); } Context *parent = lyrics; @@ -150,18 +148,15 @@ Lyric_engraver::stop_translation_timestep () text_->set_property ("self-alignment-X", scm_from_int (LEFT)); } } - + last_text_ = text_; text_ = 0; } event_ = 0; } -#include "translator.icc" - ADD_TRANSLATOR (Lyric_engraver, /* doc */ "", /* create */ "LyricText", - /* accept */ "lyric-event", /* read */ "", /* write */ "");