2 timing-translator.cc -- implement Timing_translator
5 source file of the GNU LilyPond music typesetter
7 (c) 1997--2000 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 Timing_translator::do_try_music (Music
*r
)
20 if (Timing_req
*t
= dynamic_cast <Timing_req
*> (r
))
22 for (int i
=0; i
< timing_req_l_arr_
.size (); i
++)
27 if (timing_req_l_arr_
[i
]->equal_b(t
))
29 if (String (classname (timing_req_l_arr_
[i
])) == classname (r
))
31 r
->warning (_ ("conflicting timing request"));
32 timing_req_l_arr_
[i
]->warning (_("This is the other timing request"));
37 timing_req_l_arr_
.push(t
);
45 Time_signature_change_req
*
46 Timing_translator::time_signature_req_l() const
48 Time_signature_change_req
*m_l
=0;
49 for (int i
=0; !m_l
&& i
< timing_req_l_arr_
.size (); i
++)
51 m_l
=dynamic_cast<Time_signature_change_req
*> (timing_req_l_arr_
[i
]);
57 Timing_translator::do_process_requests()
59 for (int i
=0; i
< timing_req_l_arr_
.size (); i
++)
61 Timing_req
* tr_l
= timing_req_l_arr_
[i
];
63 if (Time_signature_change_req
*m_l
= dynamic_cast <Time_signature_change_req
*> (tr_l
))
65 int b_i
= m_l
->beats_i_
;
66 int o_i
= m_l
->one_beat_i_
;
67 set_time_signature (b_i
, o_i
);
69 else if (dynamic_cast <Barcheck_req
*> (tr_l
))
71 if (measure_position ())
73 tr_l
->warning (_f ("barcheck failed at: %s",
74 measure_position ().str ()));
76 daddy_trans_l_
->set_property("measurePosition",
77 (new Moment
)->smobify_self ());
86 Timing_translator::do_pre_move_processing()
88 timing_req_l_arr_
.set_size (0);
90 Global_translator
*global_l
=0;
93 t
= t
->daddy_trans_l_
;
94 global_l
= dynamic_cast<Global_translator
*> (t
);
98 /* allbars == ! skipbars */
99 SCM sb
= get_property ("skipBars", 0);
100 bool allbars
= !to_boolean (sb
);
102 // urg: multi bar rests: should always process whole of first bar?
103 SCM tim
= get_property ("timing", 0);
104 bool timb
= to_boolean (tim
);
107 Moment barleft
= (measure_length () - measure_position ());
109 if (barleft
> Moment (0))
110 global_l
->add_moment_to_process (now_mom () + barleft
);
115 ADD_THIS_TRANSLATOR(Timing_translator
);
118 Timing_translator::do_creation_processing()
120 daddy_trans_l_
->set_property ("timing" , SCM_BOOL_T
);
121 daddy_trans_l_
->set_property ("currentBarNumber" , gh_int2scm (1));
122 daddy_trans_l_
->set_property("measurePosition",
123 (new Moment
)->smobify_self());
124 daddy_trans_l_
->set_property ("oneBeat",
125 (new Moment (1,4))->smobify_self ());
126 daddy_trans_l_
->set_property("measureLength",
127 (new Moment (1))->smobify_self());
131 Timing_translator::measure_length () const
133 SCM l
= get_property("measureLength",0);
134 if (SMOB_IS_TYPE_B(Moment
, l
))
135 return *SMOB_TO_TYPE (Moment
, l
);
142 Timing_translator::get_time_signature (int *n
, int *d
) const
144 Moment
one_beat (1,4);
145 SCM one
= get_property ("beatLength",0);
146 if (SMOB_IS_TYPE_B (Moment
, one
))
147 one_beat
= *SMOB_TO_TYPE (Moment
, one
);
148 *n
= measure_length () / one_beat
;
149 *d
= one_beat
.den_i ();
154 Timing_translator::set_time_signature (int l
, int o
)
156 Moment one_beat
= Moment (1)/Moment (o
);
157 Moment len
= Moment (l
) * one_beat
;
158 daddy_trans_l_
->set_property ("measureLength",
159 (new Moment (len
))->smobify_self ());
160 daddy_trans_l_
->set_property ("beatLength",
161 (new Moment (one_beat
))->smobify_self ());
164 Timing_translator::Timing_translator()
170 Timing_translator::measure_position () const
172 SCM sm
= get_property ("measurePosition",0);
175 if (SMOB_IS_TYPE_B (Moment
, sm
))
177 m
= *SMOB_TO_TYPE (Moment
, sm
);
178 while (m
< Moment (0))
179 m
+= measure_length ();
186 Timing_translator::do_post_move_processing()
188 Translator
*t
= this;
189 Global_translator
*global_l
=0;
192 t
= t
->daddy_trans_l_
;
193 global_l
= dynamic_cast<Global_translator
*> (t
);
197 Moment dt
= global_l
->now_mom_
- global_l
-> prev_mom_
;
200 programming_error ("Moving backwards in time");
207 Moment
* measposp
=0;
209 SCM s
= get_property ("measurePosition", 0);
210 if (SMOB_IS_TYPE_B (Moment
, s
))
212 measposp
= SMOB_TO_TYPE (Moment
,s
);
216 measposp
= new Moment
;
217 daddy_trans_l_
->set_property ("measurePosition", measposp
->smobify_self ());
221 // don't need to set_property
223 Translator_group
* tr
=daddy_trans_l_
;
224 SCM barn
= get_property ("currentBarNumber", &tr
);
226 if (gh_number_p(barn
))
228 b
= gh_scm2int (barn
);
231 SCM cad
= get_property ("timing", 0);
232 bool c
= to_boolean (cad
);
234 Moment len
= measure_length ();
235 while (c
&& *measposp
>= len
)
241 tr
->set_property ("currentBarNumber", gh_int2scm (b
));