X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fdynamic-performer.cc;h=c80d64111ee1dad5dd034b07408d6881dc757d44;hb=5b4b0d6e9a197e8f9eb085b7c2ad78b8be3e5cfc;hp=7fbca0dd698718d599a2dca4e009e224a2ed94bf;hpb=c735173d0ec717e9743a5032ac6a43bbba0da39f;p=lilypond.git diff --git a/lily/dynamic-performer.cc b/lily/dynamic-performer.cc index 7fbca0dd69..c80d64111e 100644 --- a/lily/dynamic-performer.cc +++ b/lily/dynamic-performer.cc @@ -3,110 +3,208 @@ source file of the GNU LilyPond music typesetter - (c) 2000 Jan Nieuwenhuizen + (c) 2000--2008 Jan Nieuwenhuizen */ #include "performer.hh" -#include "command-request.hh" -#include "musical-request.hh" #include "audio-item.hh" +#include "stream-event.hh" + +#include "translator.icc" -/* - TODO: - handle multiple requests - handle span requests (crescendo/decrescendo) - */ - -/** - perform absolute (text) dynamics - */ class Dynamic_performer : public Performer { public: - VIRTUAL_COPY_CONS (Translator); - - Dynamic_performer (); - ~Dynamic_performer (); - + TRANSLATOR_DECLARATIONS (Dynamic_performer); protected: - void do_print () const; - virtual bool do_try_music (Music* req_l); - virtual void do_process_music (); - virtual void do_pre_move_processing (); + void stop_translation_timestep (); + void process_music (); + Real equalize_volume (Real); + DECLARE_TRANSLATOR_LISTENER (decrescendo); + DECLARE_TRANSLATOR_LISTENER (crescendo); + DECLARE_TRANSLATOR_LISTENER (absolute_dynamic); private: - Text_script_req* text_script_req_l_; - Audio_dynamic* audio_p_; + Stream_event *script_event_; + Drul_array span_events_; + Drul_array grow_dir_; + Real last_volume_; + Audio_dynamic *absolute_; + Audio_span_dynamic *span_dynamic_; + Audio_span_dynamic *finished_span_dynamic_; }; -ADD_THIS_TRANSLATOR (Dynamic_performer); - Dynamic_performer::Dynamic_performer () { - text_script_req_l_ = 0; - audio_p_ = 0; + last_volume_ = 0.5; + script_event_ = 0; + absolute_ = 0; + span_events_[LEFT] = + span_events_[RIGHT] = 0; + span_dynamic_ = 0; + finished_span_dynamic_ = 0; } -Dynamic_performer::~Dynamic_performer () +Real +Dynamic_performer::equalize_volume (Real volume) { -} + /* + properties override default equaliser setting + */ + SCM min = get_property ("midiMinimumVolume"); + SCM max = get_property ("midiMaximumVolume"); + if (scm_is_number (min) || scm_is_number (max)) + { + Interval iv (0, 1); + if (scm_is_number (min)) + iv[MIN] = scm_to_double (min); + if (scm_is_number (max)) + iv[MAX] = scm_to_double (max); + volume = iv[MIN] + iv.length () * volume; + } + else + { + /* + urg, code duplication:: staff_performer + */ + SCM s = get_property ("midiInstrument"); -void -Dynamic_performer::do_print () const -{ -#ifndef NPRINT - if (text_script_req_l_) - text_script_req_l_->print (); -#endif + if (!scm_is_string (s)) + s = get_property ("instrumentName"); + + if (!scm_is_string (s)) + s = scm_from_locale_string ("piano"); + + SCM eq = get_property ("instrumentEqualizer"); + if (ly_is_procedure (eq)) + s = scm_call_1 (eq, s); + + if (is_number_pair (s)) + { + Interval iv = ly_scm2interval (s); + volume = iv[MIN] + iv.length () * volume; + } + } + return volume; } + void -Dynamic_performer::do_process_music () +Dynamic_performer::process_music () { - if (text_script_req_l_) + if (span_events_[STOP] || script_event_) + { + finished_span_dynamic_ = span_dynamic_; + span_dynamic_ = 0; + } + + if (span_events_[START]) { + span_dynamic_ = new Audio_span_dynamic (); + announce_element (Audio_element_info (span_dynamic_, span_events_[START])); + + span_dynamic_->grow_dir_ = grow_dir_[START]; + } + + if (script_event_ + || span_dynamic_ + || finished_span_dynamic_) + { + absolute_ = new Audio_dynamic (); + + if (script_event_) + { + SCM proc = get_property ("dynamicAbsoluteVolumeFunction"); + + SCM svolume = SCM_EOL; + if (ly_is_procedure (proc)) + { + // urg + svolume = scm_call_1 (proc, script_event_->get_property ("text")); + } + + Real volume = robust_scm2double (svolume, 0.5); + + last_volume_ + = absolute_->volume_ = equalize_volume (volume); + } - SCM s = scm_eval - (gh_list - (ly_symbol2scm ("dynamic-absolute-volume"), - ly_quote_scm (ly_str02scm (text_script_req_l_->text_str_.ch_C ())), - SCM_UNDEFINED)); - int volume = gh_scm2int (ly_eval_str ("dynamic-default-volume")); - if (gh_number_p (s)) - volume = gh_scm2int (s); - - audio_p_ = new Audio_dynamic (volume); - Audio_element_info info (audio_p_, text_script_req_l_); + Audio_element_info info (absolute_, script_event_); announce_element (info); - text_script_req_l_ = 0; } + + + if (span_dynamic_) + span_dynamic_->add_absolute (absolute_); + + if (finished_span_dynamic_) + finished_span_dynamic_->add_absolute (absolute_); } void -Dynamic_performer::do_pre_move_processing () +Dynamic_performer::stop_translation_timestep () { - if (audio_p_) + if (finished_span_dynamic_) { - play_element (audio_p_); - audio_p_ = 0; + finished_span_dynamic_->render (); + finished_span_dynamic_ = 0; } + + if (absolute_ && absolute_->volume_ < 0) + { + absolute_->volume_ = last_volume_; + } + else if (absolute_) + { + last_volume_ = absolute_->volume_; + } + + absolute_ = 0; + script_event_ = 0; + span_events_[LEFT] = + span_events_[RIGHT] = 0; } -bool -Dynamic_performer::do_try_music (Music* r) +IMPLEMENT_TRANSLATOR_LISTENER (Dynamic_performer, decrescendo); +void +Dynamic_performer::listen_decrescendo (Stream_event *r) { - if (!text_script_req_l_) - { - // urg, text script, style `dynamic' is how absolute dynamics appear - if(Text_script_req* t = dynamic_cast (r)) - { - if (t->style_str_ == "dynamic") - { - text_script_req_l_ = t; - return true; - } - } - } - return false; + Direction d = to_dir (r->get_property ("span-direction")); + span_events_[d] = r; + grow_dir_[d] = SMALLER; +} + +IMPLEMENT_TRANSLATOR_LISTENER (Dynamic_performer, crescendo); +void +Dynamic_performer::listen_crescendo (Stream_event *r) +{ + Direction d = to_dir (r->get_property ("span-direction")); + span_events_[d] = r; + grow_dir_[d] = BIGGER; } +IMPLEMENT_TRANSLATOR_LISTENER (Dynamic_performer, absolute_dynamic); +void +Dynamic_performer::listen_absolute_dynamic (Stream_event *r) +{ + if (!script_event_) + script_event_ = r; +} + +ADD_TRANSLATOR (Dynamic_performer, + /* doc */ + "", + + /* create */ + "", + + /* read */ + "dynamicAbsoluteVolumeFunction " + "instrumentEqualizer " + "midiMaximumVolume " + "midiMinimumVolume " + "midiInstrument ", + + /* write */ + "" + );