X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fspan-dynamic-performer.cc;h=28e2ea675dc02db45cd1eae079c9ed2cf4da53bd;hb=9e69cb84d6ee5b0a861cd97869b10e3bdf0c833c;hp=c0675304390a0a598b148efb0e8bc538328f3134;hpb=7f6816438d66f6d70db5b68454d80656a0f3f131;p=lilypond.git diff --git a/lily/span-dynamic-performer.cc b/lily/span-dynamic-performer.cc index c067530439..28e2ea675d 100644 --- a/lily/span-dynamic-performer.cc +++ b/lily/span-dynamic-performer.cc @@ -3,12 +3,16 @@ source file of the GNU LilyPond music typesetter - (c) 2000--2005 Jan Nieuwenhuizen + (c) 2000--2006 Jan Nieuwenhuizen */ #include "performer.hh" + #include "audio-item.hh" -#include "music.hh" +#include "international.hh" +#include "stream-event.hh" + +#include "translator.icc" /* TODO: fold this into 1 engraver: \< and \> should also stop when @@ -29,18 +33,19 @@ public: TRANSLATOR_DECLARATIONS (Span_dynamic_performer); protected: - virtual bool try_music (Music *); virtual void acknowledge_audio_element (Audio_element_info); void process_music (); void stop_translation_timestep (); + DECLARE_TRANSLATOR_LISTENER (decrescendo); + DECLARE_TRANSLATOR_LISTENER (crescendo); private: Audio_dynamic *audio_; Real last_volume_; - Music *span_start_event_; - Drul_array span_events_; - Array dynamic_tuples_; - Array finished_dynamic_tuples_; + Stream_event *span_start_event_; + Drul_array span_events_; + vector dynamic_tuples_; + vector finished_dynamic_tuples_; Direction dir_; Direction finished_dir_; }; @@ -58,9 +63,7 @@ void Span_dynamic_performer::acknowledge_audio_element (Audio_element_info i) { if (Audio_dynamic *d = dynamic_cast (i.elem_)) - { - last_volume_ = d->volume_; - } + last_volume_ = d->volume_; } void @@ -74,7 +77,7 @@ Span_dynamic_performer::process_music () : span_events_[STOP]); announce_element (info); Audio_dynamic_tuple a = { audio_, now_mom () }; - dynamic_tuples_.push (a); + dynamic_tuples_.push_back (a); } if (span_events_[STOP]) @@ -95,24 +98,20 @@ Span_dynamic_performer::process_music () if (span_events_[START]) { - dir_ = (span_events_[START]->is_mus_type ("crescendo-event")) + dir_ = (span_events_[START]->in_event_class ("crescendo-event")) ? RIGHT : LEFT; span_start_event_ = span_events_[START]; dynamic_tuples_.clear (); Audio_dynamic_tuple a = { audio_, now_mom () }; - dynamic_tuples_.push (a); + dynamic_tuples_.push_back (a); } if (span_events_[STOP]) - { - finished_dynamic_tuples_.top ().audio_->volume_ = last_volume_; - } + finished_dynamic_tuples_.back ().audio_->volume_ = last_volume_; if (span_events_[START]) - { - dynamic_tuples_[0].audio_->volume_ = last_volume_; - } + dynamic_tuples_[0].audio_->volume_ = last_volume_; span_events_[START] = 0; span_events_[STOP] = 0; @@ -124,7 +123,7 @@ Span_dynamic_performer::stop_translation_timestep () if (finished_dynamic_tuples_.size () > 1) { Real start_volume = finished_dynamic_tuples_[0].audio_->volume_; - Real dv = finished_dynamic_tuples_.top ().audio_->volume_ + Real dv = finished_dynamic_tuples_.back ().audio_->volume_ - start_volume; /* urg. @@ -142,12 +141,12 @@ Span_dynamic_performer::stop_translation_timestep () // urg. 20%: about two volume steps dv = (Real)finished_dir_ * 0.2; if (!start_volume) - start_volume = finished_dynamic_tuples_.top - ().audio_->volume_ - dv; + start_volume = finished_dynamic_tuples_.back ().audio_->volume_ + - dv; } Moment start_mom = finished_dynamic_tuples_[0].mom_; - Moment dt = finished_dynamic_tuples_.top ().mom_ - start_mom; - for (int i = 0; i < finished_dynamic_tuples_.size (); i++) + Moment dt = finished_dynamic_tuples_.back ().mom_ - start_mom; + for (vsize i = 0; i < finished_dynamic_tuples_.size (); i++) { Audio_dynamic_tuple *a = &finished_dynamic_tuples_[i]; Real volume = start_volume + dv * (Real) (a->mom_ - start_mom).main_part_ @@ -159,7 +158,6 @@ Span_dynamic_performer::stop_translation_timestep () if (audio_) { - play_element (audio_); audio_ = 0; } @@ -167,21 +165,22 @@ Span_dynamic_performer::stop_translation_timestep () span_events_[START] = 0; } -bool -Span_dynamic_performer::try_music (Music *r) +IMPLEMENT_TRANSLATOR_LISTENER (Span_dynamic_performer, decrescendo); +void +Span_dynamic_performer::listen_decrescendo (Stream_event *r) { - if (r->is_mus_type ("crescendo-event") - || r->is_mus_type ("decrescendo-event")) - { - Direction d = to_dir (r->get_property ("span-direction")); - span_events_[d] = r; - return true; - } - return false; + Direction d = to_dir (r->get_property ("span-direction")); + span_events_[d] = r; +} + +IMPLEMENT_TRANSLATOR_LISTENER (Span_dynamic_performer, crescendo); +void +Span_dynamic_performer::listen_crescendo (Stream_event *r) +{ + Direction d = to_dir (r->get_property ("span-direction")); + span_events_[d] = r; } -#include "translator.icc" ADD_TRANSLATOR (Span_dynamic_performer, "", "", - "crescendo-event decrescendo-event", - "", ""); + "", "");