lilypond-user
[Top][All Lists]
Advanced

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

Re: transpose pitch by semitones


From: Urs Liska
Subject: Re: transpose pitch by semitones
Date: Tue, 1 Dec 2015 15:54:23 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0


Am 01.12.2015 um 15:48 schrieb Gilles THIBAULT:
>> OK, this one is more straightforward...
> ...but your idea was probably the best :

:-)

Thank you for your input and sorry I didn't have time to reply earlier.
Maybe "best" is also a matter of use case here, but I have the
impression that in this case a simple lookup *is* the most
straightforward solution. In the light of your suggestions I would add a
second lis producing flats instead of sharps, though.

Still I think there should be a built-in solution. When LilyPond does
transpositions and similar operations doesn't it work on semitones
either, converting to and from?

Urs

>
> %%%%%%%%%%%%%%%%%%%%
> #(define (semitones->pitch semitone)
>    (let ((index (modulo semitone 12))
>          (octave (quotient semitone 12)))
>      (apply ly:make-pitch (cons
>       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)))))
>
> %%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))
> %%%%%%%%%%%%%%%%%%%%%%
>
> -- The End ---
>




reply via email to

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