]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/repeat-engraver.cc
release: 1.1.43
[lilypond.git] / lily / repeat-engraver.cc
index ab634c71da15e37d9e1f17629d6ccda180305a19..8de755f670dc8adc28e6f4c7e8160db8202c816f 100644 (file)
@@ -3,7 +3,7 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c) 1998 Jan Nieuwenhuizen <janneke@gnu.org>
+  (c) 1998--1999 Jan Nieuwenhuizen <janneke@gnu.org>
 */
 
 #include "repeat-engraver.hh"
 #include "command-request.hh"
 #include "time-description.hh"
 #include "engraver-group.hh"
-#include "repeated-music.hh"
+#include "new-repeated-music.hh"
 #include "time-description.hh"
 #include "volta-spanner.hh"
 #include "note-column.hh"
 #include "paper-def.hh"
+#include "music-list.hh"
 
 ADD_THIS_TRANSLATOR (Repeat_engraver);
 
-Repeat_engraver::Repeat_engraver ()
-{
-}
-
+/*
+  Urg. Hairy.  Needs redesign?
+ */
 bool
 Repeat_engraver::do_try_music (Music* m)
 {
-  if (Repeated_music* r = dynamic_cast<Repeated_music *> (m))
+  if (New_repeated_music* r = dynamic_cast<New_repeated_music *> (m))
     {
-      r->unfold_b_ = get_property ("unfoldRepeats", 0).to_bool ();
-      if (r->unfold_b_)
-        return true;
-      Music_sequence* alt = r->alternative_p_;
-      Moment stop_mom = now_moment () + r->repeat_p_->duration ();
-      for (PCursor<Music*> i (alt->music_p_list_p_->top ()); i.ok () && (i != alt->music_p_list_p_->bottom ()); i++)
+      Music_sequence* alt = r->alternatives_p_;
+      Moment repeat_length_mom = r->repeat_body_p_->length_mom ();
+      Moment stop_mom = now_mom () + repeat_length_mom;
+      Moment alt_mom = now_mom () + repeat_length_mom;
+      if (repeat_length_mom)
        {
-         stop_mom += i->duration ();
-         if (dynamic_cast<Simultaneous_music *> (alt))
-           break;
+         stop_mom += r->alternatives_length_mom ();
+         repeated_music_arr_.push (r);
+         stop_mom_arr_.push (stop_mom);
        }
-      Moment alt_mom = now_moment () + r->repeat_p_->duration ();
-      /*
-        TODO: 
-         figure out what we don't want.
-
-         we don't want to print more than one set of
-         |: :| and volta brackets on one staff.
 
-         counting nested repeats, it seems safest to forbid
-         two pieces of alternative music to start at the same time.
-       */
+      /* 
+        Counting nested repeats, it seems safest to forbid
+        two pieces of alternative music to start at the same time.
+      */
       for (int i = 0; i < alternative_start_mom_arr_.size (); i++)
         if (alternative_start_mom_arr_[i] == alt_mom)
          return false;
-      repeated_music_arr_.push (r);
-      stop_mom_arr_.push (stop_mom);
-      for (PCursor<Music*> i (alt->music_p_list_p_->top ()); i.ok (); i++)
+
+      /*
+       Coda kludge: see input/test/coda-kludge.ly
+       */
+      Moment span_mom;
+      Scalar prop = get_property ("voltaSpannerDuration", 0);
+      if (prop.length_i ())
+       span_mom = prop.to_rat ();
+
+      int alt_i = r->repeats_i_ + 1 - cons_list_size_i (alt->music_p_list_p_->head_ ) >? 1;
+      for (Cons<Music> *i = alt->music_p_list_p_->head_; i ; i = i->next_)
         {
-         alternative_music_arr_.push (i.ptr ());
+         alternative_music_arr_.push (i->car_);
          alternative_start_mom_arr_.push (alt_mom);
-         alternative_stop_mom_arr_.push (alt_mom + i->duration ());
+         if (span_mom)
+           alternative_stop_mom_arr_.push (alt_mom + span_mom);
+         else
+           alternative_stop_mom_arr_.push (alt_mom + i->car_->length_mom ());
+         String str;
+         if ((alt_i != 1) && (alt_i != r->repeats_i_) && (i == alt->music_p_list_p_->head_))
+           str = "1.-";
+         str += to_str (alt_i) + ".";
+         alt_i++;
+         alternative_str_arr_.push (str);
          if (!dynamic_cast<Simultaneous_music *> (alt))
-           alt_mom += i->duration ();
+           alt_mom += i->car_->length_mom ();
        }
       return true;
     }
@@ -75,7 +84,7 @@ Repeat_engraver::do_try_music (Music* m)
 void
 Repeat_engraver::acknowledge_element (Score_element_info i)
 {
-  Moment now = now_moment ();
+  Moment now = now_mom ();
   if (Note_column *c = dynamic_cast<Note_column *> (i.elem_l_))
     {
       for (int i = 0; i < volta_p_arr_.size (); i++)
@@ -101,12 +110,12 @@ Repeat_engraver::do_removal_processing ()
 void
 Repeat_engraver::do_process_requests ()
 {  
-  Moment now = now_moment ();
+  Moment now = now_mom ();
   Bar_engraver* bar_engraver_l = dynamic_cast <Bar_engraver*>
     (daddy_grav_l ()->get_simple_translator ("Bar_engraver"));
   for (int i = bar_b_arr_.size (); i < repeated_music_arr_.size (); i++)
     {
-      if (bar_engraver_l && (now > Moment (0)))
+      if (bar_engraver_l)
        bar_engraver_l->request_bar ("|:");
       bar_b_arr_.push (true);
     }
@@ -118,17 +127,17 @@ Repeat_engraver::do_process_requests ()
            bar_engraver_l->request_bar (":|");
        }
     }
-  int bees = volta_p_arr_.size ();
   for (int i = volta_p_arr_.size (); i < alternative_music_arr_.size (); i++)
     {
       Volta_spanner* v = new Volta_spanner;
       Scalar prop = get_property ("voltaVisibility", 0);
-      v->visible_b_ = prop.to_bool ();
-      if (i == alternative_music_arr_.size () - 1)
+      if (!prop.to_bool ())
+       v->set_elt_property (transparent_scm_sym, SCM_BOOL_T);
+      prop = get_property ("voltaSpannerDuration", 0);
+      if ((i == alternative_music_arr_.size () - 1) || prop.length_i ())
         v->last_b_ = true;
-      Text_def* t = new Text_def;
-      t->text_str_ = to_str (i - bees + 1) + ".";
-      v->number_p_.set_p (t);
+
+      v->number_str_ = alternative_str_arr_[i];
       volta_p_arr_.push (v);
       announce_element (Score_element_info (v, alternative_music_arr_[i]));
     }
@@ -137,7 +146,7 @@ Repeat_engraver::do_process_requests ()
 void 
 Repeat_engraver::do_pre_move_processing ()
 {
-  Moment now = now_moment ();
+  Moment now = now_mom ();
   for (int i = bar_b_arr_.size (); i--; )
     {
       if (bar_b_arr_[i])
@@ -161,29 +170,7 @@ Repeat_engraver::do_pre_move_processing ()
          alternative_music_arr_.del (i);
          alternative_start_mom_arr_.del (i);
          alternative_stop_mom_arr_.del (i);
+         alternative_str_arr_.del (i);
        }
     }
 }
-
-void 
-Repeat_engraver::do_post_move_processing ()
-{
-#if 0
-  Time_description const *time = get_staff_info().time_C_;
-  Moment now = now_moment ();
-  for (int i = volta_p_arr_.size (); i--; )
-    {
-      if ((now > alternative_stop_mom_arr_[i])
-         && !time->whole_in_measure_)
-        {
-         volta_p_arr_[i] = 0;
-         volta_p_arr_.del (i);
-         alternative_music_arr_[i] = 0;
-         alternative_music_arr_.del (i);
-         alternative_start_mom_arr_.del (i);
-         alternative_stop_mom_arr_.del (i);
-       }
-    }
-#endif
-}
-