lilypond-1.3.28
[lilypond.git] / lily / dynamic-reg.cc
blob3e953a651959af05f95d8e0501e22471526d61f0
1 /*
2 dynamic-reg.cc -- implement Dynamic_register
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-reg.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_register::Dynamic_register()
21 dir_i_ =0;
22 do_post_move_processing();
23 dynamic_p_ =0;
24 to_end_cresc_p_ = cresc_p_ = 0;
25 cresc_req_l_ = 0;
28 void
29 Dynamic_register::do_post_move_processing()
31 dynamic_req_l_arr_.set_size(0);
34 bool
35 Dynamic_register::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_register::do_process_requests()
46 Crescendo* new_cresc_p=0;
47 for (int i=0; i < dynamic_req_l_arr_.size(); i++) {
48 Dynamic_req *dreq_l = dynamic_req_l_arr_[i];
49 if (dreq_l->absdynamic()) {
50 Text_def * td_p = new Text_def;
51 td_p->align_i_ = 0;
52 String loud =Dynamic_req::loudness_str(
53 dreq_l->absdynamic()->loudness_);
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));
62 } else if (dreq_l->span_dynamic()) {
64 Span_dynamic_req* span_l = dreq_l->span_dynamic();
65 if (span_l->spantype == Span_req::STOP) {
66 if (!cresc_p_) {
67 span_l->warning("Can't find cresc to end " );
68 } else {
69 assert(!to_end_cresc_p_);
70 to_end_cresc_p_ =cresc_p_;
71 cresc_p_ = 0;
73 } else if (span_l->spantype == Span_req::START) {
74 cresc_req_l_ = span_l;
75 assert(!new_cresc_p);
76 new_cresc_p = new Crescendo;
77 new_cresc_p->grow_dir_i_ = span_l->dynamic_dir_i_;
78 announce_element(Score_elem_info(new_cresc_p, span_l));
83 if ( new_cresc_p ) {
84 cresc_p_ = new_cresc_p;
85 cresc_p_->left_col_l_ = get_staff_info().musical_l()->pcol_l_;
86 if (dynamic_p_) {
87 cresc_p_->left_dyn_b_ = true;
92 void
93 Dynamic_register::do_pre_move_processing()
95 Staff_symbol* s_l = get_staff_info().staff_sym_l_;
96 if (dynamic_p_) {
97 dynamic_p_->set_staffsym(s_l);
98 typeset_element(dynamic_p_);
99 dynamic_p_ = 0;
101 if ( to_end_cresc_p_) {
102 if (dynamic_p_)
103 to_end_cresc_p_->right_dyn_b_=true;
105 to_end_cresc_p_->right_col_l_ = get_staff_info().musical_l()->pcol_l_;
106 to_end_cresc_p_->set_staffsym(s_l);
107 typeset_element(to_end_cresc_p_);
108 to_end_cresc_p_ = 0;
112 void
113 Dynamic_register::set_feature(Feature i)
115 if (i.type_ == "vdir")
116 dir_i_ = i.value_;
119 IMPLEMENT_STATIC_NAME(Dynamic_register);
120 IMPLEMENT_IS_TYPE_B1(Dynamic_register,Request_register);
121 ADD_THIS_REGISTER(Dynamic_register);
123 Dynamic_register::~Dynamic_register()
125 delete dynamic_p_;
126 delete to_end_cresc_p_;
127 if (cresc_p_) {
128 cresc_req_l_->warning("unended crescendo");
130 delete cresc_p_;
132 void
133 Dynamic_register::acknowledge_element(Score_elem_info i)
135 if (i.elem_l_->name() == Note_column::static_name()) {
136 if (dynamic_p_) dynamic_p_->add_support(i.elem_l_);
137 if (to_end_cresc_p_)
138 to_end_cresc_p_->add_support(i.elem_l_);
139 if (cresc_p_)
140 cresc_p_->add_support(i.elem_l_);