Previous: Octave checks, Up: Changing multiple pitches
A music expression can be transposed with \transpose
. The
syntax is
\transpose frompitch topitch musicexpr
This means that musicexpr is transposed by the interval between the pitches frompitch and topitch: any note with pitch frompitch is changed to topitch and any other note is transposed by the same interval. Both pitches are entered in absolute mode.
Consider a piece written in the key of D-major. It can be transposed up to E-major; note that the key signature is automatically transposed as well.
\transpose d e { \relative c' { \key d \major d4 fis a d } }
If a part written in C (normal concert pitch) is to be played on the A clarinet (for which an A is notated as a C and thus sounds a minor third lower than notated), the appropriate part will be produced with:
\transpose a c' { \relative c' { \key c \major c4 d e g } }
Note that we specify \key c \major
explicitly. If we
do not specify a key signature, the notes will be transposed but
no key signature will be printed.
\transpose
distinguishes between enharmonic pitches: both
\transpose c cis
or \transpose c des
will
transpose up a semitone. The first version will print sharps and
the notes will remain on the same scale step, the second version
will print flats on the scale step above.
music = \relative c' { c d e f } \new Staff { \transpose c cis { \music } \transpose c des { \music } }
\transpose
may also be used in a different way, to input
written notes for a transposing instrument. The previous examples
show how to enter pitches in C (or concert pitch) and
typeset them for a transposing instrument, but the opposite is
also possible if you for example have a set of instrumental parts
and want to print a conductor's score. For example, when entering
music for a B-flat trumpet that begins on a notated E (concert D),
one would write:
musicInBflat = { e4 ... } \transpose c bes, \musicInBflat
To print this music in F (e.g., rearranging to a French horn) you
could wrap the existing music with another \transpose
:
musicInBflat = { e4 ... } \transpose f c' { \transpose c bes, \musicInBflat }
For more information about transposing instruments, see Instrument transpositions.
Transposing music with minimum accidentals
This example uses some Scheme code to enforce enharmonic modifications for notes in order to have the minimum number of accidentals. In this case, the following rules apply:
In this manner, the most natural enharmonic notes are chosen.
#(define (naturalize-pitch p) (let* ((o (ly:pitch-octave p)) (a (* 4 (ly:pitch-alteration p))) ; alteration, a, in quarter tone steps, for historical reasons (n (ly:pitch-notename p))) (cond ((and (> a 1) (or (eq? n 6) (eq? n 2))) (set! a (- a 2)) (set! n (+ n 1))) ((and (< a -1) (or (eq? n 0) (eq? n 3))) (set! a (+ a 2)) (set! n (- n 1)))) (cond ((> a 2) (set! a (- a 4)) (set! n (+ n 1))) ((< a -2) (set! a (+ a 4)) (set! n (- n 1)))) (if (< n 0) (begin (set! o (- o 1)) (set! n (+ n 7)))) (if (> n 6) (begin (set! o (+ o 1)) (set! n (- n 7)))) (ly:make-pitch o n (/ a 4)))) #(define (naturalize music) (let* ((es (ly:music-property music 'elements)) (e (ly:music-property music 'element)) (p (ly:music-property music 'pitch))) (if (pair? es) (ly:music-set-property! music 'elements (map (lambda (x) (naturalize x)) es))) (if (ly:music? e) (ly:music-set-property! music 'element (naturalize e))) (if (ly:pitch? p) (begin (set! p (naturalize-pitch p)) (ly:music-set-property! music 'pitch p))) music)) naturalizeMusic = #(define-music-function (parser location m) (ly:music?) (naturalize m)) music = \relative c' { c4 d e g } \score { \new Staff { \transpose c ais \music \naturalizeMusic \transpose c ais \music \transpose c deses \music \naturalizeMusic \transpose c deses \music } \layout { } }
Notation Reference: Instrument transpositions.
Snippets: Pitches.
Internals Reference: TransposedMusic.
The relative conversion will not affect \transpose
,
\chordmode
or \relative
sections in its argument.
To use relative mode within transposed music, an additional
\relative
must be placed inside \transpose
.
This page is for LilyPond-2.11.58 (development-branch).
Report errors to http://post.gmane.org/post.php?group=gmane.comp.gnu.lilypond.bugs.
Your suggestions for the documentation are welcome.