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_point();
58 virtual bool valid_end_point ();
61 TRANSLATOR_DECLARATIONS( Beam_engraver );
66 Hmm. this isn't necessary, since grace beams and normal beams are
70 Beam_engraver::valid_start_point()
72 Moment n = now_mom ();
74 return n.grace_part_ == Rational (0);
78 Beam_engraver::valid_end_point()
80 return valid_start_point ();
83 Beam_engraver::Beam_engraver ()
87 finished_beam_info_=0;
90 evs_drul_[LEFT] = evs_drul_[RIGHT] =0;
95 Beam_engraver::try_music (Music *m)
97 if (m->is_mus_type ("abort-event"))
105 else if (m->is_mus_type ("beam-event"))
107 Direction d = to_dir (m->get_mus_property ("span-direction"));
108 if (d == START && !valid_start_point ())
110 if (d == STOP && !valid_end_point ())
127 Beam_engraver::set_melisma (bool ml)
129 SCM b = get_property ("autoBeaming");
131 daddy_trans_->set_property ("beamMelismaBusy", ml ? SCM_BOOL_T :SCM_BOOL_F);
135 Beam_engraver::process_music ()
140 finished_beam_ = beam_;
141 finished_beam_info_ = beam_info_;
147 if (beam_ && !to_boolean (get_property ("allowBeamBreak")))
149 top_engraver ()->forbid_breaks ();
152 if (evs_drul_[START])
156 evs_drul_[START]->origin ()->warning (_ ("already have a beam"));
161 prev_start_ev_ = evs_drul_[START];
162 beam_ = new Spanner (get_property ("Beam"));
163 SCM smp = get_property ("measurePosition");
164 Moment mp = (unsmob_moment (smp)) ? *unsmob_moment (smp) : Moment (0);
166 beam_start_location_ = mp;
167 beam_start_mom_ = now_mom ();
169 beam_info_ = new Beaming_info_list;
171 /* urg, must copy to Auto_beam_engraver too */
173 announce_grob(beam_, evs_drul_[START]->self_scm());
180 Beam_engraver::typeset_beam ()
184 finished_beam_info_->beamify(beat_length_, subdivide_beams_);
185 Beam::set_beaming (finished_beam_, finished_beam_info_);
186 typeset_grob (finished_beam_);
187 delete finished_beam_info_;
188 finished_beam_info_ =0;
194 Beam_engraver::start_translation_timestep ()
196 evs_drul_ [START] =0;
203 subdivide_beams_ = to_boolean(get_property("subdivideBeams"));
204 beat_length_ = *unsmob_moment (get_property ("beatLength"));
209 Beam_engraver::stop_translation_timestep ()
214 finished_beam_ = beam_;
215 finished_beam_info_ = beam_info_;
226 Beam_engraver::finalize ()
231 prev_start_ev_->origin ()->warning (_ ("unterminated beam"));
234 we don't typeset it, (we used to, but it was commented
235 out. Reason unknown) */
242 Beam_engraver::acknowledge_grob (Grob_info info)
246 if (Rest::has_interface (info.grob_))
248 info.grob_->add_offset_callback (Beam::rest_collision_callback_proc, Y_AXIS);
250 else if (Stem::has_interface (info.grob_))
252 Moment now = now_mom();
254 if (!valid_start_point ())
257 Item *stem = dynamic_cast<Item*> (info.grob_);
258 if (Stem::get_beam (stem))
261 Music* m = info.music_cause();
262 if (!m->is_mus_type ("rhythmic-event"))
264 String s = _ ("stem must have Rhythmic structure");
265 if (info.music_cause ())
266 info.music_cause ()->origin ()->warning (s);
274 last_stem_added_at_ = now;
275 int durlog = unsmob_duration (m->get_mus_property ("duration"))-> duration_log ();
278 m->origin ()->warning (_ ("stem doesn't fit in beam"));
279 prev_start_ev_->origin ()->warning (_ ("beam was started here"));
283 [r4 c8] can just as well be modern notation.
287 stem->set_grob_property ("duration-log",
288 scm_int2num (durlog));
289 Moment stem_location = now - beam_start_mom_ + beam_start_location_;
290 beam_info_->add_stem (stem_location,
292 Beam::add_stem (beam_, stem);
301 ENTER_DESCRIPTION(Beam_engraver,
302 /* descr */ "Handles Beam events by engraving Beams. If omitted, then notes will be "
303 "printed with flags instead of beams.",
305 /* accepts */ "beam-event abort-event",
306 /* acks */ "stem-interface rest-interface",
307 /* reads */ "beamMelismaBusy beatLength subdivideBeams",
311 class Grace_beam_engraver : public Beam_engraver
314 TRANSLATOR_DECLARATIONS(Grace_beam_engraver);
317 virtual bool valid_start_point();
318 virtual bool valid_end_point ();
321 Grace_beam_engraver::Grace_beam_engraver()
326 Grace_beam_engraver::valid_start_point()
328 Moment n = now_mom ();
330 return n.grace_part_ != Rational (0);
335 Grace_beam_engraver::valid_end_point ()
337 return beam_ && valid_start_point ();
342 ENTER_DESCRIPTION(Grace_beam_engraver,
343 /* descr */ "Handles Beam events by engraving Beams. If omitted, then notes will "
344 "be printed with flags instead of beams. Only engraves beams when we "
345 " are at grace points in time. "
348 /* accepts */ "beam-event abort-event",
349 /* acks */ "stem-interface rest-interface",
350 /* reads */ "beamMelismaBusy beatLength allowBeamBreak subdivideBeams",