[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Convert semitones to pitch?
From: |
Gilles THIBAULT |
Subject: |
Re: Convert semitones to pitch? |
Date: |
Sun, 17 Aug 2014 21:56:29 +0200 |
User-agent: |
KMail/4.11.4 (Linux/3.12.25-desktop-3.mga4; KDE/4.11.4; x86_64; ; ) |
Le samedi 16 août 2014, 23:16:15 rm damerell a écrit :
> pitch-semitones converts a pitch to semitones. Please does the inverse
> function exist?
>
Don't know exactly what you need. Perhaps you think at something like that :
(The function takes c' as reference note, and shows all altered notes with
sharps)
%%%%%%%%%%%%%%%%%%%%%%
\version "2.18.2"
#(define (semitones-pitch n)
(let loop ((a 0)
(b 0)
(c n))
(cond
((> c 11)(loop (1+ a) b (- n 12)))
((< c 0)(loop (1- a) b (+ n 12)))
((< 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)))))))
#(for-each
(lambda(n)(format #t "~a - ~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