lilypond-user
[Top][All Lists]
Advanced

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

Re: "smart" transposition of key signatures


From: David Kastrup
Subject: Re: "smart" transposition of key signatures
Date: Mon, 07 Oct 2013 18:12:48 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

Kieren MacMillan <address@hidden> writes:

> Hello all,
>
> I've got a piece in which the key centres move thusly:
>
>    E major  -->  F minor  -->  A major  -->  F major  -->  E major
>
> I need to transpose it up a few pitches, as it was originally written for 
> medium voice, but is going to be sung by a high[er] tenor.
>
>   \transpose e g ==>    G major  -->  G# minor  (= B major) -->  C major  --> 
>  Ab major  -->  G major
>
> would be great… except what's actually happening is
>
>   \transpose e g ==>    G major  -->  Ab minor  (= Cb major, with 7 flats!!!) 
> -->  C major  -->  Ab major  -->  G major.
>
> Is there any way (like the "naturalizeMusic" function for individual notes) 
> to ensure that the key signatures in a transposed piece are the "most 
> logical"?

There is obviously no point in just enharmonizing the key signature
while not transposing at the same time.

Now one thing you can obviously do is doing a
\transpose fis ges
or vice versa on a passage, and this will also cover the key signature.
The disadvantage is that if the passage already "corrected" any triple
accidentals when transposing, they will stick out.  Personally, I think
transposition should not worry about producing printable/playable notes:
a single pass during scorification can bring the enharmonicity into the
desired range.

Now if we assume that we have not already left the good pitches behind
and that we won't need more than one corrective rotation around the
harmonic circle (both are somewhat correlated), we can hook into the
iterator: at that time, all transposition should be over.

That gives us something like

maybekey =
#(define-music-function (parser location pitch scale music)
   (ly:pitch? list? ly:music?)
   (let ((key #{ \key $pitch #scale #}))
     (make-music 'SequentialMusic
                 'elements (list key music)
                 'elements-callback
                 (lambda (m)
                   (let* ((elts (ly:music-property m 'elements))
                          (key (car elts))
                          (sh (fold (lambda (elt total) (+ (cdr elt) total))
                                    0
                                    (ly:music-property key 'pitch-alist))))
                     (cond ((< sh -3)
                            (map (lambda (m)
                                   (ly:music-transpose m #{ bis #}))
                                 elts))
                           ((> sh 3)
                            (map (lambda (m)
                                   (ly:music-transpose m #{ deses' #}))
                                 elts))
                           (else elts)))))))

music =
{
 \maybekey c\minor { c' es' g' <c' es' g'> }
 \maybekey cis\major { cis' eis' gis' <cis' eis' gis'> }
 \maybekey es\minor { es' ges' bes' <es' ges' bes'> }
}

<<
  \new Staff \music
  \new Staff \transpose c g \music
  \new Staff \transpose c es \music
  \new Staff \transpose c fis \music
>>


                
which will retranspose if it finds the suggested key signature to have a
total of more than 6 accidentals (which count for +/- 1/2 each in sh,
the harmonic shift).

You owe me a snippet submission or its monetary equivalent.

-- 
David Kastrup

reply via email to

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