2 multi_measure_rest-engraver.cc -- implement Multi_measure_rest_engraver
4 (c) 1998--2002 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 TRANSLATOR_DECLARATIONS(Multi_measure_rest_engraver);
28 virtual bool try_music (Music*);
29 virtual void process_music ();
30 virtual void stop_translation_timestep ();
31 virtual void start_translation_timestep ();
32 virtual void finalize ();
35 Span_req * new_req_l_;
36 Span_req * busy_span_req_l_;
37 Span_req * stop_req_l_;
47 Multi_measure_rest_engraver::Multi_measure_rest_engraver ()
50 mmrest_p_ = lastrest_p_ =0;
51 new_req_l_ = busy_span_req_l_ = stop_req_l_ =0;
56 Multi_measure_rest_engraver::try_music (Music* req_l)
58 if (Span_req * sp = dynamic_cast<Span_req*> (req_l))
61 if (scm_equal_p (sp->get_mus_property ("span-type"),
62 ly_str02scm ("rest")) == SCM_BOOL_T)
64 if (sp->get_span_dir () == STOP)
68 else if (sp->get_span_dir () == START && !new_req_l_)
79 Multi_measure_rest_engraver::process_music ()
81 if (new_req_l_ && stop_req_l_)
85 start_moment_ = now_mom ();
95 busy_span_req_l_ = new_req_l_;
99 if (busy_span_req_l_ && !mmrest_p_)
101 mmrest_p_ = new Spanner (get_property ("MultiMeasureRest"));
103 announce_grob(mmrest_p_, busy_span_req_l_->self_scm());
105 = gh_scm2int (get_property ("currentBarNumber"));
108 if (gh_string_p (get_property ("whichBar")))
110 Grob *cmc = unsmob_grob (get_property( "currentCommandColumn"));
111 Item *it = dynamic_cast<Item*> (cmc);
113 add_bound_item (mmrest_p_, it);
115 add_bound_item (lastrest_p_,it);
120 Multi_measure_rest_engraver::stop_translation_timestep ()
122 SCM smp = get_property ("measurePosition");
123 Moment mp = (unsmob_moment (smp)) ? *unsmob_moment (smp) : Moment (0);
125 if (mmrest_p_ && (now_mom () >= start_moment_)
127 && mmrest_p_->get_bound (LEFT) && mmrest_p_->get_bound (RIGHT))
129 typeset_grob (mmrest_p_);
131 we must keep mmrest_p_ around to set measure-count, so
132 no mmrest_p_ = 0 here.
139 if (lastrest_p_->get_bound (LEFT) && lastrest_p_->get_bound (RIGHT)
140 && lastrest_p_->get_bound (LEFT) != lastrest_p_->get_bound (RIGHT))
141 typeset_grob (lastrest_p_);
147 busy_span_req_l_ = new_req_l_;
154 Multi_measure_rest_engraver::start_translation_timestep ()
156 SCM smp = get_property ("measurePosition");
157 Moment mp = (unsmob_moment (smp)) ? *unsmob_moment (smp) : Moment (0);
159 if (mmrest_p_ && !mp.to_bool ())
161 lastrest_p_ = mmrest_p_;
162 int cur = gh_scm2int (get_property ("currentBarNumber"));
163 lastrest_p_->set_grob_property ("measure-count",
164 gh_int2scm (cur - start_measure_i_));
171 Multi_measure_rest_engraver::finalize ()
174 typeset_grob (mmrest_p_);
176 typeset_grob (lastrest_p_);
179 ENTER_DESCRIPTION(Multi_measure_rest_engraver,
180 /* descr */ "Engraves multi-measure rests that are produced with @code{R}. Reads
181 measurePosition and currentBarNumber to determine what number to print over the MultiMeasureRest
183 /* creats*/ "MultiMeasureRest",
185 /* reads */ "currentBarNumber currentCommandColumn measurePosition",