ChordType

ChordType(
    tones: Iterable[TonalVector],
    name: str,
    bass: TonalVector | None = None,
    quality: ChordQuality | None = None,
    suffix: str | None = None,
)

Chord definition, as an ordered collection of TonalVectors representing intervals from the root (0,0).

Tone order is significant: it distinguishes chords that share the same pitch classes but are conventionally named/voiced differently (for example, an added 2nd vs. an added 9th).

A ChordType is realized at a root by calling it (or the root) to get a Chord:

>>> from openmusickit.systems.wsmn.tonal.symbols import C, E, G, Bb, dom7
>>> list(dom7) == [C, E, G, Bb], dom7.root, str(dom7)
(True, TonalVector((0, 0)), '7')
>>> str(G(dom7))
'G7'

Attributes

Name Description
tones
root
name_template
name The name template formatted with root.
bass
suffix
quality

Methods

Name Description
__iter__
__len__
__getitem__
__contains__
__repr__
combinations Returns a list of all ToneCollection subsets of k members, in the collection’s order.
all_combinations Returns a list of all ToneCollection subsets of length 2 through len(self)-1.
arpeggiate Returns the chord’s tones as a ToneCollection, rotated so that the
__init__
inversion Returns a ChordType with the same tones, but a different bass tone:
transform ChordTypes are interval patterns rooted at TonalVector(0,0), so
__str__ Lead-sheet style label: the suffix if there is a non-empty one,
__call__ Returns a Chord: this ChordType realized with its root at tv.
__truediv__ Returns a ChordType with the same tones, but a different bass tone.

__iter__

__iter__()

__len__

__len__()

__getitem__

__getitem__(index)

__contains__

__contains__(tone)

__repr__

__repr__()

combinations

combinations(k: int)

Returns a list of all ToneCollection subsets of k members, in the collection’s order.

>>> from openmusickit.systems.wsmn.tonal.symbols import C, E, G
>>> [[format(t) for t in dyad] for dyad in ToneCollection([C, E, G]).combinations(2)]
[['C', 'E'], ['C', 'G'], ['E', 'G']]

all_combinations

all_combinations()

Returns a list of all ToneCollection subsets of length 2 through len(self)-1.

>>> from openmusickit.systems.wsmn.tonal.symbols import C, E, G, B
>>> len(ToneCollection([C, E, G, B]).all_combinations())  # 6 dyads and 4 triads
10

arpeggiate

arpeggiate()

Returns the chord’s tones as a ToneCollection, rotated so that the bass tone comes first and the remaining tones follow in their original (cyclic) order. Root and name are preserved.

>>> from openmusickit.systems.wsmn.tonal.symbols import maj7
>>> def names(tc): return [t.pitch.unicode for t in tc]
>>> names(maj7.arpeggiate())
['C', 'E', 'G', 'B']
>>> names(maj7.inversion(1).arpeggiate())
['E', 'G', 'B', 'C']
>>> names(maj7.inversion(2).arpeggiate())
['G', 'B', 'C', 'E']
>>> names(maj7.inversion(3).arpeggiate())
['B', 'C', 'E', 'G']

__init__

__init__(
    tones: Iterable[TonalVector],
    name: str,
    bass: TonalVector | None = None,
    quality: ChordQuality | None = None,
    suffix: str | None = None,
)

inversion

inversion(inv: int | TonalVector, name: str | None = None)

Returns a ChordType with the same tones, but a different bass tone: the inv-th tone, or the tone given.

>>> from openmusickit.systems.wsmn.tonal.symbols import maj, G
>>> maj.inversion(1).bass, str(maj.inversion(1))
(TonalVector((2, 4)), 'major 1st inv.')
>>> maj.inversion(G) == maj.inversion(2)
True

transform

transform(*args, **kwargs)

ChordTypes are interval patterns rooted at TonalVector(0,0), so there is nothing to transform: realize the type at a root first (C(maj)), then transform the resulting Chord.

>>> from openmusickit.systems.wsmn.tonal.symbols import maj, M3
>>> maj.transform(TonalVector.transpose, M3)
Traceback (most recent call last):
...
NotImplementedError: ChordTypes do not transform.

__str__

__str__()

Lead-sheet style label: the suffix if there is a non-empty one, otherwise the name, followed by the ordinal inversion when the bass is not the root. (The inversion is the index of the bass within the chord type’s tones.)

Examples

>>> from openmusickit.systems.wsmn.tonal.symbols import maj, maj7, G

Non-empty suffix, root position and inverted:

>>> str(maj7)
'maj7'
>>> str(maj7.inversion(1))
'maj7 1st inv.'
>>> str(maj7 / G)
'maj7 2nd inv.'

Empty suffix falls back to the name:

>>> str(maj)
'major'
>>> str(maj.inversion(1))
'major 1st inv.'

No suffix or name at all (degenerate; falls back to __repr__):

>>> from openmusickit.systems.wsmn.tonal.symbols import C, E
>>> str(ChordType([C, E, G], name=None))
'ChordType([TonalVector((0, 0)), TonalVector((2, 4)), TonalVector((4, 7))], root=TonalVector((0, 0)))'

__call__

__call__(tv: TonalVector)

Returns a Chord: this ChordType realized with its root at tv.

Intended to be used with TonalVector’s reverse __call__, so that a chord reads root first, as on a lead sheet:

>>> from openmusickit.systems.wsmn.tonal.symbols import E, maj
>>> [format(t) for t in maj(E)]
['E', 'G♯', 'B']
>>> E(maj) == maj(E), str(E(maj))
(True, 'E')

__truediv__

__truediv__(tv: TonalVector)

Returns a ChordType with the same tones, but a different bass tone.

This is an overload for the / operator, so a slash chord reads as written:

>>> from openmusickit.systems.wsmn.tonal.symbols import maj, G
>>> (maj / G).bass, str(maj / G)
(TonalVector((4, 7)), 'major 2nd inv.')