2 timing-translator.cc -- implement Timing_translator
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 #include "timing-translator.hh"
10 #include "command-request.hh"
11 #include "translator-group.hh"
12 #include "global-translator.hh"
13 #include "multi-measure-rest.hh"
16 Timing_translator::do_try_music (Music*r)
18 if (Timing_req *t = dynamic_cast <Timing_req *> (r))
20 for (int i=0; i < timing_req_l_arr_.size (); i++)
22 if (timing_req_l_arr_[i]->equal_b(t))
24 if (String (classname (timing_req_l_arr_[i])) == classname (r))
26 r->warning (_ ("conflicting timing request"));
31 timing_req_l_arr_.push(t);
39 Time_signature_change_req*
40 Timing_translator::time_signature_req_l() const
42 Time_signature_change_req *m_l=0;
43 for (int i=0; !m_l && i < timing_req_l_arr_.size (); i++)
45 m_l=dynamic_cast<Time_signature_change_req*> (timing_req_l_arr_[i]);
51 Timing_translator::do_process_requests()
53 for (int i=0; i < timing_req_l_arr_.size (); i++)
55 Timing_req * tr_l = timing_req_l_arr_[i];
57 if (Time_signature_change_req *m_l = dynamic_cast <Time_signature_change_req *> (tr_l))
59 int b_i= m_l->beats_i_;
60 int o_i = m_l->one_beat_i_;
61 if (! time_.allow_time_signature_change_b())
62 tr_l->warning (_ ("time signature change not allowed here"));
65 time_.set_time_signature (b_i, o_i);
68 else if (Partial_measure_req *pm = dynamic_cast <Partial_measure_req *> (tr_l))
70 Moment m = pm->length_mom_;
71 String error = time_.try_set_partial_str (m);
72 if (error.length_i ())
74 tr_l->warning (error);
79 else if (dynamic_cast <Barcheck_req *> (tr_l))
81 if (time_.whole_in_measure_)
83 tr_l ->warning (_f ("barcheck failed at: %s",
84 time_.whole_in_measure_.str ()));
86 time_.whole_in_measure_ = 0; // resync
89 else if (Cadenza_req *cr = dynamic_cast <Cadenza_req *> (tr_l))
91 time_.set_cadenza (cr->on_b_);
95 Translator_group * tr=0;
97 Scalar barn = get_property ("currentBarNumber", &tr);
98 if (!barn.empty_b () && barn.isnum_b ())
100 time_.bars_i_ = int(barn);
101 tr->set_property ("currentBarNumber", "");
109 Timing_translator::do_pre_move_processing()
111 timing_req_l_arr_.set_size (0);
112 Translator *t = this;
113 Global_translator *global_l =0;
116 t = t->daddy_trans_l_ ;
117 global_l = dynamic_cast<Global_translator*> (t);
121 /* allbars == ! skipbars */
122 bool allbars = ! get_property ("skipBars", 0).to_bool ();
124 // urg: multi bar rests: should always process whole of first bar?
125 if (!time_.cadenza_b_ && allbars)
126 global_l->add_moment_to_process (time_.next_bar_moment ());
130 ADD_THIS_TRANSLATOR(Timing_translator);
133 Timing_translator::do_creation_processing()
135 time_.when_ = now_mom ();
139 Timing_translator::do_post_move_processing()
141 time_.add (now_mom () - time_.when_);
147 Timing_translator::do_print () const