pitchtypes.enharmonic.EnharmonicPitch

class pitchtypes.enharmonic.EnharmonicPitch(value)

Bases: Enharmonic, AbstractEnharmonicPitch, 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 enharmonic pitches according to enharmonic semitone ordering.

convert_to(other_type)

convert_to_logfreq()

create_subtypes()

embed()

For a pitch class, returns the corresponding pitch in a (type-dependent) default octave.

freq()

from_semitones(semitones)

Create a pitch by directly providing its internal semitone value.

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.

name([as_int, flat_sharp])

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

Check if sub_type follows the standard naming convention.

octaves()

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_name_from_midi(midi_pitch, ...)

Return the pitch class name for the given pitch in MIDI integer.

print_options([as_int, flat_sharp])

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.

steps()

Return the number of diatonic steps corresponding to the pitch.

to_class()

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

Attributes

midi

Return the MIDI number corresponding to the pitch.

Interval

alias of EnharmonicInterval

IntervalClass

alias of EnharmonicIntervalClass

Pitch

alias of EnharmonicPitch

PitchClass

alias of EnharmonicPitchClass

__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 enharmonic pitches according to enharmonic semitone 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 (EnharmonicPitch)

Returns:

-1 / 0 / 1 (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_semitones(semitones)

Create a pitch by directly providing its internal semitone value.

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

Parameters:

semitones – the number of semitones to move from C0

Returns:

the resulting pitch (EnharmonicPitch)

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

property midi

Return the MIDI number corresponding to the 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

static pitch_class_name_from_midi(midi_pitch, flat_sharp)

Return the pitch class name for the given pitch in MIDI integer. :type midi_pitch: :param midi_pitch: MIDI pitch :type flat_sharp: :param flat_sharp: whether to use flats or sharps for accidentals :return: pitch class

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