2 span-dynamic-performer.cc -- implement Span_dynamic_performer
4 source file of the GNU LilyPond music typesetter
6 (c) 2000--2005 Jan Nieuwenhuizen <janneke@gnu.org>
9 #include "performer.hh"
10 #include "audio-item.hh"
14 TODO: fold this into 1 engraver: \< and \> should also stop when
15 absdyn is encountered.
17 struct Audio_dynamic_tuple
19 Audio_dynamic *audio_;
26 class Span_dynamic_performer : public Performer
29 TRANSLATOR_DECLARATIONS (Span_dynamic_performer);
32 virtual bool try_music (Music *);
33 virtual void acknowledge_audio_element (Audio_element_info);
34 void process_music ();
35 void stop_translation_timestep ();
38 Audio_dynamic *audio_;
40 Music *span_start_event_;
41 Drul_array<Music *> span_events_;
42 Array<Audio_dynamic_tuple> dynamic_tuples_;
43 Array<Audio_dynamic_tuple> finished_dynamic_tuples_;
45 Direction finished_dir_;
48 Span_dynamic_performer::Span_dynamic_performer ()
50 span_events_[START] = 0;
51 span_events_[STOP] = 0;
52 span_start_event_ = 0;
58 Span_dynamic_performer::acknowledge_audio_element (Audio_element_info i)
60 if (Audio_dynamic *d = dynamic_cast<Audio_dynamic *> (i.elem_))
62 last_volume_ = d->volume_;
67 Span_dynamic_performer::process_music ()
69 if (span_start_event_ || span_events_[START])
71 audio_ = new Audio_dynamic (0);
72 Audio_element_info info (audio_, span_events_[START]
74 : span_events_[STOP]);
75 announce_element (info);
76 Audio_dynamic_tuple a = { audio_, now_mom () };
77 dynamic_tuples_.push (a);
80 if (span_events_[STOP])
82 if (!span_start_event_)
84 span_events_[STOP]->origin ()->warning (_ ("can't find start of (de)crescendo"));
85 span_events_[STOP] = 0;
90 finished_dynamic_tuples_ = dynamic_tuples_;
92 dynamic_tuples_.clear ();
93 span_start_event_ = 0;
96 if (span_events_[START])
98 dir_ = (span_events_[START]->is_mus_type ("crescendo-event"))
100 span_start_event_ = span_events_[START];
102 dynamic_tuples_.clear ();
103 Audio_dynamic_tuple a = { audio_, now_mom () };
104 dynamic_tuples_.push (a);
107 if (span_events_[STOP])
109 finished_dynamic_tuples_.top ().audio_->volume_ = last_volume_;
112 if (span_events_[START])
114 dynamic_tuples_[0].audio_->volume_ = last_volume_;
117 span_events_[START] = 0;
118 span_events_[STOP] = 0;
122 Span_dynamic_performer::stop_translation_timestep ()
124 if (finished_dynamic_tuples_.size () > 1)
126 Real start_volume = finished_dynamic_tuples_[0].audio_->volume_;
127 Real dv = finished_dynamic_tuples_.top ().audio_->volume_
131 Catch and fix the case of:
135 f cresc. -- -- -- -- -- pp
137 Actually, we should provide a non-displayed dynamic/volume setting,
138 to set volume to 'ff' just before the pp.
140 if (!dv || sign (dv) != finished_dir_)
142 // urg. 20%: about two volume steps
143 dv = (Real)finished_dir_ * 0.2;
145 start_volume = finished_dynamic_tuples_.top
146 ().audio_->volume_ - dv;
148 Moment start_mom = finished_dynamic_tuples_[0].mom_;
149 Moment dt = finished_dynamic_tuples_.top ().mom_ - start_mom;
150 for (int i = 0; i < finished_dynamic_tuples_.size (); i++)
152 Audio_dynamic_tuple *a = &finished_dynamic_tuples_[i];
153 Real volume = start_volume + dv * (Real) (a->mom_ - start_mom).main_part_
154 / (Real)dt.main_part_;
155 a->audio_->volume_ = volume;
157 finished_dynamic_tuples_.clear ();
162 play_element (audio_);
166 span_events_[STOP] = 0;
167 span_events_[START] = 0;
171 Span_dynamic_performer::try_music (Music *r)
173 if (r->is_mus_type ("crescendo-event")
174 || r->is_mus_type ("decrescendo-event"))
176 Direction d = to_dir (r->get_property ("span-direction"));
182 #include "translator.icc"
184 ADD_TRANSLATOR (Span_dynamic_performer,
186 "crescendo-event decrescendo-event",