pitchtypes.spelled_array.SpelledPitchClassArray
- class pitchtypes.spelled_array.SpelledPitchClassArray(fifths)
Bases:
SpelledArray
,AbstractSpelledArrayPitch
,Pitch
Represents a spelled pitch class, i.e. a pitch without octave information.
- __init__(fifths)
Takes a numpy array of fifths as integers.
- Parameters:
fifths – the internal fifths of each pitch class (numpy array of integers)
Methods
__init__
(fifths)Takes a numpy array of fifths as integers.
Return the number of semitones by which the interval is altered from its the perfect or major variant.
array_equal
(other)Returns True if self and other are the equal, False otherwise.
compare
(other)Element-wise comparison between two spelled arrays.
copy
()Returns a shallow copy of the array.
deepcopy
()Returns a deep copy of the array.
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_array
(pitches)Create an pitch class array from an array of pitch classes.
from_onehot
(onehot, fifth_low)Create a spelled pitch-class array from a one-hot tensor.
from_strings
(strings)Create a pitch-class array from an array of strings.
Return the internal octave representation of a pitch, which is dependent on the 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).
midi
()Return the MIDI number corresponding to the pitch.
name
()Returns the names of the objects in the array as an array of strings of the same shape.
octaves
()For intervals, return the number of octaves the interval spans.
onehot
(fifth_range[, dtype])Returns a one-hot encoding of the pitch classes in fifths as the innermost dimension.
parse_pitch
(s)Parse a string as a spelled pitch or spelled pitch class.
pc
()Returns the pitch class corresponding to the pitch.
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.
- __add__(other)
Returns the pitch transposed by an interval
- Parameters:
other – an interval of matching type
- Returns:
the pitch transposed by
other
- __contains__(item)
Returns true if the array contains the given interval/pitch.
- Parameters:
item – the potential item to test
- Returns:
True
if the array containsitem
, otherwiseFalse
- __eq__(other)
Element-wise
<=
between two spelled arrays.- Parameters:
other – the spelled array or scalar to compare to
- Returns:
a boolean array that indicates where this array is
== other
- __ge__(other)
Element-wise
>=
between two spelled arrays.- Parameters:
other – the spelled array or scalar to compare to
- Returns:
a boolean array that indicates where this array is
>= other
- __getitem__(index)
Returns an item or a subarray of the spelled array. Supports advanced indexing as on numpy arrays.
- Parameters:
index – a numpy-compatible index into the array
- Returns:
a new array or a scalar value (depending on the index)
- __gt__(other)
Element-wise
>
between two spelled arrays.- Parameters:
other – the spelled array or scalar to compare to
- Returns:
a boolean array that indicates where this array is
> other
- __hash__ = None
- __le__(other)
Element-wise
<=
between two spelled arrays.- Parameters:
other – the spelled array or scalar to compare to
- Returns:
a boolean array that indicates where this array is
<= other
- __len__()
Returns the length of the array (first dimension, as in numpy).
- Returns:
the length of the array (1st dimension, integer)
- __lt__(other)
Element-wise
<
between two spelled arrays.- Parameters:
other – the spelled array or scalar to compare to
- Returns:
a boolean array that indicates where this array is
< other
- __ne__(other)
Element-wise
<=
between two spelled arrays.- Parameters:
other – the spelled array or scalar to compare to
- Returns:
a boolean array that indicates where this array is
!= other
- __repr__()
Return repr(self).
- __setitem__(index, item)
Sets the given indices to the given item(s). Supports advanced indexing as on numpy arrays.
- Parameters:
index – a numpy-compatible index into the array
item – an array or a scalar to assign to the indicated sub-array
- __str__()
Return str(self).
- __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 (if defined)
- alteration()
Return the number of semitones by which the interval is altered from its the perfect or major variant. Positive alteration always indicates augmentation, negative alteration indicates diminution (minor or smaller) of the interval’s magnitude. For interval classes, alteration refers to the upward version of the interval (e.g. for
m7
/-M2
it is -1). For pitches, return the accidentals (positive=sharps, negative=flats, 0=natural).- Returns:
an array of alterations (integers)
- array_equal(other)
Returns True if self and other are the equal, False otherwise.
- Parameters:
other – another spelled array of the same type
- Returns:
True
if the two arrays are equal,False
otherwise
- compare(other)
Element-wise comparison between two spelled arrays.
Returns 0 where the elements are equal, 1 where the first element is greater, and -1 where the second element is greater.
Spelled pitch classes use line-of-fifth ordering, for example
Bb < F < C < G < D
.This method can be indirectly used through binary comparison operators (including
==
,<
etc.). To test the overall equality of two spelled arrays, usearray_equal
- Parameters:
other – another
SpelledPitchClassArray
orSpelledPitchClass
- Returns:
an array of
-1
/0
/1
(integer)
- copy()
Returns a shallow copy of the array. This also creates copies of the underlying numpy arrays.
- Returns:
a copy of the array
- deepcopy()
Returns a deep copy of the array.
- Returns:
a deepcopy of the array
- 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:
an array of degrees (integers)
- 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:
an array of fifths (integers)
- static from_array(pitches)
Create an pitch class array from an array of pitch classes.
- Parameters:
intervals – an array-like of
SpelledPitchClass
- Returns:
the corresponding pitch-class array
- static from_onehot(onehot, fifth_low)
Create a spelled pitch-class array from a one-hot tensor.
fifth_low
denotes the lower bound of the fifth range used in the vector. The shape of the resulting array will be equivalent to the first n-1 dimensions of the input tensor.- Parameters:
onehot – a one-hot tensor representing the pitch classes (numpy array)
fifth_low – the lowest fifth expressible in the one-hot tensor (integer)
- Returns:
the corresponding pitch-class array
- static from_strings(strings)
Create a pitch-class array from an array of strings.
- Parameters:
strings – an array-like of pitch-class notation strings
- Returns:
the corresponding pitch-class array
- 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:
an array of internal/dependent octaves (integers)
- 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:
an array of pitch letters (single-character strings)
- midi()
Return the MIDI number corresponding to the pitch.
- name()
Returns the names of the objects in the array as an array of strings of the same shape.
- Returns:
an array of notation strings
- 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:
an array of external/independent octaves (integers)
- onehot(fifth_range, dtype=<class 'int'>)
Returns a one-hot encoding of the pitch classes in fifths as the innermost dimension. The range of fifths is given by
fifth_range
as a tuple(lower, upper)
. The outer shape of the output tensor is identical to the shape of the original array, so the resulting shape isoriginal_shape + (n_fifths,)
.- Parameters:
fifth_range – the (inclusive) range of fifths (pair of integers)
dtype – dtype of the resulting array (default:
int
)
- Returns:
a one-hot tensor (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
- 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