2 timing-translator.cc -- implement Timing_translator
5 source file of the GNU LilyPond music typesetter
7 (c) 1997--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
11 #include "timing-translator.hh"
13 #include "translator-group.hh"
14 #include "global-translator.hh"
15 #include "multi-measure-rest.hh"
19 Timing_translator::stop_translation_timestep ()
22 Global_translator
*global
=0;
26 global
= dynamic_cast<Global_translator
*> (t
);
30 /* allbars == ! skipbars */
31 SCM sb
= get_property ("skipBars");
32 bool allbars
= !to_boolean (sb
);
34 // urg: multi bar rests: should always process whole of first bar?
35 SCM tim
= get_property ("timing");
36 bool timb
= to_boolean (tim
);
39 Moment barleft
= (measure_length () - measure_position ());
40 Moment now
= now_mom ();
42 if (barleft
> Moment (0)
44 Hmm. We insert the bar moment every time we process a
45 moment. A waste of cpu?
48 global
->add_moment_to_process (now
+ barleft
);
53 Timing_translator::initialize ()
55 daddy_trans_
->set_property ("timing" , SCM_BOOL_T
);
56 daddy_trans_
->set_property ("currentBarNumber" , gh_int2scm (1));
58 daddy_trans_
->set_property ("timeSignatureFraction",
59 gh_cons (gh_int2scm (4), gh_int2scm (4)));
60 daddy_trans_
->set_property ("measurePosition", Moment (Rational (0)).smobbed_copy ());
61 daddy_trans_
->set_property ("measureLength", Moment (Rational (1)).smobbed_copy ());
62 daddy_trans_
->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 ()
81 Timing_translator::measure_position () const
83 SCM sm
= get_property ("measurePosition");
86 if (unsmob_moment (sm
))
88 m
= *unsmob_moment (sm
);
89 while (m
.main_part_
< Rational (0))
90 m
.main_part_
+= measure_length ();
97 Timing_translator::start_translation_timestep ()
100 Global_translator
*global
=0;
103 t
= t
->daddy_trans_
;
104 global
= dynamic_cast<Global_translator
*> (t
);
108 Moment now
= global
->now_mom_
;
109 Moment dt
= now
- global
-> prev_mom_
;
112 programming_error ("Moving backwards in time");
121 SCM s
= get_property ("measurePosition");
122 if (unsmob_moment (s
))
124 measposp
= *unsmob_moment (s
);
129 daddy_trans_
->set_property ("measurePosition", measposp
.smobbed_copy ());
134 SCM barn
= get_property ("currentBarNumber");
136 if (gh_number_p (barn
))
138 b
= gh_scm2int (barn
);
141 SCM cad
= get_property ("timing");
142 bool c
= to_boolean (cad
);
144 Rational len
= measure_length ();
145 while (c
&& measposp
.main_part_
>= len
)
147 measposp
.main_part_
-= len
;
151 daddy_trans_
->set_property ("currentBarNumber", gh_int2scm (b
));
152 daddy_trans_
->set_property ("measurePosition", measposp
.smobbed_copy ());
155 ENTER_DESCRIPTION(Timing_translator
,"","","","","","");