*/
-#include "translator-group.hh"
+#include "context.hh"
#include "lyric-combine-music.hh"
#include "event.hh"
#include "grob.hh"
class New_lyric_combine_music_iterator : public Music_iterator
{
public:
- VIRTUAL_COPY_CONS (Music_iterator);
New_lyric_combine_music_iterator ();
New_lyric_combine_music_iterator (New_lyric_combine_music_iterator const&src);
DECLARE_SCHEME_CALLBACK(constructor, ());
virtual bool run_always ()const;
virtual bool ok () const;
virtual void derived_mark () const;
+ virtual void derived_substitute (Context *,Context *);
private:
bool start_new_syllable () ;
+ void find_voice ();
- Translator_group * lyrics_context_;
- Translator_group* music_context_;
+ bool made_association_;
+ Context * lyrics_context_;
+ Context * music_context_;
Music_iterator * lyric_iter_;
};
New_lyric_combine_music_iterator::New_lyric_combine_music_iterator ()
{
+ made_association_ = false;
lyric_iter_ =0;
music_context_ =0;
lyrics_context_ = 0;
+
+ /*
+ Ugh. out of place here.
+ */
if (!busy_ev)
{
busy_ev
if (!b)
return false;
+ if (!lyrics_context_)
+ return false;
+
if (!to_boolean (lyrics_context_->get_property ("ignoreMelismata")))
{
bool m = music_context_->try_music (melisma_playing_ev);
bool
New_lyric_combine_music_iterator::ok () const
{
- return music_context_ && lyric_iter_->ok ();
+ return lyric_iter_ && lyric_iter_->ok ();
}
void
scm_gc_mark (music_context_->self_scm ());
}
-/*
- ID == "" means accept any ID.
- */
-Translator_group *
-find_context_below (Translator_group * where,
- String type, String id)
+void
+New_lyric_combine_music_iterator::derived_substitute (Context *f, Context *t)
{
- if (where->context_name () == type)
- {
- if (id == "" || where->id_string_ == id)
- return where;
- }
-
- Translator_group * found = 0;
- for (SCM s = where->trans_group_list_;
- !found && gh_pair_p (s); s = gh_cdr (s))
- {
- Translator_group * tr = dynamic_cast<Translator_group*> (unsmob_translator (gh_car (s)));
-
-
- found = find_context_below (tr, type, id);
- }
-
- return found;
+ if (lyric_iter_)
+ lyric_iter_->substitute_outlet (f,t);
+ if (lyrics_context_ && lyrics_context_==f)
+ lyrics_context_ = t;
+ if (music_context_ && music_context_ == f)
+ music_context_ = t;
}
-
void
New_lyric_combine_music_iterator::construct_children ()
{
Music *m = unsmob_music (get_music ()->get_mus_property ("element"));
lyric_iter_ = unsmob_iterator (get_iterator (m));
- SCM voice_name = get_music ()->get_mus_property ("associated-context");
-
+ find_voice ();
- Translator_group * thread = 0, *voice =0;
+ if (lyric_iter_)
+ lyrics_context_ = find_context_below (lyric_iter_->get_outlet (),
+ "Lyrics", "");
+
+ /*
+ We do not create a Lyrics context, because the user might
+ create one with a different name, and then we will not find that
+ one.
+ */
+}
- if (gh_string_p (voice_name))
+void
+New_lyric_combine_music_iterator::find_voice ()
+{
+ if (!music_context_)
{
- Translator_group *t = report_to ();
- while (t && t->daddy_trans_)
- t = t->daddy_trans_;
-
- voice = find_context_below (t, "Voice", ly_scm2string (voice_name));
- if (voice)
- thread = find_context_below (voice, "Thread", "");
- }
+ SCM voice_name = get_music ()->get_mus_property ("associated-context");
- if (thread)
- {
- music_context_ = thread;
- lyrics_context_ = find_context_below (lyric_iter_->report_to (), "LyricsVoice", "");
+ if (gh_string_p (voice_name))
+ {
+ Context *t = get_outlet ();
+ while (t && t->daddy_context_)
+ t = t->daddy_context_;
+
+ String name = ly_scm2string (voice_name);
+ Context *voice = find_context_below (t, "Voice", name);
+ if (!voice)
+ get_music ()->origin ()->warning (_f ("cannot find Voice: %s\n",
+ name.to_str0 ()));
+ else
+ music_context_ = voice;
+
+ }
+ }
- if (lyrics_context_)
- lyrics_context_->set_property ("associatedVoiceContext", voice->self_scm ());
+ if (lyrics_context_ && music_context_)
+ {
+ if (!made_association_)
+ {
+ made_association_ = true;
+ lyrics_context_->set_property ("associatedVoiceContext",
+ music_context_->self_scm ());
+ }
}
}
void
New_lyric_combine_music_iterator::process (Moment )
{
- if (!music_context_->daddy_trans_)
+ find_voice ();
+ if (!music_context_)
+ return ;
+
+ if (!music_context_->daddy_context_)
{
- music_context_ = 0;
+ /*
+ The melody has died.
+ We die too.
+ */
if (lyrics_context_)
lyrics_context_->unset_property (ly_symbol2scm ("associatedVoiceContext"));
+ lyric_iter_ = 0;
+ music_context_ = 0;
}
if (music_context_
lyric_iter_->quit();
}
-New_lyric_combine_music_iterator::New_lyric_combine_music_iterator (New_lyric_combine_music_iterator const & src)
- : Music_iterator (src)
-{
- lyric_iter_ = 0;
-
- if (src.lyric_iter_)
- lyric_iter_ = src.lyric_iter_->clone ();
-
- if (lyric_iter_)
- scm_gc_unprotect_object (lyric_iter_->self_scm());
-
- music_context_ = src.music_context_;
- lyric_iter_ = src.lyric_iter_;
-
-
- assert (false); // shouldn't copy, really.
-}
Music_iterator*