]> git.donarmstrong.com Git - lilypond.git/blob - lily/beam-engraver.cc
4ef398b499110aef61d9ee5a319586374c11ed3c
[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_request(Request*r)
27 {
28   Musical_req* mus_l = dynamic_cast <Musical_req *> (r);
29   if (!mus_l)
30     return false;
31
32   Beam_req* b = dynamic_cast <Beam_req *> (mus_l);
33   if (!b)
34     return false;
35
36   if (bool (beam_p_) == bool (b->spantype == Span_req::START))
37     return false;
38
39   Direction d = (!beam_p_) ? LEFT : RIGHT;
40   if (span_reqs_drul_[d] && !span_reqs_drul_[d]->equal_b (mus_l))
41     return false;
42
43   span_reqs_drul_[d] = b;
44   return true;
45 }
46
47 void
48 Beam_engraver::do_process_requests()
49 {
50   if (beam_p_ || !span_reqs_drul_[LEFT])
51     return;
52
53   current_grouping_p_ = new Rhythmic_grouping;
54   beam_p_ = new Beam;
55
56   Scalar prop = get_property ("beamslopedamping");
57   if (prop.isnum_b ()) 
58     beam_p_->damping_i_ = prop;
59
60   prop = get_property ("beamquantisation");
61   if (prop.isnum_b ()) 
62     beam_p_->quantisation_ = (Beam::Quantisation)(int)prop;
63  
64   announce_element (Score_element_info (beam_p_, span_reqs_drul_[LEFT]));
65 }
66
67 void
68 Beam_engraver::do_pre_move_processing()
69 {
70   if (!beam_p_ || !span_reqs_drul_[RIGHT]) 
71     return;
72
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_);
77   beam_p_ = 0;
78
79   delete current_grouping_p_;
80   current_grouping_p_ = 0;
81
82   span_reqs_drul_[RIGHT] = span_reqs_drul_[LEFT] = 0;
83 }
84
85 void
86 Beam_engraver::do_removal_processing()
87 {
88   if (beam_p_)
89     {
90       span_reqs_drul_[LEFT]->warning (_("unterminated beam"));
91       typeset_element (beam_p_);
92       beam_p_ =0;
93     }
94 }
95
96
97 void
98 Beam_engraver::acknowledge_element (Score_element_info i)
99 {
100   if (!beam_p_ || !i.elem_l_->is_type_b (Stem::static_name ()))
101     return;
102
103   Stem* s = (Stem*)dynamic_cast <Item *> (i.elem_l_);
104   if (!dynamic_cast <Rhythmic_req *> (i.req_l_))
105     {
106       ::warning ( _("Stem must have Rhythmic structure."));
107       return;
108     }
109
110   Rhythmic_req *rhythmic_req = dynamic_cast <Rhythmic_req *> (i.req_l_);
111   if (rhythmic_req->duration_.durlog_i_<= 2)
112     {
113       rhythmic_req->warning (_ ("stem doesn't fit in beam"));
114       return;
115     }
116
117   /*
118     TODO: do something sensible if it doesn't fit in the beam.
119    */
120   Moment start = get_staff_info().time_C_->whole_in_measure_;
121
122   if (!current_grouping_p_->child_fit_b (start))
123     {
124       String s (_("please fix me") + ": " 
125         + _f ("stem at %s doesn't fit in beam", now_moment ().str ()));
126       if (i.req_l_)
127         i.req_l_->warning(s);
128       else 
129         warning (s);
130     }
131   else
132     {
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);
136     }
137 }
138 IMPLEMENT_IS_TYPE_B1(Beam_engraver, Engraver);
139 ADD_THIS_TRANSLATOR(Beam_engraver);