2 beam-engraver.cc -- implement Beam_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 #include "engraver-group-engraver.hh"
10 #include "engraver.hh"
16 #include "score-engraver.hh"
18 #include "drul-array.hh"
22 class Beam_engraver
: public Engraver
25 Drul_array
<Music
*> evs_drul_
;
27 Spanner
*finished_beam_
;
29 Music
* prev_start_ev_
;
33 Beaming_info_list
* beam_info_
;
34 Beaming_info_list
* finished_beam_info_
;
36 /// location within measure where beam started.
37 Moment beam_start_location_
;
39 /// moment (global time) where beam started.
40 Moment beam_start_mom_
;
42 bool subdivide_beams_
;
46 void set_melisma (bool);
48 Moment last_stem_added_at_
;
49 virtual void stop_translation_timestep ();
50 virtual void start_translation_timestep ();
51 virtual void finalize ();
53 virtual void acknowledge_grob (Grob_info
);
54 virtual bool try_music (Music
*);
55 virtual void process_music ();
57 virtual bool valid_start_moment();
58 virtual bool valid_end_moment ();
61 TRANSLATOR_DECLARATIONS( Beam_engraver
);
66 Hmm. this isn't necessary, since grace beams and normal beams are
70 Beam_engraver::valid_start_moment()
72 Moment n
= now_mom ();
74 return n
.grace_part_
== Rational (0);
78 Beam_engraver::valid_end_moment()
80 return last_stem_added_at_
.grace_part_
== Rational(0);
84 Beam_engraver::Beam_engraver ()
88 finished_beam_info_
=0;
91 evs_drul_
[LEFT
] = evs_drul_
[RIGHT
] =0;
96 Beam_engraver::try_music (Music
*m
)
98 if (m
->is_mus_type ("abort-event"))
100 evs_drul_
[START
] = 0;
106 else if (m
->is_mus_type ("beam-event"))
108 Direction d
= to_dir (m
->get_mus_property ("span-direction"));
110 if (d
== STOP
&& !valid_end_moment())
113 if (d
== START
&& !valid_start_moment ())
118 SCM m
= get_property ("automaticMelismata");
119 SCM b
= get_property ("autoBeaming");
120 if (to_boolean (m
) && !to_boolean (b
))
129 else if (m
->is_mus_type ("new-beam-event"))
131 Direction d
= to_dir (m
->get_mus_property ("span-direction"));
132 if (d
== START
&& !valid_start_moment ())
134 if (d
== STOP
&& !valid_end_moment ())
148 Beam_engraver::set_melisma (bool m
)
150 daddy_trans_
->set_property ("beamMelismaBusy", m
? SCM_BOOL_T
:SCM_BOOL_F
);
154 Beam_engraver::process_music ()
159 finished_beam_
= beam_
;
160 finished_beam_info_
= beam_info_
;
168 top_engraver ()->forbid_breaks ();
170 if (evs_drul_
[START
])
174 evs_drul_
[START
]->origin ()->warning (_ ("already have a beam"));
178 prev_start_ev_
= evs_drul_
[START
];
179 beam_
= new Spanner (get_property ("Beam"));
180 SCM smp
= get_property ("measurePosition");
181 Moment mp
= (unsmob_moment (smp
)) ? *unsmob_moment (smp
) : Moment (0);
183 beam_start_location_
= mp
;
184 beam_start_mom_
= now_mom ();
186 beam_info_
= new Beaming_info_list
;
188 /* urg, must copy to Auto_beam_engraver too */
190 announce_grob(beam_
, evs_drul_
[START
]->self_scm());
197 Beam_engraver::typeset_beam ()
201 finished_beam_info_
->beamify(beat_length_
, subdivide_beams_
);
202 Beam::set_beaming (finished_beam_
, finished_beam_info_
);
203 typeset_grob (finished_beam_
);
204 delete finished_beam_info_
;
205 finished_beam_info_
=0;
211 Beam_engraver::start_translation_timestep ()
213 evs_drul_
[START
] =0;
218 SCM m
= get_property ("automaticMelismata");
219 SCM b
= get_property ("autoBeaming");
220 if (to_boolean (m
) && !to_boolean (b
))
224 subdivide_beams_
= to_boolean(get_property("subdivideBeams"));
225 beat_length_
= *unsmob_moment (get_property ("beatLength"));
230 Beam_engraver::stop_translation_timestep ()
235 finished_beam_
= beam_
;
236 finished_beam_info_
= beam_info_
;
246 Beam_engraver::finalize ()
251 prev_start_ev_
->origin ()->warning (_ ("unterminated beam"));
254 we don't typeset it, (we used to, but it was commented
255 out. Reason unknown) */
262 Beam_engraver::acknowledge_grob (Grob_info info
)
266 if (Rest::has_interface (info
.grob_
))
268 info
.grob_
->add_offset_callback (Beam::rest_collision_callback_proc
, Y_AXIS
);
270 else if (Stem::has_interface (info
.grob_
))
272 Moment now
= now_mom();
274 if (!valid_start_moment ())
277 Item
*stem
= dynamic_cast<Item
*> (info
.grob_
);
278 if (Stem::get_beam (stem
))
281 Music
* m
= info
.music_cause();
282 if (!m
->is_mus_type ("rhythmic-event"))
284 String s
= _ ("stem must have Rhythmic structure");
285 if (info
.music_cause ())
286 info
.music_cause ()->origin ()->warning (s
);
294 last_stem_added_at_
= now
;
295 int durlog
= unsmob_duration (m
->get_mus_property ("duration"))-> duration_log ();
298 m
->origin ()->warning (_ ("stem doesn't fit in beam"));
299 prev_start_ev_
->origin ()->warning (_ ("beam was started here"));
303 [r4 c8] can just as well be modern notation.
307 stem
->set_grob_property ("duration-log",
308 scm_int2num (durlog
));
309 Moment stem_location
= now
- beam_start_mom_
+ beam_start_location_
;
310 beam_info_
->add_stem (stem_location
,
312 Beam::add_stem (beam_
, stem
);
321 ENTER_DESCRIPTION(Beam_engraver
,
322 /* descr */ "Handles Beam events by engraving Beams. If omitted, then notes will be "
323 "printed with flags instead of beams.",
325 /* accepts */ "beam-event new-beam-event abort-event",
326 /* acks */ "stem-interface rest-interface",
327 /* reads */ "beamMelismaBusy beatLength subdivideBeams",
331 class Grace_beam_engraver
: public Beam_engraver
334 TRANSLATOR_DECLARATIONS(Grace_beam_engraver
);
337 virtual bool valid_start_moment();
338 virtual bool valid_end_moment ();
341 Grace_beam_engraver::Grace_beam_engraver()
346 Grace_beam_engraver::valid_start_moment()
348 Moment n
= now_mom ();
350 return n
.grace_part_
!= Rational (0);
355 Grace_beam_engraver::valid_end_moment ()
357 return beam_
&& last_stem_added_at_
.grace_part_
!= Rational(0);
362 ENTER_DESCRIPTION(Grace_beam_engraver
,
363 /* descr */ "Handles Beam events by engraving Beams. If omitted, then notes will "
364 "be printed with flags instead of beams. Only engraves beams when we "
365 " are at grace points in time. "
368 /* accepts */ "beam-event abort-event new-beam-event",
369 /* acks */ "stem-interface rest-interface",
370 /* reads */ "beamMelismaBusy beatLength subdivideBeams",