2 span-dynamic-performer.cc -- implement Span_dynamic_performer
4 source file of the GNU LilyPond music typesetter
6 (c) 2000--2004 Jan Nieuwenhuizen <janneke@gnu.org>
9 #include "performer.hh"
12 #include "audio-item.hh"
15 TODO: fold this into 1 engraver: \< and \> should also stop when
16 absdyn is encountered.
19 struct Audio_dynamic_tuple
21 Audio_dynamic* audio_;
28 class Span_dynamic_performer : public Performer
31 TRANSLATOR_DECLARATIONS (Span_dynamic_performer);
34 virtual bool try_music (Music*);
35 virtual void acknowledge_audio_element (Audio_element_info);
36 virtual void process_music ();
37 virtual void stop_translation_timestep ();
40 Audio_dynamic* audio_;
42 Music* span_start_event_;
43 Drul_array<Music*> span_events_;
44 Array<Audio_dynamic_tuple> dynamic_tuples_;
45 Array<Audio_dynamic_tuple> finished_dynamic_tuples_;
47 Direction finished_dir_;
50 Span_dynamic_performer::Span_dynamic_performer ()
52 span_events_[START] = 0;
53 span_events_[STOP] = 0;
54 span_start_event_ = 0;
60 Span_dynamic_performer::acknowledge_audio_element (Audio_element_info i)
62 if (Audio_dynamic * d = dynamic_cast <Audio_dynamic*> (i.elem_))
64 last_volume_ = d->volume_;
69 Span_dynamic_performer::process_music ()
71 if (span_start_event_ || span_events_[START])
73 audio_ = new Audio_dynamic (0);
74 Audio_element_info info (audio_, span_events_[START]
76 : span_events_[STOP]);
77 announce_element (info);
78 Audio_dynamic_tuple a = { audio_, now_mom () };
79 dynamic_tuples_.push (a);
82 if (span_events_[STOP])
84 if (!span_start_event_)
86 span_events_[STOP]->origin ()->warning (_ ("can't find start of (de)crescendo"));
87 span_events_[STOP] = 0;
92 finished_dynamic_tuples_ = dynamic_tuples_;
94 dynamic_tuples_.clear ();
95 span_start_event_ = 0;
98 if (span_events_[START])
100 dir_ = (span_events_[START]->is_mus_type ("crescendo-event"))
102 span_start_event_ = span_events_[START];
104 dynamic_tuples_.clear ();
105 Audio_dynamic_tuple a = { audio_, now_mom () };
106 dynamic_tuples_.push (a);
109 if (span_events_[STOP])
111 finished_dynamic_tuples_.top ().audio_->volume_ = last_volume_;
114 if (span_events_[START])
116 dynamic_tuples_[0].audio_->volume_ = last_volume_;
119 span_events_[START] = 0;
120 span_events_[STOP] = 0;
124 Span_dynamic_performer::stop_translation_timestep ()
126 if (finished_dynamic_tuples_.size () > 1)
128 Real start_volume = finished_dynamic_tuples_[0].audio_->volume_;
129 Real dv = finished_dynamic_tuples_.top ().audio_->volume_
133 Catch and fix the case of:
137 f cresc. -- -- -- -- -- pp
139 Actually, we should provide a non-displayed dynamic/volume setting,
140 to set volume to 'ff' just before the pp.
142 if (!dv || sign (dv) != finished_dir_)
144 // urg. 20%: about two volume steps
145 dv = (Real)finished_dir_ * 0.2;
147 start_volume = finished_dynamic_tuples_.top
148 ().audio_->volume_ - dv;
150 Moment start_mom = finished_dynamic_tuples_[0].mom_;
151 Moment dt = finished_dynamic_tuples_.top ().mom_ - start_mom;
152 for (int i=0; i < finished_dynamic_tuples_.size (); i++)
154 Audio_dynamic_tuple* a = &finished_dynamic_tuples_[i];
155 Real volume = start_volume + dv * (Real) (a->mom_ - start_mom).main_part_
156 / (Real)dt.main_part_;
157 a->audio_->volume_ = volume;
159 finished_dynamic_tuples_.clear ();
164 play_element (audio_);
168 span_events_[STOP] = 0;
169 span_events_[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_property ("span-direction"));
185 ENTER_DESCRIPTION (Span_dynamic_performer,
187 "crescendo-event decrescendo-event",