]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/multi-measure-rest-engraver.cc
release: 1.3.142
[lilypond.git] / lily / multi-measure-rest-engraver.cc
index d72da1d4f0e545863f2bb217a95893583c893c09..9720596664caa40c5b69bea10c17a21161d571f9 100644 (file)
 /*
   multi_measure_rest-engraver.cc -- implement Multi_measure_rest_engraver
 
-  (c) 1998 Jan Nieuwenhuizen <janneke@gnu.org>
+  (c) 1998--2001 Jan Nieuwenhuizen <janneke@gnu.org>
        Han-Wen Nienhuys <hanwen@cs.uu.nl>
 */
 
-#include "proto.hh"
 #include "musical-request.hh"
 #include "multi-measure-rest.hh"
-#include "multi-measure-rest-engraver.hh"
-#include "score-column.hh"
-#include "time-description.hh"
+#include "paper-column.hh"
+#include "engraver-group-engraver.hh"
+#include "bar.hh"
+#include "staff-symbol-referencer.hh"
+#include "engraver.hh"
+#include "moment.hh"
+#include "spanner.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 ();
+
+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_;
+  Span_req * busy_span_req_l_;
+  Span_req * stop_req_l_;
+  int start_measure_i_;
+  Moment start_moment_;
+  
+  Spanner *mmrest_p_;
+  Spanner *lastrest_p_;
+};
 
-IMPLEMENT_IS_TYPE_B1 (Multi_measure_rest_engraver, Engraver);
 ADD_THIS_TRANSLATOR (Multi_measure_rest_engraver);
 
 Multi_measure_rest_engraver::Multi_measure_rest_engraver ()
 {
   start_measure_i_ = 0;
-  rest_item_creation_mom_ = rest_req_stop_mom_ =0;
-  multi_measure_req_l_ = 0;
-  mmrest_p_ = 0;
+  mmrest_p_  = lastrest_p_ =0;
+  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::do_try_request (Request* req_l)
+Multi_measure_rest_engraver::try_music (Music* req_l)
 {
- if (Multi_measure_rest_req *mr = dynamic_cast<Multi_measure_rest_req *> (req_l))
-   {
-     if (multi_measure_req_l_)
-       if (!multi_measure_req_l_->equal_b (req_l)
-          || req_start_mom_ != now_moment ())
-        return false;
-  
-     multi_measure_req_l_ = mr;
-     req_start_mom_ = now_moment ();
-     
-     rest_req_stop_mom_ = req_start_mom_ + multi_measure_req_l_->duration_.length ();
-     return true;
-   }
- return false;
+  if (Span_req * sp = dynamic_cast<Span_req*> (req_l))
+    {
+      
+      if (scm_equal_p (sp->get_mus_property ("span-type"),
+                      ly_str02scm ("rest")) == SCM_BOOL_T)
+       {
+         if (sp->get_span_dir () == STOP)
+           {
+             stop_req_l_ = sp;
+           }
+         else if (sp->get_span_dir () == START && !new_req_l_)
+           {
+             new_req_l_ = sp;
+           }
+         return true;
+       }
+    }
+  return false;
 }
 
 void
-Multi_measure_rest_engraver::do_process_requests ()
+Multi_measure_rest_engraver::process_music ()
 {
-  if (multi_measure_req_l_ && !mmrest_p_)
+  if (new_req_l_ && stop_req_l_)
+    stop_req_l_ = 0;
+
+  if (new_req_l_)
+    start_moment_ = now_mom ();
+
+  if (stop_req_l_)
     {
-      Time_description const *time = get_staff_info().time_C_;
-      mmrest_p_ = new Multi_measure_rest;
-      rest_item_creation_mom_ =  time->when_mom ();
-      announce_element (Score_element_info (mmrest_p_, multi_measure_req_l_));
-      start_measure_i_ = time->bars_i_;
+      busy_span_req_l_ =0;
+      stop_req_l_ = 0;
     }
+  
+  if (new_req_l_)
+    {
+      busy_span_req_l_ = new_req_l_;
+      new_req_l_ =0;
+    }
+
 }
 
 void
-Multi_measure_rest_engraver::do_pre_move_processing ()
+Multi_measure_rest_engraver::create_grobs ()
 {
-  Moment now (now_moment ());
-  if (mmrest_p_ && rest_item_creation_mom_ == now)
+
+  if (busy_span_req_l_ && !mmrest_p_)
     {
-      typeset_element (mmrest_p_);
+      mmrest_p_ = new Spanner (get_property ("MultiMeasureRest"));
+
+      Multi_measure_rest::set_interface (mmrest_p_);
+      Staff_symbol_referencer::set_interface (mmrest_p_);
+
+      announce_grob (mmrest_p_, busy_span_req_l_);
+      start_measure_i_
+       = gh_scm2int (get_property ("currentBarNumber"));
     }
 }
 
 void
-Multi_measure_rest_engraver::do_post_move_processing ()
+Multi_measure_rest_engraver::stop_translation_timestep ()
 {
-  Time_description const *time = get_staff_info().time_C_;
-  Moment now (now_moment ());
-  if (rest_req_stop_mom_ <= now)
-    multi_measure_req_l_ = 0;
+  SCM smp = get_property ("measurePosition");
+  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))
+    {
+      typeset_grob (mmrest_p_);
+      /*
+       we must keep mmrest_p_ around to set measure-count.
+       */
+    }
+
+  if (lastrest_p_)
+    {
+      /* sanity check */
+      if (scm_ilength (lastrest_p_->get_grob_property ("columns")) >= 2
+         && 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;
+    }
+
+  if (new_req_l_)
+    {
+      busy_span_req_l_ = new_req_l_;
+      new_req_l_ =0;
+    }
+  
+}
 
-  if (mmrest_p_ && (!time->whole_in_measure_ || !multi_measure_req_l_))
+void
+Multi_measure_rest_engraver::start_translation_timestep ()
+{
+  SCM smp = get_property ("measurePosition");
+  Moment mp = (unsmob_moment (smp)) ? *unsmob_moment (smp) : Moment (0);
+  
+  if (mmrest_p_ && !mp)
     {
-      assert (rest_item_creation_mom_ < now);
-      mmrest_p_->measures_i_ = time->bars_i_ - start_measure_i_;
+      lastrest_p_ = mmrest_p_;
+      int cur = gh_scm2int (get_property ("currentBarNumber"));
+      lastrest_p_->set_grob_property ("measure-count",
+                                    gh_int2scm (cur - start_measure_i_));
       mmrest_p_ = 0;
     }
 }
+
+
+void
+Multi_measure_rest_engraver::finalize ()
+{
+  if (mmrest_p_)
+    typeset_grob (mmrest_p_);
+  if (lastrest_p_)
+    typeset_grob (lastrest_p_);
+}