]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/new-lyric-combine-music-iterator.cc
(Page layout): add
[lilypond.git] / lily / new-lyric-combine-music-iterator.cc
index e8f225c5f6a16634cb0c63cf13196d15c41ed896..dd2f487bdb42cdd0601e018f211bf99f5088c497 100644 (file)
@@ -1,11 +1,10 @@
-/*   
-new-lyric-combine-iterator.cc --  implement New_lyric_combine_music_iterator
-
-source file of the GNU LilyPond music typesetter
-
-(c) 2004 Han-Wen Nienhuys <hanwen@xs4all.nl>
-
- */
+/*
+  new-lyric-combine-iterator.cc -- implement New_lyric_combine_music_iterator
+  
+  source file of the GNU LilyPond music typesetter
+  
+  (c) 2004 Han-Wen Nienhuys <hanwen@xs4all.nl>
+*/
 
 #include "context.hh"
 #include "lyric-combine-music.hh"
@@ -34,10 +33,12 @@ private:
   bool start_new_syllable () ;
   void find_voice ();
 
-  bool warned_;
+  bool music_found_;
   bool made_association_;
   Context * lyrics_context_;
   Context * music_context_;
+  SCM lyricsto_voice_name_;
+  
   Music_iterator * lyric_iter_;
 };
 
@@ -50,7 +51,7 @@ static Music *melisma_playing_ev;
 
 New_lyric_combine_music_iterator::New_lyric_combine_music_iterator ()
 {
-  warned_ = false;
+  music_found_ = false;
   made_association_ = false;
   lyric_iter_ =0;
   music_context_ =0;
@@ -142,6 +143,9 @@ New_lyric_combine_music_iterator::construct_children ()
   Music *m = unsmob_music (get_music ()->get_property ("element"));
   lyric_iter_ = unsmob_iterator (get_iterator (m));
 
+  lyricsto_voice_name_ = get_music ()->get_property ("associated-context");
+
+  
   find_voice ();
   
   if (lyric_iter_)
@@ -158,28 +162,33 @@ New_lyric_combine_music_iterator::construct_children ()
 void
 New_lyric_combine_music_iterator::find_voice ()
 {
-  if (!music_context_)
+  SCM voice_name = lyricsto_voice_name_;
+  SCM running = lyrics_context_ ? lyrics_context_->get_property ("associatedVoice") : SCM_EOL;
+
+  if (scm_is_string (running))
+    voice_name = running;
+
+  if (scm_is_string (voice_name)
+      && (!music_context_ || ly_scm2string (voice_name) != music_context_->id_string ()))    
     {
-      SCM voice_name = get_music ()->get_property ("associated-context");
-  
-      if (ly_c_string_p (voice_name))
-       {
-         Context *t = get_outlet ();
-         while (t && t->get_parent_context ())
-           t = t->get_parent_context ();
-
-         String name = ly_scm2string (voice_name);
-         Context *voice = find_context_below (t, ly_symbol2scm ("Voice"), name);
-         if (!voice && !warned_)
-           {
-             warned_ = true;
-             get_music ()->origin ()->warning (_f ("cannot find Voice: %s",
-                                                   name.to_str0 ()) + "\n");
-           }
-         else
-           music_context_ = voice;
-           
-       }
+      /*
+       (spaghettini).
+       
+       Need to set associatedVoiceContext again
+       */
+      if (music_context_)
+       made_association_ = false;
+      
+      Context *t = get_outlet ();
+      while (t && t->get_parent_context ())
+       t = t->get_parent_context ();
+
+      String name = ly_scm2string (voice_name);
+      Context *voice = find_context_below (t, ly_symbol2scm ("Voice"), name);
+
+      
+      if (voice)
+       music_context_ = voice;
     }
 
   if (lyrics_context_ && music_context_)
@@ -217,12 +226,26 @@ New_lyric_combine_music_iterator::process (Moment )
     {
       Moment m= lyric_iter_->pending_moment ();
       lyric_iter_->process (m);
+
+      music_found_ = true; 
     }
 }
 
 void
 New_lyric_combine_music_iterator::do_quit ()
 {
+  if (!music_found_)
+    {
+      SCM voice_name = get_music ()->get_property ("associated-context");
+
+      String name;
+      if (scm_is_string (voice_name))
+       name = ly_scm2string (voice_name);
+
+      get_music ()->origin ()->warning (_f ("cannot find Voice `%s'",
+                                           name.to_str0 ()) + "\n");
+    }
+
   if (lyric_iter_)
     lyric_iter_->quit ();
 }