[prev in list] [next in list] [prev in thread] [next in thread]
List: lilypond-user
Subject: Re: transpose pitch by semitones
From: Gilles THIBAULT <gilles.thibault () free ! fr>
Date: 2015-11-30 23:44:52
Message-ID: 2313141.zAdzMfDk9t () pc-i3
[Download RAW message or body]
> #(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.
Sorry to answer so late.
I made this function some times ago, but don't know if is enough
straightforward :-)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\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)))))))
%%% 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
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic