2 beam-grav.cc -- implement Beam_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 #include "duration-convert.hh"
9 #include "time-description.hh"
10 #include "beam-engraver.hh"
13 #include "musical-request.hh"
14 #include "grouping.hh"
18 Beam_engraver::Beam_engraver()
20 span_reqs_drul_[LEFT] = span_reqs_drul_[RIGHT] =0;
22 current_grouping_p_ =0;
26 Beam_engraver::do_try_request(Request*r)
28 Musical_req* mus_l = dynamic_cast <Musical_req *> (r);
32 Beam_req* b = dynamic_cast <Beam_req *> (mus_l);
36 if (bool (beam_p_) == bool (b->spantype == Span_req::START))
39 Direction d = (!beam_p_) ? LEFT : RIGHT;
40 if (span_reqs_drul_[d] && !span_reqs_drul_[d]->equal_b (mus_l))
43 span_reqs_drul_[d] = b;
48 Beam_engraver::do_process_requests()
50 if (beam_p_ || !span_reqs_drul_[LEFT])
53 current_grouping_p_ = new Rhythmic_grouping;
56 Scalar prop = get_property ("beamslopedamping");
58 beam_p_->damping_i_ = prop;
60 prop = get_property ("beamquantisation");
62 beam_p_->quantisation_ = (Beam::Quantisation)(int)prop;
64 announce_element (Score_element_info (beam_p_, span_reqs_drul_[LEFT]));
68 Beam_engraver::do_pre_move_processing()
70 if (!beam_p_ || !span_reqs_drul_[RIGHT])
73 Rhythmic_grouping const * rg_C = get_staff_info().rhythmic_C_;
74 rg_C->extend (current_grouping_p_->interval());
75 beam_p_->set_grouping (*rg_C, *current_grouping_p_);
76 typeset_element (beam_p_);
79 delete current_grouping_p_;
80 current_grouping_p_ = 0;
82 span_reqs_drul_[RIGHT] = span_reqs_drul_[LEFT] = 0;
86 Beam_engraver::do_removal_processing()
90 span_reqs_drul_[LEFT]->warning (_("unterminated beam"));
91 typeset_element (beam_p_);
98 Beam_engraver::acknowledge_element (Score_element_info i)
100 if (!beam_p_ || !i.elem_l_->is_type_b (Stem::static_name ()))
103 Stem* s = (Stem*)dynamic_cast <Item *> (i.elem_l_);
104 if (!dynamic_cast <Rhythmic_req *> (i.req_l_))
106 ::warning ( _("Stem must have Rhythmic structure."));
110 Rhythmic_req *rhythmic_req = dynamic_cast <Rhythmic_req *> (i.req_l_);
111 if (rhythmic_req->duration_.durlog_i_<= 2)
113 rhythmic_req->warning (_ ("stem doesn't fit in beam"));
118 TODO: do something sensible if it doesn't fit in the beam.
120 Moment start = get_staff_info().time_C_->whole_in_measure_;
122 if (!current_grouping_p_->child_fit_b (start))
124 String s (_("please fix me") + ": "
125 + _f ("stem at %s doesn't fit in beam", now_moment ().str ()));
127 i.req_l_->warning(s);
133 current_grouping_p_->add_child (start, rhythmic_req->duration ());
134 s->flag_i_ = rhythmic_req->duration_.durlog_i_;
135 beam_p_->add_stem (s);
138 IMPLEMENT_IS_TYPE_B1(Beam_engraver, Engraver);
139 ADD_THIS_TRANSLATOR(Beam_engraver);