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"
33 Generate texts for lyric syllables. We only do one lyric at a time.
34 Multiple copies of this engraver should be used to do multiple voices.
36 class Lyric_engraver : public Engraver
39 void stop_translation_timestep ();
40 void process_music ();
41 DECLARE_TRANSLATOR_LISTENER (lyric);
44 TRANSLATOR_DECLARATIONS (Lyric_engraver);
51 Context *get_voice_context ();
54 Lyric_engraver::Lyric_engraver ()
61 IMPLEMENT_TRANSLATOR_LISTENER (Lyric_engraver, lyric);
63 Lyric_engraver::listen_lyric (Stream_event *ev)
65 ASSIGN_EVENT_ONCE (event_, ev);
69 Lyric_engraver::process_music ()
73 SCM text = event_->get_property ("text");
75 if (ly_is_equal (text, scm_from_ascii_string (" ")))
78 last_text_->set_property ("self-alignment-X",
79 get_property ("lyricMelismaAlignment"));
82 text_ = make_item ("LyricText", event_->self_scm ());
85 Context *voice = get_voice_to_lyrics (context ());
88 && to_boolean (voice->get_property ("melismaBusy"))
89 && !to_boolean (context ()->get_property ("ignoreMelismata")))
90 last_text_->set_property ("self-alignment-X",
91 get_property ("lyricMelismaAlignment"));
95 get_voice_to_lyrics (Context *lyrics)
97 bool searchForVoice = to_boolean (lyrics->get_property ("searchForVoice"));
99 SCM avc = lyrics->get_property ("associatedVoiceContext");
100 if (Context *c = unsmob<Context> (avc))
102 if (!c->is_removable ())
106 SCM voice_name = lyrics->get_property ("associatedVoice");
107 string nm = lyrics->id_string ();
109 if (scm_is_string (voice_name))
110 nm = ly_scm2string (voice_name);
111 else if (nm == "" || !searchForVoice)
115 ssize idx = nm.rfind ('-');
117 nm = nm.substr (0, idx);
120 SCM voice_type = lyrics->get_property ("associatedVoiceType");
121 if (!scm_is_symbol (voice_type))
124 Context *voice = find_context_near (lyrics, voice_type, nm);
128 return find_context_near (lyrics, voice_type, "");
132 get_current_note_head (Context *voice)
134 Moment now = voice->now_mom ();
135 for (SCM s = voice->get_property ("busyGrobs");
136 scm_is_pair (s); s = scm_cdr (s))
138 Grob *g = unsmob<Grob> (scm_cdar (s));;
139 Moment *end_mom = unsmob<Moment> (scm_caar (s));
142 programming_error ("busyGrobs invalid");
146 // It's a bit irritating that we just have the length and
147 // duration of the Grob.
148 Moment end_from_now =
149 get_event_length (unsmob<Stream_event> (g->get_property ("cause")), now)
151 // We cannot actually include more than a single grace note
152 // using busyGrobs on ungraced lyrics since a grob ending on
153 // grace time will just have disappeared from busyGrobs by the
154 // time our ungraced lyrics appear. At best we may catch a
155 // single grace note.
157 // However, a single grace note ending on a non-grace time is
158 // indistinguishable from a proper note ending on a non-grace
159 // time. So we really have no way to obey includeGraceNotes
160 // here. Not with this mechanism.
161 if ((*end_mom == end_from_now)
162 && dynamic_cast<Item *> (g)
163 && has_interface<Note_head> (g))
173 Lyric_engraver::stop_translation_timestep ()
177 Context *voice = get_voice_to_lyrics (context ());
181 Grob *head = get_current_note_head (voice);
185 text_->set_parent (head->get_parent(X_AXIS), X_AXIS);
186 if (melisma_busy (voice)
187 && !to_boolean (get_property ("ignoreMelismata")))
188 text_->set_property ("self-alignment-X",
189 get_property ("lyricMelismaAlignment"));
199 ADD_TRANSLATOR (Lyric_engraver,
201 "Engrave text for lyrics.",
208 "lyricMelismaAlignment "