2 span-dynamic-performer.cc -- implement Span_dynamic_performer
4 source file of the GNU LilyPond music typesetter
6 (c) 2000--2003 Jan Nieuwenhuizen <janneke@gnu.org>
9 #include "performer.hh"
12 #include "audio-item.hh"
14 struct Audio_dynamic_tuple
16 Audio_dynamic* audio_;
23 class Span_dynamic_performer : public Performer
26 TRANSLATOR_DECLARATIONS(Span_dynamic_performer);
29 virtual bool try_music (Music*);
30 virtual void acknowledge_audio_element (Audio_element_info);
31 virtual void process_music ();
32 virtual void stop_translation_timestep ();
33 virtual void start_translation_timestep ();
36 Audio_dynamic* audio_;
38 Music* span_start_req_;
39 Drul_array<Music*> span_req_l_drul_;
40 Array<Audio_dynamic_tuple> dynamic_tuples_;
41 Array<Audio_dynamic_tuple> finished_dynamic_tuples_;
43 Direction finished_dir_;
46 Span_dynamic_performer::Span_dynamic_performer ()
48 span_req_l_drul_[START] = 0;
49 span_req_l_drul_[STOP] = 0;
56 Span_dynamic_performer::acknowledge_audio_element (Audio_element_info i)
58 if (Audio_dynamic * d = dynamic_cast <Audio_dynamic*> (i.elem_))
60 last_volume_ = d->volume_;
65 Span_dynamic_performer::process_music ()
67 if (span_start_req_ || span_req_l_drul_[START])
69 audio_ = new Audio_dynamic (0);
70 Audio_element_info info (audio_, span_req_l_drul_[START]
71 ? span_req_l_drul_[START]
72 : span_req_l_drul_[STOP]);
73 announce_element (info);
74 Audio_dynamic_tuple a = { audio_, now_mom () };
75 dynamic_tuples_.push (a);
78 if (span_req_l_drul_[STOP])
82 span_req_l_drul_[STOP]->origin ()->warning (_ ("can't find start of (de)crescendo"));
83 span_req_l_drul_[STOP] = 0;
88 finished_dynamic_tuples_ = dynamic_tuples_;
90 dynamic_tuples_.clear ();
94 if (span_req_l_drul_[START])
96 String t = ly_scm2string (span_req_l_drul_[START]->get_mus_property ("span-type"));
97 dir_ = (t == "crescendo") ? RIGHT : LEFT;
98 span_start_req_ = span_req_l_drul_[START];
100 dynamic_tuples_.clear ();
101 Audio_dynamic_tuple a = { audio_, now_mom () };
102 dynamic_tuples_.push (a);
106 if (span_req_l_drul_[STOP])
108 finished_dynamic_tuples_.top ().audio_->volume_ = last_volume_;
111 if (span_req_l_drul_[START])
113 dynamic_tuples_[0].audio_->volume_ = last_volume_;
116 span_req_l_drul_[START] = 0;
117 span_req_l_drul_[STOP] = 0;
121 Span_dynamic_performer::stop_translation_timestep ()
123 if (finished_dynamic_tuples_.size () > 1)
125 Real start_volume = finished_dynamic_tuples_[0].audio_->volume_;
126 Real dv = finished_dynamic_tuples_.top ().audio_->volume_
130 Catch and fix the case of:
134 f cresc. -- -- -- -- -- pp
136 Actually, we should provide a non-displayed dynamic/volume setting,
137 to set volume to 'ff' just before the pp.
139 if (!dv || sign (dv) != finished_dir_)
141 // urg. 20%: about two volume steps
142 dv = (Real)finished_dir_ * 0.2;
144 start_volume = finished_dynamic_tuples_.top
145 ().audio_->volume_ - dv;
147 Moment start_mom = finished_dynamic_tuples_[0].mom_;
148 Moment dt = finished_dynamic_tuples_.top ().mom_ - start_mom;
149 for (int i=0; i < finished_dynamic_tuples_.size (); i++)
151 Audio_dynamic_tuple* a = &finished_dynamic_tuples_[i];
152 Real volume = start_volume + dv * (Real) (a->mom_ - start_mom).main_part_
153 / (Real)dt.main_part_;
154 a->audio_->volume_ = volume;
156 finished_dynamic_tuples_.clear ();
161 play_element (audio_);
167 Span_dynamic_performer::start_translation_timestep ()
169 span_req_l_drul_[STOP] = 0;
170 span_req_l_drul_[START] = 0;
174 Span_dynamic_performer::try_music (Music* r)
176 if (r->is_mus_type ("crescendo-event")
177 || r->is_mus_type ("decrescendo-event"))
179 Direction d = to_dir (r->get_mus_property ("span-direction"));
180 span_req_l_drul_[d] = r;
185 ENTER_DESCRIPTION (Span_dynamic_performer,
187 "crescendo-event decrescendo-event",