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_ != "beam")
72 Direction d =c->span_dir_;
74 if (d == STOP && !beam_p_)
76 m->origin ()->warning (_ ("can't find start of beam"));
82 SCM m = get_property ("automaticMelismata");
83 SCM b = get_property("noAutoBeaming");
84 if (to_boolean (m) && to_boolean(b))
97 Beam_engraver::set_melisma (bool m)
99 daddy_trans_l_->set_property ("beamMelismaBusy", m ? SCM_BOOL_T :SCM_BOOL_F);
104 Beam_engraver::do_process_music ()
106 if (reqs_drul_[STOP])
109 reqs_drul_[STOP]->origin ()->warning (_("can't find start of beam"));
111 finished_beam_p_ = beam_p_;
112 finished_beam_info_p_ = beam_info_p_;
119 if (beam_p_ && !to_boolean (get_property ("weAreGraceContext")))
121 Score_engraver * e = 0;
122 Translator * t = daddy_grav_l ();
123 for (; !e && t; t = t->daddy_trans_l_)
125 e = dynamic_cast<Score_engraver*> (t);
129 programming_error ("No score engraver!");
134 if (reqs_drul_[START])
138 reqs_drul_[START]->origin ()->warning (_ ("already have a beam"));
142 prev_start_req_ = reqs_drul_[START];
143 beam_p_ = new Spanner (get_property ("basicBeamProperties"));
144 Beam::set_interface (beam_p_);
146 SCM smp = get_property ("measurePosition");
147 Moment mp = (unsmob_moment (smp)) ? *unsmob_moment (smp) : Moment (0);
149 beam_start_location_ = mp;
150 beam_start_mom_ = now_mom();
151 beam_info_p_ = new Beaming_info_list;
154 /* urg, must copy to Auto_beam_engraver too */
156 announce_element (beam_p_, reqs_drul_[START]);
161 Beam_engraver::typeset_beam ()
163 if (finished_beam_p_)
165 finished_beam_info_p_->beamify ();
167 Beam::set_beaming (finished_beam_p_, finished_beam_info_p_);
168 typeset_element (finished_beam_p_);
169 delete finished_beam_info_p_;
170 finished_beam_info_p_ =0;
171 finished_beam_p_ = 0;
173 reqs_drul_[STOP] = 0;
178 Beam_engraver::do_post_move_processing ()
180 reqs_drul_ [START] =0;
182 SCM m = get_property ("automaticMelismata");
183 SCM b = get_property("noAutoBeaming");
184 if (to_boolean (m) && to_boolean(b)) {
191 Beam_engraver::do_pre_move_processing ()
197 Beam_engraver::do_removal_processing ()
202 prev_start_req_->origin ()->warning (_ ("unterminated beam"));
204 finished_beam_p_ = beam_p_;
205 finished_beam_info_p_ = beam_info_p_;
215 Beam_engraver::acknowledge_element (Score_element_info info)
219 if (Rest::has_interface (info.elem_l_))
221 info.elem_l_->add_offset_callback (Beam::rest_collision_callback, Y_AXIS);
223 else if (Stem::has_interface (info.elem_l_))
225 Item *stem_l = dynamic_cast<Item*> (info.elem_l_);
226 if (Stem::beam_l (stem_l))
229 bool stem_grace = stem_l->get_elt_property ("grace") == SCM_BOOL_T;
231 SCM wg =get_property ("weAreGraceContext");
232 bool wgb= to_boolean (wg);
234 if (wgb!= stem_grace)
237 Rhythmic_req *rhythmic_req = dynamic_cast <Rhythmic_req *> (info.req_l_);
240 String s = _ ("stem must have Rhythmic structure");
242 info.req_l_->origin ()->warning (s);
249 if (rhythmic_req->duration_.durlog_i_<= 2)
251 rhythmic_req->origin ()->warning (_ ("stem doesn't fit in beam"));
252 prev_start_req_->origin ()->warning (_ ("beam was started here"));
256 [r4 c8] can just as well be modern notation.
260 stem_l->set_elt_property ("duration-log",
261 gh_int2scm (rhythmic_req->duration_.durlog_i_));
262 Moment stem_location = now_mom () - beam_start_mom_ + beam_start_location_;
263 beam_info_p_->add_stem (stem_location,
264 (rhythmic_req->duration_.durlog_i_ - 2) >? 1);
265 Beam::add_stem (beam_p_, stem_l);
272 ADD_THIS_TRANSLATOR(Beam_engraver);