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>
9 #include "crescendo.hh"
10 #include "dynamic-engraver.hh"
11 #include "musical-request.hh"
13 #include "paper-def.hh"
14 #include "score-column.hh"
15 #include "staff-symbol.hh"
16 #include "note-column.hh"
17 #include "g-text-item.hh"
18 #include "g-staff-side.hh"
19 #include "engraver.hh"
21 #include "note-head.hh"
24 print text & hairpin dynamics.
26 class Dynamic_engraver : public Engraver
28 G_text_item * text_p_;
29 G_staff_side_item * staff_side_p_;
31 Crescendo * to_end_cresc_p_;
33 Span_req * cresc_req_l_;
34 Array<Request*> dynamic_req_l_arr_;
37 VIRTUAL_COPY_CONS(Translator);
41 virtual void do_removal_processing ();
42 virtual void acknowledge_element (Score_element_info);
43 virtual bool do_try_music (Music *req_l);
44 virtual void do_process_requests();
45 virtual void do_pre_move_processing();
46 virtual void do_post_move_processing();
51 Dynamic_engraver::Dynamic_engraver()
53 do_post_move_processing();
56 to_end_cresc_p_ = cresc_p_ = 0;
61 Dynamic_engraver::do_post_move_processing()
63 dynamic_req_l_arr_.clear();
67 Dynamic_engraver::do_try_music (Music * m)
69 Request * r = dynamic_cast<Request*> (m);
71 if(Text_script_req * d = dynamic_cast <Text_script_req *> (r))
73 if (d->style_str_ != "dynamic")
76 else if (Span_req * s = dynamic_cast <Span_req*> (r))
78 if (s-> span_type_str_ != "crescendo"
79 && s->span_type_str_ != "decrescendo")
85 for (int i=0; i < dynamic_req_l_arr_.size (); i++)
86 if (r->equal_b (dynamic_req_l_arr_[i]))
89 dynamic_req_l_arr_.push (r);
95 Dynamic_engraver::do_process_requests()
97 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]))
105 dynamic_req_l_arr_[i]->warning (_("Got a dynamic already. Continuing dazed and confused"));
109 String loud = absd->text_str_;
111 text_p_ = new G_text_item;
112 text_p_->text_str_ = loud; // ugh
113 Scalar prop = get_property ("dynamicStyle", 0);
115 text_p_->style_str_ = prop.length_i () ? prop : "dynamic";
117 staff_side_p_ = new G_staff_side_item;
118 staff_side_p_->set_elt_property (script_priority_scm_sym,
121 staff_side_p_->set_victim (text_p_);
122 staff_side_p_->axis_ = Y_AXIS;
125 prop = get_property ("dynamicDir", 0);
128 staff_side_p_->dir_ = (Direction) (int) prop;
132 announce_element (Score_element_info (text_p_, absd));
133 announce_element (Score_element_info (staff_side_p_, absd));
135 else if (Span_req *span_l
136 = dynamic_cast <Span_req *> (dynamic_req_l_arr_[i]))
138 if (span_l->span_dir_ == STOP)
142 span_l->warning (_ ("can't find (de)crescendo to end"));
146 assert (!to_end_cresc_p_);
147 to_end_cresc_p_ =cresc_p_;
149 Scalar prop = get_property ("dynamicDir", 0);
152 to_end_cresc_p_->dir_ = (Direction) (int) prop;
157 else if (span_l->span_dir_ == START)
159 cresc_req_l_ = span_l;
160 assert (!new_cresc_p);
161 new_cresc_p = new Crescendo;
162 new_cresc_p->grow_dir_ = (span_l->span_type_str_ == "crescendo") ? BIGGER : SMALLER;
163 announce_element (Score_element_info (new_cresc_p, span_l));
172 ::warning (_ ("Too many crescendi here"));
173 typeset_element (cresc_p_);
177 cresc_p_ = new_cresc_p;
178 cresc_p_->set_bounds(LEFT,get_staff_info().musical_pcol_l ());
181 cresc_p_->dyn_b_drul_[LEFT] = true;
183 to_end_cresc_p_->dyn_b_drul_[RIGHT] = true;
189 Dynamic_engraver::do_pre_move_processing()
196 ADD_THIS_TRANSLATOR(Dynamic_engraver);
199 Dynamic_engraver::do_removal_processing ()
203 typeset_element (cresc_p_ );
204 cresc_req_l_->warning (_ ("unended crescendo"));
212 Dynamic_engraver::typeset_all ()
216 to_end_cresc_p_->set_bounds(RIGHT,get_staff_info().musical_pcol_l ());
217 typeset_element (to_end_cresc_p_);
222 typeset_element (text_p_);
223 typeset_element (staff_side_p_);
231 Dynamic_engraver::acknowledge_element (Score_element_info i)
233 if (dynamic_cast<Stem *> (i.elem_l_)
234 || dynamic_cast<Note_head *> (i.elem_l_)
238 staff_side_p_->add_support (i.elem_l_);
241 to_end_cresc_p_->add_support (i.elem_l_);
244 cresc_p_->add_support (i.elem_l_);