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 ();
36 Span_req * busy_span_req_;
47 Multi_measure_rest_engraver::Multi_measure_rest_engraver ()
50 mmrest_ = lastrest_ =0;
51 new_req_ = busy_span_req_ = stop_req_ =0;
56 Multi_measure_rest_engraver::try_music (Music* req)
58 if (Span_req * sp = dynamic_cast<Span_req*> (req))
61 if (scm_equal_p (sp->get_mus_property ("span-type"),
62 scm_makfrom0str ("rest")) == SCM_BOOL_T)
64 if (sp->get_span_dir () == STOP)
68 else if (sp->get_span_dir () == START && !new_req_)
79 Multi_measure_rest_engraver::process_music ()
81 if (new_req_ && stop_req_)
85 start_moment_ = now_mom ();
95 busy_span_req_ = new_req_;
99 if (busy_span_req_ && !mmrest_)
101 mmrest_ = new Spanner (get_property ("MultiMeasureRest"));
103 announce_grob(mmrest_, busy_span_req_->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_, it);
115 add_bound_item (lastrest_,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_ && (now_mom () >= start_moment_)
127 && mmrest_->get_bound (LEFT) && mmrest_->get_bound (RIGHT))
129 typeset_grob (mmrest_);
131 we must keep mmrest_ around to set measure-count, so
139 if (lastrest_->get_bound (LEFT) && lastrest_->get_bound (RIGHT)
140 && lastrest_->get_bound (LEFT) != lastrest_->get_bound (RIGHT))
141 typeset_grob (lastrest_);
147 busy_span_req_ = new_req_;
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_ && !mp.to_bool ())
162 int cur = gh_scm2int (get_property ("currentBarNumber"));
163 lastrest_->set_grob_property ("measure-count",
164 gh_int2scm (cur - start_measure_));
171 Multi_measure_rest_engraver::finalize ()
174 typeset_grob (mmrest_);
176 typeset_grob (lastrest_);
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",