lilypond-user
[Top][All Lists]
Advanced

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

transpose pitch by semitones


From: Urs Liska
Subject: transpose pitch by semitones
Date: Fri, 27 Nov 2015 11:42:33 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0

Hi all,

I'm poking around in the reference but don't find a simpler solution.

I have a function that returns an integer that represents the semitones
over a reference (by default the middle c). From this I want to
construct a pitch so that e.g.

(pitch 2) would return the equivalent to (ly:make-pitch 0 1 0) and
(pitch 13) => (ly:make-pitch 1 0 1/2) or (ly:make-pitch 0 7 1/2)

I've implemented a lookup list like so

#(define (semitones->pitch semitone)
   (let ((index (modulo semitone 12))
         (octave (floor (/ semitone 12))))
     (list
      octave
      (list-ref
       '((0 0)   ; c
          (0 1/2) ; cis
          (1 0)   ; d
          (1 1/2) ; dis
          (2 0)   ; e
          (3 0)   ; f
          (3 1/2) ; fis %  \jiPitch 2 1
 
          (4 0)   ; g
          (4 1/2) ; gis
          (5 0)   ; a
          (5 1/2) ; ais
          (6 0))   ; b     
       index))))

but would like to find a solution that is more straightforward. Somehow
I feel LilyPond should have that function already built in.

Any suggestions?

TIA
Urs



reply via email to

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