]> git.donarmstrong.com Git - lilypond.git/blob - lily/beam-engraver.cc
b1ec28d01d134207ce929601cda2bac7d82d2d29
[lilypond.git] / lily / beam-engraver.cc
1 /*
2   beam-grav.cc -- implement Beam_engraver
3
4   source file of the GNU LilyPond music typesetter
5
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"
17
18 Beam_engraver::Beam_engraver()
19 {
20   span_reqs_drul_[LEFT] = span_reqs_drul_[RIGHT] =0;
21   beam_p_ =0;
22   current_grouping_p_ =0;
23 }
24
25 bool
26 Beam_engraver::do_try_music (Music*r)
27 {
28   Beam_req* b = dynamic_cast <Beam_req *> (r);
29   if (!b)
30     return false;
31
32   if (bool (beam_p_) == bool (b->spantype == Span_req::START))
33     return false;
34
35   Direction d = (!beam_p_) ? LEFT : RIGHT;
36   if (span_reqs_drul_[d] && !span_reqs_drul_[d]->equal_b (b))
37     return false;
38
39   span_reqs_drul_[d] = b;
40   return true;
41 }
42
43 void
44 Beam_engraver::do_process_requests()
45 {
46   if (beam_p_ || !span_reqs_drul_[LEFT])
47     return;
48
49   current_grouping_p_ = new Rhythmic_grouping;
50   beam_p_ = new Beam;
51
52   Scalar prop = get_property ("beamslopedamping");
53   if (prop.isnum_b ()) 
54     beam_p_->damping_i_ = prop;
55
56   prop = get_property ("beamquantisation");
57   if (prop.isnum_b ()) 
58     beam_p_->quantisation_ = (Beam::Quantisation)(int)prop;
59  
60   announce_element (Score_element_info (beam_p_, span_reqs_drul_[LEFT]));
61 }
62
63 void
64 Beam_engraver::do_pre_move_processing()
65 {
66   if (!beam_p_ || !span_reqs_drul_[RIGHT]) 
67     return;
68
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;
74
75   delete current_grouping_p_;
76   current_grouping_p_ = 0;
77
78   span_reqs_drul_[RIGHT] = span_reqs_drul_[LEFT] = 0;
79 }
80
81 void
82 Beam_engraver::do_removal_processing()
83 {
84   if (beam_p_)
85     {
86       span_reqs_drul_[LEFT]->warning (_("unterminated beam"));
87       typeset_element (beam_p_);
88       beam_p_ =0;
89     }
90 }
91
92
93 void
94 Beam_engraver::acknowledge_element (Score_element_info i)
95 {
96   Stem* s = dynamic_cast<Stem *> (i.elem_l_);
97   if (!beam_p_ || !s)
98     return;
99
100   if (!dynamic_cast <Rhythmic_req *> (i.req_l_))
101     {
102       ::warning ( _("Stem must have Rhythmic structure."));
103       return;
104     }
105
106   Rhythmic_req *rhythmic_req = dynamic_cast <Rhythmic_req *> (i.req_l_);
107   if (rhythmic_req->duration_.durlog_i_<= 2)
108     {
109       rhythmic_req->warning (_ ("stem doesn't fit in beam"));
110       return;
111     }
112
113   /*
114     TODO: do something sensible if it doesn't fit in the beam.
115    */
116   Moment start = get_staff_info().time_C_->whole_in_measure_;
117
118   if (!current_grouping_p_->child_fit_b (start))
119     {
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);
126     }
127   else
128     {
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);
132     }
133 }
134
135 ADD_THIS_TRANSLATOR(Beam_engraver);