2 beam-engraver.cc -- implement Beam_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #include "engraver.hh"
15 #include "score-engraver.hh"
17 #include "drul-array.hh"
22 class Beam_engraver : public Engraver
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;
95 Beam_engraver::try_music (Music *m)
97 if (m->is_mus_type ("beam-event"))
99 Direction d = to_dir (m->get_property ("span-direction"));
100 if (d == START && !valid_start_point ())
102 if (d == STOP && !valid_end_point ())
119 Beam_engraver::set_melisma (bool ml)
121 SCM b = get_property ("autoBeaming");
123 context ()->set_property ("beamMelismaBusy", ml ? SCM_BOOL_T :SCM_BOOL_F);
127 Beam_engraver::process_music ()
129 if (beam_ && !to_boolean (get_property ("allowBeamBreak")))
131 get_score_engraver ()->forbid_breaks ();
138 start_ev_->origin ()->warning (_ ("already have a beam"));
143 prev_start_ev_ = start_ev_;
144 beam_ = make_spanner ("Beam", start_ev_->self_scm ());
145 Moment mp (robust_scm2moment (get_property ("measurePosition"), Moment (0)));
147 beam_start_location_ = mp;
148 beam_start_mom_ = now_mom ();
150 beam_info_ = new Beaming_info_list;
152 /* urg, must copy to Auto_beam_engraver too */
159 Beam_engraver::typeset_beam ()
163 finished_beam_info_->beamify (beat_length_, subdivide_beams_);
164 Beam::set_beaming (finished_beam_, finished_beam_info_);
166 delete finished_beam_info_;
167 finished_beam_info_ = 0;
173 Beam_engraver::start_translation_timestep ()
181 subdivide_beams_ = to_boolean (get_property ("subdivideBeams"));
182 beat_length_ = robust_scm2moment (get_property ("beatLength"), Moment (1, 4));
187 Beam_engraver::stop_translation_timestep ()
192 finished_beam_ = beam_;
193 finished_beam_info_ = beam_info_;
204 Beam_engraver::finalize ()
209 prev_start_ev_->origin ()->warning (_ ("unterminated beam"));
212 we don't typeset it, (we used to, but it was commented
213 out. Reason unknown) */
220 Beam_engraver::acknowledge_grob (Grob_info info)
224 if (Rest::has_interface (info.grob_))
226 info.grob_->add_offset_callback (Beam::rest_collision_callback_proc, Y_AXIS);
228 else if (Stem::has_interface (info.grob_))
230 Moment now = now_mom ();
232 if (!valid_start_point ())
235 Item *stem = dynamic_cast<Item*> (info.grob_);
236 if (Stem::get_beam (stem))
239 Music* m = info.music_cause ();
240 if (!m->is_mus_type ("rhythmic-event"))
242 String s = _ ("stem must have Rhythmic structure");
243 if (info.music_cause ())
244 info.music_cause ()->origin ()->warning (s);
252 last_stem_added_at_ = now;
253 int durlog = unsmob_duration (m->get_property ("duration"))-> duration_log ();
256 m->origin ()->warning (_ ("stem doesn't fit in beam"));
257 prev_start_ev_->origin ()->warning (_ ("beam was started here"));
261 [r4 c8] can just as well be modern notation.
265 stem->set_property ("duration-log",
266 scm_int2num (durlog));
267 Moment stem_location = now - beam_start_mom_ + beam_start_location_;
268 beam_info_->add_stem (stem_location,
270 Beam::add_stem (beam_, stem);
279 ADD_TRANSLATOR (Beam_engraver,
280 /* descr */ "Handles Beam events by engraving Beams. If omitted, then notes will be "
281 "printed with flags instead of beams.",
283 /* accepts */ "beam-event",
284 /* acks */ "stem-interface rest-interface",
285 /* reads */ "beamMelismaBusy beatLength subdivideBeams",
289 class Grace_beam_engraver : public Beam_engraver
292 TRANSLATOR_DECLARATIONS (Grace_beam_engraver);
295 virtual bool valid_start_point ();
296 virtual bool valid_end_point ();
299 Grace_beam_engraver::Grace_beam_engraver ()
304 Grace_beam_engraver::valid_start_point ()
306 Moment n = now_mom ();
308 return n.grace_part_ != Rational (0);
313 Grace_beam_engraver::valid_end_point ()
315 return beam_ && valid_start_point ();
320 ADD_TRANSLATOR (Grace_beam_engraver,
321 /* descr */ "Handles Beam events by engraving Beams. If omitted, then notes will "
322 "be printed with flags instead of beams. Only engraves beams when we "
323 " are at grace points in time. "
326 /* accepts */ "beam-event",
327 /* acks */ "stem-interface rest-interface",
328 /* reads */ "beamMelismaBusy beatLength allowBeamBreak subdivideBeams",