]> git.donarmstrong.com Git - lilypond.git/blob - lily/beam-engraver.cc
patch::: 1.1.20.jcn1: patsje
[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       // must set minVerticalAlign == maxVerticalAlign to get sane results
67       // see input/test/beam-interstaff.ly
68       prop = get_property ("minVerticalAlign", 0);
69       if (prop.isnum_b ())
70         beam_p_->vertical_align_drul_[MIN] = prop;
71
72       prop = get_property ("maxVerticalAlign", 0);
73       if (prop.isnum_b ())
74         beam_p_->vertical_align_drul_[MAX] = prop;
75
76       announce_element (Score_element_info (beam_p_, reqs_drul_[START]));
77     }
78 }
79
80 void
81 Beam_engraver::typeset_beam ()
82 {
83   if (finished_beam_p_)
84     {
85       Rhythmic_grouping const * rg_C = get_staff_info().rhythmic_C_;
86       rg_C->extend (finished_grouping_p_->interval());
87       finished_beam_p_->set_grouping (*rg_C, *finished_grouping_p_);
88       typeset_element (finished_beam_p_);
89       finished_beam_p_ = 0;
90     
91       delete finished_grouping_p_;
92       finished_grouping_p_= 0;
93     
94       reqs_drul_[STOP] = 0;
95     }
96 }
97
98 void
99 Beam_engraver::do_post_move_processing ()
100 {
101   reqs_drul_ [START] =0;
102 }
103
104 void
105 Beam_engraver::do_pre_move_processing ()
106 {
107   typeset_beam ();
108 }
109
110 void
111 Beam_engraver::do_removal_processing ()
112 {
113   typeset_beam ();
114   finished_beam_p_ = beam_p_;
115   finished_grouping_p_ = grouping_p_;
116   typeset_beam ();
117 }
118
119 void
120 Beam_engraver::acknowledge_element (Score_element_info info)
121 {
122     if (beam_p_)
123       {
124         Stem* stem_l = dynamic_cast<Stem *> (info.elem_l_);
125         if (!stem_l)
126           return;
127
128
129         Rhythmic_req *rhythmic_req = dynamic_cast <Rhythmic_req *> (info.req_l_);
130         if (!rhythmic_req)
131           {
132             String s=_("Stem must have Rhythmic structure.");
133             if (info.req_l_)
134               info.req_l_->warning(s);
135             else
136               ::warning (s);
137           
138             return;
139           }
140       
141
142         if (rhythmic_req->duration_.durlog_i_<= 2)
143           {
144             rhythmic_req->warning (_ ("stem doesn't fit in beam"));
145             reqs_drul_[LEFT]->warning (_("beam was started here"));
146             return;
147           }
148
149         /*
150           TODO: do something sensible if it doesn't fit in the beam.
151         */
152         Moment start = get_staff_info().time_C_->whole_in_measure_;
153
154         if (!grouping_p_->child_fit_b (start))
155           {
156             String s (_("please fix me") + ": " 
157                       + _f ("stem at %s doesn't fit in beam", now_moment ().str ()));
158
159             if (info.req_l_)
160               info.req_l_->warning(s);
161             else 
162               warning (s);
163           }
164         else
165           {
166             grouping_p_->add_child (start, rhythmic_req->duration ());
167             stem_l->flag_i_ = rhythmic_req->duration_.durlog_i_;
168             beam_p_->add_stem (stem_l);
169           }
170       }
171 }
172
173
174
175 ADD_THIS_TRANSLATOR(Beam_engraver);