2 multi_measure_rest-engraver.cc -- implement Multi_measure_rest_engraver
4 (c) 1998--2001 Jan Nieuwenhuizen <janneke@gnu.org>
5 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 #include "musical-request.hh"
9 #include "multi-measure-rest.hh"
10 #include "paper-column.hh"
11 #include "engraver-group-engraver.hh"
13 #include "staff-symbol-referencer.hh"
14 #include "engraver.hh"
19 The name says it all: make multi measure rests
22 class Multi_measure_rest_engraver : public Engraver
25 VIRTUAL_COPY_CONS (Translator);
26 Multi_measure_rest_engraver ();
29 virtual bool try_music (Music*);
30 virtual void process_music ();
31 virtual void stop_translation_timestep ();
32 virtual void start_translation_timestep ();
33 virtual void finalize ();
36 Span_req * new_req_l_;
37 Span_req * busy_span_req_l_;
38 Span_req * stop_req_l_;
46 ADD_THIS_TRANSLATOR (Multi_measure_rest_engraver);
48 Multi_measure_rest_engraver::Multi_measure_rest_engraver ()
51 mmrest_p_ = lastrest_p_ =0;
52 new_req_l_ = busy_span_req_l_ = stop_req_l_ =0;
57 Multi_measure_rest_engraver::try_music (Music* req_l)
59 if (Span_req * sp = dynamic_cast<Span_req*> (req_l))
62 if (scm_equal_p (sp->get_mus_property ("span-type"),
63 ly_str02scm ("rest")) == SCM_BOOL_T)
65 if (sp->get_span_dir () == STOP)
69 else if (sp->get_span_dir () == START && !new_req_l_)
80 Multi_measure_rest_engraver::process_music ()
82 if (new_req_l_ && stop_req_l_)
86 start_moment_ = now_mom ();
96 busy_span_req_l_ = new_req_l_;
100 if (busy_span_req_l_ && !mmrest_p_)
102 mmrest_p_ = new Spanner (get_property ("MultiMeasureRest"));
104 Multi_measure_rest::set_interface (mmrest_p_);
105 Staff_symbol_referencer::set_interface (mmrest_p_);
107 announce_grob (mmrest_p_, busy_span_req_l_);
109 = gh_scm2int (get_property ("currentBarNumber"));
112 if (gh_string_p (get_property ("whichBar")))
114 Grob *cmc = unsmob_grob (get_property( "currentCommandColumn"));
115 Item *it = dynamic_cast<Item*> (cmc);
117 add_bound_item (mmrest_p_, it);
119 add_bound_item (lastrest_p_,it);
124 Multi_measure_rest_engraver::stop_translation_timestep ()
126 SCM smp = get_property ("measurePosition");
127 Moment mp = (unsmob_moment (smp)) ? *unsmob_moment (smp) : Moment (0);
129 if (mmrest_p_ && (now_mom () >= start_moment_)
131 && mmrest_p_->get_bound (LEFT) && mmrest_p_->get_bound (RIGHT))
133 typeset_grob (mmrest_p_);
135 we must keep mmrest_p_ around to set measure-count, so
136 no mmrest_p_ = 0 here.
143 if (lastrest_p_->get_bound (LEFT) && lastrest_p_->get_bound (RIGHT)
144 && lastrest_p_->get_bound (LEFT) != lastrest_p_->get_bound (RIGHT))
145 typeset_grob (lastrest_p_);
151 busy_span_req_l_ = new_req_l_;
158 Multi_measure_rest_engraver::start_translation_timestep ()
160 SCM smp = get_property ("measurePosition");
161 Moment mp = (unsmob_moment (smp)) ? *unsmob_moment (smp) : Moment (0);
163 if (mmrest_p_ && !mp)
165 lastrest_p_ = mmrest_p_;
166 int cur = gh_scm2int (get_property ("currentBarNumber"));
167 lastrest_p_->set_grob_property ("measure-count",
168 gh_int2scm (cur - start_measure_i_));
175 Multi_measure_rest_engraver::finalize ()
178 typeset_grob (mmrest_p_);
180 typeset_grob (lastrest_p_);