The transpose module

Transpose pitches.

class AbstractTransposer[source]

Bases: object

Base class for a Transposer.

octave = 0

a Transposer at least has an octave attribute, specifying how many octaves a pitch will be transposed.

transpose(pitch)[source]

Transpose the Pitch, by modifying its note, alter and possibly octave attribute.

class Transposer(from_pitch, to_pitch, scale=None)[source]

Bases: AbstractTransposer

Transpose pitches.

Instantiate with a from- and to-Pitch. The scale attribute is a list with the pitch height of the unaltered step (0 .. 6). The default scale is the normal scale: C, D, E, F, G, A, B.

Adding a Transposer to a Transposer creates a new Transposer, adding up both transpositions. Subtracting a Transposer from a Transposer creates a new one, reverting the last transposition.

transpose(pitch)[source]

Transpose the Pitch, by modifying its note, alter and possibly octave attribute.

class Transpose(transposer, processor=None, relative_first_pitch_absolute=None)[source]

Bases: Edit

Transpose pitches using the specified transposer. Arguments:

transposer: a Transposer instance that does the actual work.

processor: a PitchProcessor; a default one is used if none is specified.

relative_first_pitch_absolute: if True, the first pitch in a \relative expression is considered to be absolute, when a startpitch is not given. This is LilyPond >= 2.18 behaviour. If False, the first pitch in a \relative expression is considered to be relative to c’, if no startpitch is given. This is LilyPond < 2.18 behaviour. If not specified, the function looks at the LilyPond version from the document. If the version can’t be determined, defaults to False, the old behaviour.

You may change these attributes after instantiation.

transposer

The Transposer that can transpose pitches.

processor

The PitchProcessor; a default one is used if None is specified.

relative_first_pitch_absolute

Whether to consider the first pitch in a \relative expression absolute (by default dependent on LilyPond version)

edit_range(r)[source]

Perform the transposing on the specified range.

transpose(music, transposer)[source]

Convenience function to transpose all notes in music using transposer.

The music may be a parce document or cursor, a node range or an element node.