2 beam-engraver.cc -- implement Beam_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2001 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 Link_array<Stem> stems_;
29 Spanner *finished_beam_p_;
31 Span_req * prev_start_req_;
33 Beaming_info_list * beam_info_p_;
34 Beaming_info_list * finished_beam_info_p_;
36 /// location within measure where beam started.
37 Moment beam_start_location_;
39 /// moment (global time) where beam started.
40 Moment beam_start_mom_;
43 void set_melisma (bool);
45 virtual void stop_translation_timestep ();
46 virtual void start_translation_timestep ();
47 virtual void finalize ();
48 virtual void create_grobs ();
49 virtual void acknowledge_grob (Grob_info);
50 virtual bool try_music (Music*);
51 virtual void process_music ();
54 TRANSLATOR_DECLARATIONS( Beam_engraver );
58 Beam_engraver::Beam_engraver ()
62 finished_beam_info_p_=0;
64 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 ();
88 if (d == STOP && !beam_p_)
90 m->origin ()->warning (_ ("can't find start of beam"));
96 SCM m = get_property ("automaticMelismata");
97 SCM b = get_property ("noAutoBeaming");
98 if (to_boolean (m) && to_boolean (b))
112 Beam_engraver::set_melisma (bool m)
114 daddy_trans_l_->set_property ("beamMelismaBusy", m ? SCM_BOOL_T :SCM_BOOL_F);
118 Beam_engraver::process_music ()
120 if (reqs_drul_[STOP])
123 reqs_drul_[STOP]->origin ()->warning (_ ("can't find start of beam"));
125 finished_beam_p_ = beam_p_;
126 finished_beam_info_p_ = beam_info_p_;
135 Score_engraver * e = 0;
136 Translator * t = daddy_grav_l ();
137 for (; !e && t; t = t->daddy_trans_l_)
139 e = dynamic_cast<Score_engraver*> (t);
143 programming_error ("No score engraver!");
151 Beam_engraver::create_grobs ()
153 if (reqs_drul_[START])
157 reqs_drul_[START]->origin ()->warning (_ ("already have a beam"));
161 prev_start_req_ = reqs_drul_[START];
162 beam_p_ = new Spanner (get_property ("Beam"));
163 SCM smp = get_property ("measurePosition");
164 Moment mp = (unsmob_moment (smp)) ? *unsmob_moment (smp) : Moment (0);
166 beam_start_location_ = mp;
167 beam_start_mom_ = now_mom ();
169 beam_info_p_ = new Beaming_info_list;
171 /* urg, must copy to Auto_beam_engraver too */
173 announce_grob (beam_p_, reqs_drul_[START]);
175 reqs_drul_[STOP] = 0;
176 reqs_drul_[START] = 0;
180 Beam_engraver::typeset_beam ()
182 if (finished_beam_p_)
184 finished_beam_info_p_->beamify(*unsmob_moment (get_property ("beatLength")),
185 (bool)gh_scm2bool(get_property("subdivideBeams")));
187 Beam::set_beaming (finished_beam_p_, finished_beam_info_p_);
188 typeset_grob (finished_beam_p_);
189 delete finished_beam_info_p_;
190 finished_beam_info_p_ =0;
191 finished_beam_p_ = 0;
193 reqs_drul_[STOP] = 0;
198 Beam_engraver::start_translation_timestep ()
200 reqs_drul_ [START] =0;
202 SCM m = get_property ("automaticMelismata");
203 SCM b = get_property ("noAutoBeaming");
204 if (to_boolean (m) && to_boolean (b)) {
211 Beam_engraver::stop_translation_timestep ()
217 Beam_engraver::finalize ()
222 prev_start_req_->origin ()->warning (_ ("unterminated beam"));
225 we don't typeset it, (we used to, but it was commented
226 out. Reason unknown) */
233 Beam_engraver::acknowledge_grob (Grob_info info)
237 if (Rest::has_interface (info.grob_l_))
239 info.grob_l_->add_offset_callback (Beam::rest_collision_callback_proc, Y_AXIS);
241 else if (Stem::has_interface (info.grob_l_))
243 Moment now = now_mom();
245 if(bool (now.grace_part_ ) != bool (beam_start_mom_.grace_part_))
248 Item *stem_l = dynamic_cast<Item*> (info.grob_l_);
249 if (Stem::beam_l (stem_l))
252 Rhythmic_req *rhythmic_req = dynamic_cast <Rhythmic_req *> (info.req_l_);
255 String s = _ ("stem must have Rhythmic structure");
257 info.req_l_->origin ()->warning (s);
264 int durlog = unsmob_duration (rhythmic_req->get_mus_property ("duration"))-> duration_log ();
267 rhythmic_req->origin ()->warning (_ ("stem doesn't fit in beam"));
268 prev_start_req_->origin ()->warning (_ ("beam was started here"));
272 [r4 c8] can just as well be modern notation.
276 stem_l->set_grob_property ("duration-log",
277 gh_int2scm (durlog));
278 Moment stem_location = now - beam_start_mom_ + beam_start_location_;
279 beam_info_p_->add_stem (stem_location,
281 Beam::add_stem (beam_p_, stem_l);
290 ENTER_DESCRIPTION(Beam_engraver,
291 /* descr */ "Handles Beam_requests by engraving Beams. If omitted, then notes will be
292 printed with flags instead of beams.",
294 /* acks */ "stem-interface rest-interface",
295 /* reads */ "beamMelismaBusy",