]> git.donarmstrong.com Git - lilypond.git/commitdiff
Replace \key with music function
authorDavid Kastrup <dak@gnu.org>
Sun, 30 Oct 2011 07:09:57 +0000 (08:09 +0100)
committerDavid Kastrup <dak@gnu.org>
Tue, 8 Nov 2011 21:56:53 +0000 (22:56 +0100)
lily/lily-lexer.cc
lily/parser.yy
ly/music-functions-init.ly

index b19639b579d81941a4fec8d2541e0acaf36f002f..6383ab9a940dce24ec8e7057808c3c66605d4420 100644 (file)
@@ -60,7 +60,6 @@ static Keyword_ent the_key_tab[]
   {"figures", FIGURES},
   {"grobdescriptions", GROBDESCRIPTIONS},
   {"header", HEADER},
-  {"key", KEY},
   {"layout", LAYOUT},
   {"lyricmode", LYRICMODE},
   {"lyrics", LYRICS},
index a60fdefacbd06e798eac454e6badecf933590bdc..799b662a519446cdbcfe0c671a3903ca43201aab 100644 (file)
@@ -236,7 +236,6 @@ void set_music_properties (Music *p, SCM a);
 %token GROBDESCRIPTIONS "\\grobdescriptions"
 %token HEADER "\\header"
 %token INVALID "\\version-error"
-%token KEY "\\key"
 %token LAYOUT "\\layout"
 %token LYRICMODE "\\lyricmode"
 %token LYRICS "\\lyrics"
@@ -2021,24 +2020,6 @@ command_event:
        | tempo_event {
                $$ = $1;
        }
-       | KEY DEFAULT {
-               Music *key = MY_MAKE_MUSIC ("KeyChangeEvent", @$);
-               $$ = key->unprotect ();
-       }
-       | KEY NOTENAME_PITCH SCM_IDENTIFIER     {
-
-               Music *key = MY_MAKE_MUSIC ("KeyChangeEvent", @$);
-               if (scm_ilength ($3) > 0)
-               {
-                       key->set_property ("pitch-alist", $3);
-                       key->set_property ("tonic", Pitch (0, 0, 0).smobbed_copy ());
-                       key->transpose (* unsmob_pitch ($2));
-               } else {
-                       PARSER->parser_error (@3, _ ("second argument must be pitch list"));
-               }
-
-               $$ = key->unprotect ();
-       }
        ;
 
 
index c0c93788309cf5752f0cd894a2e076528ece2b12..834166131b51eee5bdc5f46cda1008c66d69008b 100644 (file)
@@ -469,6 +469,23 @@ keepWithTag =
         res)))
     music))
 
+key =
+#(define-music-function (parser location tonic pitch-alist)
+   ((ly:pitch? '()) (list? '()))
+   (_i "Set key to @var{tonic} and scale @var{pitch-alist}.
+If both are null, just generate @code{KeyChangeEvent}.")
+   (cond ((null? tonic) (make-music 'KeyChangeEvent))
+        ((null? pitch-alist)
+         (ly:parser-error parser (_ "second argument must be pitch list")
+                          location)
+         (make-music 'SequentialMusic 'void #t))
+        (else
+         (ly:music-transpose
+          (make-music 'KeyChangeEvent
+               'tonic (ly:make-pitch 0 0 0)
+               'pitch-alist pitch-alist)
+          tonic))))
+
 killCues =
 #(define-music-function (parser location music) (ly:music?)
    (_i "Remove cue notes from @var{music}.")