]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/timing-translator.cc
* lily/include/lily-guile.hh: is_x -> ly_c_X_p naming.
[lilypond.git] / lily / timing-translator.cc
index 9676e982650ff99217a38cc5f93e318fa5cdcdbc..cc96ec066d3a0fd640ce464bbe64d44d92fc79b9 100644 (file)
@@ -4,28 +4,21 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c)  1997--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 */
 
 #include "warn.hh"
 #include "timing-translator.hh"
 
 #include "translator-group.hh"
-#include "global-translator.hh"
+#include "global-context.hh"
 #include "multi-measure-rest.hh"
 
 
 void
 Timing_translator::stop_translation_timestep ()
 {
-  Translator *t = this;
-  Global_translator *global =0;
-  do
-    {
-      t = t->daddy_trans_ ;
-      global = dynamic_cast<Global_translator*> (t);
-    }
-  while (!global);
+  Global_context *global = get_global_context ();
 
   /* allbars == ! skipbars */
   SCM sb = get_property ("skipBars");
@@ -52,14 +45,22 @@ Timing_translator::stop_translation_timestep ()
 void
 Timing_translator::initialize ()
 {
-  daddy_trans_->set_property ("timing" , SCM_BOOL_T);  
-  daddy_trans_->set_property ("currentBarNumber" , gh_int2scm (1));
-
-  daddy_trans_->set_property ("timeSignatureFraction",
-                               gh_cons (gh_int2scm (4), gh_int2scm (4)));
-  daddy_trans_->set_property ("measurePosition", Moment (Rational (0)).smobbed_copy ());
-  daddy_trans_->set_property ("measureLength", Moment (Rational (1)).smobbed_copy ());
-  daddy_trans_->set_property ("beatLength", Moment (Rational (1,4)).smobbed_copy ());
+
+  /*
+    move this to engraver-init.ly? 
+   */
+  get_parent_context ()->add_alias (ly_symbol2scm ("Timing"));
+  get_parent_context ()->set_property ("timing" , SCM_BOOL_T);  
+  get_parent_context ()->set_property ("currentBarNumber" , scm_int2num (1));
+
+  get_parent_context ()->set_property ("timeSignatureFraction",
+                               scm_cons (scm_int2num (4), scm_int2num (4)));
+  /*
+    Do not init measurePosition; this should be done from global
+    context.
+   */
+  get_parent_context ()->set_property ("measureLength", Moment (Rational (1)).smobbed_copy ());
+  get_parent_context ()->set_property ("beatLength", Moment (Rational (1,4)).smobbed_copy ());
 }
 
 Rational
@@ -96,22 +97,20 @@ Timing_translator::measure_position () const
 void
 Timing_translator::start_translation_timestep ()
 {
-  Translator *t = this;
-  Global_translator *global =0;
-  do
-    {
-      t = t->daddy_trans_ ;
-      global = dynamic_cast<Global_translator*> (t);
-    }
-  while (!global);
+  Global_context *global =get_global_context ();
 
-  Moment now = global->now_mom_;
-  Moment dt = now  - global -> prev_mom_;
+  Moment now = global->now_mom ();
+  Moment dt = now  - global->previous_moment ();
   if (dt < Moment (0))
     {
       programming_error ("Moving backwards in time");
       dt = 0;
     }
+  else if (dt.main_part_.is_infinity ())
+    {
+      programming_error ("Moving infinitely to future");
+      dt = 0;
+    }
   
   if (!dt.to_bool ())
     return;
@@ -126,16 +125,17 @@ Timing_translator::start_translation_timestep ()
   else
     {
       measposp = now;
-      daddy_trans_->set_property ("measurePosition", measposp.smobbed_copy ());
+      get_parent_context ()->set_property ("measurePosition",
+                                   measposp.smobbed_copy ());
     }
   
   measposp += dt;
   
   SCM barn = get_property ("currentBarNumber");
   int b = 0;
-  if (gh_number_p (barn))
+  if (ly_c_number_p (barn))
     {
-      b = gh_scm2int (barn);
+      b = ly_scm2int (barn);
     }
 
   SCM cad = get_property ("timing");
@@ -148,8 +148,13 @@ Timing_translator::start_translation_timestep ()
       b ++;
     }
 
-  daddy_trans_->set_property ("currentBarNumber", gh_int2scm (b));
-  daddy_trans_->set_property ("measurePosition", measposp.smobbed_copy ());
+  get_parent_context ()->set_property ("currentBarNumber", scm_int2num (b));
+  get_parent_context ()->set_property ("measurePosition", measposp.smobbed_copy ());
 }
 
-ENTER_DESCRIPTION(Timing_translator,"","","","","","");
+ENTER_DESCRIPTION (Timing_translator,
+                  "This engraver adds the alias "
+                  "@code{Timing} to its containing context."
+                  ,
+
+                  "","","","","");