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 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_;
40 void set_melisma (bool);
42 virtual void do_pre_move_processing ();
43 virtual void do_post_move_processing ();
44 virtual void do_removal_processing ();
45 virtual void acknowledge_element (Score_element_info);
46 virtual bool do_try_music (Music*);
47 virtual void do_process_music ();
50 VIRTUAL_COPY_CONS (Translator);
54 Beam_engraver::Beam_engraver ()
58 finished_beam_info_p_=0;
60 reqs_drul_[LEFT] = reqs_drul_[RIGHT] =0;
65 Beam_engraver::do_try_music (Music *m)
67 if (Span_req * c = dynamic_cast<Span_req*>(m))
69 if (scm_equal_p (c->get_mus_property ("span-type"),
70 ly_str02scm ("abort")) == SCM_BOOL_T)
72 reqs_drul_[START] = 0;
78 else if (scm_equal_p (c->get_mus_property ("span-type"),
79 ly_str02scm ("beam")) == SCM_BOOL_T)
82 Direction d =c->get_span_dir ();
84 if (d == STOP && !beam_p_)
86 m->origin ()->warning (_ ("can't find start of beam"));
92 SCM m = get_property ("automaticMelismata");
93 SCM b = get_property("noAutoBeaming");
94 if (to_boolean (m) && to_boolean(b))
108 Beam_engraver::set_melisma (bool m)
110 daddy_trans_l_->set_property ("beamMelismaBusy", m ? SCM_BOOL_T :SCM_BOOL_F);
115 Beam_engraver::do_process_music ()
117 if (reqs_drul_[STOP])
120 reqs_drul_[STOP]->origin ()->warning (_("can't find start of beam"));
122 finished_beam_p_ = beam_p_;
123 finished_beam_info_p_ = beam_info_p_;
130 if (beam_p_ && !to_boolean (get_property ("weAreGraceContext")))
132 Score_engraver * e = 0;
133 Translator * t = daddy_grav_l ();
134 for (; !e && t; t = t->daddy_trans_l_)
136 e = dynamic_cast<Score_engraver*> (t);
140 programming_error ("No score engraver!");
145 if (reqs_drul_[START])
149 reqs_drul_[START]->origin ()->warning (_ ("already have a beam"));
153 prev_start_req_ = reqs_drul_[START];
154 beam_p_ = new Spanner (get_property ("Beam"));
155 Beam::set_interface (beam_p_);
157 SCM smp = get_property ("measurePosition");
158 Moment mp = (unsmob_moment (smp)) ? *unsmob_moment (smp) : Moment (0);
160 beam_start_location_ = mp;
161 beam_start_mom_ = now_mom();
162 beam_info_p_ = new Beaming_info_list;
165 /* urg, must copy to Auto_beam_engraver too */
167 announce_element (beam_p_, reqs_drul_[START]);
172 Beam_engraver::typeset_beam ()
174 if (finished_beam_p_)
176 finished_beam_info_p_->beamify ();
178 Beam::set_beaming (finished_beam_p_, finished_beam_info_p_);
179 typeset_element (finished_beam_p_);
180 delete finished_beam_info_p_;
181 finished_beam_info_p_ =0;
182 finished_beam_p_ = 0;
184 reqs_drul_[STOP] = 0;
189 Beam_engraver::do_post_move_processing ()
191 reqs_drul_ [START] =0;
193 SCM m = get_property ("automaticMelismata");
194 SCM b = get_property("noAutoBeaming");
195 if (to_boolean (m) && to_boolean(b)) {
202 Beam_engraver::do_pre_move_processing ()
208 Beam_engraver::do_removal_processing ()
213 prev_start_req_->origin ()->warning (_ ("unterminated beam"));
215 finished_beam_p_ = beam_p_;
216 finished_beam_info_p_ = beam_info_p_;
226 Beam_engraver::acknowledge_element (Score_element_info info)
230 if (Rest::has_interface (info.elem_l_))
232 info.elem_l_->add_offset_callback (Beam::rest_collision_callback_proc, Y_AXIS);
234 else if (Stem::has_interface (info.elem_l_))
236 Item *stem_l = dynamic_cast<Item*> (info.elem_l_);
237 if (Stem::beam_l (stem_l))
240 bool stem_grace = stem_l->get_elt_property ("grace") == SCM_BOOL_T;
242 SCM wg =get_property ("weAreGraceContext");
243 bool wgb= to_boolean (wg);
245 if (wgb!= stem_grace)
248 Rhythmic_req *rhythmic_req = dynamic_cast <Rhythmic_req *> (info.req_l_);
251 String s = _ ("stem must have Rhythmic structure");
253 info.req_l_->origin ()->warning (s);
260 int durlog = unsmob_duration (rhythmic_req->get_mus_property ("duration"))-> duration_log ();
263 rhythmic_req->origin ()->warning (_ ("stem doesn't fit in beam"));
264 prev_start_req_->origin ()->warning (_ ("beam was started here"));
268 [r4 c8] can just as well be modern notation.
272 stem_l->set_elt_property ("duration-log",
273 gh_int2scm (durlog));
274 Moment stem_location = now_mom () - beam_start_mom_ + beam_start_location_;
275 beam_info_p_->add_stem (stem_location,
277 Beam::add_stem (beam_p_, stem_l);
284 ADD_THIS_TRANSLATOR(Beam_engraver);