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 (c->span_type_str_ == "abort")
71 reqs_drul_[START] = 0;
77 else if (c->span_type_str_ == "beam")
80 Direction d =c->get_span_dir ();
82 if (d == STOP && !beam_p_)
84 m->origin ()->warning (_ ("can't find start of beam"));
90 SCM m = get_property ("automaticMelismata");
91 SCM b = get_property("noAutoBeaming");
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);
113 Beam_engraver::do_process_music ()
115 if (reqs_drul_[STOP])
118 reqs_drul_[STOP]->origin ()->warning (_("can't find start of beam"));
120 finished_beam_p_ = beam_p_;
121 finished_beam_info_p_ = beam_info_p_;
128 if (beam_p_ && !to_boolean (get_property ("weAreGraceContext")))
130 Score_engraver * e = 0;
131 Translator * t = daddy_grav_l ();
132 for (; !e && t; t = t->daddy_trans_l_)
134 e = dynamic_cast<Score_engraver*> (t);
138 programming_error ("No score engraver!");
143 if (reqs_drul_[START])
147 reqs_drul_[START]->origin ()->warning (_ ("already have a beam"));
151 prev_start_req_ = reqs_drul_[START];
152 beam_p_ = new Spanner (get_property ("Beam"));
153 Beam::set_interface (beam_p_);
155 SCM smp = get_property ("measurePosition");
156 Moment mp = (unsmob_moment (smp)) ? *unsmob_moment (smp) : Moment (0);
158 beam_start_location_ = mp;
159 beam_start_mom_ = now_mom();
160 beam_info_p_ = new Beaming_info_list;
163 /* urg, must copy to Auto_beam_engraver too */
165 announce_element (beam_p_, reqs_drul_[START]);
170 Beam_engraver::typeset_beam ()
172 if (finished_beam_p_)
174 finished_beam_info_p_->beamify ();
176 Beam::set_beaming (finished_beam_p_, finished_beam_info_p_);
177 typeset_element (finished_beam_p_);
178 delete finished_beam_info_p_;
179 finished_beam_info_p_ =0;
180 finished_beam_p_ = 0;
182 reqs_drul_[STOP] = 0;
187 Beam_engraver::do_post_move_processing ()
189 reqs_drul_ [START] =0;
191 SCM m = get_property ("automaticMelismata");
192 SCM b = get_property("noAutoBeaming");
193 if (to_boolean (m) && to_boolean(b)) {
200 Beam_engraver::do_pre_move_processing ()
206 Beam_engraver::do_removal_processing ()
211 prev_start_req_->origin ()->warning (_ ("unterminated beam"));
213 finished_beam_p_ = beam_p_;
214 finished_beam_info_p_ = beam_info_p_;
224 Beam_engraver::acknowledge_element (Score_element_info info)
228 if (Rest::has_interface (info.elem_l_))
230 info.elem_l_->add_offset_callback (Beam::rest_collision_callback_proc, Y_AXIS);
232 else if (Stem::has_interface (info.elem_l_))
234 Item *stem_l = dynamic_cast<Item*> (info.elem_l_);
235 if (Stem::beam_l (stem_l))
238 bool stem_grace = stem_l->get_elt_property ("grace") == SCM_BOOL_T;
240 SCM wg =get_property ("weAreGraceContext");
241 bool wgb= to_boolean (wg);
243 if (wgb!= stem_grace)
246 Rhythmic_req *rhythmic_req = dynamic_cast <Rhythmic_req *> (info.req_l_);
249 String s = _ ("stem must have Rhythmic structure");
251 info.req_l_->origin ()->warning (s);
258 if (rhythmic_req->duration_.durlog_i_<= 2)
260 rhythmic_req->origin ()->warning (_ ("stem doesn't fit in beam"));
261 prev_start_req_->origin ()->warning (_ ("beam was started here"));
265 [r4 c8] can just as well be modern notation.
269 stem_l->set_elt_property ("duration-log",
270 gh_int2scm (rhythmic_req->duration_.durlog_i_));
271 Moment stem_location = now_mom () - beam_start_mom_ + beam_start_location_;
272 beam_info_p_->add_stem (stem_location,
273 (rhythmic_req->duration_.durlog_i_ - 2) >? 1);
274 Beam::add_stem (beam_p_, stem_l);
281 ADD_THIS_TRANSLATOR(Beam_engraver);