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

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

Reply via email to