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_;
42 bool subdivide_beams_;
45 void set_melisma (bool);
47 virtual void stop_translation_timestep ();
48 virtual void start_translation_timestep ();
49 virtual void finalize ();
50 virtual void create_grobs ();
51 virtual void acknowledge_grob (Grob_info);
52 virtual bool try_music (Music*);
53 virtual void process_music ();
56 TRANSLATOR_DECLARATIONS( Beam_engraver );
60 Beam_engraver::Beam_engraver ()
64 finished_beam_info_p_=0;
66 reqs_drul_[LEFT] = reqs_drul_[RIGHT] =0;
72 Beam_engraver::try_music (Music *m)
74 if (Span_req * c = dynamic_cast<Span_req*> (m))
76 if (scm_equal_p (c->get_mus_property ("span-type"),
77 ly_str02scm ("abort")) == SCM_BOOL_T)
79 reqs_drul_[START] = 0;
85 else if (scm_equal_p (c->get_mus_property ("span-type"),
86 ly_str02scm ("beam")) == SCM_BOOL_T)
89 Direction d =c->get_span_dir ();
91 if (d == STOP && !beam_p_)
93 m->origin ()->warning (_ ("can't find start of beam"));
99 SCM m = get_property ("automaticMelismata");
100 SCM b = get_property ("noAutoBeaming");
101 if (to_boolean (m) && to_boolean (b))
115 Beam_engraver::set_melisma (bool m)
117 daddy_trans_l_->set_property ("beamMelismaBusy", m ? SCM_BOOL_T :SCM_BOOL_F);
121 Beam_engraver::process_music ()
123 if (reqs_drul_[STOP])
126 reqs_drul_[STOP]->origin ()->warning (_ ("can't find start of beam"));
128 finished_beam_p_ = beam_p_;
129 finished_beam_info_p_ = beam_info_p_;
138 top_engraver ()->forbid_breaks ();
144 Beam_engraver::create_grobs ()
146 if (reqs_drul_[START])
150 reqs_drul_[START]->origin ()->warning (_ ("already have a beam"));
154 prev_start_req_ = reqs_drul_[START];
155 beam_p_ = new Spanner (get_property ("Beam"));
156 SCM smp = get_property ("measurePosition");
157 Moment mp = (unsmob_moment (smp)) ? *unsmob_moment (smp) : Moment (0);
159 beam_start_location_ = mp;
160 beam_start_mom_ = now_mom ();
162 beam_info_p_ = new Beaming_info_list;
164 /* urg, must copy to Auto_beam_engraver too */
166 announce_grob (beam_p_, reqs_drul_[START]);
168 reqs_drul_[STOP] = 0;
169 reqs_drul_[START] = 0;
173 Beam_engraver::typeset_beam ()
175 if (finished_beam_p_)
177 finished_beam_info_p_->beamify(*unsmob_moment (get_property ("beatLength")),
180 Beam::set_beaming (finished_beam_p_, finished_beam_info_p_);
181 typeset_grob (finished_beam_p_);
182 delete finished_beam_info_p_;
183 finished_beam_info_p_ =0;
184 finished_beam_p_ = 0;
186 reqs_drul_[STOP] = 0;
191 Beam_engraver::start_translation_timestep ()
193 reqs_drul_ [START] =0;
195 SCM m = get_property ("automaticMelismata");
196 SCM b = get_property ("noAutoBeaming");
197 if (to_boolean (m) && to_boolean (b)) {
200 subdivide_beams_ = gh_scm2bool(get_property("subdivideBeams"));
205 Beam_engraver::stop_translation_timestep ()
211 Beam_engraver::finalize ()
216 prev_start_req_->origin ()->warning (_ ("unterminated beam"));
219 we don't typeset it, (we used to, but it was commented
220 out. Reason unknown) */
227 Beam_engraver::acknowledge_grob (Grob_info info)
231 if (Rest::has_interface (info.grob_l_))
233 info.grob_l_->add_offset_callback (Beam::rest_collision_callback_proc, Y_AXIS);
235 else if (Stem::has_interface (info.grob_l_))
237 Moment now = now_mom();
239 if(bool (now.grace_part_ ) != bool (beam_start_mom_.grace_part_))
242 Item *stem_l = dynamic_cast<Item*> (info.grob_l_);
243 if (Stem::beam_l (stem_l))
246 Rhythmic_req *rhythmic_req = dynamic_cast <Rhythmic_req *> (info.music_cause ());
249 String s = _ ("stem must have Rhythmic structure");
250 if (info.music_cause ())
251 info.music_cause ()->origin ()->warning (s);
258 int durlog = unsmob_duration (rhythmic_req->get_mus_property ("duration"))-> duration_log ();
261 rhythmic_req->origin ()->warning (_ ("stem doesn't fit in beam"));
262 prev_start_req_->origin ()->warning (_ ("beam was started here"));
266 [r4 c8] can just as well be modern notation.
270 stem_l->set_grob_property ("duration-log",
271 gh_int2scm (durlog));
272 Moment stem_location = now - beam_start_mom_ + beam_start_location_;
273 beam_info_p_->add_stem (stem_location,
275 Beam::add_stem (beam_p_, stem_l);
284 ENTER_DESCRIPTION(Beam_engraver,
285 /* descr */ "Handles Beam_requests by engraving Beams. If omitted, then notes will be
286 printed with flags instead of beams.",
288 /* acks */ "stem-interface rest-interface",
289 /* reads */ "beamMelismaBusy subdivideBeams",