]> git.donarmstrong.com Git - lilypond.git/blob - lily/beam-engraver.cc
release: 1.1.21
[lilypond.git] / lily / beam-engraver.cc
1 /*   
2   beam-engraver.cc --  implement Beam_engraver
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9
10 #include "beam-engraver.hh"
11 #include "musical-request.hh"
12 #include "beam.hh"
13 #include "grouping.hh"
14 #include "stem.hh"
15 #include "warn.hh"
16 #include "time-description.hh"
17
18 Beam_engraver::Beam_engraver ()
19 {
20   beam_p_ = 0;
21   finished_beam_p_ =0;
22   finished_grouping_p_ = 0;
23   grouping_p_ =0;
24   reqs_drul_[LEFT] = reqs_drul_[RIGHT] =0;
25 }
26
27 bool
28 Beam_engraver::do_try_music (Music *m)
29 {
30   if (Beam_req * c = dynamic_cast<Beam_req*>(m))
31     {
32       Direction d =c->spantype_;
33
34       /*
35         Perhaps not print warnings ?
36        */
37       if (d == START && beam_p_)
38         {
39           m->warning ("Already have a Beam");
40           return false;
41         }
42       if (d == STOP && !beam_p_)
43         {
44           m->warning ("No Beam to end");
45           return false;
46         }
47       reqs_drul_[d ] = c;
48       return true;
49     }
50   return false;
51 }
52
53
54 void
55 Beam_engraver::do_process_requests ()
56 {
57   if (reqs_drul_[STOP])
58     {
59       if (!beam_p_)
60         reqs_drul_[STOP]->warning (_("No beam to stop"));
61       finished_beam_p_ = beam_p_;
62       finished_grouping_p_ = grouping_p_;
63
64       beam_p_ = 0;
65       grouping_p_ = 0;
66     }
67   
68   if (reqs_drul_[START])
69     {
70       beam_p_ = new Beam;
71       grouping_p_ = new Rhythmic_grouping;
72
73       Scalar prop = get_property ("beamslopedamping", 0);
74       if (prop.isnum_b ()) 
75         beam_p_->damping_i_ = prop;
76
77       prop = get_property ("beamquantisation", 0);
78       if (prop.isnum_b ()) 
79         beam_p_->quantisation_ = (Beam::Quantisation)(int)prop;
80  
81       // must set minVerticalAlign == maxVerticalAlign to get sane results
82       // see input/test/beam-interstaff.ly
83       prop = get_property ("minVerticalAlign", 0);
84       if (prop.isnum_b ())
85         beam_p_->vertical_align_drul_[MIN] = prop;
86
87       prop = get_property ("maxVerticalAlign", 0);
88       if (prop.isnum_b ())
89         beam_p_->vertical_align_drul_[MAX] = prop;
90
91       announce_element (Score_element_info (beam_p_, reqs_drul_[START]));
92     }
93 }
94
95 void
96 Beam_engraver::typeset_beam ()
97 {
98   if (finished_beam_p_)
99     {
100       Rhythmic_grouping const * rg_C = get_staff_info().rhythmic_C_;
101       rg_C->extend (finished_grouping_p_->interval());
102       finished_beam_p_->set_grouping (*rg_C, *finished_grouping_p_);
103       typeset_element (finished_beam_p_);
104       finished_beam_p_ = 0;
105     
106       delete finished_grouping_p_;
107       finished_grouping_p_= 0;
108     
109       reqs_drul_[STOP] = 0;
110     }
111 }
112
113 void
114 Beam_engraver::do_post_move_processing ()
115 {
116   reqs_drul_ [START] =0;
117 }
118
119 void
120 Beam_engraver::do_pre_move_processing ()
121 {
122   typeset_beam ();
123 }
124
125 void
126 Beam_engraver::do_removal_processing ()
127 {
128   typeset_beam ();
129   if (beam_p_)
130     {
131       warning ("Unfinished beam");
132       finished_beam_p_ = beam_p_;
133       finished_grouping_p_ = grouping_p_;
134       typeset_beam ();
135     }
136 }
137
138 void
139 Beam_engraver::acknowledge_element (Score_element_info info)
140 {
141     if (beam_p_)
142       {
143         Stem* stem_l = dynamic_cast<Stem *> (info.elem_l_);
144         if (!stem_l)
145           return;
146
147
148         Rhythmic_req *rhythmic_req = dynamic_cast <Rhythmic_req *> (info.req_l_);
149         if (!rhythmic_req)
150           {
151             String s=_("Stem must have Rhythmic structure.");
152             if (info.req_l_)
153               info.req_l_->warning(s);
154             else
155               ::warning (s);
156           
157             return;
158           }
159       
160
161         if (rhythmic_req->duration_.durlog_i_<= 2)
162           {
163             rhythmic_req->warning (_ ("stem doesn't fit in beam"));
164             reqs_drul_[LEFT]->warning (_("beam was started here"));
165             return;
166           }
167
168         /*
169           TODO: do something sensible if it doesn't fit in the beam.
170         */
171         Moment start = get_staff_info().time_C_->whole_in_measure_;
172
173         if (!grouping_p_->child_fit_b (start))
174           {
175             String s (_("please fix me") + ": " 
176                       + _f ("stem at %s doesn't fit in beam", now_moment ().str ()));
177
178             if (info.req_l_)
179               info.req_l_->warning(s);
180             else 
181               warning (s);
182           }
183         else
184           {
185             grouping_p_->add_child (start, rhythmic_req->duration ());
186             stem_l->flag_i_ = rhythmic_req->duration_.durlog_i_;
187             beam_p_->add_stem (stem_l);
188           }
189       }
190 }
191
192
193
194 ADD_THIS_TRANSLATOR(Beam_engraver);