]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/multi-measure-rest-engraver.cc
patch::: 1.5.22.jcn4
[lilypond.git] / lily / multi-measure-rest-engraver.cc
index 328b9a2d779ffa8729c0fe2df55d6eb074805941..239db9779fafb80fa5a5e5e7fa4d5e537da82199 100644 (file)
@@ -9,7 +9,7 @@
 #include "multi-measure-rest.hh"
 #include "paper-column.hh"
 #include "engraver-group-engraver.hh"
-#include "bar.hh"
+
 #include "staff-symbol-referencer.hh"
 #include "engraver.hh"
 #include "moment.hh"
 /**
    The name says it all: make multi measure rests 
 
-FIXME? The MM rest engraver must be able to see bar lines, so it won't
-work at Voice level. Not a problem in practice, but aesthetically pleasing? 
-
 */
 class Multi_measure_rest_engraver : public Engraver
 {
 public:
-  VIRTUAL_COPY_CONS(Translator);
-  Multi_measure_rest_engraver ();
+  TRANSLATOR_DECLARATIONS(Multi_measure_rest_engraver);
 
 protected:
-  virtual void acknowledge_grob (Grob_info i);
   virtual bool try_music (Music*);
   virtual void process_music ();
   virtual void stop_translation_timestep ();
   virtual void start_translation_timestep ();
   virtual void finalize ();
-  virtual void create_grobs ();
 
 private:
   Span_req * new_req_l_;
@@ -48,7 +42,7 @@ private:
   Spanner *lastrest_p_;
 };
 
-ADD_THIS_TRANSLATOR (Multi_measure_rest_engraver);
+
 
 Multi_measure_rest_engraver::Multi_measure_rest_engraver ()
 {
@@ -57,18 +51,6 @@ Multi_measure_rest_engraver::Multi_measure_rest_engraver ()
   new_req_l_ = busy_span_req_l_ = stop_req_l_ =0;
 }
 
-void
-Multi_measure_rest_engraver::acknowledge_grob (Grob_info i)
-{
-  Item * item = dynamic_cast<Item*> (i.elem_l_); 
-  if (item && Bar::has_interface (item))
-    {
-      if (mmrest_p_)
-       Multi_measure_rest::add_column (mmrest_p_,item);
-      if (lastrest_p_)
-       Multi_measure_rest::add_column (lastrest_p_,item);
-    }
-}
 
 bool
 Multi_measure_rest_engraver::try_music (Music* req_l)
@@ -79,11 +61,11 @@ Multi_measure_rest_engraver::try_music (Music* req_l)
       if (scm_equal_p (sp->get_mus_property ("span-type"),
                       ly_str02scm ("rest")) == SCM_BOOL_T)
        {
-         if (sp->get_span_dir() == STOP)
+         if (sp->get_span_dir () == STOP)
            {
              stop_req_l_ = sp;
            }
-         else if (sp->get_span_dir() == START && !new_req_l_)
+         else if (sp->get_span_dir () == START && !new_req_l_)
            {
              new_req_l_ = sp;
            }
@@ -96,7 +78,7 @@ Multi_measure_rest_engraver::try_music (Music* req_l)
 void
 Multi_measure_rest_engraver::process_music ()
 {
-    if (new_req_l_ && stop_req_l_)
+  if (new_req_l_ && stop_req_l_)
     stop_req_l_ = 0;
 
   if (new_req_l_)
@@ -114,12 +96,6 @@ Multi_measure_rest_engraver::process_music ()
       new_req_l_ =0;
     }
 
-}
-
-void
-Multi_measure_rest_engraver::create_grobs ()
-{
-
   if (busy_span_req_l_ && !mmrest_p_)
     {
       mmrest_p_ = new Spanner (get_property ("MultiMeasureRest"));
@@ -131,26 +107,41 @@ Multi_measure_rest_engraver::create_grobs ()
       start_measure_i_
        = gh_scm2int (get_property ("currentBarNumber"));
     }
+
+  if (gh_string_p (get_property ("whichBar")))
+    {
+      Grob *cmc = unsmob_grob (get_property( "currentCommandColumn"));
+      Item *it = dynamic_cast<Item*> (cmc);
+      if (mmrest_p_)
+       add_bound_item (mmrest_p_, it);
+      if (lastrest_p_)
+       add_bound_item (lastrest_p_,it);
+    }
 }
 
 void
 Multi_measure_rest_engraver::stop_translation_timestep ()
 {
   SCM smp = get_property ("measurePosition");
-  Moment mp =  (unsmob_moment (smp)) ? *unsmob_moment (smp) : Moment (0);
+  Moment mp = (unsmob_moment (smp)) ? *unsmob_moment (smp) : Moment (0);
 
   if (mmrest_p_ && (now_mom () >= start_moment_) 
-    && !mp
-    && (scm_ilength (mmrest_p_->get_grob_property ("columns")) >= 2))
+      && !mp.to_bool ()
+      && mmrest_p_->get_bound (LEFT) && mmrest_p_->get_bound (RIGHT))
     {
       typeset_grob (mmrest_p_);
       /*
-       we must keep mmrest_p_ around to set measure-count.
+       we must keep mmrest_p_ around to set measure-count, so
+       no mmrest_p_ = 0 here. 
        */
     }
+
   if (lastrest_p_)
     {
-      typeset_grob (lastrest_p_);
+      /* sanity check */
+      if (lastrest_p_->get_bound (LEFT) && lastrest_p_->get_bound (RIGHT)
+         && lastrest_p_->get_bound (LEFT) != lastrest_p_->get_bound (RIGHT))
+       typeset_grob (lastrest_p_);
       lastrest_p_ = 0;
     }
 
@@ -166,9 +157,9 @@ void
 Multi_measure_rest_engraver::start_translation_timestep ()
 {
   SCM smp = get_property ("measurePosition");
-  Moment mp =  (unsmob_moment (smp)) ? *unsmob_moment (smp) : Moment (0);
+  Moment mp = (unsmob_moment (smp)) ? *unsmob_moment (smp) : Moment (0);
   
-  if (mmrest_p_ && !mp)
+  if (mmrest_p_ && !mp.to_bool ())
     {
       lastrest_p_ = mmrest_p_;
       int cur = gh_scm2int (get_property ("currentBarNumber"));
@@ -187,3 +178,12 @@ Multi_measure_rest_engraver::finalize ()
   if (lastrest_p_)
     typeset_grob (lastrest_p_);
 }
+
+ENTER_DESCRIPTION(Multi_measure_rest_engraver,
+/* descr */       "Engraves multi-measure rests that are produced with @code{R}.  Reads
+measurePosition and currentBarNumber to determine what number to print over the MultiMeasureRest
+",
+/* creats*/       "MultiMeasureRest",
+/* acks  */       "",
+/* reads */       "currentBarNumber currentCommandColumn measurePosition",
+/* write */       "");