X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fdynamic-performer.cc;h=1e538800b474c6e256b015c1e0873282a9a1cd60;hb=97759ace2c13860488de4e9498607adac8d20963;hp=b7472eaf515b87a241343f5e5644437a64ca2efd;hpb=4990a43304a74ffe431951798e9d674101f09278;p=lilypond.git diff --git a/lily/dynamic-performer.cc b/lily/dynamic-performer.cc index b7472eaf51..1e538800b4 100644 --- a/lily/dynamic-performer.cc +++ b/lily/dynamic-performer.cc @@ -3,110 +3,123 @@ source file of the GNU LilyPond music typesetter - (c) 2000 Jan Nieuwenhuizen + (c) 2000--2006 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 - */ + handle multiple events + + 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_requests (); - virtual void do_pre_move_processing (); + void stop_translation_timestep (); + void process_music (); + DECLARE_TRANSLATOR_LISTENER (absolute_dynamic); private: - Text_script_req* text_script_req_l_; - Audio_dynamic* audio_p_; + Stream_event *script_event_; + Audio_dynamic *audio_; }; -ADD_THIS_TRANSLATOR (Dynamic_performer); - Dynamic_performer::Dynamic_performer () { - text_script_req_l_ = 0; - audio_p_ = 0; -} - -Dynamic_performer::~Dynamic_performer () -{ -} - -void -Dynamic_performer::do_print () const -{ -#ifndef NPRINT - if (text_script_req_l_) - text_script_req_l_->print (); -#endif + script_event_ = 0; + audio_ = 0; } void -Dynamic_performer::do_process_requests () +Dynamic_performer::process_music () { - if (text_script_req_l_) + if (script_event_) { - - 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_); + 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); + + /* + 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"); + + if (!scm_is_string (s)) + s = get_property ("instrumentName"); + + if (!scm_is_string (s)) + s = scm_makfrom0str ("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; + } + } + + audio_ = new Audio_dynamic (volume); + Audio_element_info info (audio_, script_event_); announce_element (info); - text_script_req_l_ = 0; + script_event_ = 0; } } void -Dynamic_performer::do_pre_move_processing () +Dynamic_performer::stop_translation_timestep () { - if (audio_p_) + if (audio_) { - play_element (audio_p_); - audio_p_ = 0; + audio_ = 0; } } -bool -Dynamic_performer::do_try_music (Music* r) +IMPLEMENT_TRANSLATOR_LISTENER (Dynamic_performer, absolute_dynamic); +void +Dynamic_performer::listen_absolute_dynamic (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; + if (!script_event_) + script_event_ = r; } +ADD_TRANSLATOR (Dynamic_performer, + /* doc */ "", + /* create */ "", + /* accept */ "absolute-dynamic-event", + /* read */ "dynamicAbsoluteVolumeFunction midiMaximumVolume midiMinimumVolume midiInstrument instrumentEqualizer", + /*writes*/"");