lilypond-1.3.69
[lilypond.git] / lily / multi-measure-rest-engraver.cc
blob84d5061e7f32646692abfb949562bbc9dc91642c
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 "bar.hh"
14 #include "staff-symbol-referencer.hh"
15 #include "engraver.hh"
16 #include "moment.hh"
17 #include "spanner.hh"
19 /**
20 The name says it all: make multi measure rests
22 class Multi_measure_rest_engraver : public Engraver
24 public:
25 VIRTUAL_COPY_CONS(Translator);
26 Multi_measure_rest_engraver ();
28 protected:
29 virtual void acknowledge_element (Score_element_info i);
30 virtual void do_process_music ();
31 virtual bool do_try_music (Music*);
32 virtual void do_pre_move_processing ();
33 virtual void do_post_move_processing ();
34 virtual void do_removal_processing ();
35 private:
36 Span_req * new_req_l_;
37 Span_req * busy_span_req_l_;
38 Span_req * stop_req_l_;
39 int start_measure_i_;
40 Moment start_moment_;
42 Spanner *mmrest_p_;
43 Spanner *lastrest_p_;
46 ADD_THIS_TRANSLATOR (Multi_measure_rest_engraver);
48 Multi_measure_rest_engraver::Multi_measure_rest_engraver ()
50 start_measure_i_ = 0;
51 mmrest_p_ = lastrest_p_ =0;
52 new_req_l_ = busy_span_req_l_ = stop_req_l_ =0;
55 void
56 Multi_measure_rest_engraver::acknowledge_element (Score_element_info i)
58 Item * item = dynamic_cast<Item*> (i.elem_l_);
59 if (item && Bar::has_interface (item))
61 if (mmrest_p_)
62 Multi_measure_rest::add_column (mmrest_p_,item);
63 if (lastrest_p_)
64 Multi_measure_rest::add_column (lastrest_p_,item);
68 bool
69 Multi_measure_rest_engraver::do_try_music (Music* req_l)
71 if (Span_req * sp = dynamic_cast<Span_req*> (req_l))
73 if (sp->span_type_str_ == "rest")
75 if (sp->span_dir_ == STOP)
77 stop_req_l_ = sp;
79 else if (sp->span_dir_ == START && !new_req_l_)
81 new_req_l_ = sp;
83 return true;
86 return false;
91 void
92 Multi_measure_rest_engraver::do_process_music ()
94 if (new_req_l_ && stop_req_l_)
95 stop_req_l_ = 0;
97 if (new_req_l_)
98 start_moment_ = now_mom ();
100 if (stop_req_l_)
102 busy_span_req_l_ =0;
103 stop_req_l_ = 0;
106 if (new_req_l_)
108 busy_span_req_l_ = new_req_l_;
109 new_req_l_ =0;
112 if (busy_span_req_l_ && !mmrest_p_)
114 mmrest_p_ = new Multi_measure_rest (get_property ("basicMultiMeasureRestProperties"));
115 Multi_measure_rest::set_interface (mmrest_p_);
116 Staff_symbol_referencer::set_interface (mmrest_p_);
118 announce_element (Score_element_info (mmrest_p_, busy_span_req_l_));
119 start_measure_i_
120 = gh_scm2int (get_property ("currentBarNumber"));
124 void
125 Multi_measure_rest_engraver::do_pre_move_processing ()
127 SCM smp = get_property ("measurePosition");
128 Moment mp = (unsmob_moment (smp)) ? *unsmob_moment (smp) : Moment (0);
130 if (mmrest_p_ && (now_mom () >= start_moment_)
131 && !mp
132 && (scm_ilength (mmrest_p_->get_elt_property ("columns")) >= 2))
134 typeset_element (mmrest_p_);
136 must keep mmrest_p_ around to set measures_i_
139 if (lastrest_p_)
141 typeset_element (lastrest_p_);
142 lastrest_p_ = 0;
145 if (new_req_l_)
147 busy_span_req_l_ = new_req_l_;
148 new_req_l_ =0;
153 void
154 Multi_measure_rest_engraver::do_post_move_processing ()
156 Moment now (now_mom ());
159 SCM smp = get_property ("measurePosition");
160 Moment mp = (unsmob_moment (smp)) ? *unsmob_moment (smp) : Moment (0);
162 if (mmrest_p_ && !mp)
164 lastrest_p_ = mmrest_p_;
165 int cur = gh_scm2int (get_property ("currentBarNumber"));
166 lastrest_p_->set_elt_property ("measure-count",
167 gh_int2scm (cur - start_measure_i_));
168 mmrest_p_ = 0;
173 void
174 Multi_measure_rest_engraver::do_removal_processing ()
176 if (mmrest_p_)
177 typeset_element (mmrest_p_);
178 if (lastrest_p_)
179 typeset_element (lastrest_p_);