2 beam-engraver.cc -- implement Beam_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #include "engraver.hh"
16 #include "score-engraver.hh"
18 #include "drul-array.hh"
23 class Beam_engraver : public Engraver
28 Spanner *finished_beam_;
30 Music * prev_start_ev_;
34 Beaming_info_list * beam_info_;
35 Beaming_info_list * finished_beam_info_;
37 /// location within measure where beam started.
38 Moment beam_start_location_;
40 /// moment (global time) where beam started.
41 Moment beam_start_mom_;
43 bool subdivide_beams_;
47 void set_melisma (bool);
49 Moment last_stem_added_at_;
50 virtual void stop_translation_timestep ();
51 virtual void start_translation_timestep ();
52 virtual void finalize ();
54 virtual void acknowledge_grob (Grob_info);
55 virtual bool try_music (Music*);
56 virtual void process_music ();
58 virtual bool valid_start_point ();
59 virtual bool valid_end_point ();
62 TRANSLATOR_DECLARATIONS (Beam_engraver);
67 Hmm. this isn't necessary, since grace beams and normal beams are
71 Beam_engraver::valid_start_point ()
73 Moment n = now_mom ();
75 return n.grace_part_ == Rational (0);
79 Beam_engraver::valid_end_point ()
81 return valid_start_point ();
84 Beam_engraver::Beam_engraver ()
88 finished_beam_info_=0;
96 Beam_engraver::try_music (Music *m)
98 if (m->is_mus_type ("beam-event"))
100 Direction d = to_dir (m->get_property ("span-direction"));
101 if (d == START && !valid_start_point ())
103 if (d == STOP && !valid_end_point ())
120 Beam_engraver::set_melisma (bool ml)
122 SCM b = get_property ("autoBeaming");
124 context ()->set_property ("beamMelismaBusy", ml ? SCM_BOOL_T :SCM_BOOL_F);
128 Beam_engraver::process_music ()
130 if (beam_ && !to_boolean (get_property ("allowBeamBreak")))
132 get_score_engraver ()->forbid_breaks ();
139 start_ev_->origin ()->warning (_ ("already have a beam"));
144 prev_start_ev_ = start_ev_;
145 beam_ = make_spanner ("Beam", start_ev_->self_scm ());
146 Moment mp (robust_scm2moment (get_property ("measurePosition"), Moment (0));
148 beam_start_location_ = mp;
149 beam_start_mom_ = now_mom ();
151 beam_info_ = new Beaming_info_list;
153 /* urg, must copy to Auto_beam_engraver too */
160 Beam_engraver::typeset_beam ()
164 finished_beam_info_->beamify (beat_length_, subdivide_beams_);
165 Beam::set_beaming (finished_beam_, finished_beam_info_);
167 delete finished_beam_info_;
168 finished_beam_info_ =0;
174 Beam_engraver::start_translation_timestep ()
182 subdivide_beams_ = to_boolean (get_property ("subdivideBeams"));
183 beat_length_ = robust_scm2moment (get_property ("beatLength"), Moment (1,4));
188 Beam_engraver::stop_translation_timestep ()
193 finished_beam_ = beam_;
194 finished_beam_info_ = beam_info_;
205 Beam_engraver::finalize ()
210 prev_start_ev_->origin ()->warning (_ ("unterminated beam"));
213 we don't typeset it, (we used to, but it was commented
214 out. Reason unknown) */
221 Beam_engraver::acknowledge_grob (Grob_info info)
225 if (Rest::has_interface (info.grob_))
227 info.grob_->add_offset_callback (Beam::rest_collision_callback_proc, Y_AXIS);
229 else if (Stem::has_interface (info.grob_))
231 Moment now = now_mom ();
233 if (!valid_start_point ())
236 Item *stem = dynamic_cast<Item*> (info.grob_);
237 if (Stem::get_beam (stem))
240 Music* m = info.music_cause ();
241 if (!m->is_mus_type ("rhythmic-event"))
243 String s = _ ("stem must have Rhythmic structure");
244 if (info.music_cause ())
245 info.music_cause ()->origin ()->warning (s);
253 last_stem_added_at_ = now;
254 int durlog = unsmob_duration (m->get_property ("duration"))-> duration_log ();
257 m->origin ()->warning (_ ("stem doesn't fit in beam"));
258 prev_start_ev_->origin ()->warning (_ ("beam was started here"));
262 [r4 c8] can just as well be modern notation.
266 stem->set_property ("duration-log",
267 scm_int2num (durlog));
268 Moment stem_location = now - beam_start_mom_ + beam_start_location_;
269 beam_info_->add_stem (stem_location,
271 Beam::add_stem (beam_, stem);
280 ENTER_DESCRIPTION (Beam_engraver,
281 /* descr */ "Handles Beam events by engraving Beams. If omitted, then notes will be "
282 "printed with flags instead of beams.",
284 /* accepts */ "beam-event",
285 /* acks */ "stem-interface rest-interface",
286 /* reads */ "beamMelismaBusy beatLength subdivideBeams",
290 class Grace_beam_engraver : public Beam_engraver
293 TRANSLATOR_DECLARATIONS (Grace_beam_engraver);
296 virtual bool valid_start_point ();
297 virtual bool valid_end_point ();
300 Grace_beam_engraver::Grace_beam_engraver ()
305 Grace_beam_engraver::valid_start_point ()
307 Moment n = now_mom ();
309 return n.grace_part_ != Rational (0);
314 Grace_beam_engraver::valid_end_point ()
316 return beam_ && valid_start_point ();
321 ENTER_DESCRIPTION (Grace_beam_engraver,
322 /* descr */ "Handles Beam events by engraving Beams. If omitted, then notes will "
323 "be printed with flags instead of beams. Only engraves beams when we "
324 " are at grace points in time. "
327 /* accepts */ "beam-event",
328 /* acks */ "stem-interface rest-interface",
329 /* reads */ "beamMelismaBusy beatLength allowBeamBreak subdivideBeams",