2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1997--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
5 Jan Nieuwenhuizen <janneke@gnu.org>
7 LilyPond is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 LilyPond is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
22 #include "engraver.hh"
24 #include "note-head.hh"
25 #include "stream-event.hh"
26 #include "international.hh"
28 #include "translator.icc"
31 Generate texts for lyric syllables. We only do one lyric at a time.
32 Multiple copies of this engraver should be used to do multiple voices.
34 class Lyric_engraver : public Engraver
37 void stop_translation_timestep ();
38 void process_music ();
39 DECLARE_TRANSLATOR_LISTENER (lyric);
42 TRANSLATOR_DECLARATIONS (Lyric_engraver);
49 Context *get_voice_context ();
52 Lyric_engraver::Lyric_engraver ()
59 IMPLEMENT_TRANSLATOR_LISTENER (Lyric_engraver, lyric);
61 Lyric_engraver::listen_lyric (Stream_event *ev)
63 ASSIGN_EVENT_ONCE (event_, ev);
67 Lyric_engraver::process_music ()
71 SCM text = event_->get_property ("text");
73 if (ly_is_equal (text, scm_from_ascii_string (" ")))
76 last_text_->set_property ("self-alignment-X",
77 get_property ("lyricMelismaAlignment"));
80 text_ = make_item ("LyricText", event_->self_scm ());
83 Context *voice = get_voice_to_lyrics (context ());
86 && to_boolean (voice->get_property ("melismaBusy"))
87 && !to_boolean (context ()->get_property ("ignoreMelismata")))
88 last_text_->set_property ("self-alignment-X",
89 get_property ("lyricMelismaAlignment"));
93 get_voice_to_lyrics (Context *lyrics)
95 bool searchForVoice = to_boolean (lyrics->get_property ("searchForVoice"));
97 SCM avc = lyrics->get_property ("associatedVoiceContext");
98 if (Context *c = unsmob<Context> (avc))
101 SCM voice_name = lyrics->get_property ("associatedVoice");
102 string nm = lyrics->id_string ();
104 if (scm_is_string (voice_name))
105 nm = ly_scm2string (voice_name);
106 else if (nm == "" || !searchForVoice)
110 ssize idx = nm.rfind ('-');
112 nm = nm.substr (0, idx);
115 SCM voice_type = lyrics->get_property ("associatedVoiceType");
116 if (!scm_is_symbol (voice_type))
119 Context *voice = find_context_near (lyrics, voice_type, nm);
123 return find_context_near (lyrics, voice_type, "");
127 get_current_note_head (Context *voice)
129 Moment now = voice->now_mom ();
130 for (SCM s = voice->get_property ("busyGrobs");
131 scm_is_pair (s); s = scm_cdr (s))
133 Grob *g = unsmob<Grob> (scm_cdar (s));;
134 Moment *end_mom = unsmob<Moment> (scm_caar (s));
137 programming_error ("busyGrobs invalid");
141 // It's a bit irritating that we just have the length and
142 // duration of the Grob.
143 Moment end_from_now =
144 get_event_length (unsmob<Stream_event> (g->get_property ("cause")), now)
146 // We cannot actually include more than a single grace note
147 // using busyGrobs on ungraced lyrics since a grob ending on
148 // grace time will just have disappeared from busyGrobs by the
149 // time our ungraced lyrics appear. At best we may catch a
150 // single grace note.
152 // However, a single grace note ending on a non-grace time is
153 // indistinguishable from a proper note ending on a non-grace
154 // time. So we really have no way to obey includeGraceNotes
155 // here. Not with this mechanism.
156 if ((*end_mom == end_from_now)
157 && dynamic_cast<Item *> (g)
158 && Note_head::has_interface (g))
168 Lyric_engraver::stop_translation_timestep ()
172 Context *voice = get_voice_to_lyrics (context ());
176 Grob *head = get_current_note_head (voice);
180 text_->set_parent (head->get_parent(X_AXIS), X_AXIS);
181 if (melisma_busy (voice)
182 && !to_boolean (get_property ("ignoreMelismata")))
183 text_->set_property ("self-alignment-X",
184 get_property ("lyricMelismaAlignment"));
194 ADD_TRANSLATOR (Lyric_engraver,
196 "Engrave text for lyrics.",
203 "lyricMelismaAlignment "