]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/unfolded-repeat-iterator.cc
Run grand-replace (issue 3765)
[lilypond.git] / lily / unfolded-repeat-iterator.cc
index 4b6d40d16e499198f13efc820829c1f614b413a3..f29be92f12ee0e420aa15d902cb61d073a2b09b3 100644 (file)
-/*   
-  unfolded-repeat-iterator.cc --  implement Unfolded_repeat_iterator
-  
-  source file of the GNU LilyPond music typesetter
-  
-  (c) 1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
-  
- */
+/*
+  This file is part of LilyPond, the GNU music typesetter.
 
+  Copyright (C) 2002--2014 Han-Wen Nienhuys <hanwen@xs4all.nl>
 
-#include "new-repeated-music.hh"
-#include "music-list.hh"
-#include "unfolded-repeat-iterator.hh"
-#include "debug.hh"
-#include "translator-group.hh"
+  LilyPond is free software: you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation, either version 3 of the License, or
+  (at your option) any later version.
 
-Unfolded_repeat_iterator::~Unfolded_repeat_iterator ()
-{
-  delete current_iter_p_;
-}
-
-Unfolded_repeat_iterator::Unfolded_repeat_iterator ()
-{
-  done_count_ =0;
-  current_iter_p_ =0;
-  do_main_b_ = false;
-  alternative_count_i_ =0;
-}
+  LilyPond is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
 
-/**
+  You should have received a copy of the GNU General Public License
+  along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
+*/
 
-If we are in the body of the repeat always go to the current alternative.
+#include "music.hh"
+#include "sequential-iterator.hh"
+#include "context.hh"
 
-If we are not in the body, then we are in an alternative.  If we are
-fully unfolding, advance the current alternative and go back to main.
-If we are semi-unfolding, advance the current alternative, and go to
-the  alternative just set.
-   
- */
-void
-Unfolded_repeat_iterator::next_element () 
+class Unfolded_repeat_iterator : public Sequential_iterator
 {
-  New_repeated_music const* mus =dynamic_cast<New_repeated_music const*> (music_l_);
-  delete current_iter_p_;
-  current_iter_p_ =0;
-
-
-  if (do_main_b_)
-    {
-      done_mom_ += mus->repeat_body_p_->length_mom ();
+public:
+  DECLARE_SCHEME_CALLBACK (constructor, ());
+protected:
+  virtual SCM get_music_list () const;
+};
 
-      if (!mus->semi_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->semi_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 ();
-
-         if (mus->semi_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->semi_fold_b_)
-           done_count_ ++;
-       }
-      
-      if (done_count_ < mus->repeats_i_ && alternative_cons_l_)
-       {
-         if (mus->semi_fold_b_)
-           current_iter_p_ = get_iterator_p (alternative_cons_l_->car_);
-         else
-           {
-             current_iter_p_ = get_iterator_p (mus->repeat_body_p_);
-             do_main_b_ = true;
-           }
-       }
-    }
-}
-
-
-bool
-Unfolded_repeat_iterator::ok () const
+SCM
+Unfolded_repeat_iterator::get_music_list () const
 {
-  return current_iter_p_ ;
-}
+  SCM l = SCM_EOL;
+  SCM *tail = &l;
 
-Moment
-Unfolded_repeat_iterator::next_moment () const
-{
-  return done_mom_ + current_iter_p_->next_moment ();
-}
+  SCM body = get_music ()->get_property ("element");
+  SCM alts = get_music ()->get_property ("elements");
+  int alt_count = scm_ilength (alts);
+  int rep_count = scm_to_int (get_music ()->get_property ("repeat-count"));
 
-void
-Unfolded_repeat_iterator::construct_children ()
-{
-  New_repeated_music const* mus =dynamic_cast<New_repeated_music const*> (music_l_);
-  alternative_cons_l_ = (mus->alternatives_p_)
-    ? mus->alternatives_p_->music_p_list_p_->head_
-    : 0;
+  for (int i = 0; i < rep_count; i++)
+    {
+      if (unsmob_music (body))
+        *tail = scm_cons (body, SCM_EOL);
 
-  for (Cons<Music> *p = alternative_cons_l_; p; p = p->next_)
-    alternative_count_i_ ++;
+      tail = SCM_CDRLOC (*tail);
 
-  if (mus->repeat_body_p_)
-    {
-      current_iter_p_  = get_iterator_p (mus->repeat_body_p_);
-      do_main_b_ = true;
-    }
-  else if (alternative_cons_l_)
-    {
-      current_iter_p_ = get_iterator_p (alternative_cons_l_->car_);
-      do_main_b_ = false;
-    }
-}
+      if (alt_count)
+        {
+          *tail = scm_cons (scm_car (alts), SCM_EOL);
+          tail = SCM_CDRLOC (*tail);
+          if (i >= rep_count - alt_count)
 
-void
-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"));
+            alts = scm_cdr (alts);
+        }
     }
-  while (1)
-    {
-      while (!current_iter_p_->ok ())
-       {
-         next_element();
 
-         if (!current_iter_p_)
-           return;
-       }
-      
-      if (m - done_mom_ >= current_iter_p_->next_moment ())
-       current_iter_p_->process_and_next (m - done_mom_);
-      else
-       return;
-    }
-}
-  
-void
-Unfolded_repeat_iterator::do_print () const
-{
-#ifndef NPRINT
-  DOUT << "count " << done_count_ << "done time " << done_mom_ << '\n';
-  DOUT << "current: ";
-  current_iter_p_->print();
-#endif
+  return l;
 }
+
+IMPLEMENT_CTOR_CALLBACK (Unfolded_repeat_iterator);