2 timing-translator.cc -- implement Timing_translator
5 source file of the GNU LilyPond music typesetter
7 (c) 1997--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #include "timing-translator.hh"
13 #include "translator-group.hh"
14 #include "global-context.hh"
15 #include "multi-measure-rest.hh"
18 Timing_translator::stop_translation_timestep ()
20 Global_context *global = get_global_context ();
22 if (to_boolean (get_property ("timing"))
23 && !to_boolean (get_property ("skipBars")))
25 Moment barleft = (measure_length () - measure_position (context ()));
26 Moment now = now_mom ();
28 if (barleft > Moment (0)
30 Hmm. We insert the bar moment every time we process a
31 moment. A waste of cpu?
34 global->add_moment_to_process (now + barleft);
39 Timing_translator::initialize ()
41 context ()->add_alias (ly_symbol2scm ("Timing"));
42 context ()->set_property ("currentBarNumber", scm_from_int (1));
44 context ()->set_property ("timeSignatureFraction",
45 scm_cons (scm_from_int (4), scm_from_int (4)));
47 Do not init measurePosition; this should be done from global
50 context ()->set_property ("measureLength",
51 Moment (Rational (1)).smobbed_copy ());
52 context ()->set_property ("beatLength",
53 Moment (Rational (1, 4)).smobbed_copy ());
57 Timing_translator::measure_length () const
59 SCM l = get_property ("measureLength");
60 if (unsmob_moment (l))
61 return unsmob_moment (l)->main_part_;
66 Timing_translator::Timing_translator ()
71 Timing_translator::start_translation_timestep ()
73 Global_context *global = get_global_context ();
75 Moment now = global->now_mom ();
76 Moment dt = now - global->previous_moment ();
79 programming_error ("moving backwards in time");
82 else if (dt.main_part_.is_infinity ())
84 programming_error ("moving infinitely to future");
93 SCM s = get_property ("measurePosition");
94 if (unsmob_moment (s))
95 measposp = *unsmob_moment (s);
99 context ()->set_property ("measurePosition",
100 measposp.smobbed_copy ());
105 SCM barn = get_property ("currentBarNumber");
107 if (scm_is_number (barn))
108 b = scm_to_int (barn);
110 SCM cad = get_property ("timing");
111 bool c = to_boolean (cad);
113 Rational len = measure_length ();
114 while (c && measposp.main_part_ >= len)
116 measposp.main_part_ -= len;
120 context ()->set_property ("currentBarNumber", scm_from_int (b));
121 context ()->set_property ("measurePosition", measposp.smobbed_copy ());
124 #include "translator.icc"
126 ADD_TRANSLATOR (Timing_translator,
127 "This engraver adds the alias "
128 "@code{Timing} to its containing context."
129 "Responsible for synchronizing timing information from staves. "
130 "Normally in @code{Score}. In order to create polyrhythmic music, "
131 "this engraver should be removed from @code{Score} and placed in "
133 "\n\nThis engraver adds the alias @code{Timing} to its containing context.",