pitchtypes.generic.GenericInterval
- class pitchtypes.generic.GenericInterval(value)
Bases:
Generic
,AbstractGenericInterval
,Interval
,Diatonic
- __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
Methods
__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.abs
()For downward intervals, return their upward counterpart, otherwise just return the interval itself.
compare
(other)Comparison between two generic intervals 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.).
Create a chromatic semitone.
Returns the direction of the interval (1 = up, 0 = neutral, -1 = down).
embed
()For interval classes, return an embedding into the interval space in a (type-dependent) default octave.
from_steps
(steps)Create an interval 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.
ic
()Return the interval class that corresponds to this interval.
Return the internal octave representation of a pitch
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
()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.octave
()Create a perfect octave.
octaves
()For intervals, return the number of octaves the interval spans.
onehot
()Return a one-hot encoded tensor representing the object.
parse_interval
(s)Parse a string as a spelled interval or spelled interval class.
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])Return the number of semitones corresponding to the interval.
set_func_attr
(sub_type, flags, names, funcs)Add functions
funcs
as methods withnames
to classsub_type
, controlled byflags
.steps
()Return the step value of the interval, a value in the range [-6, 6].
to_class
()Alias for ic(), but also supported by pitch types.
unison
()Create a perfect unison.
- Interval
alias of
GenericInterval
- IntervalClass
alias of
GenericIntervalClass
- Pitch
alias of
GenericPitch
- PitchClass
alias of
GenericPitchClass
- __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, 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.
- __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).
- __str__()
Return str(self).
- __sub__(other)
Returns the difference of two intervals.
- __weakref__
list of weak references to the object (if defined)
- abs()
For downward intervals, return their upward counterpart, otherwise just return the interval itself.
- Returns:
the absolute interval
- compare(other)
Comparison between two generic 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 (GenericInterval)
- 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)
- classmethod diatonic_step()
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)
- 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
- static from_steps(steps)
Create an interval by directly providing its internal step value.
- Parameters:
steps – the steps (= interval class) of the interval (integer)
- Returns:
the resulting interval (GenericInterval)
- 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
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)
- name()
The name of the pitch or interval in string notation
- Returns:
the object’s notation name (string)
- classmethod octave()
Create a perfect octave.
- Returns:
P1:1
- 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)
- 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 semitones corresponding to the interval.
- steps()
Return the step value of the interval, a value in the range [-6, 6].
- to_class()
Alias for ic(), but also supported by pitch types.
- Returns:
the interval’s corresponding interval class
- classmethod unison()
Create a perfect unison.
- Returns:
P1:0