]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/key-performer.cc
2003 -> 2004
[lilypond.git] / lily / key-performer.cc
index d52d563e6d3c6e15e5334cbe6adf68dbca52d482..246cad751c54801b27325a48247c85231aaac2b8 100644 (file)
@@ -3,11 +3,11 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c)  1997--2002 Jan Nieuwenhuizen <janneke@gnu.org>
+  (c) 1997--2004 Jan Nieuwenhuizen <janneke@gnu.org>
 */
 
 #include "lily-guile.hh"
-#include "command-request.hh"
+
 #include "audio-item.hh"
 #include "performer.hh"
 #include "warn.hh"
@@ -25,7 +25,7 @@ protected:
   virtual void stop_translation_timestep ();
 
 private:
-  Key_change_req* key_req_;
+  Key_change_ev* key_req_;
   Audio_key* audio_;
 };
 
@@ -44,33 +44,26 @@ Key_performer::create_audio_elements ()
 {
   if (key_req_) 
     {
-
-      /*
-       UGH. primitive-eval.
-       */
       SCM pitchlist = key_req_->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)));
-                 
-      Pitch to_c (-1,
-                  (7 - gh_scm2int (ly_caar (pitchlist))) % 7,
-                  -gh_scm2int (ly_cdar (pitchlist)));
+      
+      Pitch key_do (0, 
+                   gh_scm2int (ly_caar (pitchlist)),
+                   gh_scm2int (ly_cdar (pitchlist)));
 
-      my_do.transpose (to_c);
-      to_c.alteration_ -= my_do.alteration_;
+      Pitch c_do (0, 0, 0);
+                 
+      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_primitive_eval (ly_symbol2scm ("minor"));
+      audio_ = new Audio_key (gh_scm2int (acc),
+                             SCM_BOOL_T != scm_equal_p (minor, c_pitchlist));
 
-      audio_ = new Audio_key (gh_scm2int (acc), major == SCM_BOOL_T); 
       Audio_element_info info (audio_, key_req_);
       announce_element (info);
       key_req_ = 0;
@@ -90,7 +83,7 @@ Key_performer::stop_translation_timestep ()
 bool
 Key_performer::try_music (Music* req)
 {
-  if (Key_change_req *kc = dynamic_cast <Key_change_req *> (req))
+  if (Key_change_ev *kc = dynamic_cast <Key_change_ev *> (req))
     {
       if (key_req_)
        warning (_ ("FIXME: key change merge"));
@@ -104,5 +97,5 @@ Key_performer::try_music (Music* req)
 
 ENTER_DESCRIPTION(Key_performer,
                  "","",
-                 "general-music",
+                 "key-change-event",
                  "","","");