2 multi_measure_rest-engraver.cc -- implement Multi_measure_rest_engraver
4 (c) 1998--2006 Jan Nieuwenhuizen <janneke@gnu.org>
5 Han-Wen Nienhuys <hanwen@xs4all.nl>
8 #include "multi-measure-rest.hh"
9 #include "paper-column.hh"
10 #include "engraver-group.hh"
11 #include "side-position-interface.hh"
12 #include "staff-symbol-referencer.hh"
16 The name says it all: make multi measure rests
18 class Multi_measure_rest_engraver : public Engraver
21 TRANSLATOR_DECLARATIONS (Multi_measure_rest_engraver);
24 virtual bool try_music (Music *);
25 void process_music ();
26 void stop_translation_timestep ();
27 void start_translation_timestep ();
28 virtual void finalize ();
32 vector<Music*> text_events_;
34 Rational last_main_moment_;
38 Item *last_command_item_;
42 vector<Spanner*> numbers_;
43 vector<Spanner*> last_numbers_;
46 Multi_measure_rest_engraver::Multi_measure_rest_engraver ()
48 last_command_item_ = 0;
51 For the start of a score.
61 Multi_measure_rest_engraver::try_music (Music *event)
63 if (event->is_mus_type ("multi-measure-rest-event"))
66 stop_moment_ = now_mom () + rest_ev_->get_length ();
70 else if (event->is_mus_type ("multi-measure-text-event"))
72 text_events_.push_back (event);
79 Multi_measure_rest_engraver::process_music ()
81 if (rest_ev_ && !mmrest_
82 && stop_moment_ > now_mom ())
84 mmrest_ = make_spanner ("MultiMeasureRest", rest_ev_->self_scm ());
87 = make_spanner ("MultiMeasureRestNumber", rest_ev_->self_scm ());
88 numbers_.push_back (sp);
90 if (text_events_.size ())
92 for (vsize i = 0; i < text_events_.size (); i++)
95 Music *e = text_events_[i];
97 = make_spanner ("MultiMeasureRestText", e->self_scm ());
98 SCM t = e->get_property ("text");
99 SCM dir = e->get_property ("direction");
100 sp->set_property ("text", t);
101 if (is_direction (dir))
102 sp->set_property ("direction", dir);
104 numbers_.push_back (sp);
108 Stack different scripts.
114 for (vsize i = 0; i < numbers_.size (); i++)
116 if (scm_from_int (d) == numbers_[i]->get_property ("direction"))
119 Side_position_interface::add_support (numbers_[i], last);
124 while (flip (&d) != DOWN);
127 for (vsize i = 0; i < numbers_.size (); i++)
129 Side_position_interface::add_support (numbers_[i], mmrest_);
130 numbers_[i]->set_parent (mmrest_, Y_AXIS);
134 = scm_to_int (get_property ("currentBarNumber"));
137 bar_seen_ = bar_seen_ || scm_is_string (get_property ("whichBar"));
141 Multi_measure_rest_engraver::stop_translation_timestep ()
143 /* We cannot do this earlier, as breakableSeparationItem is not yet
147 Grob *cmc = unsmob_grob (get_property ("breakableSeparationItem"));
149 cmc = unsmob_grob (get_property ("currentCommandColumn"));
151 /* Ugh, this is a kludge - need this for multi-measure-rest-grace.ly */
152 last_command_item_ = dynamic_cast<Item *> (cmc);
155 if (last_command_item_ && (mmrest_ || last_rest_))
159 add_bound_item (last_rest_, last_command_item_);
160 for (vsize i = 0; i < last_numbers_.size (); i++)
161 add_bound_item (last_numbers_[i], last_command_item_);
166 add_bound_item (mmrest_, last_command_item_);
167 for (vsize i = 0; i < numbers_.size (); i++)
168 add_bound_item (numbers_[i], last_command_item_);
170 last_command_item_ = 0;
174 Moment mp (robust_scm2moment (get_property ("measurePosition"), Moment (0)));
178 last_numbers_.clear ();
181 text_events_.clear ();
186 Multi_measure_rest_engraver::start_translation_timestep ()
188 if (now_mom ().main_part_ >= stop_moment_.main_part_)
191 Moment mp (robust_scm2moment (get_property ("measurePosition"), Moment (0)));
193 Moment now = now_mom ();
195 && now.main_part_ != last_main_moment_
196 && mp.main_part_ == Rational (0))
198 last_rest_ = mmrest_;
199 last_numbers_ = numbers_;
201 int cur = scm_to_int (get_property ("currentBarNumber"));
202 int num = cur - start_measure_;
205 We can't plug a markup directly into the grob, since the
206 measure-count determines the formatting of the mmrest.
208 last_rest_->set_property ("measure-count", scm_from_int (num));
210 SCM sml = get_property ("measureLength");
211 Rational ml = (unsmob_moment (sml)) ? unsmob_moment (sml)->main_part_ : Rational (1);
212 if (ml >= Rational (2))
213 last_rest_->set_property ("use-breve-rest", SCM_BOOL_T);
218 Grob *last = last_numbers_.size () ? last_numbers_[0] : 0;
219 if (last && last->get_property ("text") == SCM_EOL)
221 SCM thres = get_property ("restNumberThreshold");
223 if (scm_is_number (thres))
224 t = scm_to_int (thres);
231 = scm_number_to_string (scm_from_int (num), scm_from_int (10));
232 last->set_property ("text", text);
237 last_main_moment_ = now.main_part_;
241 Multi_measure_rest_engraver::finalize ()
245 #include "translator.icc"
247 ADD_TRANSLATOR (Multi_measure_rest_engraver,
249 "Engraves multi-measure rests that are produced with @code{R}. Reads "
250 "measurePosition and currentBarNumber to determine what number to print "
251 "over the MultiMeasureRest. Reads measureLength to determine if it "
252 "should use a whole rest or a breve rest to represent 1 measure ",
253 /* create */ "MultiMeasureRest MultiMeasureRestNumber MultiMeasureRestText",
254 /* accept */ "multi-measure-rest-event multi-measure-text-event",
257 "restNumberThreshold "
258 "breakableSeparationItem "
259 "currentCommandColumn "