lilypond-1.3.67
[lilypond.git] / lily / meter-reg.cc
blobe0e3829ed0414b5da75271531fc743a4bebfd343
1 /*
2 meter-reg.cc -- implement Meter_register
4 source file of the GNU LilyPond music typesetter
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
9 #include "meter-reg.hh"
10 #include "meter.hh"
11 #include "command-request.hh"
12 #include "score-reg.hh"
14 Meter_register::Meter_register()
16 meter_req_l_ = 0;
17 meter_p_ =0;
18 default_grouping_ = Rhythmic_grouping(MInterval(0,4),4); // ugh
21 void
22 Meter_register::fill_staff_info(Staff_info&inf)
24 inf.time_C_ = &time_;
25 inf.rhythmic_C_ = &default_grouping_;
28 bool
29 Meter_register::do_try_request(Request*r)
31 bool gotcha = false;
33 if (r->command() && r->command()->timing()) {
34 gotcha = true;
35 Timing_req * tr_l = r->command()->timing();
36 Meter_change_req *m_l = tr_l->meterchange();
37 if (m_l) {
38 meter_req_l_ = m_l;
40 int b_i= m_l->beats_i_;
41 int o_i = m_l->one_beat_i_;
42 if (! time_.allow_meter_change_b() )
43 tr_l->warning("Meter change not allowed here");
44 else{
45 time_.set_meter(b_i, o_i);
46 default_grouping_ =
47 Rhythmic_grouping(MInterval(0,Moment(b_i, o_i)), b_i);
49 } else if (tr_l->partial()) {
50 Moment m = tr_l->partial()->duration_;
51 String error = time_.try_set_partial_str(m);
52 if (error != "") {
53 tr_l->warning(error);
54 } else
55 time_.setpartial(m);
56 } else if (tr_l->barcheck()) {
57 if (time_.whole_in_measure_) {
58 tr_l ->warning( "Barcheck failed");
60 time_.whole_in_measure_ = 0; // resync
61 time_.error_b_ = true;
64 } else if (tr_l->cadenza()) {
65 time_.set_cadenza(tr_l->cadenza()->on_b_);
67 } else if (tr_l->measuregrouping()) {
68 default_grouping_ = parse_grouping(
69 tr_l->measuregrouping()->beat_i_arr_,
70 tr_l->measuregrouping()->elt_length_arr_);
75 return gotcha;
78 void
79 Meter_register::do_creation_processing()
81 time_.when_ = get_staff_info().when();
84 void
85 Meter_register::do_process_requests()
87 if (meter_req_l_ ) {
88 Array<Scalar> args;
89 args.push(meter_req_l_->beats_i_);
90 args.push(meter_req_l_->one_beat_i_);
92 meter_p_ = new Meter(args);
95 if (meter_p_)
96 announce_element(Score_elem_info(meter_p_, meter_req_l_) );
99 void
100 Meter_register::do_pre_move_processing()
102 if (meter_p_) {
103 typeset_breakable_item(meter_p_);
104 meter_p_ =0;
105 meter_req_l_ = 0;
108 Register_group_register * reg_l = daddy_reg_l_;
109 while (reg_l->daddy_reg_l_) {
110 reg_l = reg_l->daddy_reg_l_;
113 assert( reg_l->name() == Score_register::static_name());
114 if (!time_.cadenza_b_)
115 ((Score_register*)reg_l)->add_moment_to_process( time_.next_bar_moment());
118 void
119 Meter_register::do_post_move_processing()
121 time_.add( get_staff_info().when() - time_.when_ );
124 IMPLEMENT_STATIC_NAME(Meter_register);
125 ADD_THIS_REGISTER(Meter_register);
126 IMPLEMENT_IS_TYPE_B1(Meter_register,Request_register);