]> git.donarmstrong.com Git - lilypond.git/commitdiff
lilypond-1.3.127
authorfred <fred>
Wed, 27 Mar 2002 00:48:39 +0000 (00:48 +0000)
committerfred <fred>
Wed, 27 Mar 2002 00:48:39 +0000 (00:48 +0000)
input/bugs/repeat.ly [new file with mode: 0644]
input/regression/repeat-volta-skip-alternatives.ly [new file with mode: 0644]
lily/global-translator.cc
lily/include/repeated-music.hh
lily/include/unfolded-repeat-iterator.hh
lily/repeated-music.cc
lily/sequential-music-iterator.cc
lily/unfolded-repeat-iterator.cc

diff --git a/input/bugs/repeat.ly b/input/bugs/repeat.ly
new file mode 100644 (file)
index 0000000..c9f7e36
--- /dev/null
@@ -0,0 +1,2 @@
+
+\score { \context Staff \notes \repeat volta 3 c1 \alternative { d1 e1 }} 
diff --git a/input/regression/repeat-volta-skip-alternatives.ly b/input/regression/repeat-volta-skip-alternatives.ly
new file mode 100644 (file)
index 0000000..ed612ce
--- /dev/null
@@ -0,0 +1,3 @@
+\score {  \notes \context Voice {
+  \repeat volta 3 c1
+    \alternative { d f } e4 } } 
index 61b724d40dc4214d1595ad3273ffed130921a4d0..af8d8045370575ac102c9baab982133e9cb8be3a 100644 (file)
@@ -95,7 +95,8 @@ Global_translator::run_iterator_on_me (Music_iterator * iter)
 
       w = sneaky_insert_extra_moment (w);
       prepare (w);
-      iter->process (w);
+      if (iter->ok ())
+       iter->process (w);
       
       one_time_step ();
     }
index b7ebb339d8c06ef1fa95dcf2af65b8179f29667a..5274e35b8fd1d92bc654dc990f7fa959fcb0985a 100644 (file)
@@ -58,6 +58,7 @@ public:
 
   Moment body_length_mom () const;
   Moment alternatives_length_mom (bool fold) const;
+  Moment alternatives_volta_length_mom () const;  
 
   DECLARE_SCHEME_CALLBACK(unfolded_music_length, (SCM));
   DECLARE_SCHEME_CALLBACK(volta_music_length, (SCM));
index 11b6a8fef3035ed851419180b7be58590f0179f5..272365ecd4c90b5bcdd6e0554b84a04baabe1e1d 100644 (file)
@@ -1,76 +1,3 @@
-/*   
-  unfolded-repeat-iterator.hh -- declare Unfolded_repeat_iterator
-  
-  source file of the GNU LilyPond music typesetter
-  
-  (c) 1999--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
-  
- */
 
-#ifndef UNFOLDED_REPEAT_ITERATOR_HH
-#define UNFOLDED_REPEAT_ITERATOR_HH
-
-#include "music-iterator.hh"
-
-/**
-   Iterate repeats.  First do body, then alternatives one by one,
-   optionally interspersed by the body.
- */
-class Unfolded_repeat_iterator : public Music_iterator
-{
-  void add_repeat_command (SCM);
-
-public:
-  VIRTUAL_COPY_CONS (Music_iterator);
-  /**
-     How often have we done the body (assuming bodies are interspersed.)?
-   */
-  int done_count_;
-  static SCM constructor_cxx_function; 
-
-  /*
-    are we now busy doing the body?
-
-   */
-  bool do_main_b_;
-
-  /*
-    are we doing volta's?
-   */
-  bool volta_b_;
-
-  /** How far have we progressed into the repeat.
-      This excludes the elt currently being iterated.
-  */
-  Moment here_mom_;
-  int alternative_count_i_;
-  Music_iterator * current_iter_p_;
-  
-  /// pointer to the alternative that will be processed next.
-  SCM alternative_cons_;
-  ~Unfolded_repeat_iterator();
-  Unfolded_repeat_iterator ();
-  Unfolded_repeat_iterator (Unfolded_repeat_iterator const &);
-protected:  
-  virtual void construct_children ();
-  virtual Moment pending_moment () const;
-  virtual void process (Moment);
-  virtual Music_iterator *try_music_in_children (Music *) const;
-  virtual void skip (Moment);
-  virtual SCM get_music (Moment) const;
-  
-  virtual bool ok () const;
-  virtual void next_element (bool side_effect);
-};
-
-class Volta_repeat_iterator : public Unfolded_repeat_iterator
-{
-public:
-  Volta_repeat_iterator ();
-  static  SCM constructor_cxx_function;
-  VIRTUAL_COPY_CONS(Music_iterator);
-};
-
-
-#endif /* UNFOLDED_REPEAT_ITERATOR_HH */
+#error
 
index 9ff853a9a64bb443cddec9076bf9c80dc18fafa6..32e8202e81b883ed0963bb45c292722fa9022e82 100644 (file)
@@ -89,6 +89,23 @@ Repeated_music::alternatives_length_mom (bool fold) const
   return m;
 }
 
+/*
+  Sum all duration of all available alternatives. This is for the case
+  of volta repeats, where the alternatives are iterated just as they
+  were entered.  */
+Moment
+Repeated_music::alternatives_volta_length_mom () const
+{
+  SCM p = alternatives ()->music_list ();
+  Moment m;
+  while (gh_pair_p (p))
+    {
+      m = m + unsmob_music (gh_car (p))->length_mom ();
+      p = gh_cdr (p);
+    }
+  return m;
+}
+
 Moment
 Repeated_music::body_length_mom () const
 {
@@ -133,6 +150,6 @@ SCM
 Repeated_music::volta_music_length (SCM m)
 {
   Repeated_music* r = dynamic_cast<Repeated_music*> (unsmob_music (m));
-  Moment l =  r->body_length_mom () + r->alternatives_length_mom (false);
+  Moment l =  r->body_length_mom () + r->alternatives_volta_length_mom ();
   return l.smobbed_copy ();
 }
index 281b97c1671bc323ea52c1de0ab10501df9dfe7e..ff0940e3d593838888dfd876b88519cef018fa63 100644 (file)
@@ -99,10 +99,18 @@ void
 Sequential_music_iterator::descend_to_child ()
 {
   Translator_group  * child_report = child_report = iter_p_->report_to_l ();
+  Translator_group * me_report = report_to_l ();
+
   if (dynamic_cast<Grace_iterator*> (iter_p_))
     child_report = child_report->daddy_trans_l_;
-    
-  if (report_to_l()->depth_i () < child_report->depth_i ())
+
+  Translator_group * c = child_report;
+  while (c && c != me_report)
+    {
+      c= c->daddy_trans_l_;
+    }
+  
+  if (c == me_report)
     set_translator (child_report);
 }
 
index 89e5ba2fc60575b85c858512807d55baef8f6922..8ad34fe33159c071c73ab4b3a93bcb7b13c04a43 100644 (file)
@@ -7,13 +7,80 @@
   
  */
 
-
+/*
+  This is too hairy.  Maybe split into subclasses for volta and full
+  unfold?
+  
+ */
+#include "music-iterator.hh"
 #include "repeated-music.hh"
 #include "music-list.hh"
-#include "unfolded-repeat-iterator.hh"
 #include "debug.hh"
 #include "translator-group.hh"
 
+/**
+   Iterate repeats.  First do body, then alternatives one by one,
+   optionally interspersed by the body.
+ */
+class Unfolded_repeat_iterator : public Music_iterator
+{
+  void add_repeat_command (SCM);
+
+public:
+  VIRTUAL_COPY_CONS (Music_iterator);
+  /**
+     How often have we done the body (assuming bodies are interspersed.)?
+
+     In volta: the number to print in the bracket.
+   */
+  int done_count_;
+  static SCM constructor_cxx_function; 
+
+  /*
+    are we now busy doing the body?
+
+   */
+  bool do_main_b_;
+
+  /*
+    are we doing volta's?
+   */
+  bool volta_b_;
+
+  /** How far have we progressed into the repeat.
+      This excludes the elt currently being iterated.
+  */
+  Moment here_mom_;
+  int alternative_count_i_;
+  Music_iterator * current_iter_p_;
+  
+  /// pointer to the alternative that will be processed next.
+  SCM alternative_cons_;
+  ~Unfolded_repeat_iterator();
+  Unfolded_repeat_iterator ();
+  Unfolded_repeat_iterator (Unfolded_repeat_iterator const &);
+protected:  
+  virtual void construct_children ();
+  virtual Moment pending_moment () const;
+  virtual void process (Moment);
+  virtual Music_iterator *try_music_in_children (Music *) const;
+  virtual void skip (Moment);
+  virtual SCM get_music (Moment) const;
+  
+  virtual bool ok () const;
+  virtual void next_element (bool side_effect);
+};
+
+class Volta_repeat_iterator : public Unfolded_repeat_iterator
+{
+public:
+  Volta_repeat_iterator ();
+  static  SCM constructor_cxx_function;
+  VIRTUAL_COPY_CONS(Music_iterator);
+};
+
+
+
 Unfolded_repeat_iterator::~Unfolded_repeat_iterator ()
 {
   delete current_iter_p_;
@@ -83,7 +150,20 @@ Unfolded_repeat_iterator::next_element (bool side_effect)
 
          if (volta_b_)
            {
-             String repstr = to_str (done_count_ + 1);
+             String repstr = to_str (done_count_ + 1) + ".";
+
+             /*
+               we're coming in from main, so we're always on the first repeat.
+              */
+             assert (done_count_ == 0);
+
+             if (done_count_ == 0
+                 && alternative_count_i_ < repmus->repeat_count ())
+               {
+                 done_count_ += repmus->repeat_count () - alternative_count_i_;                  
+                 repstr = "1.--" + to_str (done_count_ + 1) + ".";               
+               }                 
+             
              if (do_repcommands)
                add_repeat_command (gh_list (ly_symbol2scm ("volta"),
                                             ly_str02scm (repstr.ch_C()), SCM_UNDEFINED));
@@ -142,7 +222,7 @@ Unfolded_repeat_iterator::next_element (bool side_effect)
        {
          if (do_repcommands)
            {
-             String repstr = to_str (done_count_ + 1);
+             String repstr = to_str (done_count_ + 1) + ".";
              add_repeat_command (gh_list (ly_symbol2scm ("volta"),
                                           ly_str02scm (repstr.ch_C()), SCM_UNDEFINED));
              add_repeat_command (ly_symbol2scm ("end-repeat"));
@@ -164,7 +244,7 @@ Unfolded_repeat_iterator::next_element (bool side_effect)
 bool
 Unfolded_repeat_iterator::ok () const
 {
-  return current_iter_p_ ;
+  return current_iter_p_;
 }
 
 Moment
@@ -195,6 +275,11 @@ Unfolded_repeat_iterator::construct_children ()
       current_iter_p_ = get_iterator_p (unsmob_music (gh_car (alternative_cons_)));
       do_main_b_ = false;
     }
+
+  while (current_iter_p_ && !current_iter_p_-> ok())
+    {
+      next_element(true);
+    }
 }
 
 /*