lilypond-1.1.67
[lilypond.git] / lily / beam-grav.cc
blob9a3f9586c2f5c1f8131037219bc9a75e7cc7bc10
1 /*
2 beam-grav.cc -- implement Beam_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1998 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8 #include "duration-convert.hh"
9 #include "time-description.hh"
10 #include "beam-grav.hh"
11 #include "stem.hh"
12 #include "beam.hh"
13 #include "musical-request.hh"
14 #include "grouping.hh"
15 #include "p-col.hh"
17 Beam_engraver::Beam_engraver()
19 span_reqs_drul_[LEFT] = span_reqs_drul_[RIGHT] =0;
20 beam_p_ =0;
21 current_grouping_p_ =0;
24 bool
25 Beam_engraver::do_try_request(Request*r)
27 Musical_req* mus_l = r->musical();
28 if (!mus_l)
29 return false;
31 Beam_req* b = mus_l->beam ();
32 if (!b)
33 return false;
35 if (bool (beam_p_) == bool (b->spantype == Span_req::START))
36 return false;
38 Direction d = (!beam_p_) ? LEFT : RIGHT;
39 if (span_reqs_drul_[d] && !span_reqs_drul_[d]->equal_b (mus_l))
40 return false;
42 span_reqs_drul_[d] = b;
43 return true;
46 void
47 Beam_engraver::do_process_requests()
49 if (beam_p_ || !span_reqs_drul_[LEFT])
50 return;
52 current_grouping_p_ = new Rhythmic_grouping;
53 beam_p_ = new Beam;
55 Scalar prop = get_property ("beamslopedamping");
56 if (prop.isnum_b ())
57 beam_p_->damping_i_ = prop;
59 prop = get_property ("beamquantisation");
60 if (prop.isnum_b ())
61 beam_p_->quantisation_ = (Beam::Quantisation)(int)prop;
63 announce_element (Score_elem_info (beam_p_, span_reqs_drul_[LEFT]));
66 void
67 Beam_engraver::do_pre_move_processing()
69 if (!beam_p_ || !span_reqs_drul_[RIGHT])
70 return;
72 Rhythmic_grouping const * rg_C = get_staff_info().rhythmic_C_;
73 rg_C->extend (current_grouping_p_->interval());
74 beam_p_->set_grouping (*rg_C, *current_grouping_p_);
75 typeset_element (beam_p_);
76 beam_p_ = 0;
78 delete current_grouping_p_;
79 current_grouping_p_ = 0;
81 span_reqs_drul_[RIGHT] = span_reqs_drul_[LEFT] = 0;
84 void
85 Beam_engraver::do_removal_processing()
87 if (beam_p_)
89 span_reqs_drul_[LEFT]->warning (_("unterminated beam"));
90 typeset_element (beam_p_);
91 beam_p_ =0;
96 void
97 Beam_engraver::acknowledge_element (Score_elem_info i)
99 if (!beam_p_ || !i.elem_l_->is_type_b (Stem::static_name ()))
100 return;
102 Stem* s = (Stem*)i.elem_l_->item();
103 Rhythmic_req *rhythmic_req = i.req_l_->musical ()->rhythmic ();
104 if (rhythmic_req->duration_.durlog_i_<= 2)
106 rhythmic_req->warning (_("Stem doesn't fit in Beam"));
107 return;
111 TODO: do something sensible if it doesn't fit in the beam.
113 Moment start = get_staff_info().time_C_->whole_in_measure_;
115 if (!current_grouping_p_->child_fit_b (start))
117 String s (_("please fix me: Stem at ")
118 + now_moment ().str ()
119 + _(" does not fit in beam"));
120 if (i.req_l_)
121 i.req_l_->warning(s);
122 else
123 warning (s);
125 else
127 current_grouping_p_->add_child (start, rhythmic_req->duration ());
128 s->flag_i_ = rhythmic_req->duration_.durlog_i_;
129 beam_p_->add (s);
132 IMPLEMENT_IS_TYPE_B1(Beam_engraver, Engraver);
133 ADD_THIS_TRANSLATOR(Beam_engraver);