summaryrefslogtreecommitdiff
path: root/lily/dynamic-reg.cc
blob: e0e38a7a595fc950559b74754ab6e103199f02e3 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
  dynamic-reg.cc -- implement Dynamic_register

  source file of the LilyPond music typesetter

  (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
*/
#include "debug.hh"
#include "crescendo.hh"
#include "dynamic-reg.hh"
#include "musical-request.hh"
#include "text-item.hh"
#include "lookup.hh"
#include "paper-def.hh"
#include "score-column.hh"

Dynamic_register::Dynamic_register()
{
    dir_i_ =0;
    post_move_processing();
    dynamic_p_ =0;
    to_end_cresc_p_ = cresc_p_ = 0;
    cresc_req_l_ = 0;
}

void
Dynamic_register::post_move_processing()
{
    dynamic_req_l_arr_.set_size(0);
}

bool    
Dynamic_register::try_request(Request * r)
{
    Musical_req * m = r->musical();
    if (!m || !m->dynamic())
	return false;
    dynamic_req_l_arr_.push(m->dynamic());
    return true;
}
void
Dynamic_register::process_requests()
{
    Crescendo*  new_cresc_p=0; 
    for (int i=0; i < dynamic_req_l_arr_.size(); i++) {
	Dynamic_req *dreq_l = dynamic_req_l_arr_[i];
	if (dreq_l->absdynamic()) {
	    Text_def * td_p = new Text_def;
	    td_p->align_i_ = 0;
	    String loud =Dynamic_req::loudness_str(
		dreq_l->absdynamic()->loudness_);
	    
	    td_p->text_str_ = paper()->lookup_l()->dynamic(loud).tex;
	    td_p->style_str_ = "dynamic";

	    assert (!dynamic_p_) ; // TODO
		
	    dynamic_p_ = new Text_item(td_p, 10 ); // TODO!
	    announce_element(Staff_elem_info(dynamic_p_, dreq_l));
	} else if (dreq_l->span_dynamic()) {

	    Span_dynamic_req* span_l = dreq_l->span_dynamic();
	    if (span_l->spantype == Span_req::STOP) {
		if (!cresc_p_) {
		    span_l->warning("Can't find cresc to end " );
		} else {
		    assert(!to_end_cresc_p_);
		    to_end_cresc_p_ =cresc_p_;
		    cresc_p_ = 0;
		}
	    } else if (span_l->spantype == Span_req::START) {
		cresc_req_l_ = span_l;
		assert(!new_cresc_p);
		new_cresc_p  = new Crescendo(10);
		new_cresc_p->grow_dir_i_ = span_l->dynamic_dir_i_;
		announce_element(Staff_elem_info(new_cresc_p, span_l));
	    }
	}
    }

    if ( new_cresc_p ) {
	cresc_p_ = new_cresc_p;
	cresc_p_->left_col_l_ = get_staff_info().musical_l()->pcol_l_;
	if (dynamic_p_) {
	    cresc_p_->left_dyn_b_ = true;
	}
    }
}

void
Dynamic_register::pre_move_processing()
{
    if (dynamic_p_) {
	typeset_element(dynamic_p_);
	dynamic_p_ = 0;
    }
    if ( to_end_cresc_p_) {
	if (dynamic_p_)
	    to_end_cresc_p_->right_dyn_b_=true;
	
	to_end_cresc_p_->right_col_l_ = get_staff_info().musical_l()->pcol_l_;
 
	typeset_element(to_end_cresc_p_);
	to_end_cresc_p_ = 0;
    }
}

bool
Dynamic_register::acceptable_request_b(Request*r)const
{
    Musical_req * m = r->musical();
    return  (m && m->dynamic());
}

void
Dynamic_register::set_feature(Features i)
{
    dir_i_ = i.direction_i_;
}

IMPLEMENT_STATIC_NAME(Dynamic_register);
ADD_THIS_REGISTER(Dynamic_register);

Dynamic_register::~Dynamic_register()
{
    delete dynamic_p_;
    delete to_end_cresc_p_;
    if (cresc_p_) {
	cresc_req_l_->warning("unended crescendo");
    }
    delete cresc_p_;
}