ly.pitch package¶
Module contents¶
Pitch manipulation.
-
class
ly.pitch.
LanguageName
[source]¶ Bases:
ly.lex._token.Token
A Token that denotes a language name.
-
class
ly.pitch.
Pitch
(note=0, alter=0, octave=0, accidental=u'', octavecheck=None)[source]¶ Bases:
object
A pitch with note, alter and octave attributes.
Attributes may be manipulated directly.
-
class
ly.pitch.
PitchIterator
(source, language=u'nederlands')[source]¶ Bases:
object
Iterate over notes or pitches in a source.
-
pitches
()[source]¶ Yields all tokens, but collects Note and Octave tokens.
When a Note is encountered, also reads octave and octave check and then a Pitch is yielded instead of the tokens.
-
-
exception
ly.pitch.
PitchNameNotAvailable
(language)[source]¶ Bases:
exceptions.Exception
Exception raised when there is no name for a pitch.
Can occur when translating pitch names, if the target language e.g. does not have quarter-tone names.
-
class
ly.pitch.
PitchWriter
(names, accs, replacements=())[source]¶ Bases:
object
-
language
= u'unknown'¶
-
-
ly.pitch.
octaveToNum
(octave)[source]¶ Converts string octave to an integer:
“” -> 0 ; “,” -> -1 ; “’‘’” -> 3 ; etc.
Submodules¶
ly.pitch.abs2rel module¶
Convert absolute music to relative music.
-
ly.pitch.abs2rel.
abs2rel
(cursor, language=u'nederlands', startpitch=True, first_pitch_absolute=False)[source]¶ Converts pitches from absolute to relative.
language: language to start reading pitch names in
- startpitch: if True, write a starting pitch before the opening bracket of
- a relative expression.
- first_pitch_absolute: this option only makes sense when startpitch is False.
If first_pitch_absolute is True, the first pitch of a relative expression is written as absolute. This mimics the behaviour of LilyPond >= 2.18. (In fact, the starting pitch is then assumed to be f.)
If False, the first pitch is written as relative to c’ (LilyPond < 2.18 behaviour).
Existing relative expressions are not changed.
ly.pitch.rel2abs module¶
Convert relative music to absolute music.
-
ly.pitch.rel2abs.
rel2abs
(cursor, language=u'nederlands', first_pitch_absolute=False)[source]¶ Converts pitches from relative to absolute.
language: language to start reading pitch names in
- first_pitch_absolute: if True, the first pitch of a relative expression
is regarded as absolute, when no starting pitch was given. This mimics the behaviour of LilyPond >= 2.18. (In fact, the starting pitch is then assumed to be f.)
If False, the starting pitch, when not given, is assumed to be c’ (LilyPond < 2.18 behaviour).
ly.pitch.translate module¶
Translating the language of pitch names
-
ly.pitch.translate.
insert_language
(document, language, version=None)[source]¶ Inserts a language command in the document.
The command is inserted at the top or just below the version line.
If the LilyPond version specified < (2, 13, 38), the include command is used, otherwise the newer language command.
-
ly.pitch.translate.
translate
(cursor, language, default_language=u'nederlands')[source]¶ Changes the language of the pitch names.
May raise ly.pitch.PitchNameNotAvailable if the current pitch language has no quarter tones.
Returns True if there also was a language or include language command that was changed. If not and the cursor specified only a part of the document, you could warn the user that a language or include command should be added to the document. Or you could call insert_language to add a language command to the top of the document.
ly.pitch.transpose module¶
Transposing music.
-
class
ly.pitch.transpose.
ModalTransposer
(numSteps=1, scaleIndex=0)[source]¶ Bases:
object
Transpose pitches by number of steps within a given scale.
Instantiate with the number of steps (+/-) in the scale to transpose by, and a mode index. The mode index is the index of the major scale in the circle of fifths (C Major = 0).
-
class
ly.pitch.transpose.
ModeShifter
(key, scale)[source]¶ Bases:
ly.pitch.transpose.Transposer
Shift pitches to optional mode/scale.
The scale should be formatted in analogy to the scale in the Transposer parent class.
The key should be an instance of ly.pitch.Pitch.
-
class
ly.pitch.transpose.
Simplifier
(scale=None)[source]¶ Bases:
ly.pitch.transpose.Transposer
Make complicated accidentals simpler by substituting naturals where possible.
-
class
ly.pitch.transpose.
Transposer
(fromPitch, toPitch, scale=None)[source]¶ Bases:
object
Transpose pitches.
Instantiate with a from- and to-Pitch, and optionally a scale. The scale 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.
-
scale
= (0, 1, 2, Fraction(5, 2), Fraction(7, 2), Fraction(9, 2), Fraction(11, 2))¶
-
-
ly.pitch.transpose.
transpose
(cursor, transposer, language=u'nederlands', relative_first_pitch_absolute=False)[source]¶ Transpose pitches using the specified transposer.
If relative_first_pitch_absolute is 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 relative_first_pitch_absolute is False, the first pitch in a relative expression is considered to be relative to c’, is no startpitch is given. This is LilyPond < 2.18 behaviour.
Currently, relative_first_pitch_absolute defaults to False.