Enharmonic Pitch
Note: This type is functional and tested, but it does not yet conform to the general API and the documentation is still incomplete.
Overview
Enharmonic pitches and intervals are specified in 12-TET semitones, with 60 as Middle C, as in the MIDI standard. Both enharmonic pitches and intervals can be represented by integers, However, we provides wrapper classes around int to distinguish the different interpretations as pitches and intervals (and their respective class variants). Enharmonic pitches can be easily created using the Enharmonic* constructors, all of which take integers.
constructor example |
printed representation |
---|---|
|
|
Reference
- class pitchtypes.Enharmonic(value, is_pitch, is_class, **kwargs)
- Interval
alias of
EnharmonicInterval
- IntervalClass
alias of
EnharmonicIntervalClass
- Pitch
alias of
EnharmonicPitch
- PitchClass
alias of
EnharmonicPitchClass
- compare(other)
Comparison between two enharmonic types.
Returns 0 if the objects are equal, 1 if the first object (
self
) is greater, and -1 if the second object (other
) is greater.This method can be indirectly used through binary comparison operators (including
==
,<
etc.).- Parameters:
other – an object to compare to (same type as
self
)- Returns:
-1
/0
/1
(integer)
- static pitch_class_name_from_midi(midi_pitch, flat_sharp)
Return the pitch class name for the given pitch in MIDI integer. :type midi_pitch: :param midi_pitch: MIDI pitch :type flat_sharp: :param flat_sharp: whether to use flats or sharps for accidentals :return: pitch class
- class pitchtypes.EnharmonicPitch(value)
- compare(other)
Comparison between two enharmonic pitches according to enharmonic semitone ordering.
Returns 0 if the objects are equal, 1 if the first pitch (
self
) is higher, and -1 if the second pitch (other
) is higher.This method can be indirectly used through binary comparison operators (including
==
,<
etc.).- Parameters:
other – a pitch to compare to (EnharmonicPitch)
- Returns:
-1
/0
/1
(integer)
- embed()
For a pitch class, returns the corresponding pitch in a (type-dependent) default octave. For non-class pitches, returns the pitch itself.
- Returns:
a non-class version of this pitch
- static from_semitones(semitones)
Create a pitch by directly providing its internal semitone value.
Each pitch is represented relative to C0 by moving the specified number of semitones upwards (or downwards for negative values).
- Parameters:
semitones – the number of semitones to move from C0
- Returns:
the resulting pitch (EnharmonicPitch)
- interval_from(other)
Computes the interval from another pitch to this pitch.
- Parameters:
other – another pitch
- Returns:
the interval from other to self
- property midi
Return the MIDI number corresponding to the pitch.
- pc()
Returns the pitch class corresponding to the pitch. For pitch classes, it returns the pitch class itself.
- Returns:
the pitch class that corresponds to this pitch
- semitones()
Return the number of chromatic semitones corresponding to the pitch.
- steps()
Return the number of diatonic steps corresponding to the pitch.
- to_class()
Alias for pc(), but also supported by interval types.
- Returns:
the pitch class that corresponds to this pitch
- class pitchtypes.EnharmonicInterval(value)
- classmethod chromatic_semitone()
Create a chromatic semitone.
- Returns:
a1:0
- compare(other)
Comparison between two enharmonic intervals according to enharmonic semitone ordering.
Returns 0 if the objects are equal, 1 if the first interval (
self
) is greater, and -1 if the second interval (other
) is greater.This method can be indirectly used through binary comparison operators (including
==
,<
etc.).- Parameters:
other – an interval to compare to (EnharmonicInterval)
- Returns:
-1
/0
/1
(integer)
- direction()
Returns the direction of the interval (1 = up, 0 = neutral, -1 = down). Only perfect unisons are considered neutral.
- Returns:
-1
/0
/1
(integer)
- embed()
For interval classes, return an embedding into the interval space in a (type-dependent) default octave. For non-class intervals, return the interval itself.
- Returns:
a non-class version of this interval
- static from_semitones(semitones)
Create an interval by directly providing its internal semitone value.
- Parameters:
semitones – the semitones (= interval class) of the interval (integer)
- Returns:
the resulting interval (EnharmonicInterval)
- ic()
Return the interval class that corresponds to this interval. If the interval is already an interval class, it is returned itself.
- Returns:
the interval’s corresponding interval class
- classmethod octave()
Create a perfect octave.
- Returns:
P1:1
- semitones()
Return the number of semitones corresponding to the interval.
- steps()
Return the number of diatonic steps corresponding to the interval.
- to_class()
Alias for ic(), but also supported by pitch types.
- Returns:
the interval’s corresponding interval class
- classmethod unison()
Create a perfect unison.
- Returns:
P1:0
- class pitchtypes.EnharmonicPitchClass(value)
- compare(other)
Comparison between two enharmonic pitch classes according to enharmonic semitone ordering.
Returns 0 if the objects are equal, 1 if the first pitch class (
self
) is higher, and -1 if the second pitch class (other
) is higher.This method can be indirectly used through binary comparison operators (including
==
,<
etc.).- Parameters:
other – a pitch class to compare to (EnharmonicPitchClass)
- Returns:
-1
/0
/1
(integer)
- embed()
For a pitch class, returns the corresponding pitch in a (type-dependent) default octave. For non-class pitches, returns the pitch itself.
- Returns:
a non-class version of this pitch
- interval_from(other)
Computes the interval from another pitch to this pitch.
- Parameters:
other – another pitch
- Returns:
the interval from other to self
- midi()
Return the MIDI value of the pitch class, a value in the range [0, 11].
- pc()
Returns the pitch class corresponding to the pitch. For pitch classes, it returns the pitch class itself.
- Returns:
the pitch class that corresponds to this pitch
- semitones()
Equivalent to the MIDI value of the pitch class.
- steps()
Return the number of diatonic steps corresponding to the pitch.
- class pitchtypes.EnharmonicIntervalClass(value)
- classmethod chromatic_semitone()
Return a chromatic semitone
- Returns:
a1
- compare(other)
Comparison between two enharmonic interval classes according to enharmonic semitone ordering.
Returns 0 if the objects are equal, 1 if the first interval class (
self
) is greater, and -1 if the second interval class (other
) is greater.This method can be indirectly used through binary comparison operators (including
==
,<
etc.).- Parameters:
other – an interval class to compare to (EnharmonicIntervalClass)
- Returns:
-1
/0
/1
(integer)
- direction()
Returns the direction of the interval (1 = up, 0 = neutral, -1 = down). Only perfect unisons are considered neutral.
- Returns:
-1
/0
/1
(integer)
- embed()
For interval classes, return an embedding into the interval space in a (type-dependent) default octave. For non-class intervals, return the interval itself.
- Returns:
a non-class version of this interval
- static from_semitones(semitones)
Create an interval class by directly providing its internal semitones.
- Parameters:
semitones – the semitones (= interval class) of the interval (integer)
- Returns:
the resulting interval class (EnharmonicIntervalClass)
- ic()
Return the interval class that corresponds to this interval. If the interval is already an interval class, it is returned itself.
- Returns:
the interval’s corresponding interval class
- classmethod octave()
Create the octave interval of this type.
- Returns:
an octave interval
- semitones()
Return the number of semitones corresponding to the interval.
- steps()
Return the number of diatonic steps corresponding to the interval.
- classmethod unison()
Return a perfect unison.
- Returns:
P1