]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/unfolded-repeat-iterator.cc
release: 1.3.0
[lilypond.git] / lily / unfolded-repeat-iterator.cc
index 0550a46f06ccd3636d27e278e9919677e26965e0..347e929b4afacca896b04f6635ae203154981f6a 100644 (file)
@@ -8,7 +8,7 @@
  */
 
 
-#include "new-repeated-music.hh"
+#include "repeated-music.hh"
 #include "music-list.hh"
 #include "unfolded-repeat-iterator.hh"
 #include "debug.hh"
@@ -24,6 +24,7 @@ Unfolded_repeat_iterator::Unfolded_repeat_iterator ()
   done_count_ =0;
   current_iter_p_ =0;
   do_main_b_ = false;
+  alternative_count_i_ =0;
 }
 
 /**
@@ -39,7 +40,7 @@ the  alternative just set.
 void
 Unfolded_repeat_iterator::next_element () 
 {
-  New_repeated_music const* mus =dynamic_cast<New_repeated_music const*> (music_l_);
+  Repeated_music const* mus =dynamic_cast<Repeated_music const*> (music_l_);
   delete current_iter_p_;
   current_iter_p_ =0;
 
@@ -47,24 +48,45 @@ Unfolded_repeat_iterator::next_element ()
   if (do_main_b_)
     {
       done_mom_ += mus->repeat_body_p_->length_mom ();
+
+      if (!mus->volta_fold_b_)
+       done_count_ ++;
+     
       if (alternative_cons_l_)
        {
          current_iter_p_ = get_iterator_p (alternative_cons_l_->car_);
          do_main_b_ = false;
        }
+      else if (done_count_ <  mus->repeats_i_ && !mus->volta_fold_b_) 
+       {
+         current_iter_p_ = get_iterator_p (mus->repeat_body_p_);
+         do_main_b_ = true;
+       }
     }
   else
     {
+      /*
+       we're not in the main part. So we're either in an alternative, or
+       we just finished.
+      */
       if (alternative_cons_l_)
        {
          done_mom_ += alternative_cons_l_->car_->length_mom ();
-         alternative_cons_l_ = alternative_cons_l_->next_;
-         done_count_ ++;         
-       }
 
+         if (mus->volta_fold_b_ || 
+             mus->repeats_i_ - done_count_  < alternative_count_i_)
+           alternative_cons_l_ = alternative_cons_l_->next_;
+         
+         /*
+           we've done the main body as well, but didn't go over the other
+           increment.  */
+         if (mus->volta_fold_b_)
+           done_count_ ++;
+       }
+      
       if (done_count_ < mus->repeats_i_ && alternative_cons_l_)
        {
-         if (mus->semi_fold_b_)
+         if (mus->volta_fold_b_)
            current_iter_p_ = get_iterator_p (alternative_cons_l_->car_);
          else
            {
@@ -75,6 +97,7 @@ Unfolded_repeat_iterator::next_element ()
     }
 }
 
+
 bool
 Unfolded_repeat_iterator::ok () const
 {
@@ -90,11 +113,14 @@ Unfolded_repeat_iterator::next_moment () const
 void
 Unfolded_repeat_iterator::construct_children ()
 {
-  New_repeated_music const* mus =dynamic_cast<New_repeated_music const*> (music_l_);
+  Repeated_music const* mus =dynamic_cast<Repeated_music const*> (music_l_);
   alternative_cons_l_ = (mus->alternatives_p_)
     ? mus->alternatives_p_->music_p_list_p_->head_
     : 0;
 
+  for (Cons<Music> *p = alternative_cons_l_; p; p = p->next_)
+    alternative_count_i_ ++;
+
   if (mus->repeat_body_p_)
     {
       current_iter_p_  = get_iterator_p (mus->repeat_body_p_);
@@ -112,9 +138,11 @@ Unfolded_repeat_iterator::do_process_and_next (Moment m)
 {
   if (!m)
     {
-      bool success = report_to_l ()->try_music (music_l_);
-      if (!success)
-       music_l_->warning ( _("No one to print a volta bracket"));
+      Music_iterator *yeah = try_music (music_l_);
+      if (yeah)
+       set_translator (yeah->report_to_l ());
+      else
+       music_l_->warning ( _("no one to print a volta bracket"));
     }
   while (1)
     {
@@ -137,8 +165,14 @@ void
 Unfolded_repeat_iterator::do_print () const
 {
 #ifndef NPRINT
-  DOUT << "count " << done_count_ << "done time " << done_mom_ << '\n';
-  DOUT << "current: ";
+  DEBUG_OUT << "count " << done_count_ << "done time " << Rational (done_mom_) << '\n';
+  DEBUG_OUT << "current: ";
   current_iter_p_->print();
 #endif
 }
+
+Music_iterator* 
+Unfolded_repeat_iterator::try_music_in_children (Music const * m) const
+{
+  return  current_iter_p_->try_music (m);
+}