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. */
23 Timing_translator::try_music (Music
*r
)
25 if (dynamic_cast<Barcheck_req
*> (r
))
34 Timing_translator::process_music ()
36 if (check_
&& measure_position ())
38 check_
->origin ()->warning (_f ("barcheck failed at: %s",
39 measure_position ().str ()));
42 if (!to_boolean (get_property ("barCheckNoSynchronize")))
43 daddy_trans_l_
->set_property ("measurePosition", zero
.smobbed_copy ());
49 Timing_translator::stop_translation_timestep ()
54 Global_translator
*global_l
=0;
57 t
= t
->daddy_trans_l_
;
58 global_l
= dynamic_cast<Global_translator
*> (t
);
62 /* allbars == ! skipbars */
63 SCM sb
= get_property ("skipBars");
64 bool allbars
= !to_boolean (sb
);
66 // urg: multi bar rests: should always process whole of first bar?
67 SCM tim
= get_property ("timing");
68 bool timb
= to_boolean (tim
);
71 Moment barleft
= (measure_length () - measure_position ());
73 if (barleft
> Moment (0))
74 global_l
->add_moment_to_process (now_mom () + barleft
);
79 ADD_THIS_TRANSLATOR (Timing_translator
);
82 Timing_translator::initialize ()
85 daddy_trans_l_
->set_property ("timing" , SCM_BOOL_T
);
86 daddy_trans_l_
->set_property ("currentBarNumber" , gh_int2scm (1));
87 daddy_trans_l_
->set_property ("measurePosition", m
.smobbed_copy ());
88 daddy_trans_l_
->set_property ("timeSignatureFraction",
89 gh_cons (gh_int2scm (4), gh_int2scm (4)));
91 daddy_trans_l_
->set_property ("measureLength", Moment (1).smobbed_copy ());
92 daddy_trans_l_
->set_property ("beatLength", Moment (1,4).smobbed_copy ());
96 Timing_translator::measure_length () const
98 SCM l
= get_property ("measureLength");
99 if (unsmob_moment (l
))
100 return *unsmob_moment (l
);
107 Timing_translator::Timing_translator ()
115 Timing_translator::measure_position () const
117 SCM sm
= get_property ("measurePosition");
120 if (unsmob_moment (sm
))
122 m
= *unsmob_moment (sm
);
123 while (m
< Moment (0))
124 m
+= measure_length ();
131 Timing_translator::start_translation_timestep ()
134 Translator
*t
= this;
135 Global_translator
*global_l
=0;
138 t
= t
->daddy_trans_l_
;
139 global_l
= dynamic_cast<Global_translator
*> (t
);
143 Moment dt
= global_l
->now_mom_
- 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
);
162 daddy_trans_l_
->set_property ("measurePosition", measposp
.smobbed_copy ());
167 SCM barn
= get_property ("currentBarNumber");
169 if (gh_number_p (barn
))
171 b
= gh_scm2int (barn
);
174 SCM cad
= get_property ("timing");
175 bool c
= to_boolean (cad
);
177 Moment len
= measure_length ();
178 while (c
&& measposp
>= len
)
184 daddy_trans_l_
->set_property ("currentBarNumber", gh_int2scm (b
));
185 daddy_trans_l_
->set_property ("measurePosition", measposp
.smobbed_copy ());