2 dynamic-reg.cc -- implement Dynamic_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1998 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-sym.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_dynamic_req * cresc_req_l_;
34 Array<Dynamic_req*> 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 * r)
69 if(Dynamic_req * d = dynamic_cast <Dynamic_req *> (r))
71 for (int i=0; i < dynamic_req_l_arr_.size (); i++)
72 if (d->equal_b (dynamic_req_l_arr_[i]))
75 dynamic_req_l_arr_.push (d);
81 Dynamic_engraver::do_process_requests()
83 Crescendo* new_cresc_p=0;
84 for (int i=0; i < dynamic_req_l_arr_.size(); i++)
86 Dynamic_req *dreq_l = dynamic_req_l_arr_[i];
87 if (Absolute_dynamic_req *absd = dynamic_cast<Absolute_dynamic_req *> (dreq_l))
91 dynamic_req_l_arr_[i]->warning (_("Got a dynamic already. Continuing dazed and confused"));
95 String loud = absd->loudness_str ();
97 text_p_ = new G_text_item;
98 text_p_->text_str_ = "dyn" + loud; // ugh
99 Scalar prop = get_property ("dynamicStyle", 0);
101 text_p_->style_str_ = prop.length_i () ? prop : "dynamic";
103 staff_side_p_ = new G_staff_side_item;
104 staff_side_p_->set_victim (text_p_);
107 prop = get_property ("dynamicDir", 0);
110 staff_side_p_->dir_ = (Direction) (int) prop;
114 announce_element (Score_element_info (text_p_, dreq_l));
115 announce_element (Score_element_info (staff_side_p_, dreq_l));
117 else if (Span_dynamic_req *span_l = dynamic_cast <Span_dynamic_req *> (dreq_l))
119 if (span_l->spantype_ == STOP)
123 span_l->warning (_ ("can't find (de)crescendo to end"));
127 assert (!to_end_cresc_p_);
128 to_end_cresc_p_ =cresc_p_;
130 Scalar prop = get_property ("dynamicDir", 0);
133 to_end_cresc_p_->dir_ = (Direction) (int) prop;
138 else if (span_l->spantype_ == START)
140 cresc_req_l_ = span_l;
141 assert (!new_cresc_p);
142 new_cresc_p = new Crescendo;
143 new_cresc_p->grow_dir_ = span_l->dynamic_dir_;
144 announce_element (Score_element_info (new_cresc_p, span_l));
153 ::warning (_ ("Too many crescendi here"));
154 typeset_element (cresc_p_);
158 cresc_p_ = new_cresc_p;
159 cresc_p_->set_bounds(LEFT,get_staff_info().musical_l ());
162 cresc_p_->dyn_b_drul_[LEFT] = true;
164 to_end_cresc_p_->dyn_b_drul_[RIGHT] = true;
170 Dynamic_engraver::do_pre_move_processing()
172 Staff_symbol* s_l = get_staff_info().staff_sym_l_;
174 to_end_cresc_p_->add_support (s_l);
176 staff_side_p_->add_support (s_l);
184 ADD_THIS_TRANSLATOR(Dynamic_engraver);
187 Dynamic_engraver::do_removal_processing ()
191 typeset_element (cresc_p_ );
192 cresc_req_l_->warning (_ ("unended crescendo"));
200 Dynamic_engraver::typeset_all ()
204 to_end_cresc_p_->set_bounds(RIGHT,get_staff_info().musical_l ());
205 typeset_element (to_end_cresc_p_);
210 typeset_element (text_p_);
211 typeset_element (staff_side_p_);
219 Dynamic_engraver::acknowledge_element (Score_element_info i)
221 if (dynamic_cast<Stem *> (i.elem_l_)
222 || dynamic_cast<Note_head *> (i.elem_l_)
226 staff_side_p_->add_support (i.elem_l_);
229 to_end_cresc_p_->add_support (i.elem_l_);
232 cresc_p_->add_support (i.elem_l_);