]> git.donarmstrong.com Git - lilypond.git/blob - lily/beam-engraver.cc
patch::: 1.1.19.jcn5: isb
[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       reqs_drul_[c->spantype_] = c;
33       return true;
34     }
35   return false;
36 }
37
38
39 void
40 Beam_engraver::do_process_requests ()
41 {
42   if (reqs_drul_[STOP])
43     {
44       if (!beam_p_)
45         reqs_drul_[STOP]->warning (_("No beam to stop"));
46       finished_beam_p_ = beam_p_;
47       finished_grouping_p_ = grouping_p_;
48
49       beam_p_ = 0;
50       grouping_p_ = 0;
51     }
52   
53   if (reqs_drul_[START])
54     {
55       beam_p_ = new Beam;
56       grouping_p_ = new Rhythmic_grouping;
57
58       Scalar prop = get_property ("beamslopedamping", 0);
59       if (prop.isnum_b ()) 
60         beam_p_->damping_i_ = prop;
61
62       prop = get_property ("beamquantisation", 0);
63       if (prop.isnum_b ()) 
64         beam_p_->quantisation_ = (Beam::Quantisation)(int)prop;
65  
66       // silly try at interstaff beam
67       // must set minVerticalAlign == maxVerticalAlign to get sane results
68       // see input/test/beam-interstaff.ly
69       prop = get_property ("minVerticalAlign", 0);
70       if (prop.isnum_b ())
71         beam_p_->vertical_align_f_ = prop;
72
73       prop = get_property ("maxVerticalAlign", 0);
74       if (prop.isnum_b ())
75         {
76           beam_p_->vertical_align_f_ += (Real)prop;
77           beam_p_->vertical_align_f_ /= (Real)2;
78         }
79
80       announce_element (Score_element_info (beam_p_, reqs_drul_[START]));
81     }
82 }
83
84 void
85 Beam_engraver::typeset_beam ()
86 {
87   if (finished_beam_p_)
88     {
89       Rhythmic_grouping const * rg_C = get_staff_info().rhythmic_C_;
90       rg_C->extend (finished_grouping_p_->interval());
91       finished_beam_p_->set_grouping (*rg_C, *finished_grouping_p_);
92       typeset_element (finished_beam_p_);
93       finished_beam_p_ = 0;
94     
95       delete finished_grouping_p_;
96       finished_grouping_p_= 0;
97     
98       reqs_drul_[STOP] = 0;
99     }
100 }
101
102 void
103 Beam_engraver::do_post_move_processing ()
104 {
105   reqs_drul_ [START] =0;
106 }
107
108 void
109 Beam_engraver::do_pre_move_processing ()
110 {
111   typeset_beam ();
112 }
113
114 void
115 Beam_engraver::do_removal_processing ()
116 {
117   typeset_beam ();
118   finished_beam_p_ = beam_p_;
119   finished_grouping_p_ = grouping_p_;
120   typeset_beam ();
121 }
122
123 void
124 Beam_engraver::acknowledge_element (Score_element_info info)
125 {
126     if (beam_p_)
127       {
128         Stem* stem_l = dynamic_cast<Stem *> (info.elem_l_);
129         if (!stem_l)
130           return;
131
132
133         Rhythmic_req *rhythmic_req = dynamic_cast <Rhythmic_req *> (info.req_l_);
134         if (!rhythmic_req)
135           {
136             String s=_("Stem must have Rhythmic structure.");
137             if (info.req_l_)
138               info.req_l_->warning(s);
139             else
140               ::warning (s);
141           
142             return;
143           }
144       
145
146         if (rhythmic_req->duration_.durlog_i_<= 2)
147           {
148             rhythmic_req->warning (_ ("stem doesn't fit in beam"));
149             return;
150           }
151
152         /*
153           TODO: do something sensible if it doesn't fit in the beam.
154         */
155         Moment start = get_staff_info().time_C_->whole_in_measure_;
156
157         if (!grouping_p_->child_fit_b (start))
158           {
159             String s (_("please fix me") + ": " 
160                       + _f ("stem at %s doesn't fit in beam", now_moment ().str ()));
161
162             if (info.req_l_)
163               info.req_l_->warning(s);
164             else 
165               warning (s);
166           }
167         else
168           {
169             grouping_p_->add_child (start, rhythmic_req->duration ());
170             stem_l->flag_i_ = rhythmic_req->duration_.durlog_i_;
171             beam_p_->add_stem (stem_l);
172           }
173       }
174 }
175
176
177
178 ADD_THIS_TRANSLATOR(Beam_engraver);