2 lyric-engraver.cc -- implement Lyric_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2005 Han-Wen Nienhuys <hanwen@cs.uu.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"
19 Generate texts for lyric syllables. We only do one lyric at a time.
20 Multiple copies of this engraver should be used to do multiple voices.
22 class Lyric_engraver : public Engraver
25 void stop_translation_timestep ();
26 virtual bool try_music (Music *);
27 void process_music ();
30 TRANSLATOR_DECLARATIONS (Lyric_engraver);
37 Context *get_voice_context ();
40 Lyric_engraver::Lyric_engraver ()
48 Lyric_engraver::try_music (Music *r)
59 Lyric_engraver::process_music ()
63 SCM text = event_->get_property ("text");
65 if (ly_is_equal (text, scm_makfrom0str (" ")))
68 last_text_->set_property ("self-alignment-X", scm_from_int (LEFT));
72 text_ = make_item ("LyricText", event_->self_scm ());
73 text_->set_property ("text", text);
79 get_voice_to_lyrics (Context *lyrics)
81 SCM avc = lyrics->get_property ("associatedVoiceContext");
82 if (Context *c = unsmob_context (avc))
85 SCM voice_name = lyrics->get_property ("associatedVoice");
86 String nm = lyrics->id_string ();
88 if (scm_is_string (voice_name))
89 nm = ly_scm2string (voice_name);
92 int idx = nm.index_last ('-');
94 nm = nm.left_string (idx);
97 Context *parent = lyrics;
99 while (parent && !voice)
101 voice = find_context_below (parent, ly_symbol2scm ("Voice"), nm);
102 parent = parent->get_parent_context ();
110 while (parent && !voice)
112 voice = find_context_below (parent, ly_symbol2scm ("Voice"), "");
113 parent = parent->get_parent_context ();
120 get_current_note_head (Context *voice)
122 for (SCM s = voice->get_property ("busyGrobs");
123 scm_is_pair (s); s = scm_cdr (s))
125 Item *g = dynamic_cast<Item *> (unsmob_grob (scm_cdar (s)));
127 if (g && !g->get_column ()
128 && Note_head::has_interface (g))
136 Lyric_engraver::stop_translation_timestep ()
140 Context *voice = get_voice_to_lyrics (context ());
144 Grob *head = get_current_note_head (voice);
148 text_->set_parent (head, X_AXIS);
149 if (melisma_busy (voice))
150 text_->set_property ("self-alignment-X", scm_from_int (LEFT));
160 #include "translator.icc"
162 ADD_TRANSLATOR (Lyric_engraver,
164 /* create */ "LyricText",
165 /* accept */ "lyric-event",