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>
11 #include "lyric-combine-music.hh"
14 #include "music-iterator.hh"
17 class New_lyric_combine_music_iterator
: public Music_iterator
20 New_lyric_combine_music_iterator ();
21 New_lyric_combine_music_iterator (New_lyric_combine_music_iterator
const&src
);
22 DECLARE_SCHEME_CALLBACK (constructor
, ());
24 virtual void construct_children ();
25 virtual Moment
pending_moment () const;
26 virtual void do_quit ();
27 virtual void process (Moment
);
28 virtual Music_iterator
*try_music_in_children (Music
*) const;
29 virtual bool run_always ()const;
30 virtual bool ok () const;
31 virtual void derived_mark () const;
32 virtual void derived_substitute (Context
*,Context
*);
34 bool start_new_syllable () ;
38 bool made_association_
;
39 Context
* lyrics_context_
;
40 Context
* music_context_
;
41 Music_iterator
* lyric_iter_
;
47 static Music
*busy_ev
;
48 static Music
*start_ev
;
49 static Music
*melisma_playing_ev
;
51 New_lyric_combine_music_iterator::New_lyric_combine_music_iterator ()
54 made_association_
= false;
60 Ugh. out of place here.
65 = make_music_by_name (ly_symbol2scm ("BusyPlayingEvent"));
67 = make_music_by_name (ly_symbol2scm ("StartPlayingEvent"));
69 = make_music_by_name (ly_symbol2scm ("MelismaPlayingEvent"));
74 New_lyric_combine_music_iterator::start_new_syllable ()
76 bool b
= music_context_
->try_music (busy_ev
);
84 if (!to_boolean (lyrics_context_
->get_property ("ignoreMelismata")))
86 bool m
= music_context_
->try_music (melisma_playing_ev
);
95 New_lyric_combine_music_iterator::pending_moment () const
105 New_lyric_combine_music_iterator::run_always () const
111 New_lyric_combine_music_iterator::ok () const
113 return lyric_iter_
&& lyric_iter_
->ok ();
117 New_lyric_combine_music_iterator::derived_mark ()const
120 scm_gc_mark (lyric_iter_
->self_scm ());
122 scm_gc_mark (lyrics_context_
->self_scm ());
124 scm_gc_mark (music_context_
->self_scm ());
128 New_lyric_combine_music_iterator::derived_substitute (Context
*f
, Context
*t
)
131 lyric_iter_
->substitute_outlet (f
,t
);
132 if (lyrics_context_
&& lyrics_context_
==f
)
134 if (music_context_
&& music_context_
== f
)
140 New_lyric_combine_music_iterator::construct_children ()
142 Music
*m
= unsmob_music (get_music ()->get_property ("element"));
143 lyric_iter_
= unsmob_iterator (get_iterator (m
));
148 lyrics_context_
= find_context_below (lyric_iter_
->get_outlet (),
149 ly_symbol2scm ("Lyrics"), "");
152 We do not create a Lyrics context, because the user might
153 create one with a different name, and then we will not find that
159 New_lyric_combine_music_iterator::find_voice ()
163 SCM voice_name
= get_music ()->get_property ("associated-context");
165 if (ly_c_string_p (voice_name
))
167 Context
*t
= get_outlet ();
168 while (t
&& t
->get_parent_context ())
169 t
= t
->get_parent_context ();
171 String name
= ly_scm2string (voice_name
);
172 Context
*voice
= find_context_below (t
, ly_symbol2scm ("Voice"), name
);
174 music_context_
= voice
;
179 if (lyrics_context_
&& music_context_
)
181 if (!made_association_
)
183 made_association_
= true;
184 lyrics_context_
->set_property ("associatedVoiceContext",
185 music_context_
->self_scm ());
191 New_lyric_combine_music_iterator::process (Moment
)
197 if (!music_context_
->get_parent_context ())
204 lyrics_context_
->unset_property (ly_symbol2scm ("associatedVoiceContext"));
210 && start_new_syllable () && lyric_iter_
->ok ())
212 Moment m
= lyric_iter_
->pending_moment ();
213 lyric_iter_
->process (m
);
220 New_lyric_combine_music_iterator::do_quit ()
224 SCM voice_name
= get_music ()->get_property ("associated-context");
227 if (ly_c_string_p (voice_name
))
228 name
= ly_scm2string (voice_name
);
230 get_music ()->origin ()->warning (_f ("Haven't found Voice `%s'.",
231 name
.to_str0 ()) + "\n");
235 lyric_iter_
->quit ();
241 New_lyric_combine_music_iterator::try_music_in_children (Music
*m
) const
243 return lyric_iter_
->try_music (m
);
247 IMPLEMENT_CTOR_CALLBACK (New_lyric_combine_music_iterator
);