lilypond-1.1.21
[lilypond.git] / lily / beam-engraver.cc
blobc8357fa38842d84bfae0fe9657e29b8d9413a325
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@cs.uu.nl>
7 */
8 #include "duration-convert.hh"
9 #include "time-description.hh"
10 #include "beam-engraver.hh"
11 #include "stem.hh"
12 #include "beam.hh"
13 #include "musical-request.hh"
14 #include "grouping.hh"
15 #include "p-col.hh"
16 #include "warn.hh"
18 Beam_engraver::Beam_engraver()
20 span_reqs_drul_[LEFT] = span_reqs_drul_[RIGHT] =0;
21 beam_p_ =0;
22 current_grouping_p_ =0;
25 bool
26 Beam_engraver::do_try_music (Music*r)
28 Beam_req* b = dynamic_cast <Beam_req *> (r);
29 if (!b)
30 return false;
32 if (bool (beam_p_) == bool (b->spantype_ == START))
33 return false;
35 Direction d = (!beam_p_) ? LEFT : RIGHT;
36 if (span_reqs_drul_[d] && !span_reqs_drul_[d]->equal_b (b))
37 return false;
39 span_reqs_drul_[d] = b;
40 return true;
43 void
44 Beam_engraver::do_process_requests()
46 if (beam_p_ || !span_reqs_drul_[LEFT])
47 return;
49 current_grouping_p_ = new Rhythmic_grouping;
50 beam_p_ = new Beam;
52 Scalar prop = get_property ("beamslopedamping");
53 if (prop.isnum_b ())
54 beam_p_->damping_i_ = prop;
56 prop = get_property ("beamquantisation");
57 if (prop.isnum_b ())
58 beam_p_->quantisation_ = (Beam::Quantisation)(int)prop;
60 announce_element (Score_element_info (beam_p_, span_reqs_drul_[LEFT]));
63 void
64 Beam_engraver::do_pre_move_processing()
66 if (!beam_p_ || !span_reqs_drul_[RIGHT])
67 return;
69 Rhythmic_grouping const * rg_C = get_staff_info().rhythmic_C_;
70 rg_C->extend (current_grouping_p_->interval());
71 beam_p_->set_grouping (*rg_C, *current_grouping_p_);
72 typeset_element (beam_p_);
73 beam_p_ = 0;
75 delete current_grouping_p_;
76 current_grouping_p_ = 0;
78 span_reqs_drul_[RIGHT] = span_reqs_drul_[LEFT] = 0;
81 void
82 Beam_engraver::do_removal_processing()
84 if (beam_p_)
86 span_reqs_drul_[LEFT]->warning (_("unterminated beam"));
87 typeset_element (beam_p_);
88 beam_p_ =0;
93 void
94 Beam_engraver::acknowledge_element (Score_element_info i)
96 Stem* s = dynamic_cast<Stem *> (i.elem_l_);
97 if (!beam_p_ || !s)
98 return;
100 if (!dynamic_cast <Rhythmic_req *> (i.req_l_))
102 ::warning ( _("Stem must have Rhythmic structure."));
103 return;
106 Rhythmic_req *rhythmic_req = dynamic_cast <Rhythmic_req *> (i.req_l_);
107 if (rhythmic_req->duration_.durlog_i_<= 2)
109 rhythmic_req->warning (_ ("stem doesn't fit in beam"));
110 return;
114 TODO: do something sensible if it doesn't fit in the beam.
116 Moment start = get_staff_info().time_C_->whole_in_measure_;
118 if (!current_grouping_p_->child_fit_b (start))
120 String s (_("please fix me") + ": "
121 + _f ("stem at %s doesn't fit in beam", now_moment ().str ()));
122 if (i.req_l_)
123 i.req_l_->warning(s);
124 else
125 warning (s);
127 else
129 current_grouping_p_->add_child (start, rhythmic_req->duration ());
130 s->flag_i_ = rhythmic_req->duration_.durlog_i_;
131 beam_p_->add_stem (s);
135 ADD_THIS_TRANSLATOR(Beam_engraver);