2 lyric-engraver.cc -- implement Lyric_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 Jan Nieuwenhuizen <janneke@gnu.org>
11 #include "engraver.hh"
12 #include "font-metric.hh"
14 #include "multi-measure-rest.hh"
15 #include "note-head.hh"
17 #include "stream-event.hh"
19 #include "translator.icc"
22 Generate texts for lyric syllables. We only do one lyric at a time.
23 Multiple copies of this engraver should be used to do multiple voices.
25 class Lyric_engraver : public Engraver
28 void stop_translation_timestep ();
29 void process_music ();
30 DECLARE_TRANSLATOR_LISTENER (lyric);
33 TRANSLATOR_DECLARATIONS (Lyric_engraver);
40 Context *get_voice_context ();
43 Lyric_engraver::Lyric_engraver ()
50 IMPLEMENT_TRANSLATOR_LISTENER (Lyric_engraver, lyric);
52 Lyric_engraver::listen_lyric (Stream_event *ev)
54 ASSIGN_EVENT_ONCE (event_, ev);
58 Lyric_engraver::process_music ()
62 SCM text = event_->get_property ("text");
64 if (ly_is_equal (text, scm_makfrom0str (" ")))
67 last_text_->set_property ("self-alignment-X", scm_from_int (LEFT));
71 text_ = make_item ("LyricText", event_->self_scm ());
77 get_voice_to_lyrics (Context *lyrics)
79 SCM avc = lyrics->get_property ("associatedVoiceContext");
80 if (Context *c = unsmob_context (avc))
83 SCM voice_name = lyrics->get_property ("associatedVoice");
84 string nm = lyrics->id_string ();
86 if (scm_is_string (voice_name))
87 nm = ly_scm2string (voice_name);
90 ssize idx = nm.rfind ('-');
92 nm = nm.substr (0, idx);
95 Context *parent = lyrics;
97 while (parent && !voice)
99 voice = find_context_below (parent, ly_symbol2scm ("Voice"), nm);
100 parent = parent->get_parent_context ();
108 while (parent && !voice)
110 voice = find_context_below (parent, ly_symbol2scm ("Voice"), "");
111 parent = parent->get_parent_context ();
118 get_current_note_head (Context *voice)
120 for (SCM s = voice->get_property ("busyGrobs");
121 scm_is_pair (s); s = scm_cdr (s))
123 Item *g = dynamic_cast<Item *> (unsmob_grob (scm_cdar (s)));
125 if (g && !g->get_column ()
126 && Note_head::has_interface (g))
134 Lyric_engraver::stop_translation_timestep ()
138 Context *voice = get_voice_to_lyrics (context ());
142 Grob *head = get_current_note_head (voice);
146 text_->set_parent (head, X_AXIS);
147 if (melisma_busy (voice))
148 text_->set_property ("self-alignment-X", scm_from_int (LEFT));
158 ADD_TRANSLATOR (Lyric_engraver,
160 /* create */ "LyricText",