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?
52 context ()->add_alias (ly_symbol2scm ("Timing"));
53 context ()->set_property ("timing" , SCM_BOOL_T
);
54 context ()->set_property ("currentBarNumber" , scm_int2num (1));
56 context ()->set_property ("timeSignatureFraction",
57 scm_cons (scm_int2num (4), scm_int2num (4)));
59 Do not init measurePosition; this should be done from global
62 context ()->set_property ("measureLength", Moment (Rational (1)).smobbed_copy ());
63 context ()->set_property ("beatLength", Moment (Rational (1,4)).smobbed_copy ());
67 Timing_translator::measure_length () const
69 SCM l
= get_property ("measureLength");
70 if (unsmob_moment (l
))
71 return unsmob_moment (l
)->main_part_
;
76 Timing_translator::Timing_translator ()
82 Timing_translator::measure_position () const
84 SCM sm
= get_property ("measurePosition");
87 if (unsmob_moment (sm
))
89 m
= *unsmob_moment (sm
);
90 while (m
.main_part_
< Rational (0))
91 m
.main_part_
+= measure_length ();
98 Timing_translator::start_translation_timestep ()
100 Global_context
*global
=get_global_context ();
102 Moment now
= global
->now_mom ();
103 Moment dt
= now
- global
->previous_moment ();
106 programming_error ("Moving backwards in time");
109 else if (dt
.main_part_
.is_infinity ())
111 programming_error ("Moving infinitely to future");
120 SCM s
= get_property ("measurePosition");
121 if (unsmob_moment (s
))
123 measposp
= *unsmob_moment (s
);
128 context ()->set_property ("measurePosition",
129 measposp
.smobbed_copy ());
134 SCM barn
= get_property ("currentBarNumber");
136 if (ly_c_number_p (barn
))
138 b
= ly_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 context ()->set_property ("currentBarNumber", scm_int2num (b
));
152 context ()->set_property ("measurePosition", measposp
.smobbed_copy ());
155 ENTER_DESCRIPTION (Timing_translator
,
156 "This engraver adds the alias "
157 "@code{Timing} to its containing context."