2 multi_measure_rest-engraver.cc -- implement Multi_measure_rest_engraver
4 (c) 1998--2004 Jan Nieuwenhuizen <janneke@gnu.org>
5 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 #include "multi-measure-rest.hh"
10 #include "paper-column.hh"
11 #include "engraver-group-engraver.hh"
12 #include "side-position-interface.hh"
13 #include "staff-symbol-referencer.hh"
14 #include "engraver.hh"
19 The name says it all: make multi measure rests
21 class Multi_measure_rest_engraver : public Engraver
24 TRANSLATOR_DECLARATIONS (Multi_measure_rest_engraver);
27 virtual bool try_music (Music*);
28 virtual void process_music ();
29 virtual void stop_translation_timestep ();
30 virtual void start_translation_timestep ();
31 virtual void finalize ();
35 Link_array<Music> text_events_;
37 Rational last_main_moment_;
41 Item *last_command_item_ ;
45 Link_array<Spanner> numbers_;
46 Link_array<Spanner> last_numbers_;
49 Multi_measure_rest_engraver::Multi_measure_rest_engraver ()
51 last_command_item_ = 0;
60 Multi_measure_rest_engraver::try_music (Music* req)
62 if (req->is_mus_type ("multi-measure-rest-event"))
65 stop_moment_ = now_mom () + rest_ev_->get_length ();
69 else if (req->is_mus_type ("multi-measure-text-event"))
71 text_events_.push (req);
78 Multi_measure_rest_engraver::process_music ()
80 if (rest_ev_ && !mmrest_
81 && stop_moment_ > now_mom ())
83 mmrest_ = make_spanner ("MultiMeasureRest", rest_ev_->self_scm ());
85 if (text_events_.size ())
87 for (int i = 0; i < text_events_.size (); i++)
90 Music* e = text_events_[i];
92 = make_spanner ("MultiMeasureRestText", e->self_scm () );
93 SCM t = e->get_property ("text");
94 SCM dir = e->get_property ("direction");
95 sp->set_property ("text",t);
96 if (is_direction (dir))
97 sp->set_property ("direction",dir);
103 Stack different scripts.
108 for (int i=0; i <numbers_.size (); i++)
110 if (scm_int2num (d) == numbers_[i]->get_property ("direction"))
113 Side_position_interface::add_support (numbers_[i], last);
117 } while (flip (&d) != DOWN);
122 = make_spanner ("MultiMeasureRestNumber", rest_ev_->self_scm () );
126 for (int i =0 ; i < numbers_.size (); i++)
128 Side_position_interface::add_support (numbers_[i], mmrest_);
129 numbers_[i]->set_parent (mmrest_, Y_AXIS);
133 = ly_scm2int (get_property ("currentBarNumber"));
136 bar_seen_ = ly_c_string_p (get_property ("whichBar"));
140 Multi_measure_rest_engraver::stop_translation_timestep ()
143 We can not do this earlier, as breakableSeparationItem is not yet there.
148 Grob *cmc = unsmob_grob (get_property ("breakableSeparationItem"));
150 cmc = unsmob_grob (get_property ("currentCommandColumn"));
153 Ugh, this is a kludge - need this for multi-measure-rest-grace.ly
155 last_command_item_ = dynamic_cast<Item*> (cmc);
158 if (last_command_item_ && (mmrest_ || last_rest_))
163 add_bound_item (last_rest_, last_command_item_);
164 for (int i = 0; i < last_numbers_.size (); i++)
165 add_bound_item (last_numbers_[i], last_command_item_);
170 add_bound_item (mmrest_, last_command_item_);
171 for (int i = 0; i < numbers_.size (); i++)
172 add_bound_item (numbers_[i], last_command_item_);
174 last_command_item_ = 0;
179 SCM smp = get_property ("measurePosition");
180 Moment mp = (unsmob_moment (smp)) ? *unsmob_moment (smp) : Moment (0);
185 last_numbers_.clear ();
188 text_events_.clear ();
192 Multi_measure_rest_engraver::start_translation_timestep ()
194 if (now_mom ().main_part_ >= stop_moment_.main_part_)
201 SCM smp = get_property ("measurePosition");
202 Moment mp = (unsmob_moment (smp)) ? *unsmob_moment (smp) : Moment (0);
204 Moment now =now_mom ();
206 && now.main_part_ != last_main_moment_
207 && mp.main_part_ == Rational (0))
209 last_rest_ = mmrest_;
210 last_numbers_ = numbers_;
212 int cur = ly_scm2int (get_property ("currentBarNumber"));
213 int num = cur - start_measure_;
216 We can't plug a markup directly into the grob, since the
217 measure-count determines the formatting of the mmrest.
219 last_rest_->set_property ("measure-count", scm_int2num (num));
221 SCM sml = get_property ("measureLength");
222 Rational ml = (unsmob_moment (sml)) ? unsmob_moment (sml)->main_part_ : Rational (1);
223 if (ml >= Rational (2))
225 last_rest_->set_property ("use-breve-rest", SCM_BOOL_T);
231 Grob * last = last_numbers_.size () ? last_numbers_[0] : 0;
232 if (last && last->get_property ("text") == SCM_EOL)
234 SCM thres = get_property ("restNumberThreshold");
236 if (ly_c_number_p (thres))
237 t = ly_scm2int (thres);
244 = scm_number_to_string (scm_int2num (num), SCM_MAKINUM (10));
245 last->set_property ("text", text);
250 last_main_moment_ = now.main_part_;
254 Multi_measure_rest_engraver::finalize ()
258 ENTER_DESCRIPTION (Multi_measure_rest_engraver,
260 "Engraves multi-measure rests that are produced with @code{R}. Reads "
261 "measurePosition and currentBarNumber to determine what number to print "
262 "over the MultiMeasureRest. Reads measureLength to determine if it "
263 "should use a whole rest or a breve rest to represent 1 measure "
265 /* creats*/ "MultiMeasureRest MultiMeasureRestNumber MultiMeasureRestText",
266 /* accepts */ "multi-measure-rest-event multi-measure-text-event",
268 /* reads */ "currentBarNumber restNumberThreshold breakableSeparationItem currentCommandColumn measurePosition measureLength",