]> git.donarmstrong.com Git - lilypond.git/blob - lily/cbeam-engraver.cc
patch::: 1.1.17.mb1: Re: LilyPond Xmas release
[lilypond.git] / lily / cbeam-engraver.cc
1 /*   
2   cbeam-engraver.cc --  implement Command_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 "cbeam-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 Command_beam_engraver::Command_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 Command_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 Command_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");
59       if (prop.isnum_b ()) 
60         beam_p_->damping_i_ = prop;
61
62       prop = get_property ("beamquantisation");
63       if (prop.isnum_b ()) 
64         beam_p_->quantisation_ = (Beam::Quantisation)(int)prop;
65  
66       announce_element (Score_element_info (beam_p_, reqs_drul_[START]));
67     }
68 }
69
70 void
71 Command_beam_engraver::typeset_beam ()
72 {
73   if (finished_beam_p_)
74     {
75       Rhythmic_grouping const * rg_C = get_staff_info().rhythmic_C_;
76       rg_C->extend (finished_grouping_p_->interval());
77       finished_beam_p_->set_grouping (*rg_C, *finished_grouping_p_);
78       typeset_element (finished_beam_p_);
79       finished_beam_p_ = 0;
80     
81       delete finished_grouping_p_;
82       finished_grouping_p_= 0;
83     
84       reqs_drul_[STOP] = 0;
85     }
86 }
87
88 void
89 Command_beam_engraver::do_post_move_processing ()
90 {
91   reqs_drul_ [START] =0;
92 }
93
94 void
95 Command_beam_engraver::do_pre_move_processing ()
96 {
97   typeset_beam ();
98 }
99
100 void
101 Command_beam_engraver::do_removal_processing ()
102 {
103   typeset_beam ();
104   finished_beam_p_ = beam_p_;
105   finished_grouping_p_ = grouping_p_;
106   typeset_beam ();
107 }
108
109 void
110 Command_beam_engraver::acknowledge_element (Score_element_info info)
111 {
112     if (beam_p_)
113       {
114         Stem* stem_l = dynamic_cast<Stem *> (info.elem_l_);
115         if (!stem_l)
116           return;
117
118
119         Rhythmic_req *rhythmic_req = dynamic_cast <Rhythmic_req *> (info.req_l_);
120         if (!rhythmic_req)
121           {
122             String s=_("Stem must have Rhythmic structure.");
123             if (info.req_l_)
124               info.req_l_->warning(s);
125             else
126               ::warning (s);
127           
128             return;
129           }
130       
131
132         if (rhythmic_req->duration_.durlog_i_<= 2)
133           {
134             rhythmic_req->warning (_ ("stem doesn't fit in beam"));
135             return;
136           }
137
138         /*
139           TODO: do something sensible if it doesn't fit in the beam.
140         */
141         Moment start = get_staff_info().time_C_->whole_in_measure_;
142
143         if (!grouping_p_->child_fit_b (start))
144           {
145             String s (_("please fix me") + ": " 
146                       + _f ("stem at %s doesn't fit in beam", now_moment ().str ()));
147
148             if (info.req_l_)
149               info.req_l_->warning(s);
150             else 
151               warning (s);
152           }
153         else
154           {
155             grouping_p_->add_child (start, rhythmic_req->duration ());
156             stem_l->flag_i_ = rhythmic_req->duration_.durlog_i_;
157             beam_p_->add_stem (stem_l);
158           }
159       }
160 }
161
162
163
164 ADD_THIS_TRANSLATOR(Command_beam_engraver);