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 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::do_try_music (Music*r)
25 if (Timing_req *t = dynamic_cast <Timing_req *> (r))
27 for (int i=0; i < timing_req_l_arr_.size (); i++)
32 if (timing_req_l_arr_[i]->equal_b(t))
34 if (String (classname (timing_req_l_arr_[i])) == classname (r))
36 r->origin ()->warning (_ ("conflicting timing request"));
37 timing_req_l_arr_[i]->origin ()->warning (_("This is the other timing request"));
42 timing_req_l_arr_.push(t);
50 Time_signature_change_req*
51 Timing_translator::time_signature_req_l() const
53 Time_signature_change_req *m_l=0;
54 for (int i=0; !m_l && i < timing_req_l_arr_.size (); i++)
56 m_l=dynamic_cast<Time_signature_change_req*> (timing_req_l_arr_[i]);
62 Timing_translator::do_process_music()
64 for (int i=0; i < timing_req_l_arr_.size (); i++)
66 Timing_req * tr_l = timing_req_l_arr_[i];
68 if (Time_signature_change_req *m_l = dynamic_cast <Time_signature_change_req *> (tr_l))
70 int b_i= m_l->beats_i_;
71 int o_i = m_l->one_beat_i_;
72 set_time_signature (b_i, o_i);
74 else if (dynamic_cast <Barcheck_req *> (tr_l))
76 if (measure_position ())
79 tr_l ->origin ()->warning (_f ("barcheck failed at: %s",
80 measure_position ().str ()));
82 daddy_trans_l_->set_property("measurePosition", nm.make_scm ());
90 Timing_translator::do_pre_move_processing()
92 timing_req_l_arr_.set_size (0);
94 Global_translator *global_l =0;
97 t = t->daddy_trans_l_ ;
98 global_l = dynamic_cast<Global_translator*> (t);
102 /* allbars == ! skipbars */
103 SCM sb = get_property ("skipBars");
104 bool allbars = !to_boolean (sb);
106 // urg: multi bar rests: should always process whole of first bar?
107 SCM tim = get_property ("timing");
108 bool timb = to_boolean (tim);
111 Moment barleft = (measure_length () - measure_position ());
113 if (barleft > Moment (0))
114 global_l->add_moment_to_process (now_mom () + barleft);
119 ADD_THIS_TRANSLATOR(Timing_translator);
122 Timing_translator::do_creation_processing()
125 daddy_trans_l_->set_property ("timing" , SCM_BOOL_T);
126 daddy_trans_l_->set_property ("currentBarNumber" , gh_int2scm (1));
127 daddy_trans_l_->set_property ("measurePosition", m.make_scm ());
128 daddy_trans_l_->set_property ("beatLength", Moment (1,4).make_scm ());
129 daddy_trans_l_->set_property ("measureLength", Moment (1).make_scm());
133 Timing_translator::measure_length () const
135 SCM l = get_property("measureLength");
136 if (unsmob_moment(l))
137 return *unsmob_moment (l);
144 Timing_translator::set_time_signature (int l, int o)
146 Moment one_beat = Moment (1)/Moment (o);
147 Moment len = Moment (l) * one_beat;
148 daddy_trans_l_->set_property ("measureLength", len.make_scm ());
149 daddy_trans_l_->set_property ("beatLength", one_beat.make_scm ());
152 Timing_translator::Timing_translator()
158 Timing_translator::measure_position () const
160 SCM sm = get_property ("measurePosition");
163 if (unsmob_moment (sm))
165 m = *unsmob_moment(sm);
166 while (m < Moment (0))
167 m += measure_length ();
174 Timing_translator::do_post_move_processing()
176 Translator *t = this;
177 Global_translator *global_l =0;
180 t = t->daddy_trans_l_ ;
181 global_l = dynamic_cast<Global_translator*> (t);
185 Moment dt = global_l->now_mom_ - global_l -> prev_mom_;
188 programming_error ("Moving backwards in time");
197 SCM s = get_property ("measurePosition");
198 if (unsmob_moment (s))
200 measposp = *unsmob_moment(s);
204 daddy_trans_l_->set_property ("measurePosition", measposp.make_scm());
209 SCM barn = get_property ("currentBarNumber");
211 if (gh_number_p(barn))
213 b = gh_scm2int (barn);
216 SCM cad = get_property ("timing");
217 bool c= to_boolean (cad );
219 Moment len = measure_length ();
220 while (c && measposp >= len)
226 daddy_trans_l_->set_property ("currentBarNumber", gh_int2scm (b));
227 daddy_trans_l_->set_property ("measurePosition", measposp.make_scm());