Transposing chords

2011-03-18 Thread John Donovan
Hi,
As part of a teaching aid, I have the C major scale and the seven main chords 
that I then want to transpose to other keys.
The code I have so far works well, but I'm having difficulty getting Lilypond 
to 
keep the transposed chords in the right range. For instance, in C major the 
first two chords I have are C and F, with the F chord higher than the C. But 
when it is transposed to G major, the G chord is in the right range, but the C 
goes up to the next octave instead of down. I understand this is standard 
Lilypond behaviour, but is there any way of overriding it? I've tried \relative 
commands in various places but to no avail. A minimal example of what I have is 
here:

\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}
}
}

\layout{ }

What I want is the last C chord to be the same as the first. Is this possible? 
I 
did think about writing each chord sequence manually but that sort of defeats 
the point...

-John


___
lilypond-user mailing list
lilypond-user@gnu.org
http://lists.gnu.org/mailman/listinfo/lilypond-user


Re: Transposing chords

2011-03-18 Thread Michael Ellis
On Fri, Mar 18, 2011 at 6:24 PM, John Donovan mersey.vik...@gmail.com 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

___
lilypond-user mailing list
lilypond-user@gnu.org
http://lists.gnu.org/mailman/listinfo/lilypond-user