lilypond-0.1.30
[lilypond.git] / lily / dynamic-grav.cc
blobd4b9544e3a5282b8a51c4e9b0c83254fe8942504
1 /*
2 dynamic-reg.cc -- implement Dynamic_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997 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 || !m->dynamic())
39 return false;
40 dynamic_req_l_arr_.push (m->dynamic());
41 return true;
43 void
44 Dynamic_engraver::do_process_requests()
46 Crescendo* new_cresc_p=0;
47 for (int i=0; i < dynamic_req_l_arr_.size(); i++)
49 Dynamic_req *dreq_l = dynamic_req_l_arr_[i];
50 if (dreq_l->absdynamic())
52 Text_def * td_p = new Text_def;
53 td_p->align_i_ = 0;
54 String loud = dreq_l->absdynamic()->loudness_str ();
55 td_p->text_str_ = paper()->lookup_l ()->dynamic (loud).tex_;
56 td_p->style_str_ = "dynamic";
58 assert (!dynamic_p_) ; // TODO
60 dynamic_p_ = new Text_item (td_p);
61 announce_element (Score_elem_info (dynamic_p_, dreq_l));
63 else if (dreq_l->span_dynamic())
66 Span_dynamic_req* span_l = dreq_l->span_dynamic();
67 if (span_l->spantype == Span_req::STOP)
69 if (!cresc_p_)
71 span_l->warning (_("Can't find cresc to end "));
73 else
75 assert (!to_end_cresc_p_);
76 to_end_cresc_p_ =cresc_p_;
77 cresc_p_ = 0;
80 else if (span_l->spantype == Span_req::START)
82 cresc_req_l_ = span_l;
83 assert (!new_cresc_p);
84 new_cresc_p = new Crescendo;
85 new_cresc_p->grow_dir_ = span_l->dynamic_dir_;
86 announce_element (Score_elem_info (new_cresc_p, span_l));
91 if (new_cresc_p)
93 cresc_p_ = new_cresc_p;
94 cresc_p_->set_bounds(LEFT,get_staff_info().musical_l ());
95 if (dynamic_p_)
97 cresc_p_->dyn_b_drul_[LEFT] = true;
102 void
103 Dynamic_engraver::do_pre_move_processing()
105 Staff_symbol* s_l = get_staff_info().staff_sym_l_;
106 if (dynamic_p_)
109 dynamic_p_->add_support (s_l);
110 typeset_element (dynamic_p_);
111 dynamic_p_ = 0;
113 if (to_end_cresc_p_)
115 if (dynamic_p_)
116 to_end_cresc_p_->dyn_b_drul_[RIGHT]=true;
118 to_end_cresc_p_->set_bounds(RIGHT,get_staff_info().musical_l ());
119 to_end_cresc_p_->add_support (s_l);
120 typeset_element (to_end_cresc_p_);
121 to_end_cresc_p_ = 0;
126 IMPLEMENT_IS_TYPE_B1(Dynamic_engraver,Engraver);
127 ADD_THIS_TRANSLATOR(Dynamic_engraver);
129 void
130 Dynamic_engraver::do_removal_processing ()
132 if (cresc_p_)
134 typeset_element (cresc_p_ );
135 cresc_p_ =0;
137 if (to_end_cresc_p_)
139 typeset_element (to_end_cresc_p_);
140 cresc_req_l_->warning (_("unended crescendo"));
141 to_end_cresc_p_ =0;
143 if (dynamic_p_)
145 typeset_element (dynamic_p_);
146 dynamic_p_ =0;
150 void
151 Dynamic_engraver::acknowledge_element (Score_elem_info i)
153 if (i.elem_l_->name() == Note_column::static_name ())
155 if (dynamic_p_) dynamic_p_->add_support (i.elem_l_);
156 if (to_end_cresc_p_)
157 to_end_cresc_p_->add_support (i.elem_l_);
158 if (cresc_p_)
159 cresc_p_->add_support (i.elem_l_);