]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/percent-repeat-engraver.cc
(class Phrasing_slur_engraver):
[lilypond.git] / lily / percent-repeat-engraver.cc
index 8b5c04f5300624cd6ff7db8b9dfb3b3a505eedbc..d68a44e274eee71e4cb13da8f1ac6b7547b920db 100644 (file)
@@ -1,11 +1,10 @@
-/*   
-  new-chord-tremolo-engraver.cc --  implement Chord_tremolo_engraver
-  
+/*
+  new-chord-tremolo-engraver.cc -- implement Chord_tremolo_engraver
+
   source file of the GNU LilyPond music typesetter
-  
-  (c) 2000--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
-  
- */
+
+  (c) 2000--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+*/
 
 #include "repeated-music.hh"
 #include "global-context.hh"
 #include "score-engraver.hh"
 
 /**
-  This acknowledges repeated music with "percent" style.  It typesets
-  a % sign.  
+   This acknowledges repeated music with "percent" style.  It typesets
+   a % sign.
 
-  TODO:
+   TODO:
 
-  - BEAT case: Create items for single beat repeats, i.e. c4 / / /
+   - BEAT case: Create items for single beat repeats, i.e. c4 / / /
 
-  - DOUBLE_MEASURE case: attach a % to an appropriate barline.
-  
+   - DOUBLE_MEASURE case: attach a % to an appropriate barline.
 */
 class Percent_repeat_engraver : public Engraver
 {
@@ -34,7 +32,7 @@ class Percent_repeat_engraver : public Engraver
 public:
   TRANSLATOR_DECLARATIONS (Percent_repeat_engraver);
 protected:
-  Repeated_music * repeat_;
+  Music *repeat_;
 
   /// moment (global time) where beam started.
   Moment start_mom_;
@@ -45,44 +43,45 @@ protected:
   Moment next_moment_;
   Moment body_length_;
 
-  enum {
-    UNKNOWN,
-    MEASURE,
-    DOUBLE_MEASURE,
-  } repeat_sign_type_ ;
+  enum
+    {
+      UNKNOWN,
+      MEASURE,
+      DOUBLE_MEASURE,
+    }
+    repeat_sign_type_;
 
-  Item * double_percent_;
-  Spanner * perc_;
-  Spanner * finished_perc_;
+  Item *double_percent_;
+  Spanner *perc_;
+  Spanner *finished_perc_;
 protected:
   virtual void finalize ();
-  virtual bool try_music (Music*);
-  virtual void stop_translation_timestep ();
-  virtual void start_translation_timestep ();
-  virtual void process_music ();
+  virtual bool try_music (Music *);
+  void stop_translation_timestep ();
+  void start_translation_timestep ();
+  void process_music ();
 };
 
 Percent_repeat_engraver::Percent_repeat_engraver ()
 {
-  perc_  = 0;
+  perc_ = 0;
   finished_perc_ = 0;
-  repeat_ =0;
+  repeat_ = 0;
 
   double_percent_ = 0;
 }
 
 bool
-Percent_repeat_engraver::try_music (Music * m)
+Percent_repeat_engraver::try_music (Music *m)
 {
-  Repeated_music * rp = dynamic_cast<Repeated_music*> (m);
-  if (rp
-      && rp->get_property ("iterator-ctor")
-         == Percent_repeat_iterator::constructor_proc
+  if (m->is_mus_type ("repeated-music")
+      && m->get_property ("iterator-ctor")
+      == Percent_repeat_iterator::constructor_proc
       && !repeat_)
     {
-      body_length_ = rp->body_get_length ();
-      int count =   rp->repeat_count ();
-      
+      body_length_ = Repeated_music::body_get_length (m);
+      int count = Repeated_music::repeat_count (m);
+
       Moment now = now_mom ();
       start_mom_ = now;
       stop_mom_ = start_mom_ + Moment (count) * body_length_;
@@ -91,33 +90,33 @@ Percent_repeat_engraver::try_music (Music * m)
       Moment meas_len (robust_scm2moment (get_property ("measureLength"), Moment (1)));
       if (meas_len == body_length_)
        repeat_sign_type_ = MEASURE;
-      else if (Moment (2)* meas_len == body_length_)
+      else if (Moment (2) * meas_len == body_length_)
        {
          repeat_sign_type_ = DOUBLE_MEASURE;
-         next_moment_ += meas_len ;
        }
       else
        {
-         warning (_ ("Don't know how to handle a percent repeat of this length."));
+         warning (_f ("can't handle a percent repeat of length: %s",
+                      body_length_.to_string ()));
          return false;
        }
 
-      repeat_ = rp;
+      repeat_ = m;
 
-      
       Global_context *global = get_global_context ();
-      for (int i = 0; i < count; i++)  
+      for (int i = 1; i < count; i++)
        {
-         global->add_moment_to_process (next_moment_ + Moment (i) * body_length_);
+         Moment m = next_moment_ + Moment (i) * body_length_;
+         global->add_moment_to_process (m);
 
-         /*
-           bars between % too.
-          */
+         /* bars between % too.  */
          if (repeat_sign_type_ == DOUBLE_MEASURE)
-           global->add_moment_to_process (next_moment_ + meas_len + Moment (i) * body_length_);
-         
+           global->add_moment_to_process (m - meas_len);
        }
-  
+
+      if (repeat_sign_type_ == DOUBLE_MEASURE)
+       next_moment_ += meas_len;
+      
       return true;
     }
 
@@ -134,21 +133,22 @@ Percent_repeat_engraver::process_music ()
          finished_perc_ = perc_;
          typeset_perc ();
          perc_ = make_spanner ("PercentRepeat", repeat_->self_scm ());
-         SCM col =get_property ("currentCommandColumn");
+         SCM col = get_property ("currentCommandColumn");
          perc_->set_bound (LEFT, unsmob_grob (col));
        }
       else if (repeat_sign_type_ == DOUBLE_MEASURE)
        {
          double_percent_ = make_item ("DoublePercentRepeat", repeat_->self_scm ());
-      /*
-       forbid breaks on a % line. Should forbid all breaks, really.
-       */
+         
+         /*
+           forbid breaks on a % line. Should forbid all breaks, really.
 
-         get_score_engraver ()->forbid_breaks ();      // guh. Use properties!      
+           Ugh. Why can't this be regular communication between
+           contexts?
+         */
+         get_score_engraver ()->forbid_breaks ();
        }
       next_moment_ = next_moment_ + body_length_;
-
-      get_global_context ()->add_moment_to_process (next_moment_);
     }
 }
 
@@ -168,7 +168,7 @@ Percent_repeat_engraver::typeset_perc ()
 {
   if (finished_perc_)
     {
-      SCM col =get_property ("currentCommandColumn");
+      SCM col = get_property ("currentCommandColumn");
       finished_perc_->set_bound (RIGHT, unsmob_grob (col));
       finished_perc_ = 0;
     }
@@ -176,9 +176,6 @@ Percent_repeat_engraver::typeset_perc ()
   double_percent_ = 0;
 }
 
-
-
-
 void
 Percent_repeat_engraver::start_translation_timestep ()
 {
@@ -195,20 +192,17 @@ Percent_repeat_engraver::start_translation_timestep ()
     }
 }
 
-
 void
 Percent_repeat_engraver::stop_translation_timestep ()
 {
   typeset_perc ();
 }
 
+#include "translator.icc"
 
-
-
-ENTER_DESCRIPTION (Percent_repeat_engraver,
-/* descr */       "Make whole bar and double bar repeats.",
-/* creats*/       "PercentRepeat DoublePercentRepeat",
-/* accepts */     "repeated-music",
-/* acks  */      "",
-/* reads */       "measureLength currentCommandColumn",
-/* write */       "");
+ADD_TRANSLATOR (Percent_repeat_engraver,
+               /* doc */ "Make whole bar and double bar repeats.",
+               /* create */ "PercentRepeat DoublePercentRepeat",
+               /* accept */ "repeated-music",
+               /* read */ "measureLength currentCommandColumn",
+               /* write */ "");