pitchtypes.generic.GenericPitch

class pitchtypes.generic.GenericPitch(value)

Bases: Generic, AbstractGenericPitch, 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.

or the MIDI value (str or int) of the pitch.

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

compare(other)

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

from_steps(steps)

Create a pitch by directly providing its internal step value.

generic_interval_class_from_fifths(fifth_steps)

Return the generic interval class corresponding to the given number of fifths.

internal_octaves()

Return the internal octave representation of a pitch

interval_from(other)

Computes the interval from another pitch to this pitch.

interval_to(other)

Computes the interval from this pitch to another pitch.

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.

midi()

Return the MIDI number corresponding to the pitch.

name([as_int])

The name of the pitch or interval in string notation

name_check(cls, sub_type, suffix, ...)

Check if sub_type follows the standard naming convention.

octaves()

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

onehot()

Return a one-hot encoded tensor representing the object.

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

Return the pitch class given the number of steps

pitch_class_name_from_steps(step_pitch)

Return the pitch class name for the given pitch in steps, alias for pitch_class_from_diatonic_steps

print_options([as_int])

semitones()

Return the number of chromatic semitones corresponding to the pitch.

set_func_attr(sub_type, flags, names, funcs)

Add functions funcs as methods with names to class sub_type, controlled by flags.

to_class()

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

Attributes

steps

Return the position of the interval in diatonic steps.

Interval

alias of GenericInterval

IntervalClass

alias of GenericIntervalClass

Pitch

alias of GenericPitch

PitchClass

alias of GenericPitchClass

__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, NotImplemented=NotImplemented)

Return a >= b. Computed by @total_ordering from (not a < b).

__gt__(other, NotImplemented=NotImplemented)

Return a > b. Computed by @total_ordering from (not a < b) and (a != b).

__hash__ = None
__le__(other, NotImplemented=NotImplemented)

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

__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; if other is a pitch, the interval between both pitches

__weakref__

list of weak references to the object (if defined)

compare(other)

Comparison between two generic 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 (GenericPitch)

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

static from_steps(steps)

Create a pitch by directly providing its internal step value.

Each pitch is represented relative to C0 by moving the specified number of steps upwards (or downwards for negative values).

Parameters:

steps – the number of steps to move from C0

Returns:

the resulting pitch (GenericPitch)

internal_octaves()

Return the internal octave representation of a pitch

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

midi()

Return the MIDI number corresponding to the pitch.

name(as_int=None)

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

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)

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

static pitch_class_from_diatonic_steps(diatonic_steps)

Return the pitch class given the number of steps

Parameters:

diatonic_steps – number of diatonic steps

Returns:

pitch class (C, D, E, F, G, A, B)

static pitch_class_name_from_steps(step_pitch)

Return the pitch class name for the given pitch in steps, alias for pitch_class_from_diatonic_steps

Parameters:

step_pitch – step pitch

Returns:

pitch class

semitones()

Return the number of chromatic semitones corresponding to the pitch.

property steps

Return the position of the interval in diatonic steps.

Returns:

fifth position (integer)

to_class()

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

Returns:

the pitch class that corresponds to this pitch