lilypond-1.5.9
[lilypond.git] / lily / dynamic-grav.cc
blob9a0913c1296cee425430dc46136183200ef0a180
1 /*
2 dynamic-reg.cc -- implement Dynamic_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1998 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8 #include "debug.hh"
9 #include "crescendo.hh"
10 #include "dynamic-grav.hh"
11 #include "musical-request.hh"
12 #include "text-item.hh"
13 #include "lookup.hh"
14 #include "paper-def.hh"
15 #include "score-column.hh"
16 #include "staff-sym.hh"
17 #include "note-column.hh"
19 Dynamic_engraver::Dynamic_engraver()
21 do_post_move_processing();
22 dir_ = CENTER;
23 dynamic_p_ =0;
24 to_end_cresc_p_ = cresc_p_ = 0;
25 cresc_req_l_ = 0;
28 void
29 Dynamic_engraver::do_post_move_processing()
31 dynamic_req_l_arr_.clear();
34 bool
35 Dynamic_engraver::do_try_request (Request * r)
37 Musical_req * m = r->musical();
38 if (!m)
39 return false;
40 Dynamic_req * d = m->dynamic ();
41 if (!d)
42 return false;
44 if (cresc_p_ && d->span_dynamic ()
45 && d->span_dynamic ()->spantype == Span_req::START)
46 return false;
47 if (d->absdynamic ())
49 for (int i=0; i < dynamic_req_l_arr_.size (); i++)
50 if (d->equal_b (dynamic_req_l_arr_[i]))
51 return true;
54 dynamic_req_l_arr_.push (m->dynamic());
55 return true;
57 void
58 Dynamic_engraver::do_process_requests()
60 Crescendo* new_cresc_p=0;
61 for (int i=0; i < dynamic_req_l_arr_.size(); i++)
63 Dynamic_req *dreq_l = dynamic_req_l_arr_[i];
64 if (dreq_l->absdynamic())
66 Text_def * td_p = new Text_def;
67 td_p->align_i_ = CENTER;
68 String loud = dreq_l->absdynamic()->loudness_str ();
69 td_p->text_str_ = paper()->lookup_l ()->dynamic (loud).tex_;
70 td_p->style_str_ = "dynamic";
72 assert (!dynamic_p_) ; // TODO
74 dynamic_p_ = new Text_item (td_p);
75 announce_element (Score_elem_info (dynamic_p_, dreq_l));
77 else if (dreq_l->span_dynamic())
80 Span_dynamic_req* span_l = dreq_l->span_dynamic();
81 if (span_l->spantype == Span_req::STOP)
83 if (!cresc_p_)
85 span_l->warning (_("Can't find cresc to end "));
87 else
89 assert (!to_end_cresc_p_);
90 to_end_cresc_p_ =cresc_p_;
91 cresc_p_ = 0;
94 else if (span_l->spantype == Span_req::START)
96 cresc_req_l_ = span_l;
97 assert (!new_cresc_p);
98 new_cresc_p = new Crescendo;
99 new_cresc_p->grow_dir_ = span_l->dynamic_dir_;
100 announce_element (Score_elem_info (new_cresc_p, span_l));
105 if (new_cresc_p)
107 cresc_p_ = new_cresc_p;
108 cresc_p_->set_bounds(LEFT,get_staff_info().musical_l ());
109 if (dynamic_p_)
111 cresc_p_->dyn_b_drul_[LEFT] = true;
116 void
117 Dynamic_engraver::do_pre_move_processing()
119 Staff_symbol* s_l = get_staff_info().staff_sym_l_;
120 if (to_end_cresc_p_)
122 if (dynamic_p_)
123 to_end_cresc_p_->dyn_b_drul_[RIGHT]=true;
125 to_end_cresc_p_->set_bounds(RIGHT,get_staff_info().musical_l ());
126 to_end_cresc_p_->add_support (s_l);
127 typeset_element (to_end_cresc_p_);
128 to_end_cresc_p_ = 0;
130 if (dynamic_p_)
133 dynamic_p_->add_support (s_l);
134 typeset_element (dynamic_p_);
135 dynamic_p_ = 0;
140 IMPLEMENT_IS_TYPE_B1(Dynamic_engraver,Engraver);
141 ADD_THIS_TRANSLATOR(Dynamic_engraver);
143 void
144 Dynamic_engraver::do_removal_processing ()
146 if (cresc_p_)
148 typeset_element (cresc_p_ );
150 cresc_req_l_->warning (_("unended crescendo"));
151 cresc_p_ =0;
153 if (to_end_cresc_p_)
155 typeset_element (to_end_cresc_p_);
156 to_end_cresc_p_ =0;
158 if (dynamic_p_)
160 typeset_element (dynamic_p_);
161 dynamic_p_ =0;
165 void
166 Dynamic_engraver::acknowledge_element (Score_elem_info i)
168 if (i.elem_l_->is_type_b (Note_column::static_name ()))
170 if (dynamic_p_)
171 dynamic_p_->add_support (i.elem_l_);
173 if (to_end_cresc_p_)
174 to_end_cresc_p_->add_support (i.elem_l_);
176 if (cresc_p_)
177 cresc_p_->add_support (i.elem_l_);