2 timing-translator.cc -- implement Timing_translator
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1998 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"
15 Timing_translator::Timing_translator ()
17 default_grouping_ = Rhythmic_grouping (MInterval (0, 1), 4); // ugh
21 Timing_translator::do_try_request(Request*r)
23 Command_req * c = r->access_Command_req ();
24 if (!(c && c->access_Timing_req ()))
26 for (int i=0; i < timing_req_l_arr_.size (); i++)
28 if (timing_req_l_arr_[i]->equal_b(r))
30 if (timing_req_l_arr_[i]->name() == r->name())
32 r->warning (_ ("conflicting timing request"));
37 timing_req_l_arr_.push(c->access_Timing_req ());
41 Time_signature_change_req*
42 Timing_translator::time_signature_req_l() const
44 Time_signature_change_req *m_l=0;
45 for (int i=0; !m_l && i < timing_req_l_arr_.size (); i++)
47 m_l=timing_req_l_arr_[i]->access_Time_signature_change_req ();
53 Timing_translator::do_process_requests()
55 for (int i=0; i < timing_req_l_arr_.size (); i++)
57 Timing_req * tr_l = timing_req_l_arr_[i];
58 Time_signature_change_req *m_l = tr_l->access_Time_signature_change_req ();
61 int b_i= m_l->beats_i_;
62 int o_i = m_l->one_beat_i_;
63 if (! time_.allow_time_signature_change_b())
64 tr_l->warning (_ ("time signature change not allowed here"));
67 time_.set_time_signature (b_i, o_i);
69 Rhythmic_grouping (MInterval (0,Moment (b_i, o_i)), b_i);
72 else if (tr_l->access_Partial_measure_req ())
74 Moment m = tr_l->access_Partial_measure_req ()->duration_;
75 String error = time_.try_set_partial_str (m);
76 if (error.length_i ())
78 tr_l->warning (error);
83 else if (tr_l->access_Barcheck_req())
85 if (time_.whole_in_measure_)
87 tr_l ->warning (_f ("barcheck failed by: %s",
88 time_.whole_in_measure_.str ()));
90 time_.whole_in_measure_ = 0; // resync
91 time_.error_b_ = true;
95 else if (tr_l->access_Cadenza_req ())
97 time_.set_cadenza (tr_l->access_Cadenza_req ()->on_b_);
99 else if (tr_l->access_Measure_grouping_req ())
102 parse_grouping (tr_l->access_Measure_grouping_req ()->beat_i_arr_,
103 tr_l->access_Measure_grouping_req ()->elt_length_arr_);
111 Timing_translator::do_pre_move_processing()
113 timing_req_l_arr_.set_size (0);
114 Global_translator *global_l =
115 daddy_trans_l_->ancestor_l (100)->global_l (); // ugh 100.
118 bool allbars = ! get_property ("SkipBars").to_bool ();
119 if (!time_.cadenza_b_ && allbars)
120 global_l->add_moment_to_process (time_.next_bar_moment ());
123 IMPLEMENT_IS_TYPE_B1(Timing_translator, Translator);
124 ADD_THIS_TRANSLATOR(Timing_translator);
127 Timing_translator::do_creation_processing()
129 time_.when_ = now_moment ();
133 Timing_translator::do_post_move_processing()
135 time_.add (now_moment () - time_.when_);
139 Timing_translator::do_print () const
143 default_grouping_.print ();