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>
14 #include "score-engraver.hh"
16 #include "drul-array.hh"
21 class Beam_engraver : public Engraver
26 Spanner *finished_beam_;
28 Music *prev_start_ev_;
32 Beaming_info_list *beam_info_;
33 Beaming_info_list *finished_beam_info_;
35 /// location within measure where beam started.
36 Moment beam_start_location_;
38 /// moment (global time) where beam started.
39 Moment beam_start_mom_;
41 bool subdivide_beams_;
45 void set_melisma (bool);
47 Moment last_stem_added_at_;
48 virtual void stop_translation_timestep ();
49 virtual void start_translation_timestep ();
50 virtual void finalize ();
52 virtual void acknowledge_grob (Grob_info);
53 virtual bool try_music (Music *);
54 virtual void process_music ();
56 virtual bool valid_start_point ();
57 virtual bool valid_end_point ();
60 TRANSLATOR_DECLARATIONS (Beam_engraver);
64 Hmm. this isn't necessary, since grace beams and normal beams are
68 Beam_engraver::valid_start_point ()
70 Moment n = now_mom ();
72 return n.grace_part_ == Rational (0);
76 Beam_engraver::valid_end_point ()
78 return valid_start_point ();
81 Beam_engraver::Beam_engraver ()
85 finished_beam_info_ = 0;
93 Beam_engraver::try_music (Music *m)
95 if (m->is_mus_type ("beam-event"))
97 Direction d = to_dir (m->get_property ("span-direction"));
98 if (d == START && !valid_start_point ())
100 if (d == STOP && !valid_end_point ())
117 Beam_engraver::set_melisma (bool ml)
119 SCM b = get_property ("autoBeaming");
121 context ()->set_property ("beamMelismaBusy", ml ? SCM_BOOL_T : SCM_BOOL_F);
125 Beam_engraver::process_music ()
127 if (beam_ && !to_boolean (get_property ("allowBeamBreak")))
129 get_score_engraver ()->forbid_breaks ();
136 start_ev_->origin ()->warning (_ ("already have a beam"));
141 prev_start_ev_ = start_ev_;
142 beam_ = make_spanner ("Beam", start_ev_->self_scm ());
143 Moment mp (robust_scm2moment (get_property ("measurePosition"), Moment (0)));
145 beam_start_location_ = mp;
146 beam_start_mom_ = now_mom ();
148 beam_info_ = new Beaming_info_list;
150 /* urg, must copy to Auto_beam_engraver too */
155 Beam_engraver::typeset_beam ()
159 finished_beam_info_->beamify (beat_length_, subdivide_beams_);
160 Beam::set_beaming (finished_beam_, finished_beam_info_);
162 delete finished_beam_info_;
163 finished_beam_info_ = 0;
169 Beam_engraver::start_translation_timestep ()
177 subdivide_beams_ = to_boolean (get_property ("subdivideBeams"));
178 beat_length_ = robust_scm2moment (get_property ("beatLength"), Moment (1, 4));
183 Beam_engraver::stop_translation_timestep ()
188 finished_beam_ = beam_;
189 finished_beam_info_ = beam_info_;
200 Beam_engraver::finalize ()
205 prev_start_ev_->origin ()->warning (_ ("unterminated beam"));
208 we don't typeset it, (we used to, but it was commented
209 out. Reason unknown) */
216 Beam_engraver::acknowledge_grob (Grob_info info)
220 if (Rest::has_interface (info.grob ()))
222 info.grob ()->add_offset_callback (Beam::rest_collision_callback_proc, Y_AXIS);
224 else if (Stem::has_interface (info.grob ()))
226 Moment now = now_mom ();
228 if (!valid_start_point ())
231 Item *stem = dynamic_cast<Item *> (info.grob ());
232 if (Stem::get_beam (stem))
235 Music *m = info.music_cause ();
236 if (!m->is_mus_type ("rhythmic-event"))
238 String s = _ ("stem must have Rhythmic structure");
239 if (info.music_cause ())
240 info.music_cause ()->origin ()->warning (s);
247 last_stem_added_at_ = now;
248 int durlog = unsmob_duration (m->get_property ("duration"))->duration_log ();
251 m->origin ()->warning (_ ("stem doesn't fit in beam"));
252 prev_start_ev_->origin ()->warning (_ ("beam was started here"));
256 [r4 c8] can just as well be modern notation.
260 stem->set_property ("duration-log",
261 scm_int2num (durlog));
262 Moment stem_location = now - beam_start_mom_ + beam_start_location_;
263 beam_info_->add_stem (stem_location,
265 Beam::add_stem (beam_, stem);
270 ADD_TRANSLATOR (Beam_engraver,
271 /* descr */ "Handles Beam events by engraving Beams. If omitted, then notes will be "
272 "printed with flags instead of beams.",
274 /* accepts */ "beam-event",
275 /* acks */ "stem-interface rest-interface",
276 /* reads */ "beamMelismaBusy beatLength subdivideBeams",
279 class Grace_beam_engraver : public Beam_engraver
282 TRANSLATOR_DECLARATIONS (Grace_beam_engraver);
285 virtual bool valid_start_point ();
286 virtual bool valid_end_point ();
289 Grace_beam_engraver::Grace_beam_engraver ()
294 Grace_beam_engraver::valid_start_point ()
296 Moment n = now_mom ();
298 return n.grace_part_ != Rational (0);
302 Grace_beam_engraver::valid_end_point ()
304 return beam_ && valid_start_point ();
307 ADD_TRANSLATOR (Grace_beam_engraver,
308 /* descr */ "Handles Beam events by engraving Beams. If omitted, then notes will "
309 "be printed with flags instead of beams. Only engraves beams when we "
310 " are at grace points in time. ",
312 /* accepts */ "beam-event",
313 /* acks */ "stem-interface rest-interface",
314 /* reads */ "beamMelismaBusy beatLength allowBeamBreak subdivideBeams",