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 /* allbars == ! skipbars */
23 SCM sb = get_property ("skipBars");
24 bool allbars = !to_boolean (sb);
26 // urg: multi bar rests: should always process whole of first bar?
27 SCM tim = get_property ("timing");
28 bool timb = to_boolean (tim);
31 Moment barleft = (measure_length () - measure_position (context ()));
32 Moment now = now_mom ();
34 if (barleft > Moment (0)
36 Hmm. We insert the bar moment every time we process a
37 moment. A waste of cpu?
40 global->add_moment_to_process (now + barleft);
45 Timing_translator::initialize ()
49 move this to engraver-init.ly?
51 context ()->add_alias (ly_symbol2scm ("Timing"));
52 context ()->set_property ("timing", SCM_BOOL_T);
53 context ()->set_property ("currentBarNumber", scm_from_int (1));
55 context ()->set_property ("timeSignatureFraction",
56 scm_cons (scm_from_int (4), scm_from_int (4)));
58 Do not init measurePosition; this should be done from global
61 context ()->set_property ("measureLength", Moment (Rational (1)).smobbed_copy ());
62 context ()->set_property ("beatLength", Moment (Rational (1, 4)).smobbed_copy ());
66 Timing_translator::measure_length () const
68 SCM l = get_property ("measureLength");
69 if (unsmob_moment (l))
70 return unsmob_moment (l)->main_part_;
75 Timing_translator::Timing_translator ()
80 Timing_translator::start_translation_timestep ()
82 Global_context *global = get_global_context ();
84 Moment now = global->now_mom ();
85 Moment dt = now - global->previous_moment ();
88 programming_error ("moving backwards in time");
91 else if (dt.main_part_.is_infinity ())
93 programming_error ("moving infinitely to future");
102 SCM s = get_property ("measurePosition");
103 if (unsmob_moment (s))
105 measposp = *unsmob_moment (s);
110 context ()->set_property ("measurePosition",
111 measposp.smobbed_copy ());
116 SCM barn = get_property ("currentBarNumber");
118 if (scm_is_number (barn))
120 b = scm_to_int (barn);
123 SCM cad = get_property ("timing");
124 bool c = to_boolean (cad);
126 Rational len = measure_length ();
127 while (c && measposp.main_part_ >= len)
129 measposp.main_part_ -= len;
133 context ()->set_property ("currentBarNumber", scm_from_int (b));
134 context ()->set_property ("measurePosition", measposp.smobbed_copy ());
137 #include "translator.icc"
139 ADD_TRANSLATOR (Timing_translator,
140 "This engraver adds the alias "
141 "@code{Timing} to its containing context."
142 "Responsible for synchronizing timing information from staves. "
143 "Normally in @code{Score}. In order to create polyrhythmic music, "
144 "this engraver should be removed from @code{Score} and placed in "
146 "\n\nThis engraver adds the alias @code{Timing} to its containing context."