2 multi_measure_rest-engraver.cc -- implement Multi_measure_rest_engraver
4 (c) 1998--2009 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"
13 #include "stream-event.hh"
17 #include "translator.icc"
20 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 void process_music ();
29 void stop_translation_timestep ();
30 void start_translation_timestep ();
31 virtual void finalize ();
32 DECLARE_TRANSLATOR_LISTENER (multi_measure_rest
);
33 DECLARE_TRANSLATOR_LISTENER (multi_measure_text
);
36 Stream_event
*rest_ev_
;
37 vector
<Stream_event
*> text_events_
;
39 Rational last_main_moment_
;
43 Item
*last_command_item_
;
47 vector
<Spanner
*> numbers_
;
48 vector
<Spanner
*> last_numbers_
;
51 Multi_measure_rest_engraver::Multi_measure_rest_engraver ()
53 last_command_item_
= 0;
56 For the start of a score.
65 IMPLEMENT_TRANSLATOR_LISTENER (Multi_measure_rest_engraver
, multi_measure_rest
);
67 Multi_measure_rest_engraver::listen_multi_measure_rest (Stream_event
*ev
)
69 /* FIXME: Should use ASSIGN_EVENT_ONCE. Can't do that yet because of
70 the kill-mm-rests hack in part-combine-iterator. */
72 stop_moment_
= now_mom () + get_event_length (rest_ev_
, now_mom ());
74 if (ASSIGN_EVENT_ONCE (rest_ev_, ev))
75 stop_moment_ = now_mom () + get_event_length (rest_ev_);
79 IMPLEMENT_TRANSLATOR_LISTENER (Multi_measure_rest_engraver
, multi_measure_text
);
81 Multi_measure_rest_engraver::listen_multi_measure_text (Stream_event
*ev
)
83 text_events_
.push_back (ev
);
87 Multi_measure_rest_engraver::process_music ()
89 if (rest_ev_
&& !mmrest_
90 && stop_moment_
> now_mom ())
92 mmrest_
= make_spanner ("MultiMeasureRest", rest_ev_
->self_scm ());
95 = make_spanner ("MultiMeasureRestNumber", rest_ev_
->self_scm ());
96 numbers_
.push_back (sp
);
98 if (text_events_
.size ())
100 for (vsize i
= 0; i
< text_events_
.size (); i
++)
102 Stream_event
*e
= text_events_
[i
];
104 = make_spanner ("MultiMeasureRestText", e
->self_scm ());
105 SCM t
= e
->get_property ("text");
106 SCM dir
= e
->get_property ("direction");
107 sp
->set_property ("text", t
);
108 if (is_direction (dir
))
109 sp
->set_property ("direction", dir
);
111 numbers_
.push_back (sp
);
115 Stack different scripts.
121 for (vsize i
= 0; i
< numbers_
.size (); i
++)
123 if (scm_from_int (d
) == numbers_
[i
]->get_property ("direction"))
126 Side_position_interface::add_support (numbers_
[i
], last
);
131 while (flip (&d
) != DOWN
);
134 for (vsize i
= 0; i
< numbers_
.size (); i
++)
136 Side_position_interface::add_support (numbers_
[i
], mmrest_
);
137 numbers_
[i
]->set_parent (mmrest_
, Y_AXIS
);
141 = scm_to_int (get_property ("internalBarNumber"));
144 bar_seen_
= bar_seen_
|| scm_is_string (get_property ("whichBar"));
148 Multi_measure_rest_engraver::stop_translation_timestep ()
150 /* We cannot do this earlier, as breakableSeparationItem is not yet
153 Actually, we no longer use breakableSeparationItem -- should this be moved?
157 Grob
*cmc
= unsmob_grob (get_property ("currentCommandColumn"));
159 /* Ugh, this is a kludge - need this for multi-measure-rest-grace.ly */
160 last_command_item_
= dynamic_cast<Item
*> (cmc
);
163 if (last_command_item_
&& (mmrest_
|| last_rest_
))
167 add_bound_item (last_rest_
, last_command_item_
);
168 for (vsize i
= 0; i
< last_numbers_
.size (); i
++)
169 add_bound_item (last_numbers_
[i
], last_command_item_
);
174 add_bound_item (mmrest_
, last_command_item_
);
175 for (vsize i
= 0; i
< numbers_
.size (); i
++)
176 add_bound_item (numbers_
[i
], last_command_item_
);
178 last_command_item_
= 0;
182 Moment
mp (robust_scm2moment (get_property ("measurePosition"), Moment (0)));
186 last_numbers_
.clear ();
189 text_events_
.clear ();
194 Multi_measure_rest_engraver::start_translation_timestep ()
196 if (now_mom ().main_part_
>= stop_moment_
.main_part_
)
199 Moment
mp (robust_scm2moment (get_property ("measurePosition"), Moment (0)));
201 Moment now
= now_mom ();
203 && now
.main_part_
!= last_main_moment_
204 && mp
.main_part_
== Rational (0))
206 last_rest_
= mmrest_
;
207 last_numbers_
= numbers_
;
209 int cur
= scm_to_int (get_property ("internalBarNumber"));
210 int num
= cur
- start_measure_
;
213 We can't plug a markup directly into the grob, since the
214 measure-count determines the formatting of the mmrest.
216 last_rest_
->set_property ("measure-count", scm_from_int (num
));
218 SCM sml
= get_property ("measureLength");
219 Rational ml
= (unsmob_moment (sml
)) ? unsmob_moment (sml
)->main_part_
: Rational (1);
220 if (ml
>= Rational (2))
221 last_rest_
->set_property ("use-breve-rest", SCM_BOOL_T
);
226 Grob
*last
= last_numbers_
.size () ? last_numbers_
[0] : 0;
227 if (last
&& last
->get_property ("text") == SCM_EOL
)
229 SCM thres
= get_property ("restNumberThreshold");
231 if (scm_is_number (thres
))
232 t
= scm_to_int (thres
);
239 = scm_number_to_string (scm_from_int (num
), scm_from_int (10));
240 last
->set_property ("text", text
);
245 last_main_moment_
= now
.main_part_
;
249 Multi_measure_rest_engraver::finalize ()
253 ADD_TRANSLATOR (Multi_measure_rest_engraver
,
255 "Engrave multi-measure rests that are produced with"
256 " @samp{R}. It reads @code{measurePosition} and"
257 " @code{internalBarNumber} to determine what number to print"
258 " over the @ref{MultiMeasureRest}. Reads @code{measureLength}"
259 " to determine whether it should use a whole rest or a breve"
260 " rest to represent one measure.",
264 "MultiMeasureRestNumber "
265 "MultiMeasureRestText ",
269 "restNumberThreshold "
270 "currentCommandColumn "