]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/timing-engraver.cc
* lily/span-bar.cc (print): sort bar line extents. Fixes problem
[lilypond.git] / lily / timing-engraver.cc
index feb368ba3665018d8046541c8404f2f926aaf419..1c30fcd34f085bb5ba56a07d408e7d1f7648dd01 100644 (file)
 /*
-  timing-grav.cc -- implement Timing_engraver
+  timing-engraver.cc -- implement Timing_engraver
 
   source file of the GNU LilyPond music typesetter
 
-  (c)  1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c) 1997--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 */
 
-#include "score-engraver.hh"
-#include "timing-engraver.hh"
-#include "command-request.hh"
-#include "score-element-info.hh"
+#include "timing-translator.hh"
+#include "engraver.hh"
+
+#include "context.hh"
 #include "multi-measure-rest.hh"
+#include "grob.hh"
+#include "warn.hh"
 
 
+class Timing_engraver : public Timing_translator, public Engraver
+{
+protected:
+  /* Need to know whether we're advancing in grace notes, or not. */
+  Moment last_moment_;
 
-ADD_THIS_TRANSLATOR(Timing_engraver);
+  virtual void start_translation_timestep ();
+  virtual void process_music ();
+  virtual void stop_translation_timestep ();
 
+public:
+  TRANSLATOR_DECLARATIONS (Timing_engraver);
+};
 
-void
-Timing_engraver::do_post_move_processing( )
+ADD_TRANSLATOR (Timing_engraver,
+               /* descr */ " Responsible for synchronizing timing information from staves.  "
+               "Normally in @code{Score}.  In order to create polyrhythmic music, "
+               "this engraver should be removed from @code{Score} and placed in "
+               "@code{Staff}. "
+               "\n\nThis engraver adds the alias @code{Timing} to its containing context.",
+               /* creats*/ "",
+               /* accepts */ "",
+               /* acks  */ "",
+               /* reads */ "automaticBars whichBar barAlways defaultBarType "
+               "skipBars timing measureLength measurePosition currentBarNumber",
+               /* write */ "");
+
+
+Timing_engraver::Timing_engraver ()
 {
-  bar_req_l_ = 0;
-  Timing_translator::do_post_move_processing ();
+  last_moment_.main_part_ = Rational (-1);
 }
 
-bool
-Timing_engraver::do_try_music (Music*m)
+void
+Timing_engraver::process_music ()
 {
-  if (Bar_req  * b= dynamic_cast <Bar_req *> (m))
+  Timing_translator::process_music ();
+
+  bool start_of_measure = (last_moment_.main_part_ != now_mom ().main_part_
+                          && !measure_position ().main_part_);
+
+  /*
+    We can't do this in start_translation_timestep(), since time sig
+    changes won't have happened by then.
+  */
+  if (start_of_measure)
     {
-      if (bar_req_l_ && bar_req_l_->equal_b (b)) // huh?
-       return false;
-      
-      bar_req_l_ = b;
-      return true;
+      Moment mlen = Moment (measure_length ());
+      Grob * column = unsmob_grob (get_property ("currentCommandColumn"));
+      if (column)
+       column->set_property ("measure-length", mlen.smobbed_copy ());
+      else
+       programming_error("No command column?");
     }
-  
-  return Timing_translator::do_try_music (m);
 }
 
-
-String
-Timing_engraver::which_bar ()
+void
+Timing_engraver::start_translation_timestep ()
 {
-  if (!bar_req_l_)
+  Timing_translator::start_translation_timestep ();
+
+  SCM automatic_bars = get_property ("automaticBars");
+  Moment now = now_mom ();
+  SCM which = get_property ("whichBar");
+
+  /* Set the first bar of the score? */
+  if (!scm_is_string (which))
+    which = SCM_EOL;
+
+  Moment mp = measure_position ();
+  bool start_of_measure = (last_moment_.main_part_ != now.main_part_
+                          && !mp.main_part_);
+
+  if (!scm_is_string (which) && to_boolean (automatic_bars))
     {
-      if (!now_mom ())
-       return "|";
+      SCM always = get_property ("barAlways");
 
-      SCM nonauto = get_property ("barNonAuto", 0);
-      if (!to_boolean (nonauto))
+      if ((start_of_measure && last_moment_.main_part_ >= Moment (0))
+         || to_boolean (always))
        {
-         SCM always = get_property ("barAlways", 0);
-         if (!measure_position ()
-             || (to_boolean (always)))
-           {
-             SCM def=get_property ("defaultBarType" ,0);
-             return (gh_string_p (def))? ly_scm2string (def) : "";
-           }
+         /* should this work, or be junked?  See input/bugs/no-bars.ly */
+         which = get_property ("defaultBarType");
        }
-      return "";
-    }
-  else
-    {
-      return bar_req_l_->type_str_;
     }
+
+  context ()->set_property ("whichBar", which);
+}
+
+void
+Timing_engraver::stop_translation_timestep ()
+{
+  Timing_translator::stop_translation_timestep ();
+  context ()->set_property ("whichBar", SCM_EOL);
+  last_moment_ = now_mom ();
 }