2 new-lyric-combine-iterator.cc -- implement New_lyric_combine_music_iterator
4 source file of the GNU LilyPond music typesetter
6 (c) 2004 Han-Wen Nienhuys <hanwen@xs4all.nl>
10 #include "lyric-combine-music.hh"
13 #include "music-iterator.hh"
16 class New_lyric_combine_music_iterator : public Music_iterator
19 New_lyric_combine_music_iterator ();
20 New_lyric_combine_music_iterator (New_lyric_combine_music_iterator const&src);
21 DECLARE_SCHEME_CALLBACK (constructor, ());
23 virtual void construct_children ();
24 virtual Moment pending_moment () const;
25 virtual void do_quit ();
26 virtual void process (Moment);
27 virtual Music_iterator *try_music_in_children (Music *) const;
28 virtual bool run_always ()const;
29 virtual bool ok () const;
30 virtual void derived_mark () const;
31 virtual void derived_substitute (Context *,Context *);
33 bool start_new_syllable () ;
37 bool made_association_;
38 Context * lyrics_context_;
39 Context * music_context_;
40 SCM lyricsto_voice_name_;
42 Music_iterator * lyric_iter_;
48 static Music *busy_ev;
49 static Music *start_ev;
50 static Music *melisma_playing_ev;
52 New_lyric_combine_music_iterator::New_lyric_combine_music_iterator ()
55 made_association_ = false;
61 Ugh. out of place here.
66 = make_music_by_name (ly_symbol2scm ("BusyPlayingEvent"));
68 = make_music_by_name (ly_symbol2scm ("StartPlayingEvent"));
70 = make_music_by_name (ly_symbol2scm ("MelismaPlayingEvent"));
75 New_lyric_combine_music_iterator::start_new_syllable ()
77 bool b = music_context_->try_music (busy_ev);
85 if (!to_boolean (lyrics_context_->get_property ("ignoreMelismata")))
87 bool m = music_context_->try_music (melisma_playing_ev);
96 New_lyric_combine_music_iterator::pending_moment () const
106 New_lyric_combine_music_iterator::run_always () const
112 New_lyric_combine_music_iterator::ok () const
114 return lyric_iter_ && lyric_iter_->ok ();
118 New_lyric_combine_music_iterator::derived_mark ()const
121 scm_gc_mark (lyric_iter_->self_scm ());
123 scm_gc_mark (lyrics_context_->self_scm ());
125 scm_gc_mark (music_context_->self_scm ());
129 New_lyric_combine_music_iterator::derived_substitute (Context *f, Context *t)
132 lyric_iter_->substitute_outlet (f,t);
133 if (lyrics_context_ && lyrics_context_==f)
135 if (music_context_ && music_context_ == f)
141 New_lyric_combine_music_iterator::construct_children ()
143 Music *m = unsmob_music (get_music ()->get_property ("element"));
144 lyric_iter_ = unsmob_iterator (get_iterator (m));
146 lyricsto_voice_name_ = get_music ()->get_property ("associated-context");
152 lyrics_context_ = find_context_below (lyric_iter_->get_outlet (),
153 ly_symbol2scm ("Lyrics"), "");
156 We do not create a Lyrics context, because the user might
157 create one with a different name, and then we will not find that
163 New_lyric_combine_music_iterator::find_voice ()
165 SCM voice_name = lyricsto_voice_name_;
166 SCM running = lyrics_context_ ? lyrics_context_->get_property ("associatedVoice") : SCM_EOL;
168 if (ly_c_string_p (running))
169 voice_name = running;
171 if (ly_c_string_p (voice_name)
172 && (!music_context_ || ly_scm2string (voice_name) != music_context_->id_string ()))
177 Need to set associatedVoiceContext again
180 made_association_ = false;
182 Context *t = get_outlet ();
183 while (t && t->get_parent_context ())
184 t = t->get_parent_context ();
186 String name = ly_scm2string (voice_name);
187 Context *voice = find_context_below (t, ly_symbol2scm ("Voice"), name);
191 music_context_ = voice;
194 if (lyrics_context_ && music_context_)
196 if (!made_association_)
198 made_association_ = true;
199 lyrics_context_->set_property ("associatedVoiceContext",
200 music_context_->self_scm ());
206 New_lyric_combine_music_iterator::process (Moment )
212 if (!music_context_->get_parent_context ())
219 lyrics_context_->unset_property (ly_symbol2scm ("associatedVoiceContext"));
225 && start_new_syllable () && lyric_iter_->ok ())
227 Moment m= lyric_iter_->pending_moment ();
228 lyric_iter_->process (m);
235 New_lyric_combine_music_iterator::do_quit ()
239 SCM voice_name = get_music ()->get_property ("associated-context");
242 if (ly_c_string_p (voice_name))
243 name = ly_scm2string (voice_name);
245 get_music ()->origin ()->warning (_f ("cannot find Voice `%s'",
246 name.to_str0 ()) + "\n");
250 lyric_iter_->quit ();
256 New_lyric_combine_music_iterator::try_music_in_children (Music *m) const
258 return lyric_iter_->try_music (m);
262 IMPLEMENT_CTOR_CALLBACK (New_lyric_combine_music_iterator);