2 beam-engraver.cc -- implement Beam_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2009 Han-Wen Nienhuys <hanwen@xs4all.nl>
10 #include "beaming-pattern.hh"
12 #include "directional-element-interface.hh"
13 #include "drul-array.hh"
14 #include "duration.hh"
15 #include "engraver.hh"
16 #include "international.hh"
20 #include "stream-event.hh"
24 #include "translator.icc"
26 class Beam_engraver
: public Engraver
29 DECLARE_ACKNOWLEDGER (stem
);
30 DECLARE_ACKNOWLEDGER (rest
);
33 Stream_event
*start_ev_
;
35 Spanner
*finished_beam_
;
37 Stream_event
*prev_start_ev_
;
39 Stream_event
*stop_ev_
;
41 Direction forced_direction_
;
43 Beaming_pattern
*beam_info_
;
44 Beaming_pattern
*finished_beam_info_
;
46 /// location within measure where beam started.
47 Moment beam_start_location_
;
49 /// moment (global time) where beam started.
50 Moment beam_start_mom_
;
52 Beaming_options beaming_options_
;
53 Beaming_options finished_beaming_options_
;
56 void set_melisma (bool);
58 Moment last_stem_added_at_
;
59 void stop_translation_timestep ();
60 void start_translation_timestep ();
61 virtual void finalize ();
63 void process_music ();
65 virtual bool valid_start_point ();
66 virtual bool valid_end_point ();
68 DECLARE_TRANSLATOR_LISTENER (beam
);
70 TRANSLATOR_DECLARATIONS (Beam_engraver
);
74 Hmm. this isn't necessary, since grace beams and normal beams are
78 Beam_engraver::valid_start_point ()
80 Moment n
= now_mom ();
82 return n
.grace_part_
== Rational (0);
86 Beam_engraver::valid_end_point ()
88 return valid_start_point ();
91 Beam_engraver::Beam_engraver ()
95 finished_beam_info_
= 0;
97 forced_direction_
= CENTER
;
103 IMPLEMENT_TRANSLATOR_LISTENER (Beam_engraver
, beam
);
105 Beam_engraver::listen_beam (Stream_event
*ev
)
107 Direction d
= to_dir (ev
->get_property ("span-direction"));
109 if (d
== START
&& valid_start_point ())
111 ASSIGN_EVENT_ONCE (start_ev_
, ev
);
113 Direction updown
= to_dir (ev
->get_property ("direction"));
115 forced_direction_
= updown
;
117 else if (d
== STOP
&& valid_end_point ())
118 ASSIGN_EVENT_ONCE (stop_ev_
, ev
);
122 Beam_engraver::set_melisma (bool ml
)
124 SCM b
= get_property ("autoBeaming");
126 context ()->set_property ("beamMelismaBusy", ml
? SCM_BOOL_T
: SCM_BOOL_F
);
130 Beam_engraver::process_music ()
136 start_ev_
->origin ()->warning (_ ("already have a beam"));
141 prev_start_ev_
= start_ev_
;
142 beam_
= make_spanner ("Beam", start_ev_
->self_scm ());
144 Moment
mp (robust_scm2moment (get_property ("measurePosition"),
147 beam_start_location_
= mp
;
148 beam_start_mom_
= now_mom ();
150 beaming_options_
.from_context (context ());
151 beam_info_
= new Beaming_pattern
;
152 /* urg, must copy to Auto_beam_engraver too */
156 if (stop_ev_
&& beam_
)
158 announce_end_grob (beam_
, stop_ev_
->self_scm ());
164 Beam_engraver::typeset_beam ()
168 if (!finished_beam_
->get_bound (RIGHT
))
169 finished_beam_
->set_bound (RIGHT
, finished_beam_
->get_bound (LEFT
));
170 if (forced_direction_
)
172 Grob
*stem
= finished_beam_
->get_bound (RIGHT
);
173 set_grob_direction (stem
, forced_direction_
);
174 forced_direction_
= CENTER
;
176 finished_beam_info_
->beamify (finished_beaming_options_
);
178 Beam::set_beaming (finished_beam_
, finished_beam_info_
);
180 delete finished_beam_info_
;
181 finished_beam_info_
= 0;
188 Beam_engraver::start_translation_timestep ()
197 Beam_engraver::stop_translation_timestep ()
201 finished_beam_
= beam_
;
202 finished_beam_info_
= beam_info_
;
203 finished_beaming_options_
= beaming_options_
;
214 Beam_engraver::finalize ()
219 prev_start_ev_
->origin ()->warning (_ ("unterminated beam"));
222 we don't typeset it, (we used to, but it was commented
223 out. Reason unknown) */
230 Beam_engraver::acknowledge_rest (Grob_info info
)
233 && !scm_is_number (info
.grob ()->get_property_data ("staff-position")))
234 chain_offset_callback (info
.grob (),
235 Beam::rest_collision_callback_proc
, Y_AXIS
);
239 Beam_engraver::acknowledge_stem (Grob_info info
)
244 Moment now
= now_mom ();
245 if (!valid_start_point ())
248 Item
*stem
= dynamic_cast<Item
*> (info
.grob ());
249 if (Stem::get_beam (stem
))
252 Stream_event
*ev
= info
.ultimate_event_cause ();
253 if (!ev
->in_event_class ("rhythmic-event"))
255 info
.grob ()->warning (_ ("stem must have Rhythmic structure"));
259 last_stem_added_at_
= now
;
260 int durlog
= unsmob_duration (ev
->get_property ("duration"))->duration_log ();
263 ev
->origin ()->warning (_ ("stem does not fit in beam"));
264 prev_start_ev_
->origin ()->warning (_ ("beam was started here"));
268 [r4 c8] can just as well be modern notation.
272 if (forced_direction_
)
273 set_grob_direction (stem
, forced_direction_
);
275 stem
->set_property ("duration-log", scm_from_int (durlog
));
276 Moment stem_location
= now
- beam_start_mom_
+ beam_start_location_
;
277 beam_info_
->add_stem (stem_location
,
279 Stem::is_invisible (stem
));
280 Beam::add_stem (beam_
, stem
);
283 ADD_ACKNOWLEDGER (Beam_engraver
, stem
);
284 ADD_ACKNOWLEDGER (Beam_engraver
, rest
);
286 ADD_TRANSLATOR (Beam_engraver
,
288 "Handle @code{Beam} events by engraving beams. If omitted,"
289 " then notes are printed with flags instead of beams.",
303 class Grace_beam_engraver
: public Beam_engraver
306 TRANSLATOR_DECLARATIONS (Grace_beam_engraver
);
308 DECLARE_TRANSLATOR_LISTENER (beam
);
311 virtual bool valid_start_point ();
312 virtual bool valid_end_point ();
315 Grace_beam_engraver::Grace_beam_engraver ()
320 Grace_beam_engraver::valid_start_point ()
322 Moment n
= now_mom ();
324 return n
.grace_part_
!= Rational (0);
328 Grace_beam_engraver::valid_end_point ()
330 return beam_
&& valid_start_point ();
336 IMPLEMENT_TRANSLATOR_LISTENER (Grace_beam_engraver
, beam
);
338 Grace_beam_engraver::listen_beam (Stream_event
*ev
)
340 Direction d
= to_dir (ev
->get_property ("span-direction"));
342 if (d
== START
&& valid_start_point ())
344 else if (d
== STOP
&& valid_end_point ())
349 ADD_ACKNOWLEDGER (Grace_beam_engraver
, stem
);
350 ADD_ACKNOWLEDGER (Grace_beam_engraver
, rest
);
352 ADD_TRANSLATOR (Grace_beam_engraver
,
354 "Handle @code{Beam} events by engraving beams. If omitted,"
355 " then notes are printed with flags instead of beams. Only"
356 " engraves beams when we are at grace points in time.",