lilypond-1.3.12
[lilypond.git] / lily / dynamic-engraver.cc
blobf117c9c49d5c2a401b922f97705dd6ebc69398f0
1 /*
2 dynamic-reg.cc -- implement Dynamic_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8 #include "debug.hh"
9 #include "crescendo.hh"
10 #include "musical-request.hh"
11 #include "lookup.hh"
12 #include "paper-def.hh"
13 #include "score-column.hh"
14 #include "staff-symbol.hh"
15 #include "note-column.hh"
16 #include "text-item.hh"
17 #include "side-position-interface.hh"
18 #include "engraver.hh"
19 #include "stem.hh"
20 #include "note-head.hh"
22 /**
23 print text & hairpin dynamics.
25 class Dynamic_engraver : public Engraver
27 Text_item * text_p_;
28 Crescendo * to_end_cresc_p_;
29 Crescendo * cresc_p_;
31 Span_req * cresc_req_l_;
32 Array<Request*> dynamic_req_l_arr_;
33 void typeset_all ();
34 public:
35 VIRTUAL_COPY_CONS(Translator);
36 Dynamic_engraver();
38 protected:
39 virtual void do_removal_processing ();
40 virtual void acknowledge_element (Score_element_info);
41 virtual bool do_try_music (Music *req_l);
42 virtual void do_process_requests();
43 virtual void do_pre_move_processing();
44 virtual void do_post_move_processing();
49 Dynamic_engraver::Dynamic_engraver()
51 do_post_move_processing();
52 text_p_ =0;
54 to_end_cresc_p_ = cresc_p_ = 0;
56 cresc_req_l_ = 0;
59 void
60 Dynamic_engraver::do_post_move_processing()
62 dynamic_req_l_arr_.clear();
65 bool
66 Dynamic_engraver::do_try_music (Music * m)
68 Request * r = dynamic_cast<Request*> (m);
70 if(Text_script_req * d = dynamic_cast <Text_script_req *> (r))
72 if (d->style_str_ != "dynamic")
73 return false;
75 else if (Span_req * s = dynamic_cast <Span_req*> (r))
77 if (s-> span_type_str_ != "crescendo"
78 && s->span_type_str_ != "decrescendo")
79 return false;
81 else
82 return false;
84 for (int i=0; i < dynamic_req_l_arr_.size (); i++)
85 if (r->equal_b (dynamic_req_l_arr_[i]))
86 return true;
88 dynamic_req_l_arr_.push (r);
89 return true;
93 void
94 Dynamic_engraver::do_process_requests()
96 Crescendo* new_cresc_p=0;
98 for (int i=0; i < dynamic_req_l_arr_.size(); i++)
100 if (Text_script_req *absd =
101 dynamic_cast<Text_script_req *> ( dynamic_req_l_arr_[i]))
103 if (text_p_)
105 dynamic_req_l_arr_[i]->warning (_("Got a dynamic already. Continuing dazed and confused."));
106 continue;
109 String loud = absd->text_str_;
111 text_p_ = new Text_item;
112 text_p_->text_str_ = loud; // ugh
113 text_p_->set_elt_property ("style", gh_str02scm ("dynamic"));
114 text_p_->set_elt_property ("script-priority",
115 gh_int2scm (100));
116 text_p_->set_elt_property ("staff-support", SCM_BOOL_T);
118 Side_position_interface (text_p_).set_axis (Y_AXIS);
121 if (absd->get_direction ())
123 text_p_->set_elt_property ("direction", gh_int2scm (absd->get_direction ()));
128 UGH UGH
130 SCM prop = get_property ("dynamicDirection", 0);
131 if (!isdir_b (prop))
133 prop = get_property ("verticalDirection", 0);
136 if (isdir_b (prop) && to_dir (prop))
137 text_p_->set_elt_property ("direction", prop);
139 prop = get_property ("dynamicPadding", 0);
140 if (gh_number_p(prop))
142 text_p_->set_elt_property ("padding", prop);
144 announce_element (Score_element_info (text_p_, absd));
146 else if (Span_req *span_l
147 = dynamic_cast <Span_req *> (dynamic_req_l_arr_[i]))
149 if (span_l->span_dir_ == STOP)
151 if (!cresc_p_)
153 span_l->warning (_ ("Can't find (de)crescendo to end"));
155 else
157 assert (!to_end_cresc_p_);
158 to_end_cresc_p_ =cresc_p_;
160 cresc_p_ = 0;
163 else if (span_l->span_dir_ == START)
165 cresc_req_l_ = span_l;
166 assert (!new_cresc_p);
167 new_cresc_p = new Crescendo;
168 new_cresc_p->grow_dir_ = (span_l->span_type_str_ == "crescendo") ? BIGGER : SMALLER;
169 new_cresc_p->set_elt_property ("staff-support", SCM_BOOL_T);
172 Side_position_interface (new_cresc_p).set_axis (Y_AXIS);
173 announce_element (Score_element_info (new_cresc_p, span_l));
178 if (new_cresc_p)
180 if (cresc_p_)
182 ::warning (_ ("Too many crescendi here"));
185 typeset_element (cresc_p_);
187 cresc_p_ = 0;
190 cresc_p_ = new_cresc_p;
191 cresc_p_->set_bounds(LEFT,get_staff_info().musical_pcol_l ());
193 if (text_p_)
195 cresc_p_->dyn_b_drul_[LEFT] = true;
196 if (to_end_cresc_p_)
197 to_end_cresc_p_->dyn_b_drul_[RIGHT] = true;
202 void
203 Dynamic_engraver::do_pre_move_processing()
205 typeset_all ();
210 ADD_THIS_TRANSLATOR(Dynamic_engraver);
212 void
213 Dynamic_engraver::do_removal_processing ()
215 if (cresc_p_)
217 typeset_element (cresc_p_ );
218 cresc_req_l_->warning (_ ("unended crescendo"));
219 cresc_p_ =0;
221 typeset_all ();
225 void
226 Dynamic_engraver::typeset_all ()
228 if (to_end_cresc_p_)
230 to_end_cresc_p_->set_bounds(RIGHT,get_staff_info().musical_pcol_l ());
231 typeset_element (to_end_cresc_p_);
233 to_end_cresc_p_ =0;
237 if (text_p_)
239 typeset_element (text_p_);
240 text_p_ =0;
245 void
246 Dynamic_engraver::acknowledge_element (Score_element_info i)
248 if (dynamic_cast<Stem *> (i.elem_l_)
249 || dynamic_cast<Note_head *> (i.elem_l_)
252 if (text_p_)
253 Side_position_interface (text_p_).add_support (i.elem_l_);
255 if (to_end_cresc_p_)
256 Side_position_interface (to_end_cresc_p_).add_support (i.elem_l_);
258 if (cresc_p_)
259 Side_position_interface(cresc_p_).add_support (i.elem_l_);