pitchtypes.spelled.SpelledPitch
- class pitchtypes.spelled.SpelledPitch(value)
Bases:
Spelled
,AbstractSpelledPitch
,AbstractPitch
Represents a spelled pitch.
- __init__(value)
Takes a string consisting of the form
<letter><accidentals?><octave>
, e.g."C#4"
,"E5"
, or"Db-2"
. Accidentals may be written as ASCII symbols (#/b) or with unicode symbols (♯/♭), but not mixed within the same note.- Parameters:
value – a string or internal numeric representation of the pitch
Methods
__init__
(value)Takes a string consisting of the form
<letter><accidentals?><octave>
, e.g."C#4"
,"E5"
, or"Db-2"
.Return the number of semitones by which the interval is altered from its perfect or major variant.
compare
(other)Comparison between two spelled pitches according to diatonic ordering.
convert_to
(other_type)create_subtypes
()degree
()Return the "relative scale degree" (0-6) to which the interval points (unison=0, 2nd=1, octave=0, 2nd down=6, etc.).
embed
()For a pitch class, returns the corresponding pitch in a (type-dependent) default octave.
fifths
()Return the position of the interval on the line of fifths.
from_fifths_and_octaves
(fifths, octaves)Create a pitch by directly providing its internal fifths and octaves.
from_independent
(fifths, octaves)Create a pitch from fifths (pitch class) and independent/external octaves (octave number).
from_onehot
(onehot, fifth_low, octave_low)Create a spelled pitch from a one-hot matrix.
Return the internal octave representation of a pitch, which is dependent on the fifths.
interval_class_from_fifths
(fifths[, inverse])Return the interval class corresponding to the given number of steps along the line of fifths.
interval_from
(other)Computes the interval from another pitch to this pitch.
interval_to
(other)Computes the interval from this pitch to another pitch.
letter
()Returns the letter associated with the pitch (without accidentals).
link_interval_class_type
([skip_name_check, ...])A decorator to link an interval class type to its base type.
link_interval_type
([skip_name_check, ...])A decorator to link an interval type to its base type.
link_pitch_class_type
([skip_name_check, ...])A decorator to link a pitch class type to its base type.
link_pitch_type
([skip_name_check, ...])A decorator to link a pitch type to its base type.
name
()The name of the pitch or interval in string notation
octaves
()For intervals, return the number of octaves the interval spans.
onehot
(fifth_range, octave_range[, dtype])Returns a one-hot encoding of the pitch in fifths (first dimension) and external octaves (second dimension).
parse_interval
(s)Parse a string as a spelled interval or spelled interval class.
parse_pitch
(s)Parse a string as a spelled pitch or spelled pitch class.
pc
()Returns the pitch class corresponding to the pitch.
pitch_class_from_fifths
(fifth_steps)Return the pitch class given the number of steps along the line of fifths
to_class
()Alias for pc(), but also supported by interval types.
- Interval
alias of
SpelledInterval
- IntervalClass
alias of
SpelledIntervalClass
- Pitch
alias of
SpelledPitch
- PitchClass
alias of
SpelledPitchClass
- __add__(other)
Returns the pitch transposed by an interval
- Parameters:
other – an interval of matching type
- Returns:
the pitch transposed by
other
- __eq__(other)
Return self==value.
- __ge__(other)
Return a >= b. Computed by @total_ordering from (not a < b).
- __getattr__(item)
This method is called when an attribute is not found in the instance’s __dict__. It allows to access the linked Pitch, Interval, PitchClass, and IntervalClass types via the base type.
- __gt__(other)
Return a > b. Computed by @total_ordering from (not a < b) and (a != b).
- __hash__ = None
- __le__(other)
Return a <= b. Computed by @total_ordering from (a < b) or (a == b).
- __lt__(other)
Return self<value.
- __repr__()
Return repr(self).
- __setattr__(key, value)
Implement setattr(self, name, value).
- __sub__(other)
When subtracting another pitch (p1 - p2), return the interval from p2 to p1. When subtracting an interval (p - i), transpose the pitch by the inverse interval (p + -i).
- Parameters:
other – pitch or interval
- Returns:
if
other
is an interval, the transposed pitch; ifother
is a pitch, the interval between both pitches
- __weakref__
list of weak references to the object
- alteration()
Return the number of semitones by which the interval is altered from its perfect or major variant. Positive alteration always indicates augmentation, negative alteration indicates diminution (minor or smaller) of the interval. For pitches, return the accidentals (positive=sharps, negative=flats, 0=natural).
- Returns:
alteration (integer)
- compare(other)
Comparison between two spelled pitches according to diatonic 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 (SpelledPitch)
- Returns:
-1
/0
/1
(integer)
- degree()
Return the “relative scale degree” (0-6) to which the interval points (unison=0, 2nd=1, octave=0, 2nd down=6, etc.). For pitches, return the integer that corresponds to the letter (C=0, D=1, …).
- Returns:
degree (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
- fifths()
Return the position of the interval on the line of fifths.
- Returns:
fifth position (integer)
- static from_fifths_and_octaves(fifths, octaves)
Create a pitch by directly providing its internal fifths and octaves.
Each pitch is represented relative to C0 by moving the specified number of fifths and octaves upwards (or downwards for negative values).
- Parameters:
fifths – the fifth (= pitch class) of the pitch (integer)
octaves – the internal/dependent octave of the pitch (integer)
- Returns:
the resulting pitch (SpelledPitch)
- static from_independent(fifths, octaves)
Create a pitch from fifths (pitch class) and independent/external octaves (octave number).
- Parameters:
fifths – the fifth (= pitch class) of the pitch (integer)
octaves – the external/independent octave of the pitch (integer)
- Returns:
the resulting pitch (SpelledPitch)
- static from_onehot(onehot, fifth_low, octave_low)
Create a spelled pitch from a one-hot matrix.
Requires the lower bounds of the fifth and octave range used by the one-hot matrix.
- Parameters:
onehot – a one-hot matrix representing the pitch (numpy array)
fifth_low – the lowest fifth expressible in the one-hot matrix
octave_low – the lowest octave expressible in the one-hot matrix
- Returns:
the resulting pitch (SpelledPitch)
- internal_octaves()
Return the internal octave representation of a pitch, which is dependent on the fifths.
Only use this if you know what you are doing.
- Returns:
internal/dependent octave (integer)
- interval_from(other)
Computes the interval from another pitch to this pitch.
- Parameters:
other – another pitch
- Returns:
the interval from other to self
- interval_to(other)
Computes the interval from this pitch to another pitch.
- Parameters:
other – another pitch
- Returns:
the interval from self to other
- letter()
Returns the letter associated with the pitch (without accidentals).
- Returns:
letter (single-character string)
- classmethod link_interval_class_type(skip_name_check=False, create_init=None, create_add=None, create_sub=None, create_mul=None, create_div=None, create_neg=None)
A decorator to link an interval class type to its base type. :type skip_name_check:
bool
:param skip_name_check: skip the name check and don’t raise :type create_init:Optional
[bool
] :param create_init: if True, create a default __init__ method :type create_add:Optional
[bool
] :param create_add: if True, create a default __add__ method :type create_sub:Optional
[bool
] :param create_sub: if True, create a default __sub__ method :type create_mul:Optional
[bool
] :param create_mul: if True, create a default __mul__ method :type create_div:Optional
[bool
] :param create_div: if True, create a default __truediv__ method :type create_neg:Optional
[bool
] :param create_neg: if True, create a default __neg__ method :meta private:
- classmethod link_interval_type(skip_name_check=False, create_init=None, create_add=None, create_sub=None, create_mul=None, create_div=None, create_neg=None, create_to_class=None)
A decorator to link an interval type to its base type. :type skip_name_check:
bool
:param skip_name_check: skip the name check and don’t raise :type create_init:Optional
[bool
] :param create_init: if True, create a default __init__ method :type create_add:Optional
[bool
] :param create_add: if True, create a default __add__ method :type create_sub:Optional
[bool
] :param create_sub: if True, create a default __sub__ method :type create_mul:Optional
[bool
] :param create_mul: if True, create a default __mul__ method :type create_div:Optional
[bool
] :param create_div: if True, create a default __truediv__ method :type create_neg:Optional
[bool
] :param create_neg: if True, create a default __neg__ method :type create_to_class:Optional
[bool
] :param create_to_class: if True, create a default to_class method :meta private:
- classmethod link_pitch_class_type(skip_name_check=False, create_init=None, create_add=None, create_sub=None)
A decorator to link a pitch class type to its base type. :type skip_name_check:
bool
:param skip_name_check: skip the name check and don’t raise :type create_init:Optional
[bool
] :param create_init: if True, create a default __init__ method :type create_add:Optional
[bool
] :param create_add: if True, create a default __add__ method :type create_sub:Optional
[bool
] :param create_sub: if True, create a default __sub__ method :return: a decorator that links the pitch class type to the base type :meta private:
- classmethod link_pitch_type(skip_name_check=False, create_init=None, create_add=None, create_sub=None, create_to_class=None)
A decorator to link a pitch type to its base type. :type skip_name_check:
bool
:param skip_name_check: skip the name check and don’t raise :type create_init:Optional
[bool
] :param create_init: if True, create a default __init__ method :type create_add:Optional
[bool
] :param create_add: if True, create a default __add__ method :type create_sub:Optional
[bool
] :param create_sub: if True, create a default __sub__ method :type create_to_class:Optional
[bool
] :param create_to_class: if True, create a default to_class method :meta private:
- name()
The name of the pitch or interval in string notation
- Returns:
the object’s notation name (string)
- octaves()
For intervals, return the number of octaves the interval spans. Negative intervals start with -1, decreasing. For pitches, return the absolute octave of the pitch.
- Returns:
external/independent octave (integer)
- onehot(fifth_range, octave_range, dtype=<class 'int'>)
Returns a one-hot encoding of the pitch in fifths (first dimension) and external octaves (second dimension). The range of fifths and octaves is given by
fifth_range
andoctave_range
respectively, where each is a pair(lower, upper)
.- Parameters:
fifth_range – the (inclusive) range of fifths (pair of integers)
octave_range – the (inclusive) range of octaves (pair of integers)
dtype – dtype of the resulting array
- Returns:
a one-hot matrix (numpy array)
- 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
- to_class()
Alias for pc(), but also supported by interval types.
- Returns:
the pitch class that corresponds to this pitch