lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to generate notes in a scale


From: Peter Chubb
Subject: Re: How to generate notes in a scale
Date: Mon, 21 Apr 2008 11:17:49 +1000
User-agent: Wanderlust/2.15.6 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (Gojō) APEL/10.7 MULE XEmacs/21.4 (patch 20) (Double Solitaire) (i486-linux-gnu)

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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]