> I made this function some times ago, but don't know if is enough
> straightforward :-)
OK, this one is more straightforward...
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% sharp
#(define (semitones->pitch n)
(let ((a (quotient n 12))
(b 0)
(c (modulo n 12)))
(cond ;; 2 semitones in a tone but not between E and F (c=5)
((< c 5) (ly:make-pitch a (quotient c 2) (* 1/2 (modulo c 2))))
(else (ly:make-pitch a (quotient (1+ c) 2) (* 1/2 (modulo (1+ c) 2)))))))
%% flat
%{ %comment this line if you want notes with flats instead sharps
#(define (semitones->pitch n)
(let ((a (quotient n 12))
(b 0)
(c (modulo n 12)))
(cond
((< c 5) (ly:make-pitch a (+ (quotient c 2) (modulo c 2))
(* -1/2 (modulo c 2))))
(else (ly:make-pitch a (+ (quotient (1+ c) 2) (modulo (1+ c) 2))
(* -1/2 (modulo (1+ c) 2)))))))
%}
%%test
#(for-each
(lambda(n)(format #t "~2,' d - ~a\n" n (semitones->pitch n)))
'(-5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15))
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
--
Gilles
_______________________________________________
lilypond-user mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/lilypond-user