OK, here's how I did it in the end.  Is there a better way???

#(define ac:current-key (make-music
          'KeyChangeEvent
          'tonic
          (ly:make-pitch -1 0 0)
          'pitch-alist
          (list (cons 0 0)
                (cons 1 0)
                (cons 2 0)
                (cons 3 0)
                (cons 4 0)
                (cons 5 0)
                (cons 6 0))))

#(define (ac:up note)
        "Given a NoteEvent, replace its pitch with the next one 
         up in the current scale.
         Doesn't cope too well with melodic minors"
  (let* ((pitch (ly:music-property note 'pitch))
         (notename (ly:pitch-notename pitch))
         (new-notename (if (eq? notename 6) 0 (+ 1 notename)))
         (alterations (ly:music-property ac:current-key 'pitch-alist))
         (new-alteration (cdr (assq new-notename alterations)))
         (new-octave (if (eq? new-notename 0) (+ 1 (ly:pitch-octave pitch))
                      (ly:pitch-octave pitch)))
       )
   (set! 
        (ly:music-property note 'pitch)
        (ly:make-pitch new-octave new-notename new-alteration))))

(ac:down is analogous to ac:up)

Whenever I see a KeyChangeEvent in the rest of the program I update
ac:current-key.

Is there a better way?  Does Lilypond keep track of the current key
signature for me?

--
Dr Peter Chubb  http://www.gelato.unsw.edu.au  peterc AT gelato.unsw.edu.au
http://www.ertos.nicta.com.au           ERTOS within National ICT Australia


_______________________________________________
lilypond-user mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to