2 dynamic-reg.cc -- implement Dynamic_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 #include "crescendo.hh"
10 #include "musical-request.hh"
12 #include "paper-def.hh"
13 #include "paper-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"
20 #include "note-head.hh"
21 #include "group-interface.hh"
25 multiple type of span dynamic:
29 - `cresc. poco a poco -- -- --'
33 print text & hairpin dynamics.
35 class Dynamic_engraver : public Engraver
38 Crescendo * to_end_cresc_p_;
41 Span_req * cresc_req_l_;
42 Array<Request*> dynamic_req_l_arr_;
45 VIRTUAL_COPY_CONS(Translator);
50 void announce_element (Score_element_info);
52 virtual void do_removal_processing ();
53 virtual void acknowledge_element (Score_element_info);
54 virtual bool do_try_music (Music *req_l);
55 virtual void do_process_requests();
56 virtual void do_pre_move_processing();
57 virtual void do_post_move_processing();
58 virtual void typeset_element (Score_element*);
62 Dynamic_engraver::announce_element (Score_element_info i)
64 group (i.elem_l_, "interfaces").add_thing (ly_symbol2scm ("dynamic"));
66 Engraver::announce_element (i);
70 Dynamic_engraver::Dynamic_engraver()
72 do_post_move_processing();
75 to_end_cresc_p_ = cresc_p_ = 0;
81 Dynamic_engraver::do_post_move_processing()
83 dynamic_req_l_arr_.clear();
87 Dynamic_engraver::do_try_music (Music * m)
89 Request * r = dynamic_cast<Request*> (m);
91 if(Text_script_req * d = dynamic_cast <Text_script_req *> (r))
93 if (d->style_str_ != "dynamic")
96 else if (Span_req * s = dynamic_cast <Span_req*> (r))
98 if (s-> span_type_str_ != "crescendo"
99 && s->span_type_str_ != "decrescendo")
105 for (int i=0; i < dynamic_req_l_arr_.size (); i++)
106 if (r->equal_b (dynamic_req_l_arr_[i]))
109 dynamic_req_l_arr_.push (r);
115 Dynamic_engraver::do_process_requests()
117 Crescendo* new_cresc_p=0;
119 for (int i=0; i < dynamic_req_l_arr_.size(); i++)
121 if (Text_script_req *absd =
122 dynamic_cast<Text_script_req *> ( dynamic_req_l_arr_[i]))
126 dynamic_req_l_arr_[i]->warning (_("Got a dynamic already. Continuing dazed and confused."));
130 String loud = absd->text_str_;
132 text_p_ = new Text_item;
133 text_p_->set_elt_property ("text",
134 ly_str02scm (loud.ch_C()));
135 text_p_->set_elt_property ("style", gh_str02scm ("dynamic"));
136 text_p_->set_elt_property ("script-priority",
139 Side_position_interface (text_p_).set_axis (Y_AXIS);
142 if (absd->get_direction ())
144 text_p_->set_elt_property ("direction", gh_int2scm (absd->get_direction ()));
151 SCM prop = get_property ("dynamicDirection");
154 prop = get_property ("verticalDirection");
157 if (isdir_b (prop) && to_dir (prop))
158 text_p_->set_elt_property ("direction", prop);
160 prop = get_property ("dynamicPadding");
161 if (gh_number_p(prop))
163 text_p_->set_elt_property ("padding", prop);
165 announce_element (Score_element_info (text_p_, absd));
167 else if (Span_req *span_l
168 = dynamic_cast <Span_req *> (dynamic_req_l_arr_[i]))
170 if (span_l->span_dir_ == STOP)
174 span_l->warning (_ ("Can't find (de)crescendo to end"));
178 assert (!to_end_cresc_p_);
179 to_end_cresc_p_ =cresc_p_;
184 else if (span_l->span_dir_ == START)
186 cresc_req_l_ = span_l;
187 assert (!new_cresc_p);
188 new_cresc_p = new Crescendo;
190 ->set_elt_property ("grow-direction",
191 gh_int2scm ((span_l->span_type_str_ == "crescendo") ? BIGGER : SMALLER));
193 side_position (new_cresc_p).set_axis (Y_AXIS);
194 announce_element (Score_element_info (new_cresc_p, span_l));
203 ::warning (_ ("Too many crescendi here"));
205 typeset_element (cresc_p_);
210 cresc_p_ = new_cresc_p;
211 cresc_p_->set_bounds(LEFT,get_staff_info().musical_pcol_l ());
215 index_set_cell (cresc_p_->get_elt_property ("dynamic-drul"),
218 index_set_cell (to_end_cresc_p_->get_elt_property ("dynamic-drul"),
225 Dynamic_engraver::do_pre_move_processing()
232 ADD_THIS_TRANSLATOR(Dynamic_engraver);
235 Dynamic_engraver::do_removal_processing ()
239 typeset_element (cresc_p_ );
240 cresc_req_l_->warning (_ ("unended crescendo"));
248 Dynamic_engraver::typeset_all ()
252 to_end_cresc_p_->set_bounds(RIGHT,get_staff_info().musical_pcol_l ());
253 typeset_element (to_end_cresc_p_);
261 typeset_element (text_p_);
267 Dynamic_engraver::typeset_element (Score_element * e)
269 side_position(e).add_staff_support ();
270 Engraver::typeset_element (e);
274 Dynamic_engraver::acknowledge_element (Score_element_info i)
276 if (dynamic_cast<Stem *> (i.elem_l_)
277 || dynamic_cast<Note_head *> (i.elem_l_)
281 Side_position_interface (text_p_).add_support (i.elem_l_);
284 Side_position_interface (to_end_cresc_p_).add_support (i.elem_l_);
287 Side_position_interface(cresc_p_).add_support (i.elem_l_);