2 beam-engraver.cc -- implement Beam_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
10 #include "beaming-pattern.hh"
12 #include "drul-array.hh"
13 #include "duration.hh"
14 #include "engraver.hh"
15 #include "international.hh"
19 #include "stream-event.hh"
23 #include "translator.icc"
25 class Beam_engraver : public Engraver
28 DECLARE_ACKNOWLEDGER (stem);
29 DECLARE_ACKNOWLEDGER (rest);
32 Stream_event *start_ev_;
34 Spanner *finished_beam_;
36 Stream_event *prev_start_ev_;
38 Stream_event *stop_ev_;
40 Beaming_pattern *beam_info_;
41 Beaming_pattern *finished_beam_info_;
43 /// location within measure where beam started.
44 Moment beam_start_location_;
46 /// moment (global time) where beam started.
47 Moment beam_start_mom_;
49 Beaming_options beaming_options_;
50 Beaming_options finished_beaming_options_;
53 void set_melisma (bool);
55 Moment last_stem_added_at_;
56 void stop_translation_timestep ();
57 void start_translation_timestep ();
58 virtual void finalize ();
60 void process_music ();
62 virtual bool valid_start_point ();
63 virtual bool valid_end_point ();
65 DECLARE_TRANSLATOR_LISTENER (beam);
67 TRANSLATOR_DECLARATIONS (Beam_engraver);
71 Hmm. this isn't necessary, since grace beams and normal beams are
75 Beam_engraver::valid_start_point ()
77 Moment n = now_mom ();
79 return n.grace_part_ == Rational (0);
83 Beam_engraver::valid_end_point ()
85 return valid_start_point ();
88 Beam_engraver::Beam_engraver ()
92 finished_beam_info_ = 0;
99 IMPLEMENT_TRANSLATOR_LISTENER (Beam_engraver, beam);
101 Beam_engraver::listen_beam (Stream_event *ev)
103 Direction d = to_dir (ev->get_property ("span-direction"));
105 if (d == START && valid_start_point ())
106 ASSIGN_EVENT_ONCE (start_ev_, ev);
107 else if (d == STOP && valid_end_point ())
108 ASSIGN_EVENT_ONCE (stop_ev_, ev);
112 Beam_engraver::set_melisma (bool ml)
114 SCM b = get_property ("autoBeaming");
116 context ()->set_property ("beamMelismaBusy", ml ? SCM_BOOL_T : SCM_BOOL_F);
120 Beam_engraver::process_music ()
126 start_ev_->origin ()->warning (_ ("already have a beam"));
131 prev_start_ev_ = start_ev_;
132 beam_ = make_spanner ("Beam", start_ev_->self_scm ());
133 Moment mp (robust_scm2moment (get_property ("measurePosition"), Moment (0)));
135 beam_start_location_ = mp;
136 beam_start_mom_ = now_mom ();
138 beaming_options_.from_context (context ());
139 beam_info_ = new Beaming_pattern;
140 /* urg, must copy to Auto_beam_engraver too */
144 if (stop_ev_ && beam_)
146 announce_end_grob (beam_, stop_ev_->self_scm ());
152 Beam_engraver::typeset_beam ()
156 if (!finished_beam_->get_bound (RIGHT))
157 finished_beam_->set_bound (RIGHT, finished_beam_->get_bound (LEFT));
159 finished_beam_info_->beamify (finished_beaming_options_);
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 ()
180 Beam_engraver::stop_translation_timestep ()
184 finished_beam_ = beam_;
185 finished_beam_info_ = beam_info_;
186 finished_beaming_options_ = beaming_options_;
197 Beam_engraver::finalize ()
202 prev_start_ev_->origin ()->warning (_ ("unterminated beam"));
205 we don't typeset it, (we used to, but it was commented
206 out. Reason unknown) */
213 Beam_engraver::acknowledge_rest (Grob_info info)
216 && !scm_is_number (info.grob ()->get_property_data ("staff-position")))
218 chain_offset_callback (info.grob (),
219 Beam::rest_collision_callback_proc, Y_AXIS);
226 Beam_engraver::acknowledge_stem (Grob_info info)
231 Moment now = now_mom ();
232 if (!valid_start_point ())
235 Item *stem = dynamic_cast<Item *> (info.grob ());
236 if (Stem::get_beam (stem))
241 Stream_event *ev = info.ultimate_event_cause ();
242 if (!ev->in_event_class ("rhythmic-event"))
244 info.grob ()->warning (_ ("stem must have Rhythmic structure"));
248 last_stem_added_at_ = now;
249 int durlog = unsmob_duration (ev->get_property ("duration"))->duration_log ();
252 ev->origin ()->warning (_ ("stem does not fit in beam"));
253 prev_start_ev_->origin ()->warning (_ ("beam was started here"));
257 [r4 c8] can just as well be modern notation.
261 stem->set_property ("duration-log",
262 scm_from_int (durlog));
263 Moment stem_location = now - beam_start_mom_ + beam_start_location_;
264 beam_info_->add_stem (stem_location,
266 Beam::add_stem (beam_, stem);
269 ADD_ACKNOWLEDGER (Beam_engraver, stem);
270 ADD_ACKNOWLEDGER (Beam_engraver, rest);
272 ADD_TRANSLATOR (Beam_engraver,
275 "Handles Beam events by engraving Beams. If omitted, then notes will be "
276 "printed with flags instead of beams.",
288 class Grace_beam_engraver : public Beam_engraver
291 TRANSLATOR_DECLARATIONS (Grace_beam_engraver);
293 DECLARE_TRANSLATOR_LISTENER (beam);
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);
313 Grace_beam_engraver::valid_end_point ()
315 return beam_ && valid_start_point ();
321 IMPLEMENT_TRANSLATOR_LISTENER (Grace_beam_engraver, beam);
323 Grace_beam_engraver::listen_beam (Stream_event *ev)
325 Direction d = to_dir (ev->get_property ("span-direction"));
327 if (d == START && valid_start_point ())
329 else if (d == STOP && valid_end_point ())
334 ADD_ACKNOWLEDGER (Grace_beam_engraver, stem);
335 ADD_ACKNOWLEDGER (Grace_beam_engraver, rest);
337 ADD_TRANSLATOR (Grace_beam_engraver,
341 "Handles Beam events by engraving Beams. If omitted, then notes will "
342 "be printed with flags instead of beams. Only engraves beams when we "
343 " are at grace points in time. ",