lilypond-user
[Top][All Lists]
Advanced

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

Re: Transposing chords


From: Michael Ellis
Subject: Re: Transposing chords
Date: Fri, 18 Mar 2011 23:29:49 -0400

On Fri, Mar 18, 2011 at 6:24 PM, John Donovan <address@hidden> wrote:
> \version "2.12.3"
>
> thechords = \chordmode {
>   c2 f
> }
>
> scale = \relative c' {
>  \clef treble
>  \key c \major
>  \time 4/4
>  c4 d e f g a b c \chordmode {\thechords}
> }
>
> \score {
>    \new Staff {
>      \scale
>      \transpose c g {\scale}
>    }
> }
>

Hi John,
I've run into essentially the same problem transposing sets of
exercises into different keys.  What's needed -- I think -- is a
scheme function that takes an absolute pitch range as one of its
arguments and alters the octave of the target pitch it if falls
outside the range.  This would not be too terribly difficult to
program but getting it "right" could be a bit fussy because "right" is
somewhat subjective. For instance, do you want the scale to always
ascend without wrapping notes but keep the chord pitches within a
certain range?  Is it ok to change the chord inversions?   ....

I ended up doing it manually because I only had a few example forms to
transpose to all keys.  If you have hundreds examples, it might be
worthwhile to write a scheme function.  Hopefully someone has already
created something in the LSR that you might be able to adapt.   I
wrote some code a few of months ago to do modal transpositions and
inversions.  You might be able to scavenge some of procedures as a
starting point.  For example, here's a function that takes some music
as input and applies a converter function to each pitch.  If you can
figure out how to define an appropriate converter function to pass as
an argument you might be halfway there.

(define-public (change-pitches music converter)
  "Recurse through music, applying converter to pitches.
   Converter is typically a transposer or an inverter as
   defined above in this module, but may be user-defined.
   The converter function must take a single pitch as its
   argument and return a new pitch.  These are LilyPond
   scheme pitches, e.g. (ly:make-pitch 0 2 0)."

  (let ((elements (ly:music-property music 'elements))
        (element (ly:music-property music 'element))
        (pitch (ly:music-property music 'pitch)))

    (cond
     ((ly:pitch? pitch)
      (ly:music-set-property! music 'pitch (converter pitch)))

     ((pair? elements)
      (map (lambda (x) (change-pitches x converter)) elements))

     ((ly:music? element)
      (change-pitches element converter)))))


HTH,
Mike



reply via email to

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