Chords
The chords module computes chord notes and diatonic chord relationships across 22 chord types:
- Triads:
major-triad,minor-triad,diminished-triad,augmented-triad - 7th chords:
major-7th,minor-7th,dominant-7th,diminished-7th,half-diminished-7th - 6th chords:
major-6th,minor-6th - Suspended chords:
sus2,sus4 - 9th chords:
major-9th,minor-9th,dominant-9th - 11th chords:
major-11th,minor-11th,dominant-11th - 13th chords:
major-13th,minor-13th,dominant-13th
getChordNotes(root, chordType) returns the notes of any chord type built on a root.
getDiatonicChords(root, mode) returns the 7 diatonic triads for a key/mode, one per scale degree, in degree order (defaults to Ionian/major). getChordByDegree(degree, root, mode) returns just the chord at one degree (1-7).
getAvailableInversions(chordType) returns every valid value for a chord type’s inversion parameter - 0 is root position, not itself an inversion. A triad allows 0-2 (root position plus 2 inversions); a 13th chord allows 0-6 (root position plus 6 inversions).
getChordInversion(chord, inversion) reorders a chord’s notes so the given inversion’s tone is lowest, throwing a RangeError if it’s out of range for that chord’s type.
detectChords(notes) identifies every chord (root, type) match for a set of notes, keyed by root - the reverse of getChordNotes. Exact match only; returns {} if nothing matches.
Multiple valid roots are common: symmetric chords (augmented-triad, diminished-7th), minor-7th/major-6th overlap, and the whole 13th-chord family all produce more than one entry.
Live Playground
Section titled “Live Playground”getChordNotes
getChordNotes(root: Note, chordType: ChordType): Note[]Returns the notes of a chord type built on a root.
C, E, GgetDiatonicChords
getDiatonicChords(root: Note, mode?: ModeName): Chord[]Returns the 7 diatonic triads for a key/mode, one per scale degree.
[
{
"root": "C",
"type": "major-triad"
},
{
"root": "D",
"type": "minor-triad"
},
{
"root": "E",
"type": "minor-triad"
},
{
"root": "F",
"type": "major-triad"
},
{
"root": "G",
"type": "major-triad"
},
{
"root": "A",
"type": "minor-triad"
},
{
"root": "B",
"type": "diminished-triad"
}
]getChordByDegree
getChordByDegree(degree: number, root: Note, mode?: ModeName): ChordReturns the diatonic chord at a specific scale degree (1-7).
{
"root": "C",
"type": "major-triad"
}getAvailableInversions
getAvailableInversions(chordType: ChordType): readonly ChordInversion[]Returns the valid inversion numbers for a chord type, based on its note count.
[0, 1, 2]getChordInversion
getChordInversion(chord: Chord, inversion: ChordInversion): Note[]Reorders a chord's notes so the given inversion's chord tone is lowest.
C, E, GdetectChords
detectChords(notes: Note[]): Partial<Record<Note, ChordType[]>>Returns every chord that matches a set of notes, as key-value pairs mapping each matching root note to its list of matching chord types. Pick an example to see how a note set can match more than one root.
C, E, G{
"C": [
"major-triad"
]
}