pitchtypes.spelled.SpelledIntervalClass

class pitchtypes.spelled.SpelledIntervalClass(value)

Bases: Spelled, AbstractSpelledInterval, AbstractInterval, Diatonic, Chromatic

Represents a spelled interval class, i.e. an interval without octave information.

__init__(value)

Takes a string consisting of the form -?<quality><generic-size>, e.g. "M6", "-m3", or "aa2", which stand for a major sixth, a minor third down (= major sixth up), and a double-augmented second, respectively. Possible qualities are d (diminished), m (minor), M (major), P (perfect), and a (augmented), where d and a can be repeated.

Parameters:

value – a string or internal numeric representation of the interval class

Methods

__init__(value)

Takes a string consisting of the form -?<quality><generic-size>, e.g. "M6", "-m3", or "aa2", which stand for a major sixth, a minor third down (= major sixth up), and a double-augmented second, respectively.

abs()

For downward intervals, return their upward counterpart, otherwise just return the interval itself.

alteration()

Return the number of semitones by which the interval is altered from its perfect or major variant.

chromatic_semitone()

Return a chromatic semitone

compare(other)

Comparison between two spelled interval classes according to line-of-fifth.

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

diatonic_steps()

Return the diatonic steps of the interval (unison=0, 2nd=1, ..., octave=7, ...).

direction()

Returns the direction of smallest realization of the interval class (1 = up, 0 = neutral, -1 = down).

embed()

For interval classes, return an embedding into the interval space in a (type-dependent) default octave.

fifths()

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

from_fifths(fifths)

Create an interval class by directly providing its internal fifths.

from_onehot(onehot, fifth_low)

Create a spelled interval class from a one-hot vector.

generic()

Return the generic interval, i.e. the number of diatonic steps modulo octave.

ic()

Return the interval class that corresponds to this interval.

internal_octaves()

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.

is_step()

Return True if the interval is considered a step, False otherwise.

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([inverse])

The name of the pitch or interval in string notation

octave()

Return a perfect unison, which is the same as an octave for interval classes.

octaves()

For intervals, return the number of octaves the interval spans.

onehot(fifth_range[, dtype])

Returns a one-hot encoding of the interval class in fifths.

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.

pitch_class_from_fifths(fifth_steps)

Return the pitch class given the number of steps along the line of fifths

to_class()

Alias for ic(), but also supported by pitch types.

unison()

Return a perfect unison.

Interval

alias of SpelledInterval

IntervalClass

alias of SpelledIntervalClass

Pitch

alias of SpelledPitch

PitchClass

alias of SpelledPitchClass

__abs__()

For downward intervals, return their upward counterpart, otherwise just return the interval itself.

__add__(other)

Returns the sum of two intervals.

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

__mul__(other)

Returns an integer multiple of the interval.

__neg__()

Returns the inversion of the interval (same size in the other direction).

__repr__()

Return repr(self).

__rmul__(other)

Returns an integer multiple of the interval.

__setattr__(key, value)

Implement setattr(self, name, value).

__sub__(other)

Returns the difference of two intervals.

__weakref__

list of weak references to the object

abs()

For downward intervals, return their upward counterpart, otherwise just return the interval itself.

Returns:

the absolute interval

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)

classmethod chromatic_semitone()

Return a chromatic semitone

Returns:

a1

compare(other)

Comparison between two spelled interval classes according to line-of-fifth.

Returns 0 if the interval classes are equal, 1 if the first interval class (self) is greater (“sharper”), and -1 if the second interval class (other) is greater (“sharper”).

This method can be indirectly used through binary comparison operators (including ==, < etc.).

Parameters:

other – an interval class to compare to (SpelledIntervalClass)

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)

diatonic_steps()

Return the diatonic steps of the interval (unison=0, 2nd=1, …, octave=7, …). Respects both direction and octaves.

Returns:

number of diatonic steps (integer)

direction()

Returns the direction of smallest realization of the interval class (1 = up, 0 = neutral, -1 = down). For example, the direction of M7 (= m2) is down.

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

fifths()

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

Returns:

fifth position (integer)

static from_fifths(fifths)

Create an interval class by directly providing its internal fifths.

Parameters:

fifths – the line-of-fifths position of the interval class (integer)

Returns:

the resulting interval class (SpelledIntervalClass)

static from_onehot(onehot, fifth_low)

Create a spelled interval class from a one-hot vector.

Requires the lower bounds of the fifth range used by the one-hot vector.

Parameters:
  • onehot – a one-hot vector representing the interval (numpy array)

  • fifth_low – the lowest fifth expressible in the one-hot vector

Returns:

the resulting interval class (SpelledIntervalClass)

generic()

Return the generic interval, i.e. the number of diatonic steps modulo octave. Unlike degree(), the result respects the sign of the interval (unison=0, 2nd up=1, 2nd down=-1).

Returns:

generic interval (integer)

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

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)

is_step()

Return True if the interval is considered a step, False otherwise.

Returns:

the stepness of the interval (boolean)

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:

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:

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:

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(inverse=False)

The name of the pitch or interval in string notation

Returns:

the object’s notation name (string)

classmethod octave()

Return a perfect unison, which is the same as an octave for interval classes.

Returns:

P1

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, dtype=<class 'int'>)

Returns a one-hot encoding of the interval class in fifths. The range of fifths is given by fifth_range as a tuple (lower, upper).

Parameters:
  • fifth_range – the (inclusive) range of fifths (pair of integers)

  • dtype – dtype of the resulting array

Returns:

a one-hot vector (numpy array)

to_class()

Alias for ic(), but also supported by pitch types.

Returns:

the interval’s corresponding interval class

classmethod unison()

Return a perfect unison.

Returns:

P1