Chord¶
chord ¶
Chord parsing, transposition, and detection.
The Chord namespace handles musical chords end-to-end: parse names like
"Cmaj7" or "F#dim/A", get the constituent notes and intervals, find
related chords or compatible scales, transpose, and detect chords from
note lists.
Chord names follow the standard format <tonic><type>[/<bass>]:
- Tonic: any note name (
C,Bb,F#) - Type: any chord type from the ChordType dictionary
by full name (
maj7) or alias (Δ,^7,M7) - Bass: optional slash-bass note (
/A)
Example
from tonal_py import Chord Chord.get("Cmaj7").notes ('C', 'E', 'G', 'B') Chord.get("F#dim/A").bass 'A' Chord.detect(["C", "E", "G"]) ['CM', 'Em#5/C']
Source parity: @tonaljs/chord
tokenize_bass ¶
Internal helper for tokenize: split off /bass if present.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
note_str
|
str
|
The tonic portion already extracted. |
required |
chord_str
|
str
|
The remaining chord string (potentially with |
required |
Returns:
| Type | Description |
|---|---|
tuple[str, str, str]
|
|
Example
from tonal_py.chord import tokenize_bass tokenize_bass("C", "maj7") ('C', 'maj7', '') tokenize_bass("C", "maj7/E") ('C', 'maj7', 'E')
Source code in src/tonal_py/chord.py
tokenize ¶
Parse a chord name into (tonic, type, bass) components.
Special case: "Aug" is interpreted as the chord type "aug", not as
the note A with suffix "ug". This mirrors a workaround in tonal.js.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
A chord name string. |
required |
Returns:
| Type | Description |
|---|---|
tuple[str, str, str]
|
|
Example
from tonal_py import Chord Chord.tokenize("Cmaj7") ('C', 'maj7', '') Chord.tokenize("F#dim/A") ('F#', 'dim', 'A') Chord.tokenize("Aug") ('', 'aug', '')
Source code in src/tonal_py/chord.py
get_chord ¶
Build a Chord from explicit (type, tonic, bass) arguments.
Lower-level than get: skips the chord-string
tokenizer and constructs directly from named parts. Useful when you
already have parsed components.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
type_name
|
str
|
A chord type name or alias (e.g. |
required |
optional_tonic
|
str
|
The tonic note (e.g. |
''
|
optional_bass
|
str
|
An optional slash-bass note (e.g. |
''
|
Returns:
| Type | Description |
|---|---|
Chord
|
A |
Example
from tonal_py import Chord Chord.get_chord("maj7", "C").notes ('C', 'E', 'G', 'B') Chord.get_chord("maj7", "C", "E").bass 'E'
Source code in src/tonal_py/chord.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
get ¶
Get Chord properties from a chord name or pre-tokenized list.
Accepts a chord name string ("Cmaj7", "F#dim/A") or a 3-element list
[tonic, type, bass]. Returns NO_CHORD for empty or invalid input.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
src
|
Any
|
A chord name string or |
required |
Returns:
| Type | Description |
|---|---|
Chord
|
A |
Example
from tonal_py import Chord c = Chord.get("Cmaj7") c.notes ('C', 'E', 'G', 'B') c.quality 'Major' c.intervals ('1P', '3M', '5P', '7M') Chord.get("F#dim/A").bass 'A' Chord.get("").empty True
Source code in src/tonal_py/chord.py
transpose ¶
Transpose a chord name by an interval.
Both the tonic and the bass (if any) are transposed; the chord type is preserved.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chord_name
|
str
|
A chord name string. |
required |
ivl
|
str
|
An interval string. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The transposed chord name. Returns the input unchanged if the |
str
|
chord has no parseable tonic. |
Example
from tonal_py import Chord Chord.transpose("Cmaj7", "M3") 'Emaj7' Chord.transpose("F#dim/A", "P5") 'C#dim/E'
Source code in src/tonal_py/chord.py
chord_scales ¶
Find scales whose notes contain all of this chord's notes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
A chord name string. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
Scale names whose pitch class set is a superset of the chord's. |
Example
from tonal_py import Chord "major" in Chord.chord_scales("Cmaj7") True
Source code in src/tonal_py/chord.py
extended ¶
Find chords that extend this one (contain all its notes plus more).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chord_name
|
str
|
A chord name string. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
Chord names whose pitch class set is a strict superset. |
Example
from tonal_py import Chord any("maj9" in c for c in Chord.extended("Cmaj7")) True
Source code in src/tonal_py/chord.py
reduced ¶
Find simpler chords contained within this one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chord_name
|
str
|
A chord name string. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
Chord names whose pitch class set is a strict subset. |
Example
from tonal_py import Chord any(c == "CM" for c in Chord.reduced("Cmaj7")) True
Source code in src/tonal_py/chord.py
notes ¶
Get the notes of a chord, optionally overriding the tonic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chord_name
|
str
|
A chord name string. |
required |
tonic
|
str | None
|
Optional tonic override. When provided, transposes the chord type to that tonic instead of using the chord's own. |
None
|
Returns:
| Type | Description |
|---|---|
list[str]
|
List of note names. Empty if the chord has no resolvable tonic. |
Example
from tonal_py import Chord Chord.notes("Cmaj7") ['C', 'E', 'G', 'B'] Chord.notes("maj7", "Eb") ['Eb', 'G', 'Bb', 'D']
Source code in src/tonal_py/chord.py
degrees ¶
Return a function mapping 1-based chord degree to a note name.
Degree 0 is invalid (returns ""). Negative degrees count backwards
from the chord's last note. The function wraps cyclically through the
chord's interval pattern.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chord_name
|
str
|
A chord name string. |
required |
tonic
|
str | None
|
Optional tonic override. |
None
|
Returns:
| Type | Description |
|---|---|
Callable[[int], str]
|
A function |
Example
from tonal_py import Chord deg = Chord.degrees("Cmaj7") deg(1) 'C' deg(2) 'E' deg(0) ''
Source code in src/tonal_py/chord.py
steps ¶
Return a function mapping 0-based step to a note name.
Like degrees but 0-indexed and accepts any
integer (wraps cyclically).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chord_name
|
str
|
A chord name string. |
required |
tonic
|
str | None
|
Optional tonic override. |
None
|
Returns:
| Type | Description |
|---|---|
Callable[[int], str]
|
A function |
Example
from tonal_py import Chord step = Chord.steps("Cmaj7") step(0) 'C' step(1) 'E' step(4) # wraps; pitch-class tonic so no octave shift 'C'