X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fkey-performer.cc;h=f217742603da17e4f9478289d10a14096a0ea60b;hb=2be67678488b5829a52acdf36ab4278477375b6d;hp=d80177c26d403480f41edb84c01b3cb56fc04976;hpb=fc5394c7751ea902382ecc9022854583aff0d95e;p=lilypond.git diff --git a/lily/key-performer.cc b/lily/key-performer.cc index d80177c26d..f217742603 100644 --- a/lily/key-performer.cc +++ b/lily/key-performer.cc @@ -3,71 +3,100 @@ source file of the GNU LilyPond music typesetter - (c) 1997--1999 Jan Nieuwenhuizen + (c) 1997--2004 Jan Nieuwenhuizen */ -#include "key-performer.hh" -#include "command-request.hh" +#include "lily-guile.hh" + #include "audio-item.hh" +#include "performer.hh" +#include "warn.hh" +class Key_performer : public Performer +{ +public: + TRANSLATOR_DECLARATIONS (Key_performer); + ~Key_performer (); +protected: + virtual bool try_music (Music* req); + virtual void create_audio_elements (); + virtual void stop_translation_timestep (); -ADD_THIS_TRANSLATOR (Key_performer); +private: + 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 () { } -void -Key_performer::do_print () const -{ -#ifndef NPRINT - if (key_req_l_) - key_req_l_->print (); -#endif -} - void -Key_performer::do_process_requests () +Key_performer::create_audio_elements () { - if (key_req_l_) + if (key_req_) { - audio_p_ = new Audio_key (key_req_l_->key_); - Audio_element_info info (audio_p_, key_req_l_); + 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); + + SCM c_pitchlist + = ly_transpose_key_alist (pitchlist, + interval (key_do, c_do).smobbed_copy ()); + + /* 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_element_info info (audio_, key_req_); announce_element (info); - key_req_l_ = 0; + key_req_ = 0; } } void -Key_performer::do_pre_move_processing () +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::do_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, + "","", + "key-change-event", + "","","");