2 lyric-engraver.cc -- implement Lyric_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 Jan Nieuwenhuizen <janneke@gnu.org>
11 #include "engraver.hh"
13 #include "note-head.hh"
14 #include "stream-event.hh"
15 #include "international.hh"
17 #include "translator.icc"
20 Generate texts for lyric syllables. We only do one lyric at a time.
21 Multiple copies of this engraver should be used to do multiple voices.
23 class Lyric_engraver : public Engraver
26 void stop_translation_timestep ();
27 void process_music ();
28 DECLARE_TRANSLATOR_LISTENER (lyric);
31 TRANSLATOR_DECLARATIONS (Lyric_engraver);
38 Context *get_voice_context ();
41 Lyric_engraver::Lyric_engraver ()
48 IMPLEMENT_TRANSLATOR_LISTENER (Lyric_engraver, lyric);
50 Lyric_engraver::listen_lyric (Stream_event *ev)
52 ASSIGN_EVENT_ONCE (event_, ev);
56 Lyric_engraver::process_music ()
60 SCM text = event_->get_property ("text");
62 if (ly_is_equal (text, scm_from_locale_string (" ")))
65 last_text_->set_property ("self-alignment-X", scm_from_int (LEFT));
69 text_ = make_item ("LyricText", event_->self_scm ());
75 get_voice_to_lyrics (Context *lyrics)
77 SCM avc = lyrics->get_property ("associatedVoiceContext");
78 if (Context *c = unsmob_context (avc))
81 SCM voice_name = lyrics->get_property ("associatedVoice");
82 string nm = lyrics->id_string ();
84 if (scm_is_string (voice_name))
85 nm = ly_scm2string (voice_name);
88 ssize idx = nm.rfind ('-');
90 nm = nm.substr (0, idx);
93 Context *parent = lyrics;
95 while (parent && !voice)
97 voice = find_context_below (parent, ly_symbol2scm ("Voice"), nm);
98 parent = parent->get_parent_context ();
106 while (parent && !voice)
108 voice = find_context_below (parent, ly_symbol2scm ("Voice"), "");
109 parent = parent->get_parent_context ();
116 get_current_note_head (Context *voice)
118 for (SCM s = voice->get_property ("busyGrobs");
119 scm_is_pair (s); s = scm_cdr (s))
121 Item *g = dynamic_cast<Item *> (unsmob_grob (scm_cdar (s)));
123 if (g && !g->get_column ()
124 && Note_head::has_interface (g))
132 Lyric_engraver::stop_translation_timestep ()
136 Context *voice = get_voice_to_lyrics (context ());
140 Grob *head = get_current_note_head (voice);
144 text_->set_parent (head, X_AXIS);
145 if (melisma_busy (voice))
146 text_->set_property ("self-alignment-X", scm_from_int (LEFT));
150 text_->warning (_ ("Lyric syllable does not have note. Use \\lyricsto or associatedVoice."));
151 text_->set_property ("X-offset", scm_from_int (0));
161 ADD_TRANSLATOR (Lyric_engraver,
163 /* create */ "LyricText",