lilypond-1.3.28
[lilypond.git] / lily / multi-measure-rest-engraver.cc
blobd34a75adbdc374299700eaf66c8b91cee1df15c1
1 /*
2 multi_measure_rest-engraver.cc -- implement Multi_measure_rest_engraver
4 (c) 1998--2000 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 "paper-column.hh"
12 #include "engraver-group-engraver.hh"
13 #include "timing-translator.hh"
14 #include "bar.hh"
15 #include "staff-symbol-referencer.hh"
16 #include "engraver.hh"
17 #include "moment.hh"
19 /**
21 class Multi_measure_rest_engraver : public Engraver
23 public:
24 VIRTUAL_COPY_CONS(Translator);
25 Multi_measure_rest_engraver ();
27 protected:
28 virtual void acknowledge_element (Score_element_info i);
29 virtual void do_process_requests ();
30 virtual bool do_try_music (Music*);
31 virtual void do_pre_move_processing ();
32 virtual void do_post_move_processing ();
33 virtual void do_removal_processing ();
34 private:
35 Span_req * new_req_l_;
36 Span_req * busy_span_req_l_;
37 Span_req * stop_req_l_;
38 int start_measure_i_;
39 Moment start_moment_;
41 Multi_measure_rest *mmrest_p_;
42 Multi_measure_rest *lastrest_p_;
45 ADD_THIS_TRANSLATOR (Multi_measure_rest_engraver);
47 Multi_measure_rest_engraver::Multi_measure_rest_engraver ()
49 start_measure_i_ = 0;
50 mmrest_p_ = lastrest_p_ =0;
51 new_req_l_ = busy_span_req_l_ = stop_req_l_ =0;
54 void
55 Multi_measure_rest_engraver::acknowledge_element (Score_element_info i)
57 if (Bar *c = dynamic_cast<Bar*> (i.elem_l_))
59 if (mmrest_p_)
60 mmrest_p_->add_column (c);
61 if (lastrest_p_)
62 lastrest_p_->add_column (c);
66 bool
67 Multi_measure_rest_engraver::do_try_music (Music* req_l)
69 if (Span_req * sp = dynamic_cast<Span_req*> (req_l))
71 if (sp->span_type_str_ == "rest")
73 if (sp->span_dir_ == STOP)
75 stop_req_l_ = sp;
77 else if (sp->span_dir_ == START && !new_req_l_)
79 new_req_l_ = sp;
81 return true;
84 return false;
89 void
90 Multi_measure_rest_engraver::do_process_requests ()
92 if (new_req_l_ && stop_req_l_)
93 stop_req_l_ = 0;
95 if (new_req_l_)
96 start_moment_ = now_mom ();
98 if (stop_req_l_)
100 busy_span_req_l_ =0;
101 stop_req_l_ = 0;
104 if (new_req_l_)
106 busy_span_req_l_ = new_req_l_;
107 new_req_l_ =0;
110 if (busy_span_req_l_ && !mmrest_p_)
112 Translator * tr = daddy_grav_l()->get_simple_translator ("Timing_engraver"); // ugh
113 Timing_translator * time = dynamic_cast<Timing_translator*> (tr);
115 mmrest_p_ = new Multi_measure_rest;
116 Staff_symbol_referencer_interface si (mmrest_p_);
117 si.set_interface ();
119 announce_element (Score_element_info (mmrest_p_, busy_span_req_l_));
120 start_measure_i_
121 = gh_scm2int (time->get_property ("currentBarNumber", 0));
125 void
126 Multi_measure_rest_engraver::do_pre_move_processing ()
128 Moment now (now_mom ());
129 Translator * tr = daddy_grav_l()->get_simple_translator ("Timing_engraver"); // ugh
130 Timing_translator * time = dynamic_cast<Timing_translator*> (tr);
132 if (mmrest_p_ && (now >= start_moment_)
133 && !time->measure_position ()
134 && (scm_ilength (mmrest_p_->get_elt_property ("columns")) >= 2))
136 typeset_element (mmrest_p_);
138 must keep mmrest_p_ around to set measures_i_
141 if (lastrest_p_)
143 typeset_element (lastrest_p_);
144 lastrest_p_ = 0;
147 if (new_req_l_)
149 busy_span_req_l_ = new_req_l_;
150 new_req_l_ =0;
155 void
156 Multi_measure_rest_engraver::do_post_move_processing ()
158 Translator * tr = daddy_grav_l()->get_simple_translator ("Timing_engraver"); // ugh
159 Timing_translator * time = dynamic_cast<Timing_translator*> (tr);
161 Moment now (now_mom ());
163 if (mmrest_p_ && !time->measure_position ())
165 lastrest_p_ = mmrest_p_;
166 int cur = gh_scm2int (time->get_property ("currentBarNumber", 0));
167 lastrest_p_->set_elt_property ("measure-count",
168 gh_int2scm (cur - start_measure_i_));
169 mmrest_p_ = 0;
174 void
175 Multi_measure_rest_engraver::do_removal_processing ()
177 if (mmrest_p_)
178 typeset_element (mmrest_p_);
179 if (lastrest_p_)
180 typeset_element (lastrest_p_);