pitchtypes.spelled_array.SpelledArray

class pitchtypes.spelled_array.SpelledArray

Bases: ABC

A common base class for vectorized spelled pitch and interval types. Uses the same interface as the Spelled types.

__init__()

Methods

__init__()

alteration()

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.).

fifths()

Return the position of the interval on the line of fifths.

from_onehot()

internal_octaves()

Return the internal octave representation of a pitch, which is dependent on the fifths.

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()

Return a one-hot encoded tensor representing the elements of the array.

abstract __contains__(item)

Returns true if the array contains the given interval/pitch.

Parameters:

item – the potential item to test

Returns:

True if the array contains item, otherwise False

__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

abstract __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

abstract __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).

abstract __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).

__weakref__

list of weak references to the object (if defined)

abstract 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

abstract 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.

The respective ordering differs between types. Non-class pitches and intervals use diatonic ordering, interval/pitch classes use line-of-fifths ordering.

This method can be indirectly used through binary comparison operators (including ==, < etc.). To test the overall equality of two spelled arrays, use array_equal

Parameters:

other – another spelled array or scalar

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)

abstract fifths()

Return the position of the interval on the line of fifths.

Returns:

an array of fifths (integers)

abstract 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)

abstract 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

abstract 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)

abstract onehot()

Return a one-hot encoded tensor representing the elements of the array. Specialized versions of this method take ranges for their respective dimensions.

Returns:

a one-hot tensor for the array