X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fkey-performer.cc;h=f217742603da17e4f9478289d10a14096a0ea60b;hb=98ca84585c45f75503adff82fc0a8cec2a105769;hp=a14edf077bfa730ba0cf3c30c83c2ed552bee71f;hpb=d9b43b93f2c885409bafdb157138158f65cc49aa;p=lilypond.git diff --git a/lily/key-performer.cc b/lily/key-performer.cc index a14edf077b..f217742603 100644 --- a/lily/key-performer.cc +++ b/lily/key-performer.cc @@ -3,35 +3,36 @@ source file of the GNU LilyPond music typesetter - (c) 1997--2002 Jan Nieuwenhuizen + (c) 1997--2004 Jan Nieuwenhuizen */ #include "lily-guile.hh" -#include "command-request.hh" + #include "audio-item.hh" #include "performer.hh" +#include "warn.hh" class Key_performer : public Performer { public: - TRANSLATOR_DECLARATIONS(Key_performer); + TRANSLATOR_DECLARATIONS (Key_performer); ~Key_performer (); protected: - virtual bool try_music (Music* req_l); + virtual bool try_music (Music* req); virtual void create_audio_elements (); virtual void stop_translation_timestep (); private: - Key_change_req* key_req_l_; - Audio_key* audio_p_; + Key_change_ev* key_req_; + Audio_key* audio_; }; Key_performer::Key_performer () { - key_req_l_ = 0; - audio_p_ = 0; + key_req_ = 0; + audio_ = 0; } Key_performer::~Key_performer () @@ -41,60 +42,61 @@ Key_performer::~Key_performer () void Key_performer::create_audio_elements () { - if (key_req_l_) + if (key_req_) { - SCM pitchlist = key_req_l_->get_mus_property ("pitch-alist"); - SCM proc = scm_primitive_eval (ly_symbol2scm ("accidentals-in-key")); - SCM acc = gh_call1 (proc, pitchlist); - proc = scm_primitive_eval (ly_symbol2scm ("major-key")); - - Pitch my_do (0, - gh_scm2int (ly_caar (pitchlist)), - gh_scm2int (ly_cdar (pitchlist))); + SCM pitchlist = key_req_->get_property ("pitch-alist"); + SCM proc = ly_scheme_function ("alterations-in-key"); + + SCM acc = scm_call_1 (proc, pitchlist); + + Pitch key_do (0, + ly_scm2int (ly_caar (pitchlist)), + ly_scm2int (ly_cdar (pitchlist))); + + Pitch c_do (0, 0, 0); - Pitch to_c (-1, - (7 - gh_scm2int (ly_caar (pitchlist))) % 7, - -gh_scm2int (ly_cdar (pitchlist))); - - my_do.transpose (to_c); - to_c.alteration_i_ -= my_do.alteration_i_; + SCM c_pitchlist + = ly_transpose_key_alist (pitchlist, + interval (key_do, c_do).smobbed_copy ()); - Key_change_req *key = new Key_change_req; - key->set_mus_property ("pitch-alist", scm_list_copy (pitchlist)); - ((Music*)key)->transpose (to_c); - SCM c_pitchlist = key->get_mus_property ("pitch-alist"); - SCM major = gh_call1 (proc, c_pitchlist); + /* MIDI keys are too limited for lilypond scales. + We check for minor scale and assume major otherwise. */ + SCM minor = scm_c_eval_string ("minor"); + audio_ = new Audio_key (ly_scm2int (acc), + SCM_BOOL_T != scm_equal_p (minor, c_pitchlist)); - audio_p_ = new Audio_key (gh_scm2int (acc), major == SCM_BOOL_T); - Audio_element_info info (audio_p_, key_req_l_); + Audio_element_info info (audio_, key_req_); announce_element (info); - key_req_l_ = 0; + key_req_ = 0; } } void Key_performer::stop_translation_timestep () { - if (audio_p_) + if (audio_) { - play_element (audio_p_); - audio_p_ = 0; + play_element (audio_); + audio_ = 0; } } bool -Key_performer::try_music (Music* req_l) +Key_performer::try_music (Music* req) { - if (Key_change_req *kc = dynamic_cast (req_l)) + if (Key_change_ev *kc = dynamic_cast (req)) { - if (key_req_l_) + if (key_req_) warning (_ ("FIXME: key change merge")); - key_req_l_ = kc; + key_req_ = kc; return true; } return false; } -ENTER_DESCRIPTION(Key_performer,"","","","",""); +ENTER_DESCRIPTION (Key_performer, + "","", + "key-change-event", + "","","");