2 beam-engraver.cc -- implement Beam_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2000 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 ();
55 VIRTUAL_COPY_CONS (Translator);
59 Beam_engraver::Beam_engraver ()
63 finished_beam_info_p_=0;
65 reqs_drul_[LEFT] = reqs_drul_[RIGHT] =0;
70 Beam_engraver::try_music (Music *m)
72 if (Span_req * c = dynamic_cast<Span_req*>(m))
74 if (scm_equal_p (c->get_mus_property ("span-type"),
75 ly_str02scm ("abort")) == SCM_BOOL_T)
77 reqs_drul_[START] = 0;
83 else if (scm_equal_p (c->get_mus_property ("span-type"),
84 ly_str02scm ("beam")) == SCM_BOOL_T)
87 Direction d =c->get_span_dir ();
89 if (d == STOP && !beam_p_)
91 m->origin ()->warning (_ ("can't find start of beam"));
97 SCM m = get_property ("automaticMelismata");
98 SCM b = get_property("noAutoBeaming");
99 if (to_boolean (m) && to_boolean(b))
113 Beam_engraver::set_melisma (bool m)
115 daddy_trans_l_->set_property ("beamMelismaBusy", m ? SCM_BOOL_T :SCM_BOOL_F);
119 Beam_engraver::process_music ()
121 if (reqs_drul_[STOP])
124 reqs_drul_[STOP]->origin ()->warning (_("can't find start of beam"));
126 finished_beam_p_ = beam_p_;
127 finished_beam_info_p_ = beam_info_p_;
134 if (beam_p_ && !to_boolean (get_property ("weAreGraceContext")))
136 Score_engraver * e = 0;
137 Translator * t = daddy_grav_l ();
138 for (; !e && t; t = t->daddy_trans_l_)
140 e = dynamic_cast<Score_engraver*> (t);
144 programming_error ("No score engraver!");
152 Beam_engraver::create_grobs ()
154 if (reqs_drul_[START])
158 reqs_drul_[START]->origin ()->warning (_ ("already have a beam"));
162 prev_start_req_ = reqs_drul_[START];
163 beam_p_ = new Spanner (get_property ("Beam"));
164 Beam::set_interface (beam_p_);
166 SCM smp = get_property ("measurePosition");
167 Moment mp = (unsmob_moment (smp)) ? *unsmob_moment (smp) : Moment (0);
169 beam_start_location_ = mp;
170 beam_start_mom_ = now_mom();
171 beam_info_p_ = new Beaming_info_list;
174 /* urg, must copy to Auto_beam_engraver too */
176 announce_grob (beam_p_, reqs_drul_[START]);
178 reqs_drul_[STOP] = 0;
179 reqs_drul_[START] = 0;
183 Beam_engraver::typeset_beam ()
185 if (finished_beam_p_)
187 finished_beam_info_p_->beamify ();
189 Beam::set_beaming (finished_beam_p_, finished_beam_info_p_);
190 typeset_grob (finished_beam_p_);
191 delete finished_beam_info_p_;
192 finished_beam_info_p_ =0;
193 finished_beam_p_ = 0;
195 reqs_drul_[STOP] = 0;
200 Beam_engraver::start_translation_timestep ()
202 reqs_drul_ [START] =0;
204 SCM m = get_property ("automaticMelismata");
205 SCM b = get_property("noAutoBeaming");
206 if (to_boolean (m) && to_boolean(b)) {
213 Beam_engraver::stop_translation_timestep ()
219 Beam_engraver::finalize ()
224 prev_start_req_->origin ()->warning (_ ("unterminated beam"));
226 finished_beam_p_ = beam_p_;
227 finished_beam_info_p_ = beam_info_p_;
237 Beam_engraver::acknowledge_grob (Grob_info info)
241 if (Rest::has_interface (info.elem_l_))
243 info.elem_l_->add_offset_callback (Beam::rest_collision_callback_proc, Y_AXIS);
245 else if (Stem::has_interface (info.elem_l_))
247 Item *stem_l = dynamic_cast<Item*> (info.elem_l_);
248 if (Stem::beam_l (stem_l))
251 bool stem_grace = stem_l->get_grob_property ("grace") == SCM_BOOL_T;
253 SCM wg =get_property ("weAreGraceContext");
254 bool wgb= to_boolean (wg);
256 if (wgb!= stem_grace)
259 Rhythmic_req *rhythmic_req = dynamic_cast <Rhythmic_req *> (info.req_l_);
262 String s = _ ("stem must have Rhythmic structure");
264 info.req_l_->origin ()->warning (s);
271 int durlog = unsmob_duration (rhythmic_req->get_mus_property ("duration"))-> duration_log ();
274 rhythmic_req->origin ()->warning (_ ("stem doesn't fit in beam"));
275 prev_start_req_->origin ()->warning (_ ("beam was started here"));
279 [r4 c8] can just as well be modern notation.
283 stem_l->set_grob_property ("duration-log",
284 gh_int2scm (durlog));
285 Moment stem_location = now_mom () - beam_start_mom_ + beam_start_location_;
286 beam_info_p_->add_stem (stem_location,
288 Beam::add_stem (beam_p_, stem_l);
295 ADD_THIS_TRANSLATOR(Beam_engraver);