X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fdynamic-performer.cc;h=a08c500dce4db9f35e52a867e5a07a7942afabbd;hb=94375d04f45b415ad705fd444fdb344416f116d9;hp=b7472eaf515b87a241343f5e5644437a64ca2efd;hpb=4990a43304a74ffe431951798e9d674101f09278;p=lilypond.git diff --git a/lily/dynamic-performer.cc b/lily/dynamic-performer.cc index b7472eaf51..a08c500dce 100644 --- a/lily/dynamic-performer.cc +++ b/lily/dynamic-performer.cc @@ -14,7 +14,6 @@ /* TODO: handle multiple requests - handle span requests (crescendo/decrescendo) */ /** @@ -23,67 +22,95 @@ 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_requests (); - virtual void do_pre_move_processing (); + virtual bool try_music (Music* req_l); + virtual void stop_translation_timestep (); + virtual void create_audio_elements (); private: - Text_script_req* text_script_req_l_; + Music* script_req_l_; Audio_dynamic* audio_p_; }; -ADD_THIS_TRANSLATOR (Dynamic_performer); + Dynamic_performer::Dynamic_performer () { - text_script_req_l_ = 0; + script_req_l_ = 0; audio_p_ = 0; } -Dynamic_performer::~Dynamic_performer () -{ -} - void -Dynamic_performer::do_print () const +Dynamic_performer::create_audio_elements () { -#ifndef NPRINT - if (text_script_req_l_) - text_script_req_l_->print (); -#endif -} - -void -Dynamic_performer::do_process_requests () -{ - if (text_script_req_l_) + if (script_req_l_) { - - 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); + SCM proc = get_property ("dynamicAbsoluteVolumeFunction"); + + SCM svolume = SCM_EOL; + if (gh_procedure_p (proc)) + { + // urg + svolume = gh_call1 (proc, script_req_l_->get_mus_property ("text")); + } + Real volume = 0.5; + if (gh_number_p (svolume)) + volume = gh_scm2double (svolume); + + /* + properties override default equaliser setting + */ + SCM min = get_property ("midiMinimumVolume"); + SCM max = get_property ("midiMaximumVolume"); + if (gh_number_p (min) || gh_number_p (max)) + { + Interval iv (0, 1); + if (gh_number_p (min)) + iv[MIN] = gh_scm2double (min); + if (gh_number_p (max)) + iv[MAX] = gh_scm2double (max); + volume = iv[MIN] + iv.length () * volume; + } + else + { + /* + urg, code duplication:: staff_performer + */ + SCM s = get_property ("midiInstrument"); + + if (!gh_string_p (s)) + s = get_property ("instrument"); + + if (!gh_string_p (s)) + s = ly_str02scm ("piano"); + + + SCM eq = get_property ("instrumentEqualizer"); + if (gh_procedure_p (eq)) + { + s = gh_call1 (eq, s); + } + + if (gh_pair_p (s)) + { + Interval iv; + iv[MIN] = gh_scm2double (ly_car (s)); + iv[MAX] = gh_scm2double (ly_cdr (s)); + volume = iv[MIN] + iv.length () * volume; + } + } + audio_p_ = new Audio_dynamic (volume); - Audio_element_info info (audio_p_, text_script_req_l_); + Audio_element_info info (audio_p_, script_req_l_); announce_element (info); - text_script_req_l_ = 0; + script_req_l_ = 0; } } void -Dynamic_performer::do_pre_move_processing () +Dynamic_performer::stop_translation_timestep () { if (audio_p_) { @@ -93,20 +120,19 @@ Dynamic_performer::do_pre_move_processing () } bool -Dynamic_performer::do_try_music (Music* r) +Dynamic_performer::try_music (Music* r) { - if (!text_script_req_l_) + if (!script_req_l_) { - // urg, text script, style `dynamic' is how absolute dynamics appear - if(Text_script_req* t = dynamic_cast (r)) + if (dynamic_cast (r) + && r->get_mus_property ("text-type") == ly_symbol2scm ("dynamic")) { - if (t->style_str_ == "dynamic") - { - text_script_req_l_ = t; - return true; - } + script_req_l_ = r; + return true; } } return false; } +ENTER_DESCRIPTION(Dynamic_performer, + "","","","","");