Spelled Pitch

Overview

Spelled pitches and intervals are the standard types of the Western music notation system. Unlike MIDI pitches, spelled pitches distinguish between enharmonically equivalent pitches such as E♭ and D♯. Similarly, spelled intervals distinguish between intervals such as m3 (minor 3rd) and a2 (augmented second) that would be equivalent in the MIDI system.

You can construct spelled pitches and intervals by calling the constructor of a class on a string representation of a pitch or interval. Spelled pitch classes are represented by an uppercase letter followed by zero or more accidentals, which can be either written as b/# or as ♭/♯. Spelled pitches take an additional octave number after the letter and the accidentals.

>>> from pitchtypes import *
>>> SpelledPitchClass("Eb")
Eb
>>> SpelledPitch("Eb4")
Eb4

Spelled interval classes consist of one or more letters that indicate the quality of the interval and a number between 1 and 7 that indicates the generic interval, e.g. P1 for a perfect unison, m3 for a minor 3rd or aa4 for a double augmented 4th.

letter

quality

dd…

diminished multiple times

d

diminished

m

minor

P

perfect

M

major

a

augmented

aa…

augmented multiple times

Spelled intervals have the same elements as intervals but additionally take a number of octaves, written a suffix :n, e.g. P1:0 or m3:20. By default, intervals are directed upwards. Downwards intervals are indicated by a negative sign, e.g. -M2:1 (a major 9th down). For interval classes, downward and upward intervals cannot be distinguish, so a downward interval is represented by its complementary upward interval:

>>> -SpelledIntervalClass("M3")
m6
>>> SpelledIntervalClass("-M3")
m6

Working with Spelled Intervals

Fifths and Octaves

Internally, spelled intervals are represented by, 5ths and octaves. Both dimensions are logically dependent: a major 2nd up is represented by going two 5ths up and one octave down.

>>> SpelledInterval.from_fifths_and_octaves(2,-1) # two 5ths, one octave
M2:0

This representation is convenient for arithmetics, which can usually be done component-wise. However, special care needs to be taken when converting to other representations. For example, the notated octave number (e.g. :0 in i"M2:0") does not correspond to the internal octaves of the interval (-1 in this case). In the notation, the interval class (M2) and the octave (:0) are independent.

Interpreting the “internal” (or dependent) octave dimension of the interval does not make much sense without looking at the fifths. Therefore, the function octaves returns the “external” (or independent) octaves as used in the string representation, e.g.

>>> SpelledInterval("M2:0").octaves()
0
>>> SpelledInterval("M2:1").octaves()
1
>>> SpelledInterval("-M2:0").octaves()
-1

If you want to look at the internal octaves, use internal_octaves.

Diatonic Steps and Alterations

We provide a number of convenience functions to derive other properties from this representation. The generic interval (i.e. the number of diatonic steps) can be obtained using generic. generic respects the direction of the interval but is limitied to a single octave (0 to ±6). If you need the total number of diatonic steps, including octaves, use diatonic_steps. The method degree returns the scale degree implied by the interval relative to some root. Since scale degrees are always above the root, degree treats negative intervals like their positive complements, expressing the interval as a diatonic scale degree (I = 0, II = 1, …):

>>> SpelledInterval("-M3:1").generic() # some kind of 3rd down
-2
>>> SpelledInterval("-M3:1").diatonic_steps() # a 10th down
-9
>>> SpelledInterval("-M3:1").degree() # scale degree VI
5

For interval classes, all three functions are equivalent. Note that all three count from 0 (for unison/I), not 1.

Complementary to the generic interval methods, alteration returns the specific quality of the interval. For perfect or major intervals, it returns 0. Larger absolute intervals return positive values, smaller intervals return negative values. For interval classes, alteration always refers to the upward interval, just like degree:

>>> SpelledIntervalClass("-M3")
m6
>>> SpelledIntervalClass("-M3").degree() # VI
5
>>> SpelledIntervalClass("-M3").alteration()
-1

degree and alteration also work on pitches. degree(p) returns an integer corresponding to the letter (C=0, D=1, …), while alteration(p) provides the accidentals (natural=0, sharps -> positive, flats -> negative). For convenience, letter returns the letter as an uppercase character.

>>> SpelledPitch("Dbb4").degree()
1
>>> SpelledPitch("Dbb4").alteration()
-2

Ordering

Spelled intervals and pitches can be compared through binary comparison operators (==, <, etc.) or through the compare method.

Non-class intervals/pitches have a meaningful diatonic ordering, that goes by the diatonic step (or note name + octave) first and by alteration second:

P4:0 < a4:0 < aaaa4:0 < dddd5:0 < d5:0 < P5:0
F4   < F#4  < F####4  < Gbbbb4  < Gb4  < G4

Interval/pitch classes are circular in their diatonic ordering, so a line-of-fifths ordering is used instead:

m7 < P4 < P1 < P5 < M2
Bb < F  < C  < G  < D

Examples:

>>> sorted(map(SpelledInterval, ["P5:0", "d5:0", "dddd5:0", "aaaa4:0", "a4:0", "P4:0"]))
[P4:0, a4:0, aaaa4:0, dddd5:0, d5:0, P5:0]
>>> SpelledIntervalClass("P4") < SpelledIntervalClass("P1") # LoF ordering
True
>>> SpelledPitchClass("Eb").compare(SpelledPitchClass("D#")) # Eb < D# (LoF)
-1

One-hot Encoding

Spelled types support conversion to and from one-hot vectors. Pitch and interval classes are one-dimensional and are expressed on a segment of the line of fifths. When converting to one-hot vectors, the LoF range must be provided as a tuple (lower, upper), where the range includes both bounds. When converting back from a one-hot vector only the lower bound is required:

>>> SpelledIntervalClass("M7").onehot(fifth_range=(-7,7))
array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0])
>>> SpelledPitchClass.from_onehot(np.array([0, 0, 0, 1, 0]), -2)
G

Non-class intervals and pitches are two dimensional and are thus encoded in a one-hot matrix. The first dimension corresponds to the line of fifths (as for classes), the second dimension corresponds to independent octaves. Both ranges must be provided as (lower, upper) tuples (inclusive) for encoding while only the lower bounds are required for decoding:

>>> SpelledInterval("M2:0").onehot((-3,3), (-1,1))
array([[0, 0, 0],
       [0, 0, 0],
       [0, 0, 0],
       [0, 0, 0],
       [0, 0, 0],
       [0, 1, 0],
       [0, 0, 0]])
>>> SpelledPitch.from_onehot(np.array([[0,0,0],
...                                    [0,0,0],
...                                    [0,0,0],
...                                    [1,0,0],
...                                    [0,0,0]]), -2, 3)
G3

In the above example, the interval M2:0 (fifth = 2, independent octaves = 0) is encoded with the fifths dimension (1st dimension, 7 entries) ranging from -3 (m3) to 3 (M6) and an octave dimension (2nd, 3 entries) ranging from -1 to 1. The pitch G3 (fifths = 2, independent octaves = 3) is encoded with fifths dimension (5 entries) ranging from -2 (Bb) to 2 (D) and the octaves dimension (3 entries) ranging from 3 to 5.

M2:0 (f=2, o=0)

0  0  0  -3
0  0  0  -2
0  0  0  -1
0  0  0   0 fifth
0  0  0   1
0  1  0   2
0  0  0   3

-1 0  1
octave

G3 (f=1, o=3)

0  0  0  -2
0  0  0  -1
0  0  0   0 fifth
1  0  0   1
0  0  0   2

3  4  5
octave

Reference

General Interface

class pitchtypes.Spelled(value, is_pitch, is_class, **kwargs)

A common base class for spelled pitch and interval types. See below for a set of common operations.

name()

The name of the pitch or interval in string notation

Returns:

the object’s notation name (string)

compare(other)

Comparison between two spelled 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.

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

Parameters:

other – an object to compare to (same type as self)

Returns:

-1 / 0 / 1 (integer)

fifths()

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

Returns:

fifth position (integer)

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)

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)

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)

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. For pitches, return the accidentals (positive=sharps, negative=flats, 0=natural).

Returns:

alteration (integer)

onehot()

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

Returns:

one-hot encoding of the object (numpy array)

Interval

alias of SpelledInterval

IntervalClass

alias of SpelledIntervalClass

Pitch

alias of SpelledPitch

PitchClass

alias of SpelledPitchClass

Spelled Interval and Pitch

class pitchtypes.SpelledInterval(string)

Represents a spelled interval.

semitones()

Return the number of semitones corresponding to the interval.

steps()

Return the number of diatonic steps corresponding to the interval.

__init__(value)

Takes a string consisting of the form -?<quality><generic-size>:<octaves>, e.g. "M6:0", "-m3:0", or "aa2:1", which stand for a major sixth, a minor third down, and a double-augmented ninth, 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

static from_fifths_and_octaves(fifths, octaves)

Create an interval by directly providing its internal fifths and octaves.

Parameters:
  • fifths – the fifths (= interval class) of the interval (integer)

  • octaves – the internal/dependent octaves of the interval (integer)

Returns:

the resulting interval (SpelledInterval)

static from_independent(fifths, octaves)

Create an interval from fifths (interval class) and independent/external octaves.

Parameters:
  • fifths – the fifth (= interval class) of the interval (integer)

  • octaves – the external/independent octaves the interval spans (integer)

Returns:

the resulting interval (SpelledInterval)

static from_onehot(onehot, fifth_low, octave_low)

Create a spelled interval 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 interval (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 interval (SpelledInterval)

classmethod unison()

Create a perfect unison.

Returns:

P1:0

classmethod octave()

Create a perfect octave.

Returns:

P1:1

classmethod chromatic_semitone()

Create a chromatic semitone.

Returns:

a1:0

direction()

Returns the direction of the interval (1 = up, 0 = neutral, -1 = down). Only perfect unisons are considered neutral.

Returns:

-1 / 0 / 1 (integer)

to_class()

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

Returns:

the interval’s corresponding interval class

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

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

is_step()

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

Returns:

the stepness of the interval (boolean)

name()

The name of the pitch or interval in string notation

Returns:

the object’s notation name (string)

compare(other)

Comparison between two spelled intervals according to diatonic ordering.

Returns 0 if the intervals 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 (SpelledInterval)

Returns:

-1 / 0 / 1 (integer)

fifths()

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

Returns:

fifth position (integer)

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)

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)

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)

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)

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. For pitches, return the accidentals (positive=sharps, negative=flats, 0=natural).

Returns:

alteration (integer)

onehot(fifth_range, octave_range, dtype=<class 'int'>)

Returns a one-hot encoding of the interval in fifths (first dimension) and independent octaves (second dimension). The range of fifths and octaves is given by fifth_range and octave_range respectively, where each is a tuple (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)

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.

Returns:

the absolute interval

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)

class pitchtypes.SpelledPitch(string)

Represents a spelled pitch.

semitones()

Return the number of chromatic semitones corresponding to the pitch.

steps()

Return the number of diatonic steps corresponding to the pitch.

midi()

Return the MIDI value, in the interval [0,127].

Returns:

MIDI value (integer)

__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

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)

interval_from(other)

Computes the interval from another pitch to this pitch.

Parameters:

other – another pitch

Returns:

the interval from other to self

to_class()

Alias for pc(), but also supported by interval types.

Returns:

the pitch class that corresponds to this 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

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

name()

The name of the pitch or interval in string notation

Returns:

the object’s notation name (string)

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)

fifths()

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

Returns:

fifth position (integer)

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)

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)

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. For pitches, return the accidentals (positive=sharps, negative=flats, 0=natural).

Returns:

alteration (integer)

letter()

Returns the letter associated with the pitch (without accidentals).

Returns:

letter (single-character string)

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 and octave_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)

Interval

alias of SpelledInterval

IntervalClass

alias of SpelledIntervalClass

Pitch

alias of SpelledPitch

PitchClass

alias of SpelledPitchClass

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)

interval_to(other)

Computes the interval from this pitch to another pitch.

Parameters:

other – another pitch

Returns:

the interval from self to other

Spelled Interval and Pitch Class

class pitchtypes.SpelledIntervalClass(string)

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

semitones()

Return the number of semitones corresponding to the interval.

steps()

Return the number of diatonic steps corresponding to the interval.

__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

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

classmethod unison()

Return a perfect unison.

Returns:

P1

classmethod octave()

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

Returns:

P1

classmethod chromatic_semitone()

Return a chromatic semitone

Returns:

a1

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)

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

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

is_step()

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

Returns:

the stepness of the interval (boolean)

name(inverse=False)

The name of the pitch or interval in string notation

Returns:

the object’s notation name (string)

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)

fifths()

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

Returns:

fifth position (integer)

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)

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)

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)

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)

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. For pitches, return the accidentals (positive=sharps, negative=flats, 0=natural).

Returns:

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

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.

Returns:

the absolute interval

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)

to_class()

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

Returns:

the interval’s corresponding interval class

class pitchtypes.SpelledPitchClass(string)

Represents a spelled pitch class, i.e. a pitch without octave information.

semitones()

Return the number of chromatic semitones corresponding to the pitch.

steps()

Return the number of diatonic steps corresponding to the pitch.

midi()

Return the MIDI number of the pitch class, in the interval [0,11].

Returns:

MIDI number (integer)

__init__(value)

Takes a string consisting of the form <letter><accidentals?>, e.g. "C#", "E", or "Dbb". 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 class

static from_fifths(fifths)

Create a pitch class by directly providing its position on the line of fifths (C=0, G=1, D=2, …).

Parameters:

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

Returns:

the resulting pitch class (SpelledPitchClass)

static from_onehot(onehot, fifth_low)

Create a spelled pitch 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 pitch (numpy array)

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

Returns:

the resulting pitch class (SpelledPitchClass)

interval_from(other)

Computes the interval from another pitch to this pitch.

Parameters:

other – another pitch

Returns:

the interval from other to self

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

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

name()

The name of the pitch or interval in string notation

Returns:

the object’s notation name (string)

compare(other)

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

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

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

Parameters:

other – a pitch class to compare to (SpelledPitchClass)

Returns:

-1 / 0 / 1 (integer)

fifths()

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

Returns:

fifth position (integer)

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)

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)

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. For pitches, return the accidentals (positive=sharps, negative=flats, 0=natural).

Returns:

alteration (integer)

letter()

Returns the letter associated with the pitch (without accidentals).

Returns:

letter (single-character string)

onehot(fifth_range, dtype=<class 'int'>)

Returns a one-hot encoding of the pitch 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)

Interval

alias of SpelledInterval

IntervalClass

alias of SpelledIntervalClass

Pitch

alias of SpelledPitch

PitchClass

alias of SpelledPitchClass

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)

interval_to(other)

Computes the interval from this pitch to another pitch.

Parameters:

other – another pitch

Returns:

the interval from self to other

to_class()

Alias for pc(), but also supported by interval types.

Returns:

the pitch class that corresponds to this pitch