2 timing-translator.cc -- implement Timing_translator
5 source file of the GNU LilyPond music typesetter
7 (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
11 #include "timing-translator.hh"
13 #include "translator-group.hh"
14 #include "global-context.hh"
15 #include "multi-measure-rest.hh"
19 Timing_translator::stop_translation_timestep ()
21 Global_context *global = get_global_context ();
23 /* allbars == ! skipbars */
24 SCM sb = get_property ("skipBars");
25 bool allbars = !to_boolean (sb);
27 // urg: multi bar rests: should always process whole of first bar?
28 SCM tim = get_property ("timing");
29 bool timb = to_boolean (tim);
32 Moment barleft = (measure_length () - measure_position ());
33 Moment now = now_mom ();
35 if (barleft > Moment (0)
37 Hmm. We insert the bar moment every time we process a
38 moment. A waste of cpu?
41 global->add_moment_to_process (now + barleft);
46 Timing_translator::initialize ()
50 move this to engraver-init.ly?
53 daddy_context_->set_property ("timing" , SCM_BOOL_T);
54 daddy_context_->set_property ("currentBarNumber" , gh_int2scm (1));
56 daddy_context_->set_property ("timeSignatureFraction",
57 gh_cons (gh_int2scm (4), gh_int2scm (4)));
58 daddy_context_->set_property ("measurePosition", Moment (Rational (0)).smobbed_copy ());
59 daddy_context_->set_property ("measureLength", Moment (Rational (1)).smobbed_copy ());
60 daddy_context_->set_property ("beatLength", Moment (Rational (1,4)).smobbed_copy ());
64 Timing_translator::measure_length () const
66 SCM l = get_property ("measureLength");
67 if (unsmob_moment (l))
68 return unsmob_moment (l)->main_part_;
73 Timing_translator::Timing_translator ()
79 Timing_translator::measure_position () const
81 SCM sm = get_property ("measurePosition");
84 if (unsmob_moment (sm))
86 m = *unsmob_moment (sm);
87 while (m.main_part_ < Rational (0))
88 m.main_part_ += measure_length ();
95 Timing_translator::start_translation_timestep ()
97 Global_context *global =get_global_context ();
99 Moment now = global->now_mom_;
100 Moment dt = now - global->prev_mom_;
103 programming_error ("Moving backwards in time");
106 else if (dt.main_part_.is_infinity ())
108 programming_error ("Moving infinitely to future");
117 SCM s = get_property ("measurePosition");
118 if (unsmob_moment (s))
120 measposp = *unsmob_moment (s);
125 daddy_context_->set_property ("measurePosition", measposp.smobbed_copy ());
130 SCM barn = get_property ("currentBarNumber");
132 if (gh_number_p (barn))
134 b = gh_scm2int (barn);
137 SCM cad = get_property ("timing");
138 bool c= to_boolean (cad);
140 Rational len = measure_length ();
141 while (c && measposp.main_part_ >= len)
143 measposp.main_part_ -= len;
147 daddy_context_->set_property ("currentBarNumber", gh_int2scm (b));
148 daddy_context_->set_property ("measurePosition", measposp.smobbed_copy ());
151 ENTER_DESCRIPTION(Timing_translator,"","","","","","");