]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/percent-repeat-engraver.cc
* lily/side-position-interface.cc: remove add_staff_support ()
[lilypond.git] / lily / percent-repeat-engraver.cc
index b063ad46603f8399b47daae86cc85f7023bae8d0..837c82ce189129a8f31a04a8a433666e5eb197b5 100644 (file)
@@ -3,7 +3,7 @@
   
   source file of the GNU LilyPond music typesetter
   
-  (c) 2000--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c) 2000--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
   
  */
 
 #include "spanner.hh"
 #include "item.hh"
 #include "percent-repeat-iterator.hh"
+#include "bar-line.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_;
 
@@ -48,18 +51,16 @@ protected:
 
   enum {
     UNKNOWN,
-    BEAT,
     MEASURE,
     DOUBLE_MEASURE,
   } repeat_sign_type_ ;
-  
-  Spanner * perc_p_;
-  Spanner * finished_perc_p_;
-  Item * stem_tremolo_;
+
+  Item * double_percent_;
+  Spanner * perc_;
+  Spanner * finished_perc_;
 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 ();
@@ -67,9 +68,11 @@ protected:
 
 Percent_repeat_engraver::Percent_repeat_engraver ()
 {
-  perc_p_  = finished_perc_p_ = 0;
+  perc_  = 0;
+  finished_perc_ = 0;
   repeat_ =0;
-  stem_tremolo_ = 0;
+
+  double_percent_ = 0;
 }
 
 bool
@@ -78,10 +81,10 @@ Percent_repeat_engraver::try_music (Music * m)
   Repeated_music * rp = dynamic_cast<Repeated_music*> (m);
   if (rp
       && rp->get_mus_property ("iterator-ctor")
-         == Percent_repeat_iterator::constructor_cxx_function
+         == Percent_repeat_iterator::constructor_proc
       && !repeat_)
     {
-      body_length_ = rp->body_length_mom ();
+      body_length_ = rp->body_get_length ();
       int count =   rp->repeat_count ();
       
       Moment now = now_mom ();
@@ -89,41 +92,30 @@ 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_)
-       repeat_sign_type_ = BEAT;
+      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;
 
       
-      Global_translator *global_l =0;
-      Translator *t = this;
-      do
-       {
-         t = t->daddy_trans_l_ ;
-         global_l = dynamic_cast<Global_translator*> (t);
-       }
-      while (!global_l);
-
+      Global_translator *global =top_engraver();
       for (int i = 0; i < count; i++)  
-       global_l->add_moment_to_process (now + Moment (1+i) * body_length_);
+       global->add_moment_to_process (next_moment_ + Moment (i) * body_length_);
   
       return true;
     }
@@ -136,62 +128,76 @@ Percent_repeat_engraver::process_music ()
 {
   if (repeat_ && now_mom () == next_moment_)
     {
-      if (repeat_sign_type_ == BEAT)
-       {
-         ;
-       }
-      else if (repeat_sign_type_ == MEASURE)
+      if (repeat_sign_type_ == MEASURE)
        {
-         finished_perc_p_ = perc_p_;
+         finished_perc_ = perc_;
          typeset_perc ();
-         perc_p_ = new Spanner (get_property ("PercentRepeat"));
+         perc_ = make_spanner ("PercentRepeat");
          SCM col =get_property ("currentCommandColumn");
-         perc_p_->set_bound (LEFT, unsmob_grob (col));
-         announce_grob (perc_p_, repeat_);
+         perc_->set_bound (LEFT, unsmob_grob (col));
+         announce_grob(perc_, repeat_->self_scm());
        }
+      else if (repeat_sign_type_ == DOUBLE_MEASURE)
+       {
+         double_percent_ = make_item ("DoublePercentRepeat");
+         announce_grob(double_percent_, repeat_->self_scm());
+
+      /*
+       forbid breaks on a % line. Should forbid all breaks, really.
+       */
 
+           top_engraver()->forbid_breaks ();   // guh. Use properties!      
+       }
       next_moment_ = next_moment_ + body_length_;
+
+      top_engraver()->add_moment_to_process (next_moment_);
     }
 }
+
 void
 Percent_repeat_engraver::finalize ()
 {
   typeset_perc ();
-  if (perc_p_)
+  if (perc_)
     {
-      repeat_->origin ()->warning (_ ("unterminated chord tremolo"));
-      perc_p_->suicide ();
+      repeat_->origin ()->warning (_ ("unterminated percent repeat"));
+      perc_->suicide ();
     }
 }
 
 void
 Percent_repeat_engraver::typeset_perc ()
 {
-  if (finished_perc_p_)
+  if (finished_perc_)
     {
       SCM col =get_property ("currentCommandColumn");
-      finished_perc_p_->set_bound (RIGHT, unsmob_grob (col));
-      typeset_grob (finished_perc_p_);
-      finished_perc_p_ = 0;
+      finished_perc_->set_bound (RIGHT, unsmob_grob (col));
+      typeset_grob (finished_perc_);
+      finished_perc_ = 0;
+    }
+
+  if (double_percent_)
+    {
+      typeset_grob (double_percent_);
+      double_percent_ = 0;
     }
 }
 
 
-void
-Percent_repeat_engraver::acknowledge_grob (Grob_info info)
-{
-}
 
 
 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_)
+       {
+         finished_perc_ = perc_;
+         typeset_perc ();
+       }
       repeat_ = 0;
-      perc_p_ = 0;
+      perc_ = 0;
       repeat_sign_type_ = UNKNOWN;
     }
 }
@@ -203,6 +209,13 @@ Percent_repeat_engraver::stop_translation_timestep ()
   typeset_perc ();
 }
 
-ADD_THIS_TRANSLATOR (Percent_repeat_engraver);
 
 
+
+ENTER_DESCRIPTION(Percent_repeat_engraver,
+/* descr */       "Make whole bar and double bar repeats.",
+/* creats*/       "PercentRepeat DoublePercentRepeat",
+/* accepts */     "repeated-music",
+/* acks  */      "",
+/* reads */       "measureLength currentCommandColumn",
+/* write */       "");