lilypond-1.1.23
[lilypond.git] / lily / multi-measure-rest-engraver.cc
blob6f3ba9597aed4d8991bea7340982d8710dc76710
1 /*
2 multi_measure_rest-engraver.cc -- implement Multi_measure_rest_engraver
4 (c) 1998 Jan Nieuwenhuizen <janneke@gnu.org>
5 Han-Wen Nienhuys <hanwen@cs.uu.nl>
6 */
8 #include "proto.hh"
9 #include "musical-request.hh"
10 #include "multi-measure-rest.hh"
11 #include "multi-measure-rest-engraver.hh"
12 #include "score-column.hh"
13 #include "time-description.hh"
14 //#include "paper-score.hh"
15 //#include "p-score.hh"
16 //#include "paper-def.hh"
17 //#include "main.hh"
18 //#include "global-translator.hh"
19 #include "bar.hh"
22 ADD_THIS_TRANSLATOR (Multi_measure_rest_engraver);
24 Multi_measure_rest_engraver::Multi_measure_rest_engraver ()
26 start_measure_i_ = 0;
27 rest_stop_mom_ =0;
28 // rest_item_creation_mom_ = 0;
29 multi_measure_req_l_ = 0;
30 mmrest_p_ = 0;
33 void
34 Multi_measure_rest_engraver::acknowledge_element (Score_element_info i)
36 if (Bar *c = dynamic_cast<Bar*> (i.elem_l_))
38 if (mmrest_p_)
39 mmrest_p_->add_column (c);
40 if (lastrest_p_)
41 lastrest_p_->add_column (c);
45 bool
46 Multi_measure_rest_engraver::do_try_music (Music* req_l)
48 if (Multi_measure_rest_req *mr = dynamic_cast<Multi_measure_rest_req *> (req_l))
50 if (multi_measure_req_l_)
51 if (!multi_measure_req_l_->equal_b (mr)
52 || rest_start_mom_ != now_moment ())
53 return false;
55 multi_measure_req_l_ = mr;
56 rest_start_mom_ = now_moment ();
58 rest_stop_mom_ = rest_start_mom_ + multi_measure_req_l_->duration_.length ();
59 return true;
61 return false;
64 void
65 Multi_measure_rest_engraver::do_process_requests ()
67 if (multi_measure_req_l_ && !mmrest_p_)
69 Time_description const *time = get_staff_info().time_C_;
70 mmrest_p_ = new Multi_measure_rest;
71 announce_element (Score_element_info (mmrest_p_, multi_measure_req_l_));
72 start_measure_i_ = time->bars_i_;
76 void
77 Multi_measure_rest_engraver::do_pre_move_processing ()
79 Moment now (now_moment ());
80 Time_description const *time = get_staff_info().time_C_;
81 if (mmrest_p_ && (now >= rest_start_mom_)
82 && !time->whole_in_measure_
83 && (mmrest_p_->column_arr_.size () >= 2))
85 typeset_element (mmrest_p_);
87 must keep mmrest_p_ around to set measures_i_
90 if (lastrest_p_)
92 typeset_element (lastrest_p_);
93 lastrest_p_ = 0;
97 void
98 Multi_measure_rest_engraver::do_post_move_processing ()
100 Time_description const *time = get_staff_info().time_C_;
101 Moment now (now_moment ());
103 if (mmrest_p_ && !time->whole_in_measure_)
105 lastrest_p_ = mmrest_p_;
106 lastrest_p_->measures_i_ = time->bars_i_ - start_measure_i_;
107 mmrest_p_ = 0;
110 if (now >= rest_stop_mom_)
112 multi_measure_req_l_ = 0;
113 mmrest_p_ = 0;