2 beam-engraver.cc -- implement Beam_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #include "beam-engraver.hh"
11 #include "musical-request.hh"
13 #include "rhythmic-grouping.hh"
16 #include "time-description.hh"
18 Beam_engraver::Beam_engraver ()
22 finished_grouping_p_ = 0;
24 reqs_drul_[LEFT] = reqs_drul_[RIGHT] =0;
29 Beam_engraver::do_try_music (Music *m)
31 if (Span_req * c = dynamic_cast<Span_req*>(m))
33 if (c->span_type_str_ != "beam")
36 Direction d =c->span_dir_;
38 if (d == STOP && !beam_p_)
40 m->warning (_ ("No Beam to end"));
51 Beam_engraver::do_process_requests ()
56 reqs_drul_[STOP]->warning (_("No beam to end"));
58 finished_beam_p_ = beam_p_;
59 finished_grouping_p_ = grouping_p_;
65 if (reqs_drul_[START])
69 reqs_drul_[START]->warning (_ ("Already have a Beam"));
73 prev_start_req_ = reqs_drul_[START];
75 grouping_p_ = new Rhythmic_grouping;
77 Scalar prop = get_property ("beamslopedamping", 0);
79 beam_p_->set_elt_property (damping_scm_sym, gh_int2scm( prop));
81 prop = get_property ("beamquantisation", 0);
83 beam_p_->quantisation_ = (Beam::Quantisation)(int)prop;
85 announce_element (Score_element_info (beam_p_, reqs_drul_[START]));
90 Beam_engraver::typeset_beam ()
94 Rhythmic_grouping const * rg_C = get_staff_info().rhythmic_C_;
95 rg_C->extend (finished_grouping_p_->interval());
96 finished_beam_p_->set_grouping (*rg_C, *finished_grouping_p_);
97 typeset_element (finished_beam_p_);
100 delete finished_grouping_p_;
101 finished_grouping_p_= 0;
103 reqs_drul_[STOP] = 0;
108 Beam_engraver::do_post_move_processing ()
110 reqs_drul_ [START] =0;
114 Beam_engraver::do_pre_move_processing ()
120 Beam_engraver::do_removal_processing ()
125 prev_start_req_->warning (_ ("Unfinished beam"));
126 finished_beam_p_ = beam_p_;
127 finished_grouping_p_ = grouping_p_;
133 Beam_engraver::acknowledge_element (Score_element_info info)
137 Stem* stem_l = dynamic_cast<Stem *> (info.elem_l_);
138 if (!stem_l || stem_l->beam_l_)
142 bool stem_grace = stem_l->get_elt_property (grace_scm_sym) != SCM_BOOL_F;
144 if (get_property ("weAreGraceContext",0).to_bool () != stem_grace)
147 Rhythmic_req *rhythmic_req = dynamic_cast <Rhythmic_req *> (info.req_l_);
150 String s = _ ("Stem must have Rhythmic structure.");
152 info.req_l_->warning (s);
160 if (rhythmic_req->duration_.durlog_i_<= 2)
162 rhythmic_req->warning (_ ("stem doesn't fit in beam"));
163 prev_start_req_->warning (_ ("beam was started here"));
168 TODO: do something sensible if it doesn't fit in the beam.
170 Moment start = get_staff_info().time_C_->whole_in_measure_;
172 if (!grouping_p_->child_fit_b (start))
174 String s (_ ("please fix me") + ": "
175 + _f ("stem at %s doesn't fit in beam", now_mom ().str ()));
178 info.req_l_->warning(s);
184 grouping_p_->add_child (start, rhythmic_req->length_mom ());
185 stem_l->flag_i_ = rhythmic_req->duration_.durlog_i_;
186 beam_p_->add_stem (stem_l);
193 ADD_THIS_TRANSLATOR(Beam_engraver);