]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/multi-measure-rest-engraver.cc
``slikken kreng''
[lilypond.git] / lily / multi-measure-rest-engraver.cc
index 552865111bdd9c3073a09fd84827b1d196354e3f..38318d19b952e5109b72739b5413fe7bf9f60f8a 100644 (file)
@@ -1,7 +1,7 @@
 /*
   multi_measure_rest-engraver.cc -- implement Multi_measure_rest_engraver
 
-  (c) 1998--2000 Jan Nieuwenhuizen <janneke@gnu.org>
+  (c) 1998--2002 Jan Nieuwenhuizen <janneke@gnu.org>
        Han-Wen Nienhuys <hanwen@cs.uu.nl>
 */
 
@@ -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_element (Score_element_info i);
-  virtual void do_process_music ();
-  virtual bool do_try_music (Music*);
-  virtual void do_pre_move_processing ();
-  virtual void do_post_move_processing ();
-  virtual void do_removal_processing ();
+  virtual bool try_music (Music*);
+  virtual void process_music ();
+  virtual void stop_translation_timestep ();
+  virtual void start_translation_timestep ();
+  virtual void finalize ();
+
 private:
-  Span_req * new_req_l_;
-  Span_req * busy_span_req_l_;
-  Span_req * stop_req_l_;
-  int start_measure_i_;
+  Span_req * new_req_;
+  Span_req * busy_span_req_;
+  Span_req * stop_req_;
+  int start_measure_;
   Moment start_moment_;
   
-  Spanner *mmrest_p_;
-  Spanner *lastrest_p_;
+  Spanner *mmrest_;
+  Spanner *lastrest_;
 };
 
-ADD_THIS_TRANSLATOR (Multi_measure_rest_engraver);
+
 
 Multi_measure_rest_engraver::Multi_measure_rest_engraver ()
 {
-  start_measure_i_ = 0;
-  mmrest_p_  = lastrest_p_ =0;
-  new_req_l_ = busy_span_req_l_ = stop_req_l_ =0;
+  start_measure_ = 0;
+  mmrest_  = lastrest_ =0;
+  new_req_ = busy_span_req_ = stop_req_ =0;
 }
 
-void
-Multi_measure_rest_engraver::acknowledge_element (Score_element_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::do_try_music (Music* req_l)
+Multi_measure_rest_engraver::try_music (Music* req)
 {
-  if (Span_req * sp = dynamic_cast<Span_req*> (req_l))
+  if (Span_req * sp = dynamic_cast<Span_req*> (req))
     {
-      if (sp->span_type_str_ == "rest")
+      
+      if (scm_equal_p (sp->get_mus_property ("span-type"),
+                      ly_str02scm ("rest")) == SCM_BOOL_T)
        {
-         if (sp->span_dir_ == STOP)
+         if (sp->get_span_dir () == STOP)
            {
-             stop_req_l_ = sp;
+             stop_req_ = sp;
            }
-         else if (sp->span_dir_ == START && !new_req_l_)
+         else if (sp->get_span_dir () == START && !new_req_)
            {
-             new_req_l_ = sp;
+             new_req_ = sp;
            }
          return true;
        }
@@ -89,93 +75,112 @@ Multi_measure_rest_engraver::do_try_music (Music* req_l)
   return false;
 }
 
-
-
 void
-Multi_measure_rest_engraver::do_process_music ()
+Multi_measure_rest_engraver::process_music ()
 {
-  if (new_req_l_ && stop_req_l_)
-    stop_req_l_ = 0;
+  if (new_req_ && stop_req_)
+    stop_req_ = 0;
 
-  if (new_req_l_)
+  if (new_req_)
     start_moment_ = now_mom ();
 
-  if (stop_req_l_)
+  if (stop_req_)
     {
-      busy_span_req_l_ =0;
-      stop_req_l_ = 0;
+      busy_span_req_ =0;
+      stop_req_ = 0;
     }
   
-  if (new_req_l_)
+  if (new_req_)
     {
-      busy_span_req_l_ = new_req_l_;
-      new_req_l_ =0;
+      busy_span_req_ = new_req_;
+      new_req_ =0;
     }
 
-  if (busy_span_req_l_ && !mmrest_p_)
+  if (busy_span_req_ && !mmrest_)
     {
-      mmrest_p_ = new Spanner (get_property ("basicMultiMeasureRestProperties"));
+      mmrest_ = new Spanner (get_property ("MultiMeasureRest"));
 
-      Multi_measure_rest::set_interface (mmrest_p_);
-      Staff_symbol_referencer::set_interface (mmrest_p_);
-
-      announce_element (mmrest_p_, busy_span_req_l_);
-      start_measure_i_
+      announce_grob(mmrest_, busy_span_req_->self_scm());
+      start_measure_
        = 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_)
+       add_bound_item (mmrest_, it);
+      if (lastrest_)
+       add_bound_item (lastrest_,it);
+    }
 }
 
 void
-Multi_measure_rest_engraver::do_pre_move_processing ()
+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_elt_property ("columns")) >= 2))
+  if (mmrest_ && (now_mom () >= start_moment_) 
+      && !mp.to_bool ()
+      && mmrest_->get_bound (LEFT) && mmrest_->get_bound (RIGHT))
     {
-      typeset_element (mmrest_p_);
+      typeset_grob (mmrest_);
       /*
-       must keep mmrest_p_ around to set measures_i_
+       we must keep mmrest_ around to set measure-count, so
+       no mmrest_ = 0 here. 
        */
     }
-  if (lastrest_p_)
+
+  if (lastrest_)
     {
-      typeset_element (lastrest_p_);
-      lastrest_p_ = 0;
+      /* sanity check */
+      if (lastrest_->get_bound (LEFT) && lastrest_->get_bound (RIGHT)
+         && lastrest_->get_bound (LEFT) != lastrest_->get_bound (RIGHT))
+       typeset_grob (lastrest_);
+      lastrest_ = 0;
     }
 
-  if (new_req_l_)
+  if (new_req_)
     {
-      busy_span_req_l_ = new_req_l_;
-      new_req_l_ =0;
+      busy_span_req_ = new_req_;
+      new_req_ =0;
     }
   
 }
 
 void
-Multi_measure_rest_engraver::do_post_move_processing ()
+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_ && !mp.to_bool ())
     {
-      lastrest_p_ = mmrest_p_;
+      lastrest_ = mmrest_;
       int cur = gh_scm2int (get_property ("currentBarNumber"));
-      lastrest_p_->set_elt_property ("measure-count",
-                                    gh_int2scm (cur - start_measure_i_));
-      mmrest_p_ = 0;
+      lastrest_->set_grob_property ("measure-count",
+                                    gh_int2scm (cur - start_measure_));
+      mmrest_ = 0;
     }
 }
 
 
 void
-Multi_measure_rest_engraver::do_removal_processing ()
+Multi_measure_rest_engraver::finalize ()
 {
-  if (mmrest_p_)
-    typeset_element (mmrest_p_);
-  if (lastrest_p_)
-    typeset_element (lastrest_p_);
+  if (mmrest_)
+    typeset_grob (mmrest_);
+  if (lastrest_)
+    typeset_grob (lastrest_);
 }
+
+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 */       "");