]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/percent-repeat-engraver.cc
release: 1.5.22
[lilypond.git] / lily / percent-repeat-engraver.cc
index b063ad46603f8399b47daae86cc85f7023bae8d0..7dac5fc84d7b8f7641af8d2fe1763e84987aa599 100644 (file)
 #include "spanner.hh"
 #include "item.hh"
 #include "percent-repeat-iterator.hh"
+#include "bar.hh"
+
+#include "score-engraver.hh"
+#include "translator-group.hh"
 
 /**
   This acknowledges repeated music with "percent" style.  It typesets
@@ -32,8 +36,7 @@ class Percent_repeat_engraver : public Engraver
 {
   void typeset_perc ();
 public:
-  VIRTUAL_COPY_CONS (Translator);
-  Percent_repeat_engraver ();
+  TRANSLATOR_DECLARATIONS(Percent_repeat_engraver);
 protected:
   Repeated_music * repeat_;
 
@@ -52,14 +55,15 @@ protected:
     MEASURE,
     DOUBLE_MEASURE,
   } repeat_sign_type_ ;
-  
+
+  Item * beat_slash_;
+  Item * double_percent_;
   Spanner * perc_p_;
   Spanner * finished_perc_p_;
   Item * stem_tremolo_;
 protected:
   virtual void finalize ();
   virtual bool try_music (Music*);
-  virtual void acknowledge_grob (Grob_info);
   virtual void stop_translation_timestep ();
   virtual void start_translation_timestep ();
   virtual void process_music ();
@@ -70,6 +74,9 @@ Percent_repeat_engraver::Percent_repeat_engraver ()
   perc_p_  = finished_perc_p_ = 0;
   repeat_ =0;
   stem_tremolo_ = 0;
+
+  beat_slash_ = 0;
+  double_percent_ = 0;
 }
 
 bool
@@ -89,25 +96,25 @@ Percent_repeat_engraver::try_music (Music * m)
       stop_mom_ = start_mom_ + Moment (count) * body_length_;
       next_moment_ = start_mom_ + body_length_;
 
-      SCM m = get_property ("timeSignatureFraction");
-      Moment mlen (1,
-                 gh_scm2int (gh_cdr (m)));
+      SCM m = get_property ("measureLength");
+      Moment meas_len;
+      if (unsmob_moment (m))
+       meas_len = *unsmob_moment (m);
 
-      if (mlen == body_length_)
+      if (body_length_ < meas_len &&
+         meas_len.main_part_.mod_rat (body_length_.main_part_) == Moment (Rational (0,0)))
        repeat_sign_type_ = BEAT;
+      else if (meas_len == body_length_)
+       repeat_sign_type_ = MEASURE;
+      else if (Moment (2)* meas_len == body_length_)
+       {
+         repeat_sign_type_ = DOUBLE_MEASURE;
+         next_moment_ += meas_len ;
+       }
       else
        {
-         mlen *= gh_scm2int (gh_car (m));
-         if (mlen == body_length_)
-           repeat_sign_type_ = MEASURE;
-         else if (Moment (2)* mlen == body_length_)
-           repeat_sign_type_ = DOUBLE_MEASURE;
-
-         if (repeat_sign_type_ != MEASURE)
-           {
-             warning (_ ("Don't know yet how to handle this percent repeat."));
-             return false;
-           }
+         warning (_ ("Don't know how to handle a percent repeat of this length."));
+         return false;
        }
 
       repeat_ = rp;
@@ -138,7 +145,8 @@ Percent_repeat_engraver::process_music ()
     {
       if (repeat_sign_type_ == BEAT)
        {
-         ;
+         beat_slash_ = new Item (get_property ("RepeatSlash"));
+         announce_grob (beat_slash_, repeat_);
        }
       else if (repeat_sign_type_ == MEASURE)
        {
@@ -149,10 +157,22 @@ Percent_repeat_engraver::process_music ()
          perc_p_->set_bound (LEFT, unsmob_grob (col));
          announce_grob (perc_p_, repeat_);
        }
+      else if (repeat_sign_type_ == DOUBLE_MEASURE)
+       
+       {
+         double_percent_ = new Item (get_property ("DoublePercentRepeat"));
+         announce_grob (double_percent_, repeat_);
+
+      /*
+       forbid breaks on a % line. Should forbid all breaks, really.
+       */
 
+           top_engraver()->forbid_breaks ();   // guh. Use properties!      
+       }
       next_moment_ = next_moment_ + body_length_;
     }
 }
+
 void
 Percent_repeat_engraver::finalize ()
 {
@@ -174,22 +194,33 @@ Percent_repeat_engraver::typeset_perc ()
       typeset_grob (finished_perc_p_);
       finished_perc_p_ = 0;
     }
-}
 
+  if (beat_slash_)
+    {
+      typeset_grob (beat_slash_);
+      beat_slash_ = 0;
+    }
 
-void
-Percent_repeat_engraver::acknowledge_grob (Grob_info info)
-{
+  if (double_percent_)
+    {
+      typeset_grob (double_percent_);
+      double_percent_ = 0;
+    }
 }
 
 
+
+
 void
 Percent_repeat_engraver::start_translation_timestep ()
 {
-  if (perc_p_ && stop_mom_ == now_mom ())
+  if (stop_mom_ == now_mom ())
     {
-      finished_perc_p_ = perc_p_;
-      typeset_perc ();
+      if (perc_p_)
+       {
+         finished_perc_p_ = perc_p_;
+         typeset_perc ();
+       }
       repeat_ = 0;
       perc_p_ = 0;
       repeat_sign_type_ = UNKNOWN;
@@ -203,6 +234,12 @@ Percent_repeat_engraver::stop_translation_timestep ()
   typeset_perc ();
 }
 
-ADD_THIS_TRANSLATOR (Percent_repeat_engraver);
 
 
+
+ENTER_DESCRIPTION(Percent_repeat_engraver,
+/* descr */       "Make beat, whole bar and double bar repeats.",
+/* creats*/       "PercentRepeat RepeatSlash DoublePercentRepeat",
+/* acks  */       "",
+/* reads */       "measureLength currentCommandColumn",
+/* write */       "");