2 timing-translator.cc -- implement Timing_translator
5 source file of the GNU LilyPond music typesetter
7 (c) 1997--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
11 #include "timing-translator.hh"
12 #include "command-request.hh"
13 #include "translator-group.hh"
14 #include "global-translator.hh"
15 #include "multi-measure-rest.hh"
18 TODO: change the rest of lily, so communication with
19 Timing_translator is only done through properties. This means the
20 class declaration can go here. */
22 Timing_translator::try_music (Music
*r
)
24 if (dynamic_cast<Barcheck_req
*> (r
))
33 Timing_translator::process_music ()
35 if (check_
&& measure_position ().main_part_
)
37 check_
->origin ()->warning (_f ("barcheck failed at: %s",
38 measure_position ().str ()));
41 if (!to_boolean (get_property ("barCheckNoSynchronize")))
42 daddy_trans_l_
->set_property ("measurePosition", zero
.smobbed_copy ());
47 Timing_translator::stop_translation_timestep ()
52 Global_translator
*global_l
=0;
55 t
= t
->daddy_trans_l_
;
56 global_l
= dynamic_cast<Global_translator
*> (t
);
60 /* allbars == ! skipbars */
61 SCM sb
= get_property ("skipBars");
62 bool allbars
= !to_boolean (sb
);
64 // urg: multi bar rests: should always process whole of first bar?
65 SCM tim
= get_property ("timing");
66 bool timb
= to_boolean (tim
);
69 Moment barleft
= (measure_length () - measure_position ());
70 Moment now
= now_mom ();
72 if (barleft
> Moment (0)
74 Hmm. We insert the bar moment every time we process a
75 moment. A waste of cpu?
78 global_l
->add_moment_to_process (now
+ barleft
);
83 ADD_THIS_TRANSLATOR (Timing_translator
);
86 Timing_translator::initialize ()
88 daddy_trans_l_
->set_property ("timing" , SCM_BOOL_T
);
89 daddy_trans_l_
->set_property ("currentBarNumber" , gh_int2scm (1));
91 daddy_trans_l_
->set_property ("timeSignatureFraction",
92 gh_cons (gh_int2scm (4), gh_int2scm (4)));
93 daddy_trans_l_
->set_property ("measurePosition", Moment (Rational (0)).smobbed_copy ());
94 daddy_trans_l_
->set_property ("measureLength", Moment (Rational (1)).smobbed_copy ());
95 daddy_trans_l_
->set_property ("beatLength", Moment (Rational (1,4)).smobbed_copy ());
99 Timing_translator::measure_length () const
101 SCM l
= get_property ("measureLength");
102 if (unsmob_moment (l
))
103 return unsmob_moment (l
)->main_part_
;
108 Timing_translator::Timing_translator ()
114 Timing_translator::measure_position () const
116 SCM sm
= get_property ("measurePosition");
119 if (unsmob_moment (sm
))
121 m
= *unsmob_moment (sm
);
122 while (m
.main_part_
< Rational (0))
123 m
.main_part_
+= measure_length ();
130 Timing_translator::start_translation_timestep ()
133 Translator
*t
= this;
134 Global_translator
*global_l
=0;
137 t
= t
->daddy_trans_l_
;
138 global_l
= dynamic_cast<Global_translator
*> (t
);
142 Moment now
= global_l
->now_mom_
;
143 Moment dt
= now
- global_l
-> prev_mom_
;
146 programming_error ("Moving backwards in time");
155 SCM s
= get_property ("measurePosition");
156 if (unsmob_moment (s
))
158 measposp
= *unsmob_moment (s
);
163 daddy_trans_l_
->set_property ("measurePosition", measposp
.smobbed_copy ());
168 SCM barn
= get_property ("currentBarNumber");
170 if (gh_number_p (barn
))
172 b
= gh_scm2int (barn
);
175 SCM cad
= get_property ("timing");
176 bool c
= to_boolean (cad
);
178 Rational len
= measure_length ();
179 while (c
&& measposp
.main_part_
>= len
)
181 measposp
.main_part_
-= len
;
185 daddy_trans_l_
->set_property ("currentBarNumber", gh_int2scm (b
));
186 daddy_trans_l_
->set_property ("measurePosition", measposp
.smobbed_copy ());