X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fspan-dynamic-performer.cc;h=45aba8177cf1244b0ca33a00a73f500657ed048e;hb=f47a52d0c0b6f0f2bc39708528ba9cec4882aaa2;hp=c6f115901a8bf1404d0c2d2dccb426366e1afb5e;hpb=3667c501f00ea9da03b3d7dfb0133bb48276a398;p=lilypond.git diff --git a/lily/span-dynamic-performer.cc b/lily/span-dynamic-performer.cc index c6f115901a..45aba8177c 100644 --- a/lily/span-dynamic-performer.cc +++ b/lily/span-dynamic-performer.cc @@ -3,151 +3,184 @@ source file of the GNU LilyPond music typesetter - (c) 2000 Jan Nieuwenhuizen + (c) 2000--2004 Jan Nieuwenhuizen */ #include "performer.hh" -#include "command-request.hh" -#include "musical-request.hh" #include "audio-item.hh" +/* + TODO: fold this into 1 engraver: \< and \> should also stop when + absdyn is encountered. + */ + struct Audio_dynamic_tuple { - Audio_dynamic* audio_l_; + Audio_dynamic* audio_; Moment mom_; }; /** - handle perform span-dynamics + perform span-dynamics */ class Span_dynamic_performer : public Performer { public: - VIRTUAL_COPY_CONS (Translator); - - Span_dynamic_performer (); + TRANSLATOR_DECLARATIONS (Span_dynamic_performer); protected: - virtual bool do_try_music (Music* req_l); - virtual void acknowledge_element (Audio_element_info); - virtual void do_process_requests (); - virtual void do_pre_move_processing (); + virtual bool try_music (Music*); + virtual void acknowledge_audio_element (Audio_element_info); + virtual void process_music (); + virtual void stop_translation_timestep (); private: - Drul_array request_drul_; - Drul_array moment_drul_; - Drul_array volume_drul_; - Array dynamic_tuple_arr_; - - // BURP - Drul_array done_moment_drul_; - Drul_array done_volume_drul_; - Array done_dynamic_tuple_arr_; - - Audio_dynamic* audio_p_; + Audio_dynamic* audio_; + Real last_volume_; + Music* span_start_event_; + Drul_array span_events_; + Array dynamic_tuples_; + Array finished_dynamic_tuples_; + Direction dir_; + Direction finished_dir_; }; -ADD_THIS_TRANSLATOR (Span_dynamic_performer); - Span_dynamic_performer::Span_dynamic_performer () { - request_drul_[START] = request_drul_[STOP] = 0; - volume_drul_[START] = volume_drul_[STOP] = 0; - audio_p_ = 0; + span_events_[START] = 0; + span_events_[STOP] = 0; + span_start_event_ = 0; + audio_ = 0; + last_volume_ = 0; } void -Span_dynamic_performer::acknowledge_element (Audio_element_info i) +Span_dynamic_performer::acknowledge_audio_element (Audio_element_info i) { - if (Audio_dynamic * d = dynamic_cast (i.elem_l_)) + if (Audio_dynamic * d = dynamic_cast (i.elem_)) { - Direction dir = volume_drul_[START] ? STOP : START; - volume_drul_[dir] = d->volume_i_; - if (done_dynamic_tuple_arr_.size ()) - done_volume_drul_[STOP] = d->volume_i_; -#if 0 - Audio_dynamic_tuple a = { d, now_mom () }; - dynamic_tuple_arr_.push (a); -#endif + last_volume_ = d->volume_; } } void -Span_dynamic_performer::do_process_requests () +Span_dynamic_performer::process_music () { - if (request_drul_[START]) + if (span_start_event_ || span_events_[START]) { - audio_p_ = new Audio_dynamic (volume_drul_[START]); - Audio_element_info info (audio_p_, 0); + audio_ = new Audio_dynamic (0); + Audio_element_info info (audio_, span_events_[START] + ? span_events_[START] + : span_events_[STOP]); announce_element (info); - - Audio_dynamic_tuple a = { audio_p_, now_mom () }; - dynamic_tuple_arr_.push (a); + Audio_dynamic_tuple a = { audio_, now_mom () }; + dynamic_tuples_.push (a); } - - if (done_dynamic_tuple_arr_.size ()) + + if (span_events_[STOP]) { - if (done_volume_drul_[STOP]) + if (!span_start_event_) + { + span_events_[STOP]->origin ()->warning (_ ("can't find start of (de)crescendo")); + span_events_[STOP] = 0; + } + else { - Real dv = done_volume_drul_[STOP] - done_volume_drul_[START]; - Moment dt = done_moment_drul_[STOP] - done_moment_drul_[START]; - for (int i=0; i < done_dynamic_tuple_arr_.size (); i++) - { - Real volume = - (done_volume_drul_[START] - + dv * (Real)(done_dynamic_tuple_arr_[i].mom_ - - done_moment_drul_[START]) / (Real)dt); - done_dynamic_tuple_arr_[i].audio_l_->volume_i_ = (int)volume; - } + finished_dir_ = dir_; + finished_dynamic_tuples_ = dynamic_tuples_; } - done_dynamic_tuple_arr_.clear (); + dynamic_tuples_.clear (); + span_start_event_ = 0; + } + + if (span_events_[START]) + { + dir_ = (span_events_[START]->is_mus_type ("crescendo-event")) + ? RIGHT : LEFT; + span_start_event_ = span_events_[START]; + + dynamic_tuples_.clear (); + Audio_dynamic_tuple a = { audio_, now_mom () }; + dynamic_tuples_.push (a); } - if (request_drul_[STOP]) + if (span_events_[STOP]) + { + finished_dynamic_tuples_.top ().audio_->volume_ = last_volume_; + } + + if (span_events_[START]) { - done_dynamic_tuple_arr_ = dynamic_tuple_arr_; - dynamic_tuple_arr_.clear (); - done_volume_drul_[START] = volume_drul_[START]; - done_volume_drul_[STOP] = volume_drul_[STOP]; - done_moment_drul_[START] = moment_drul_[START]; - done_moment_drul_[STOP] = moment_drul_[STOP]; - request_drul_[STOP] = 0; - volume_drul_[START] = volume_drul_[STOP]; - volume_drul_[STOP] = 0; + dynamic_tuples_[0].audio_->volume_ = last_volume_; } + + span_events_[START] = 0; + span_events_[STOP] = 0; } void -Span_dynamic_performer::do_pre_move_processing () +Span_dynamic_performer::stop_translation_timestep () { - if (audio_p_) + if (finished_dynamic_tuples_.size () > 1) + { + Real start_volume = finished_dynamic_tuples_[0].audio_->volume_; + Real dv = finished_dynamic_tuples_.top ().audio_->volume_ + - start_volume; + /* + urg. + Catch and fix the case of: + + | | + x| x| + f cresc. -- -- -- -- -- pp + + Actually, we should provide a non-displayed dynamic/volume setting, + to set volume to 'ff' just before the pp. + */ + if (!dv || sign (dv) != finished_dir_) + { + // urg. 20%: about two volume steps + dv = (Real)finished_dir_ * 0.2; + if (!start_volume) + start_volume = finished_dynamic_tuples_.top + ().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++) + { + Audio_dynamic_tuple* a = &finished_dynamic_tuples_[i]; + Real volume = start_volume + dv * (Real) (a->mom_ - start_mom).main_part_ + / (Real)dt.main_part_; + a->audio_->volume_ = volume; + } + finished_dynamic_tuples_.clear (); + } + + if (audio_) { - play_element (audio_p_); - audio_p_ = 0; + play_element (audio_); + audio_ = 0; } + + span_events_[STOP] = 0; + span_events_[START] = 0; + } bool -Span_dynamic_performer::do_try_music (Music* r) +Span_dynamic_performer::try_music (Music* r) { - if (Span_req * s = dynamic_cast(r)) + if (r->is_mus_type ("crescendo-event") + || r->is_mus_type ("decrescendo-event")) { - if (s-> span_type_str_ != "crescendo" - && s->span_type_str_ != "decrescendo") - return false; - - Direction d = s->span_dir_; - - if (d == STOP && !request_drul_[START]) - { - r->warning (_ ("No (de)crescendo to end")); - return false; - } - request_drul_[d] = s; - moment_drul_[d] = now_mom (); - if (d == START && volume_drul_[STOP]) - volume_drul_[START] = volume_drul_[STOP]; + Direction d = to_dir (r->get_property ("span-direction")); + span_events_[d] = r; return true; } return false; } +ADD_TRANSLATOR (Span_dynamic_performer, + "", "", + "crescendo-event decrescendo-event", + "", "", "");