2 beam-engraver.cc -- implement Beam_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 #include "engraver-group-engraver.hh"
10 #include "engraver.hh"
11 #include "musical-request.hh"
16 #include "score-engraver.hh"
18 #include "drul-array.hh"
22 class Beam_engraver : public Engraver
24 Drul_array<Span_req*> reqs_drul_;
26 Spanner *finished_beam_p_;
28 Span_req * prev_start_req_;
30 Beaming_info_list * beam_info_p_;
31 Beaming_info_list * finished_beam_info_p_;
33 /// location within measure where beam started.
34 Moment beam_start_location_;
36 /// moment (global time) where beam started.
37 Moment beam_start_mom_;
39 bool subdivide_beams_;
42 void set_melisma (bool);
44 virtual void stop_translation_timestep ();
45 virtual void start_translation_timestep ();
46 virtual void finalize ();
48 virtual void acknowledge_grob (Grob_info);
49 virtual bool try_music (Music*);
50 virtual void process_music ();
53 TRANSLATOR_DECLARATIONS( Beam_engraver );
57 Beam_engraver::Beam_engraver ()
61 finished_beam_info_p_=0;
63 reqs_drul_[LEFT] = reqs_drul_[RIGHT] =0;
69 Beam_engraver::try_music (Music *m)
71 if (Span_req * c = dynamic_cast<Span_req*> (m))
73 if (scm_equal_p (c->get_mus_property ("span-type"),
74 ly_str02scm ("abort")) == SCM_BOOL_T)
76 reqs_drul_[START] = 0;
82 else if (scm_equal_p (c->get_mus_property ("span-type"),
83 ly_str02scm ("beam")) == SCM_BOOL_T)
86 Direction d =c->get_span_dir ();
90 SCM m = get_property ("automaticMelismata");
91 SCM b = get_property ("autoBeaming");
92 if (to_boolean (m) && !to_boolean (b))
106 Beam_engraver::set_melisma (bool m)
108 daddy_trans_l_->set_property ("beamMelismaBusy", m ? SCM_BOOL_T :SCM_BOOL_F);
112 Beam_engraver::process_music ()
114 if (reqs_drul_[STOP])
117 reqs_drul_[STOP]->origin ()->warning (_ ("can't find start of beam"));
119 finished_beam_p_ = beam_p_;
120 finished_beam_info_p_ = beam_info_p_;
129 top_engraver ()->forbid_breaks ();
131 if (reqs_drul_[START])
135 reqs_drul_[START]->origin ()->warning (_ ("already have a beam"));
139 prev_start_req_ = reqs_drul_[START];
140 beam_p_ = new Spanner (get_property ("Beam"));
141 SCM smp = get_property ("measurePosition");
142 Moment mp = (unsmob_moment (smp)) ? *unsmob_moment (smp) : Moment (0);
144 beam_start_location_ = mp;
145 beam_start_mom_ = now_mom ();
147 beam_info_p_ = new Beaming_info_list;
149 /* urg, must copy to Auto_beam_engraver too */
151 announce_grob(beam_p_, reqs_drul_[START]->self_scm());
158 Beam_engraver::typeset_beam ()
160 if (finished_beam_p_)
162 finished_beam_info_p_->beamify(*unsmob_moment (get_property ("beatLength")),
165 Beam::set_beaming (finished_beam_p_, finished_beam_info_p_);
166 typeset_grob (finished_beam_p_);
167 delete finished_beam_info_p_;
168 finished_beam_info_p_ =0;
169 finished_beam_p_ = 0;
174 Beam_engraver::start_translation_timestep ()
176 reqs_drul_ [START] =0;
177 reqs_drul_[STOP] = 0;
181 SCM m = get_property ("automaticMelismata");
182 SCM b = get_property ("autoBeaming");
183 if (to_boolean (m) && !to_boolean (b))
187 subdivide_beams_ = to_boolean(get_property("subdivideBeams"));
192 Beam_engraver::stop_translation_timestep ()
198 Beam_engraver::finalize ()
203 prev_start_req_->origin ()->warning (_ ("unterminated beam"));
206 we don't typeset it, (we used to, but it was commented
207 out. Reason unknown) */
214 Beam_engraver::acknowledge_grob (Grob_info info)
218 if (Rest::has_interface (info.grob_l_))
220 info.grob_l_->add_offset_callback (Beam::rest_collision_callback_proc, Y_AXIS);
222 else if (Stem::has_interface (info.grob_l_))
224 Moment now = now_mom();
226 if(bool (now.grace_part_ ) != bool (beam_start_mom_.grace_part_))
229 Item *stem_l = dynamic_cast<Item*> (info.grob_l_);
230 if (Stem::beam_l (stem_l))
233 Rhythmic_req *rhythmic_req = dynamic_cast <Rhythmic_req *> (info.music_cause ());
236 String s = _ ("stem must have Rhythmic structure");
237 if (info.music_cause ())
238 info.music_cause ()->origin ()->warning (s);
245 int durlog = unsmob_duration (rhythmic_req->get_mus_property ("duration"))-> duration_log ();
248 rhythmic_req->origin ()->warning (_ ("stem doesn't fit in beam"));
249 prev_start_req_->origin ()->warning (_ ("beam was started here"));
253 [r4 c8] can just as well be modern notation.
257 stem_l->set_grob_property ("duration-log",
258 gh_int2scm (durlog));
259 Moment stem_location = now - beam_start_mom_ + beam_start_location_;
260 beam_info_p_->add_stem (stem_location,
262 Beam::add_stem (beam_p_, stem_l);
271 ENTER_DESCRIPTION(Beam_engraver,
272 /* descr */ "Handles Beam_requests by engraving Beams. If omitted, then notes will be
273 printed with flags instead of beams.",
275 /* acks */ "stem-interface rest-interface",
276 /* reads */ "beamMelismaBusy subdivideBeams",