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"));
109 if (d == START && !valid_start_moment ())
111 if (d == STOP && !valid_end_moment ())
128 Beam_engraver::set_melisma (bool ml)
130 SCM b = get_property ("autoBeaming");
132 daddy_trans_->set_property ("beamMelismaBusy", ml ? SCM_BOOL_T :SCM_BOOL_F);
136 Beam_engraver::process_music ()
141 finished_beam_ = beam_;
142 finished_beam_info_ = beam_info_;
148 if (beam_ && !to_boolean (get_property ("allowBeamBreak")))
150 top_engraver ()->forbid_breaks ();
153 if (evs_drul_[START])
157 evs_drul_[START]->origin ()->warning (_ ("already have a beam"));
162 prev_start_ev_ = evs_drul_[START];
163 beam_ = new Spanner (get_property ("Beam"));
164 SCM smp = get_property ("measurePosition");
165 Moment mp = (unsmob_moment (smp)) ? *unsmob_moment (smp) : Moment (0);
167 beam_start_location_ = mp;
168 beam_start_mom_ = now_mom ();
170 beam_info_ = new Beaming_info_list;
172 /* urg, must copy to Auto_beam_engraver too */
174 announce_grob(beam_, evs_drul_[START]->self_scm());
181 Beam_engraver::typeset_beam ()
185 finished_beam_info_->beamify(beat_length_, subdivide_beams_);
186 Beam::set_beaming (finished_beam_, finished_beam_info_);
187 typeset_grob (finished_beam_);
188 delete finished_beam_info_;
189 finished_beam_info_ =0;
195 Beam_engraver::start_translation_timestep ()
197 evs_drul_ [START] =0;
204 subdivide_beams_ = to_boolean(get_property("subdivideBeams"));
205 beat_length_ = *unsmob_moment (get_property ("beatLength"));
210 Beam_engraver::stop_translation_timestep ()
215 finished_beam_ = beam_;
216 finished_beam_info_ = beam_info_;
227 Beam_engraver::finalize ()
232 prev_start_ev_->origin ()->warning (_ ("unterminated beam"));
235 we don't typeset it, (we used to, but it was commented
236 out. Reason unknown) */
243 Beam_engraver::acknowledge_grob (Grob_info info)
247 if (Rest::has_interface (info.grob_))
249 info.grob_->add_offset_callback (Beam::rest_collision_callback_proc, Y_AXIS);
251 else if (Stem::has_interface (info.grob_))
253 Moment now = now_mom();
255 if (!valid_start_moment ())
258 Item *stem = dynamic_cast<Item*> (info.grob_);
259 if (Stem::get_beam (stem))
262 Music* m = info.music_cause();
263 if (!m->is_mus_type ("rhythmic-event"))
265 String s = _ ("stem must have Rhythmic structure");
266 if (info.music_cause ())
267 info.music_cause ()->origin ()->warning (s);
275 last_stem_added_at_ = now;
276 int durlog = unsmob_duration (m->get_mus_property ("duration"))-> duration_log ();
279 m->origin ()->warning (_ ("stem doesn't fit in beam"));
280 prev_start_ev_->origin ()->warning (_ ("beam was started here"));
284 [r4 c8] can just as well be modern notation.
288 stem->set_grob_property ("duration-log",
289 scm_int2num (durlog));
290 Moment stem_location = now - beam_start_mom_ + beam_start_location_;
291 beam_info_->add_stem (stem_location,
293 Beam::add_stem (beam_, stem);
302 ENTER_DESCRIPTION(Beam_engraver,
303 /* descr */ "Handles Beam events by engraving Beams. If omitted, then notes will be "
304 "printed with flags instead of beams.",
306 /* accepts */ "beam-event abort-event",
307 /* acks */ "stem-interface rest-interface",
308 /* reads */ "beamMelismaBusy beatLength subdivideBeams",
312 class Grace_beam_engraver : public Beam_engraver
315 TRANSLATOR_DECLARATIONS(Grace_beam_engraver);
318 virtual bool valid_start_moment();
319 virtual bool valid_end_moment ();
322 Grace_beam_engraver::Grace_beam_engraver()
327 Grace_beam_engraver::valid_start_moment()
329 Moment n = now_mom ();
331 return n.grace_part_ != Rational (0);
336 Grace_beam_engraver::valid_end_moment ()
338 return beam_ && last_stem_added_at_.grace_part_ != Rational(0);
343 ENTER_DESCRIPTION(Grace_beam_engraver,
344 /* descr */ "Handles Beam events by engraving Beams. If omitted, then notes will "
345 "be printed with flags instead of beams. Only engraves beams when we "
346 " are at grace points in time. "
349 /* accepts */ "beam-event abort-event",
350 /* acks */ "stem-interface rest-interface",
351 /* reads */ "beamMelismaBusy beatLength allowBeamBreak subdivideBeams",