@tonaljs/key 4.12.4 → 4.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +117 -3
- package/dist/index.d.mts +204 -1
- package/dist/index.d.ts +204 -1
- package/dist/index.js +683 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +683 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -5
package/README.md
CHANGED
|
@@ -96,8 +96,8 @@ Key.minorKey("C"); // =>
|
|
|
96
96
|
chordScales: ["C minor", "D locrian", "Eb major", "F dorian", "G phrygian", "Ab lydian", "Bb mixolydian"],
|
|
97
97
|
secondaryDominants: ["G7", "", "", "C7", "D7", "Eb7", "F7"],
|
|
98
98
|
secondaryDominantSupertonics: ["Dm7b5", "", "", "Gm7b5", "Am7b5", "Bbm7", "Cm7"],
|
|
99
|
-
substituteDominants: ["Db7", "", "", "Gb7", "Ab7", "A7", "
|
|
100
|
-
substituteDominantSupertonics: ["Abm7", "", "", "Dbm7", "Ebm7", "Em7", "
|
|
99
|
+
substituteDominants: ["Db7", "", "", "Gb7", "Ab7", "A7", "B7"],
|
|
100
|
+
substituteDominantSupertonics: ["Abm7", "", "", "Dbm7", "Ebm7", "Em7", "F#m7"],
|
|
101
101
|
},
|
|
102
102
|
harmonic: {
|
|
103
103
|
tonic: "C",
|
|
@@ -168,7 +168,121 @@ Return a list of all available chords for a given minor key:
|
|
|
168
168
|
Key.minorKeyChords("C")
|
|
169
169
|
.map((chord) => chord.name)
|
|
170
170
|
.join(", ");
|
|
171
|
-
// => "Cm7, Dm7b5, Ebmaj7, Fm7, Gm7, Abmaj7, Bb7, G7, C7, D7, Eb7, F7, Gm7b5, Am7b5, Bbm7, Db7, Gb7, Ab7, A7,
|
|
171
|
+
// => "Cm7, Dm7b5, Ebmaj7, Fm7, Gm7, Abmaj7, Bb7, G7, C7, D7, Eb7, F7, Gm7b5, Am7b5, Bbm7, Db7, Gb7, Ab7, A7, B7, Abm7, Dbm7, Ebm7, Em7, F#m7, CmMaj7, Eb+maj7, Bo7, Am7, Cm6, Dm7, Bm7b5, Em7b5"
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### `Key.analyzeChord`
|
|
175
|
+
|
|
176
|
+
`analyzeChord(key: string, chord: string, options?: { previous?: string, next?: string }) => ChordReading[]`
|
|
177
|
+
|
|
178
|
+
What a chord does in a key: every reading, ranked, the first being the default. The key is `"C major"`, `"A minor"` or a tonic alone (major). The neighbours are optional, but some readings need them:
|
|
179
|
+
|
|
180
|
+
```js
|
|
181
|
+
Key.analyzeChord("C major", "A7", { next: "Dm7" })[0];
|
|
182
|
+
// => {
|
|
183
|
+
// chord: "A7",
|
|
184
|
+
// numeral: "V7/ii", // as the books write it
|
|
185
|
+
// degree: "VI7", // the chord's numeral on the tonic
|
|
186
|
+
// source: "secondary dominant",
|
|
187
|
+
// function: "D", // "T", "SD", "D" or ""
|
|
188
|
+
// scale: "", // the scale it comes from, for diatonic and borrowed chords
|
|
189
|
+
// target: "ii", // the numeral it leads to
|
|
190
|
+
// resolution: "functioning", // does the next chord go to the target?
|
|
191
|
+
// chordScale: "A mixolydian b6",
|
|
192
|
+
// }
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
The same chord can be several things. `Bb7` before `C` in C major is a backdoor dominant, a chord borrowed from C minor and a tritone substitute of `E7`:
|
|
196
|
+
|
|
197
|
+
```js
|
|
198
|
+
Key.analyzeChord("C major", "Bb7", { next: "C" }).map((r) => r.source);
|
|
199
|
+
// => ["backdoor", "borrowed", "tritone substitute"]
|
|
200
|
+
Key.analyzeChord("C major", "Am7", { next: "D7" }).map((r) => r.numeral);
|
|
201
|
+
// => ["ii7/V", "vi7"]
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
The readings, by source:
|
|
205
|
+
|
|
206
|
+
| Source | Rule | Example in C major |
|
|
207
|
+
| ------------------------ | ------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------- |
|
|
208
|
+
| `diatonic` | every note in a scale of the key (minor: natural, harmonic, melodic), root on a degree | `Dm9` is `ii9` |
|
|
209
|
+
| `secondary dominant` | a dominant or major triad a fifth above a degree whose chord is major or minor, not the tonic | `A7` is `V7/ii`, `E` is `V/vi` |
|
|
210
|
+
| `tritone substitute` | a dominant a half step above one of those degrees or the tonic | `Db7` is `subV7/I` |
|
|
211
|
+
| `related ii` | a m7 or m7b5 a fifth above a next chord that is a secondary dominant | `Am7` before `D7` is `ii7/V` |
|
|
212
|
+
| `borrowed` | in the parallel key, or in a parallel mode when nothing else reads the chord | `Fm7` is `iv7` (C minor), `Bbmaj7` is `bVIImaj7` (C mixolydian) |
|
|
213
|
+
| `backdoor` | a dominant a whole step below the tonic, before the tonic | `Bb7` before `C` |
|
|
214
|
+
| `passing diminished` | a dim7 a half step below a next chord on a degree, or between two chords a whole step apart going down | `C#o7` before `Dm7` is `viio7/ii`; `Em7 Ebo7 Dm7` |
|
|
215
|
+
| `common-tone diminished` | a dim7 on the root of the chord before or after | `Co7` before `C` |
|
|
216
|
+
| `chromatic` | nothing else matches | `F#maj7` is `#IVmaj7` |
|
|
217
|
+
|
|
218
|
+
Readings the neighbours confirm come first (the next chord on the target, a related ii, a backdoor or diminished chord, a secondary dominant after its related ii), then the sources in the order of the table. The vi of a major key before the V is `"SD"` instead of `"T"`.
|
|
219
|
+
|
|
220
|
+
Every numeral but `subV` gives the chord back with `Progression.fromRomanNumerals`. Lowercase numerals are minor or diminished chords (`ii7` is `Dm7`, `viio` is `Bdim`).
|
|
221
|
+
|
|
222
|
+
To analyse a progression, pass each chord its neighbours:
|
|
223
|
+
|
|
224
|
+
```js
|
|
225
|
+
const chords = ["Cmaj7", "A7", "Dm7", "G7"];
|
|
226
|
+
chords.map(
|
|
227
|
+
(chord, i) =>
|
|
228
|
+
Key.analyzeChord("C major", chord, {
|
|
229
|
+
previous: chords[i - 1],
|
|
230
|
+
next: chords[i + 1],
|
|
231
|
+
})[0].numeral,
|
|
232
|
+
);
|
|
233
|
+
// => ["Imaj7", "V7/ii", "ii7", "V7"]
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
The key stays the same for every chord: finding the local keys of a progression (a ii-V-I in another key) is not part of it.
|
|
237
|
+
|
|
238
|
+
### `Key.borrowedChords`
|
|
239
|
+
|
|
240
|
+
`borrowedChords(key: string) => { chord, numeral, from, replaces }[]`
|
|
241
|
+
|
|
242
|
+
The chords a key borrows from its parallel scales (modal interchange), with the scale they come from and the numerals of the key's chords they replace. Major keys follow Pease's tables (_Jazz Composition_); minor keys borrow from the parallel major: Imaj7 (the Picardy 3rd), iim7 for ii7b5, IVmaj7 for IV7.
|
|
243
|
+
|
|
244
|
+
```js
|
|
245
|
+
Key.borrowedChords("C major").map((b) => b.chord);
|
|
246
|
+
// => ["Dm7b5", "Ebmaj7", "Fm7", "Fm6", "Gm7", "Abmaj7", "Bb7", "Dbmaj7", "Bbmaj7", "Cmaj7#11"]
|
|
247
|
+
Key.borrowedChords("C major")[5];
|
|
248
|
+
// => { chord: "Abmaj7", numeral: "bVImaj7", from: "C minor", replaces: ["iv"] }
|
|
249
|
+
Key.borrowedChords("A minor").map((b) => b.chord); // => ["Amaj7", "Bm7", "Dmaj7"]
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
### `Key.substitutes`
|
|
253
|
+
|
|
254
|
+
`substitutes(key: string, chord: string, options?: { next?, kinds?, minor? }) => { chords: string[], kind: string }[]`
|
|
255
|
+
|
|
256
|
+
`Chord.substitutes` in a key, plus the key's own: `"diatonic"`, the key's chords with the same harmonic function (iii and vi for I, ii for IV, vii for V), and `"borrowed"`, the borrowed chords that replace it. The related ii of a dominant to a minor chord of the key is an m7b5.
|
|
257
|
+
|
|
258
|
+
```js
|
|
259
|
+
Key.substitutes("C major", "Fmaj7").map((s) => `${s.kind}: ${s.chords}`);
|
|
260
|
+
// => ["contained: Am", "diatonic: Dm7", "borrowed: Ebmaj7", "borrowed: Fm7", "borrowed: Fm6", "borrowed: Bbmaj7"]
|
|
261
|
+
Key.substitutes("C major", "E7", { kinds: ["related ii"] });
|
|
262
|
+
// => [{ chords: ["Bm7b5", "E7"], kind: "related ii" }]
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
### `Key.pivotChords`
|
|
266
|
+
|
|
267
|
+
`pivotChords(from: string, to: string, options?: { sevenths?: boolean, chromatic?: boolean }) => { chord, from, to, fromSource, toSource }[]`
|
|
268
|
+
|
|
269
|
+
The chords two keys share, to modulate from one to the other, with the numeral of each in both keys. Triads by default, 7th chords with `sevenths`; a minor key has the chords of its natural, harmonic and melodic forms. Chords are spelled as in the second key:
|
|
270
|
+
|
|
271
|
+
```js
|
|
272
|
+
Key.pivotChords("C major", "G major").map(
|
|
273
|
+
(p) => `${p.chord}: ${p.from} ${p.to}`,
|
|
274
|
+
);
|
|
275
|
+
// => ["C: I IV", "Em: iii vi", "G: V I", "Am: vi ii"]
|
|
276
|
+
Key.pivotChords("C major", "G major", { sevenths: true }).map((p) => p.chord); // => ["Cmaj7", "Em7", "Am7"]
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
With `chromatic`, also the chords of one key that have a functional reading in the other (a secondary dominant, a chord borrowed from the parallel major or minor), with the source of each reading:
|
|
280
|
+
|
|
281
|
+
```js
|
|
282
|
+
Key.pivotChords("C major", "G major", { chromatic: true })
|
|
283
|
+
.slice(4)
|
|
284
|
+
.map((p) => `${p.chord}: ${p.from} ${p.to}`);
|
|
285
|
+
// => ["Dm: ii v", "F: IV bVII", "D: V/V V"]
|
|
172
286
|
```
|
|
173
287
|
|
|
174
288
|
## How to...
|
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,88 @@
|
|
|
1
|
+
import { SubstituteKind } from "@tonaljs/chord";
|
|
2
|
+
/** Where a reading of a chord in a key comes from. */
|
|
3
|
+
type ChordSource = "diatonic" | "secondary dominant" | "tritone substitute" | "related ii" | "borrowed" | "backdoor" | "passing diminished" | "common-tone diminished" | "chromatic";
|
|
4
|
+
/** One reading of a chord in a key, as returned by `Key.analyzeChord`. */
|
|
5
|
+
interface ChordReading {
|
|
6
|
+
/** The chord as given, like "A7". */
|
|
7
|
+
chord: string;
|
|
8
|
+
/** The reading as the books write it: "ii7", "V7/ii", "subV7/I", "ii7/V", "bVIImaj7". */
|
|
9
|
+
numeral: string;
|
|
10
|
+
/** The chord's numeral on the key's tonic, like "VI7" for "A7" in C. */
|
|
11
|
+
degree: string;
|
|
12
|
+
/** Where the reading comes from: "diatonic", "secondary dominant", "borrowed"... */
|
|
13
|
+
source: ChordSource;
|
|
14
|
+
/** Harmonic function: "T" (tonic), "SD" (subdominant), "D" (dominant) or "". */
|
|
15
|
+
function: "T" | "SD" | "D" | "";
|
|
16
|
+
/** The scale the chord comes from, like "C harmonic minor" or "C mixolydian"; "" if none. */
|
|
17
|
+
scale: string;
|
|
18
|
+
/** The numeral the chord leads to, like "ii" for "V7/ii"; "" if none. */
|
|
19
|
+
target: string;
|
|
20
|
+
/** With a target and a next chord: "functioning" if the next chord is on the target, "non-functioning" if not; "" otherwise. */
|
|
21
|
+
resolution: "functioning" | "non-functioning" | "";
|
|
22
|
+
/** The chord scale for this reading, like "A mixolydian b6". */
|
|
23
|
+
chordScale: string;
|
|
24
|
+
}
|
|
25
|
+
/** Options of `Key.analyzeChord`. */
|
|
26
|
+
interface AnalyzeChordOptions {
|
|
27
|
+
/** The chord before, like "Em7". */
|
|
28
|
+
previous?: string;
|
|
29
|
+
/** The chord after, like "Dm7". */
|
|
30
|
+
next?: string;
|
|
31
|
+
}
|
|
32
|
+
/** A chord borrowed from a parallel scale, as returned by `Key.borrowedChords`. */
|
|
33
|
+
interface BorrowedChord {
|
|
34
|
+
/** The chord, like "Abmaj7". */
|
|
35
|
+
chord: string;
|
|
36
|
+
/** Its numeral in the key, like "bVImaj7". */
|
|
37
|
+
numeral: string;
|
|
38
|
+
/** The scale it comes from, like "C minor" or "C phrygian". */
|
|
39
|
+
from: string;
|
|
40
|
+
/** The numerals of the key's chords it replaces, like ["iv"]. */
|
|
41
|
+
replaces: string[];
|
|
42
|
+
}
|
|
43
|
+
/** The kind of a substitute in a key, as returned by `Key.substitutes`. */
|
|
44
|
+
type KeySubstituteKind = SubstituteKind | "diatonic" | "borrowed";
|
|
45
|
+
/** A substitute in a key: the chords that take a chord's place, and its kind. */
|
|
46
|
+
interface KeySubstitute {
|
|
47
|
+
chords: string[];
|
|
48
|
+
kind: KeySubstituteKind;
|
|
49
|
+
}
|
|
50
|
+
/** Options of `Key.substitutes`. */
|
|
51
|
+
interface KeySubstitutesOptions {
|
|
52
|
+
/** The chord after, like "Dm7": adds the approach chords to it. */
|
|
53
|
+
next?: string;
|
|
54
|
+
/** Only these kinds, like ["diatonic", "borrowed"]. */
|
|
55
|
+
kinds?: KeySubstituteKind[];
|
|
56
|
+
/**
|
|
57
|
+
* The related ii is an m7b5. By default, when the dominant's target (a 4th
|
|
58
|
+
* up) is a minor chord of the key, or the dominant has a b9.
|
|
59
|
+
*/
|
|
60
|
+
minor?: boolean;
|
|
61
|
+
}
|
|
62
|
+
/** A chord two keys share, as returned by `Key.pivotChords`. */
|
|
63
|
+
interface PivotChord {
|
|
64
|
+
/** The chord, spelled in the destination key (or in the key it belongs to). */
|
|
65
|
+
chord: string;
|
|
66
|
+
/** Its numeral in the first key, like "iii". */
|
|
67
|
+
from: string;
|
|
68
|
+
/** Its numeral in the second key, like "vi". */
|
|
69
|
+
to: string;
|
|
70
|
+
/** Where its reading in the first key comes from: "diatonic", "secondary dominant"... */
|
|
71
|
+
fromSource: ChordSource;
|
|
72
|
+
/** Where its reading in the second key comes from. */
|
|
73
|
+
toSource: ChordSource;
|
|
74
|
+
}
|
|
75
|
+
/** Options of `Key.pivotChords`. */
|
|
76
|
+
interface PivotChordsOptions {
|
|
77
|
+
/** 7th chords instead of triads. */
|
|
78
|
+
sevenths?: boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Also the chords of one key that have a functional reading in the other
|
|
81
|
+
* (secondary dominants, borrowed from the parallel major or minor...): D7
|
|
82
|
+
* is V7/V in C and V7 in G.
|
|
83
|
+
*/
|
|
84
|
+
chromatic?: boolean;
|
|
85
|
+
}
|
|
1
86
|
interface Key {
|
|
2
87
|
readonly type: "major" | "minor";
|
|
3
88
|
/** The tonic pitch class, like "F". Empty for an invalid key. */
|
|
@@ -122,11 +207,129 @@ declare function minorKey(tnc: string): MinorKey;
|
|
|
122
207
|
* Key.majorTonicFromKeySignature(""); // => "C"
|
|
123
208
|
*/
|
|
124
209
|
declare function majorTonicFromKeySignature(sig: string | number): string | null;
|
|
210
|
+
/**
|
|
211
|
+
* Analyse a chord in a key: every reading of what the chord does there,
|
|
212
|
+
* ranked, the first being the default. Each reading has its numeral as the
|
|
213
|
+
* books write it ("V7/ii", "subV7/I", "ii7/V", "bVIImaj7"), the chord's plain
|
|
214
|
+
* numeral on the tonic (`degree`), its source, harmonic function ("T", "SD",
|
|
215
|
+
* "D" or ""), the scale it comes from, the numeral it leads to (`target`),
|
|
216
|
+
* whether the next chord goes there (`resolution`) and a chord scale chosen
|
|
217
|
+
* by function. Returns `[]` for an invalid key or chord; a valid chord always
|
|
218
|
+
* has at least one reading.
|
|
219
|
+
*
|
|
220
|
+
* The key is "C major", "A minor" or a tonic alone ("C", major). A minor key
|
|
221
|
+
* has the chords of its natural, harmonic and melodic forms. A slash chord is
|
|
222
|
+
* read without its bass. The readings, by source:
|
|
223
|
+
*
|
|
224
|
+
* - "diatonic": every note in a scale of the key, root on a degree.
|
|
225
|
+
* - "secondary dominant": a dominant or major triad a fifth above a degree
|
|
226
|
+
* whose chord is major or minor, not the tonic ("A7" in C is "V7/ii").
|
|
227
|
+
* - "tritone substitute": a dominant a half step above one of those degrees
|
|
228
|
+
* or the tonic ("Db7" in C is "subV7/I"); chord scale lydian dominant.
|
|
229
|
+
* - "related ii": a m7 or m7b5 a fifth above a next chord that is a
|
|
230
|
+
* secondary dominant ("Am7" before "D7" in C is "ii7/V").
|
|
231
|
+
* - "borrowed": in the parallel key (major or the minor forms), or in a
|
|
232
|
+
* parallel mode when nothing else reads the chord ("Fm7" in C is "iv7").
|
|
233
|
+
* - "backdoor": a dominant a whole step below the tonic, before the tonic.
|
|
234
|
+
* - "passing diminished": a dim7 a half step below a next chord on a degree
|
|
235
|
+
* ("C#o7" before "Dm7" is "viio7/ii"), or between two chords a whole step
|
|
236
|
+
* apart going down ("Em7 Ebo7 Dm7").
|
|
237
|
+
* - "common-tone diminished": a dim7 on the root of the chord before or after.
|
|
238
|
+
* - "chromatic": when nothing else matches.
|
|
239
|
+
*
|
|
240
|
+
* Ranking: readings the neighbours confirm first (the next chord on the
|
|
241
|
+
* target, a related ii, a backdoor or diminished chord, a secondary dominant
|
|
242
|
+
* after its related ii), then by source in the order above. The vi of a
|
|
243
|
+
* major key before the V is "SD" instead of "T".
|
|
244
|
+
*
|
|
245
|
+
* @param key - the key, like "C major" or "A minor"
|
|
246
|
+
* @param chord - the chord symbol, like "A7"
|
|
247
|
+
* @param options - `previous` and `next`, the chords around it
|
|
248
|
+
* @example
|
|
249
|
+
* Key.analyzeChord("C major", "A7", { next: "Dm7" })[0].numeral; // => "V7/ii"
|
|
250
|
+
* Key.analyzeChord("C major", "Bb7", { next: "C" }).map((r) => r.source); // => ["backdoor", "borrowed", "tritone substitute"]
|
|
251
|
+
* Key.analyzeChord("C major", "Am7", { next: "D7" }).map((r) => r.numeral); // => ["ii7/V", "vi7"]
|
|
252
|
+
* Key.analyzeChord("A minor", "E7")[0].scale; // => "A harmonic minor"
|
|
253
|
+
*/
|
|
254
|
+
declare function analyzeChord(key: string, chord: string, options?: AnalyzeChordOptions): ChordReading[];
|
|
255
|
+
/**
|
|
256
|
+
* Get the chords a key borrows from its parallel scales (modal interchange),
|
|
257
|
+
* as Pease lists them, with their numeral, the scale they come from and the
|
|
258
|
+
* numerals of the key's chords they replace. In a major key (C):
|
|
259
|
+
*
|
|
260
|
+
* - from C minor: Dm7b5 (ii7b5) for ii7; Ebmaj7 (bIIImaj7) for IV or V7;
|
|
261
|
+
* Fm7 and Fm6 (iv7, iv6) for IV; Gm7 (v7) for V7; Abmaj7 (bVImaj7) and
|
|
262
|
+
* Bb7 (bVII7) for iv;
|
|
263
|
+
* - from C phrygian: Dbmaj7 (bIImaj7) for iv;
|
|
264
|
+
* - from C mixolydian: Bbmaj7 (bVIImaj7) for IV;
|
|
265
|
+
* - from C lydian: Cmaj7#11 (Imaj7#11), a tonic alias.
|
|
266
|
+
*
|
|
267
|
+
* In a minor key, from the parallel major (Jazzology, and Pease's Ionian
|
|
268
|
+
* into Dorian): Imaj7 for i (the Picardy 3rd, the most common), iim7 for
|
|
269
|
+
* ii7b5, and IVmaj7 for IV7. It returns `[]` for an invalid key.
|
|
270
|
+
*
|
|
271
|
+
* @param key - a key name, like "C major" (or "C") or "A minor"
|
|
272
|
+
* @example
|
|
273
|
+
* Key.borrowedChords("C major")[0]; // => { chord: "Dm7b5", numeral: "ii7b5", from: "C minor", replaces: ["ii7"] }
|
|
274
|
+
* Key.borrowedChords("C major").map((b) => b.chord); // => ["Dm7b5", "Ebmaj7", "Fm7", "Fm6", "Gm7", "Abmaj7", "Bb7", "Dbmaj7", "Bbmaj7", "Cmaj7#11"]
|
|
275
|
+
* Key.borrowedChords("A minor").map((b) => b.chord); // => ["Amaj7", "Bm7", "Dmaj7"]
|
|
276
|
+
*/
|
|
277
|
+
declare function borrowedChords(key: string): BorrowedChord[];
|
|
278
|
+
/**
|
|
279
|
+
* Get the substitutes of a chord in a key: `Chord.substitutes`, then the
|
|
280
|
+
* key's own, each as `{ chords, kind }`:
|
|
281
|
+
*
|
|
282
|
+
* - "diatonic": the key's chords with the same harmonic function
|
|
283
|
+
* (`chordsHarmonicFunction`), triads for a triad and 7th chords otherwise:
|
|
284
|
+
* Em7 and Am7 for Cmaj7 in C, Dm7 for Fmaj7, Bm7b5 for G7. Only for a chord
|
|
285
|
+
* of the key: its root a degree and its notes in the scale (the natural
|
|
286
|
+
* minor's, in a minor key);
|
|
287
|
+
* - "borrowed": the chords of `Key.borrowedChords` that replace the chord's
|
|
288
|
+
* numeral (by root, 3rd, and a dominant for "V7").
|
|
289
|
+
*
|
|
290
|
+
* The related ii of a dominant is an m7b5 when its target (a 4th up) is a
|
|
291
|
+
* minor chord of the key, unless `minor` says otherwise: Bm7b5 for E7 in C.
|
|
292
|
+
* `kinds` keeps only those kinds. It returns `[]` for an invalid key or a
|
|
293
|
+
* chord without root.
|
|
294
|
+
*
|
|
295
|
+
* @param key - a key name, like "C major" (or "C") or "A minor"
|
|
296
|
+
* @param chord - the chord symbol, like "G7"
|
|
297
|
+
* @param options - `next`: the chord after; `kinds`; `minor`
|
|
298
|
+
* @example
|
|
299
|
+
* Key.substitutes("C major", "Fmaj7").map((s) => `${s.kind}: ${s.chords}`);
|
|
300
|
+
* // => ["contained: Am", "diatonic: Dm7", "borrowed: Ebmaj7", "borrowed: Fm7", "borrowed: Fm6", "borrowed: Bbmaj7"]
|
|
301
|
+
* Key.substitutes("C major", "E7", { kinds: ["related ii"] }); // => [{ chords: ["Bm7b5", "E7"], kind: "related ii" }]
|
|
302
|
+
*/
|
|
303
|
+
declare function substitutes(key: string, chord: string, options?: KeySubstitutesOptions): KeySubstitute[];
|
|
304
|
+
/**
|
|
305
|
+
* Get the chords two keys share (pivot chords, to modulate from one to the
|
|
306
|
+
* other), with the numeral of each in both keys (as `Key.analyzeChord`
|
|
307
|
+
* writes it). Triads by default, 7th chords with `sevenths`. A minor key has
|
|
308
|
+
* the chords of its natural, harmonic and melodic forms. Chords match by
|
|
309
|
+
* root and type, whatever their spelling, and are spelled as in the second
|
|
310
|
+
* key, in the order of the first key's chords.
|
|
311
|
+
*
|
|
312
|
+
* With `chromatic`, then the chords of one key that have a functional
|
|
313
|
+
* reading in the other: the first reading of `Key.analyzeChord` that isn't
|
|
314
|
+
* "chromatic" or borrowed from a mode (borrowed from the parallel major or
|
|
315
|
+
* minor counts). D7 is V7/V in C and V7 in G. The chords of the first key
|
|
316
|
+
* come first, then the second's. `fromSource` and `toSource` say where each
|
|
317
|
+
* reading comes from. It returns `[]` for an invalid key.
|
|
318
|
+
*
|
|
319
|
+
* @param from - a key name, like "C major" (or "C") or "A minor"
|
|
320
|
+
* @param to - the other key
|
|
321
|
+
* @param options - `sevenths`, `chromatic`
|
|
322
|
+
* @example
|
|
323
|
+
* Key.pivotChords("C major", "G major").map((p) => `${p.chord}: ${p.from} ${p.to}`); // => ["C: I IV", "Em: iii vi", "G: V I", "Am: vi ii"]
|
|
324
|
+
* Key.pivotChords("C major", "G major", { sevenths: true }).map((p) => p.chord); // => ["Cmaj7", "Em7", "Am7"]
|
|
325
|
+
* Key.pivotChords("C major", "G major", { chromatic: true }).slice(4).map((p) => `${p.chord}: ${p.from} ${p.to}`); // => ["Dm: ii v", "F: IV bVII", "D: V/V V"]
|
|
326
|
+
*/
|
|
327
|
+
declare function pivotChords(from: string, to: string, options?: PivotChordsOptions): PivotChord[];
|
|
125
328
|
/** @deprecated Use the named exports instead. */
|
|
126
329
|
declare const _default: {
|
|
127
330
|
majorKey: typeof majorKey;
|
|
128
331
|
majorTonicFromKeySignature: typeof majorTonicFromKeySignature;
|
|
129
332
|
minorKey: typeof minorKey;
|
|
130
333
|
};
|
|
131
|
-
export { Key, KeyChord, KeyScale, MajorKey, MinorKey, _default as default, majorKey, majorKeyChords, majorTonicFromKeySignature, minorKey, minorKeyChords };
|
|
334
|
+
export { type AnalyzeChordOptions, type BorrowedChord, type ChordReading, type ChordSource, Key, KeyChord, KeyScale, type KeySubstitute, type KeySubstituteKind, type KeySubstitutesOptions, MajorKey, MinorKey, type PivotChord, type PivotChordsOptions, analyzeChord, borrowedChords, _default as default, majorKey, majorKeyChords, majorTonicFromKeySignature, minorKey, minorKeyChords, pivotChords, substitutes };
|
|
132
335
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,88 @@
|
|
|
1
|
+
import { SubstituteKind } from "@tonaljs/chord";
|
|
2
|
+
/** Where a reading of a chord in a key comes from. */
|
|
3
|
+
type ChordSource = "diatonic" | "secondary dominant" | "tritone substitute" | "related ii" | "borrowed" | "backdoor" | "passing diminished" | "common-tone diminished" | "chromatic";
|
|
4
|
+
/** One reading of a chord in a key, as returned by `Key.analyzeChord`. */
|
|
5
|
+
interface ChordReading {
|
|
6
|
+
/** The chord as given, like "A7". */
|
|
7
|
+
chord: string;
|
|
8
|
+
/** The reading as the books write it: "ii7", "V7/ii", "subV7/I", "ii7/V", "bVIImaj7". */
|
|
9
|
+
numeral: string;
|
|
10
|
+
/** The chord's numeral on the key's tonic, like "VI7" for "A7" in C. */
|
|
11
|
+
degree: string;
|
|
12
|
+
/** Where the reading comes from: "diatonic", "secondary dominant", "borrowed"... */
|
|
13
|
+
source: ChordSource;
|
|
14
|
+
/** Harmonic function: "T" (tonic), "SD" (subdominant), "D" (dominant) or "". */
|
|
15
|
+
function: "T" | "SD" | "D" | "";
|
|
16
|
+
/** The scale the chord comes from, like "C harmonic minor" or "C mixolydian"; "" if none. */
|
|
17
|
+
scale: string;
|
|
18
|
+
/** The numeral the chord leads to, like "ii" for "V7/ii"; "" if none. */
|
|
19
|
+
target: string;
|
|
20
|
+
/** With a target and a next chord: "functioning" if the next chord is on the target, "non-functioning" if not; "" otherwise. */
|
|
21
|
+
resolution: "functioning" | "non-functioning" | "";
|
|
22
|
+
/** The chord scale for this reading, like "A mixolydian b6". */
|
|
23
|
+
chordScale: string;
|
|
24
|
+
}
|
|
25
|
+
/** Options of `Key.analyzeChord`. */
|
|
26
|
+
interface AnalyzeChordOptions {
|
|
27
|
+
/** The chord before, like "Em7". */
|
|
28
|
+
previous?: string;
|
|
29
|
+
/** The chord after, like "Dm7". */
|
|
30
|
+
next?: string;
|
|
31
|
+
}
|
|
32
|
+
/** A chord borrowed from a parallel scale, as returned by `Key.borrowedChords`. */
|
|
33
|
+
interface BorrowedChord {
|
|
34
|
+
/** The chord, like "Abmaj7". */
|
|
35
|
+
chord: string;
|
|
36
|
+
/** Its numeral in the key, like "bVImaj7". */
|
|
37
|
+
numeral: string;
|
|
38
|
+
/** The scale it comes from, like "C minor" or "C phrygian". */
|
|
39
|
+
from: string;
|
|
40
|
+
/** The numerals of the key's chords it replaces, like ["iv"]. */
|
|
41
|
+
replaces: string[];
|
|
42
|
+
}
|
|
43
|
+
/** The kind of a substitute in a key, as returned by `Key.substitutes`. */
|
|
44
|
+
type KeySubstituteKind = SubstituteKind | "diatonic" | "borrowed";
|
|
45
|
+
/** A substitute in a key: the chords that take a chord's place, and its kind. */
|
|
46
|
+
interface KeySubstitute {
|
|
47
|
+
chords: string[];
|
|
48
|
+
kind: KeySubstituteKind;
|
|
49
|
+
}
|
|
50
|
+
/** Options of `Key.substitutes`. */
|
|
51
|
+
interface KeySubstitutesOptions {
|
|
52
|
+
/** The chord after, like "Dm7": adds the approach chords to it. */
|
|
53
|
+
next?: string;
|
|
54
|
+
/** Only these kinds, like ["diatonic", "borrowed"]. */
|
|
55
|
+
kinds?: KeySubstituteKind[];
|
|
56
|
+
/**
|
|
57
|
+
* The related ii is an m7b5. By default, when the dominant's target (a 4th
|
|
58
|
+
* up) is a minor chord of the key, or the dominant has a b9.
|
|
59
|
+
*/
|
|
60
|
+
minor?: boolean;
|
|
61
|
+
}
|
|
62
|
+
/** A chord two keys share, as returned by `Key.pivotChords`. */
|
|
63
|
+
interface PivotChord {
|
|
64
|
+
/** The chord, spelled in the destination key (or in the key it belongs to). */
|
|
65
|
+
chord: string;
|
|
66
|
+
/** Its numeral in the first key, like "iii". */
|
|
67
|
+
from: string;
|
|
68
|
+
/** Its numeral in the second key, like "vi". */
|
|
69
|
+
to: string;
|
|
70
|
+
/** Where its reading in the first key comes from: "diatonic", "secondary dominant"... */
|
|
71
|
+
fromSource: ChordSource;
|
|
72
|
+
/** Where its reading in the second key comes from. */
|
|
73
|
+
toSource: ChordSource;
|
|
74
|
+
}
|
|
75
|
+
/** Options of `Key.pivotChords`. */
|
|
76
|
+
interface PivotChordsOptions {
|
|
77
|
+
/** 7th chords instead of triads. */
|
|
78
|
+
sevenths?: boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Also the chords of one key that have a functional reading in the other
|
|
81
|
+
* (secondary dominants, borrowed from the parallel major or minor...): D7
|
|
82
|
+
* is V7/V in C and V7 in G.
|
|
83
|
+
*/
|
|
84
|
+
chromatic?: boolean;
|
|
85
|
+
}
|
|
1
86
|
interface Key {
|
|
2
87
|
readonly type: "major" | "minor";
|
|
3
88
|
/** The tonic pitch class, like "F". Empty for an invalid key. */
|
|
@@ -122,11 +207,129 @@ declare function minorKey(tnc: string): MinorKey;
|
|
|
122
207
|
* Key.majorTonicFromKeySignature(""); // => "C"
|
|
123
208
|
*/
|
|
124
209
|
declare function majorTonicFromKeySignature(sig: string | number): string | null;
|
|
210
|
+
/**
|
|
211
|
+
* Analyse a chord in a key: every reading of what the chord does there,
|
|
212
|
+
* ranked, the first being the default. Each reading has its numeral as the
|
|
213
|
+
* books write it ("V7/ii", "subV7/I", "ii7/V", "bVIImaj7"), the chord's plain
|
|
214
|
+
* numeral on the tonic (`degree`), its source, harmonic function ("T", "SD",
|
|
215
|
+
* "D" or ""), the scale it comes from, the numeral it leads to (`target`),
|
|
216
|
+
* whether the next chord goes there (`resolution`) and a chord scale chosen
|
|
217
|
+
* by function. Returns `[]` for an invalid key or chord; a valid chord always
|
|
218
|
+
* has at least one reading.
|
|
219
|
+
*
|
|
220
|
+
* The key is "C major", "A minor" or a tonic alone ("C", major). A minor key
|
|
221
|
+
* has the chords of its natural, harmonic and melodic forms. A slash chord is
|
|
222
|
+
* read without its bass. The readings, by source:
|
|
223
|
+
*
|
|
224
|
+
* - "diatonic": every note in a scale of the key, root on a degree.
|
|
225
|
+
* - "secondary dominant": a dominant or major triad a fifth above a degree
|
|
226
|
+
* whose chord is major or minor, not the tonic ("A7" in C is "V7/ii").
|
|
227
|
+
* - "tritone substitute": a dominant a half step above one of those degrees
|
|
228
|
+
* or the tonic ("Db7" in C is "subV7/I"); chord scale lydian dominant.
|
|
229
|
+
* - "related ii": a m7 or m7b5 a fifth above a next chord that is a
|
|
230
|
+
* secondary dominant ("Am7" before "D7" in C is "ii7/V").
|
|
231
|
+
* - "borrowed": in the parallel key (major or the minor forms), or in a
|
|
232
|
+
* parallel mode when nothing else reads the chord ("Fm7" in C is "iv7").
|
|
233
|
+
* - "backdoor": a dominant a whole step below the tonic, before the tonic.
|
|
234
|
+
* - "passing diminished": a dim7 a half step below a next chord on a degree
|
|
235
|
+
* ("C#o7" before "Dm7" is "viio7/ii"), or between two chords a whole step
|
|
236
|
+
* apart going down ("Em7 Ebo7 Dm7").
|
|
237
|
+
* - "common-tone diminished": a dim7 on the root of the chord before or after.
|
|
238
|
+
* - "chromatic": when nothing else matches.
|
|
239
|
+
*
|
|
240
|
+
* Ranking: readings the neighbours confirm first (the next chord on the
|
|
241
|
+
* target, a related ii, a backdoor or diminished chord, a secondary dominant
|
|
242
|
+
* after its related ii), then by source in the order above. The vi of a
|
|
243
|
+
* major key before the V is "SD" instead of "T".
|
|
244
|
+
*
|
|
245
|
+
* @param key - the key, like "C major" or "A minor"
|
|
246
|
+
* @param chord - the chord symbol, like "A7"
|
|
247
|
+
* @param options - `previous` and `next`, the chords around it
|
|
248
|
+
* @example
|
|
249
|
+
* Key.analyzeChord("C major", "A7", { next: "Dm7" })[0].numeral; // => "V7/ii"
|
|
250
|
+
* Key.analyzeChord("C major", "Bb7", { next: "C" }).map((r) => r.source); // => ["backdoor", "borrowed", "tritone substitute"]
|
|
251
|
+
* Key.analyzeChord("C major", "Am7", { next: "D7" }).map((r) => r.numeral); // => ["ii7/V", "vi7"]
|
|
252
|
+
* Key.analyzeChord("A minor", "E7")[0].scale; // => "A harmonic minor"
|
|
253
|
+
*/
|
|
254
|
+
declare function analyzeChord(key: string, chord: string, options?: AnalyzeChordOptions): ChordReading[];
|
|
255
|
+
/**
|
|
256
|
+
* Get the chords a key borrows from its parallel scales (modal interchange),
|
|
257
|
+
* as Pease lists them, with their numeral, the scale they come from and the
|
|
258
|
+
* numerals of the key's chords they replace. In a major key (C):
|
|
259
|
+
*
|
|
260
|
+
* - from C minor: Dm7b5 (ii7b5) for ii7; Ebmaj7 (bIIImaj7) for IV or V7;
|
|
261
|
+
* Fm7 and Fm6 (iv7, iv6) for IV; Gm7 (v7) for V7; Abmaj7 (bVImaj7) and
|
|
262
|
+
* Bb7 (bVII7) for iv;
|
|
263
|
+
* - from C phrygian: Dbmaj7 (bIImaj7) for iv;
|
|
264
|
+
* - from C mixolydian: Bbmaj7 (bVIImaj7) for IV;
|
|
265
|
+
* - from C lydian: Cmaj7#11 (Imaj7#11), a tonic alias.
|
|
266
|
+
*
|
|
267
|
+
* In a minor key, from the parallel major (Jazzology, and Pease's Ionian
|
|
268
|
+
* into Dorian): Imaj7 for i (the Picardy 3rd, the most common), iim7 for
|
|
269
|
+
* ii7b5, and IVmaj7 for IV7. It returns `[]` for an invalid key.
|
|
270
|
+
*
|
|
271
|
+
* @param key - a key name, like "C major" (or "C") or "A minor"
|
|
272
|
+
* @example
|
|
273
|
+
* Key.borrowedChords("C major")[0]; // => { chord: "Dm7b5", numeral: "ii7b5", from: "C minor", replaces: ["ii7"] }
|
|
274
|
+
* Key.borrowedChords("C major").map((b) => b.chord); // => ["Dm7b5", "Ebmaj7", "Fm7", "Fm6", "Gm7", "Abmaj7", "Bb7", "Dbmaj7", "Bbmaj7", "Cmaj7#11"]
|
|
275
|
+
* Key.borrowedChords("A minor").map((b) => b.chord); // => ["Amaj7", "Bm7", "Dmaj7"]
|
|
276
|
+
*/
|
|
277
|
+
declare function borrowedChords(key: string): BorrowedChord[];
|
|
278
|
+
/**
|
|
279
|
+
* Get the substitutes of a chord in a key: `Chord.substitutes`, then the
|
|
280
|
+
* key's own, each as `{ chords, kind }`:
|
|
281
|
+
*
|
|
282
|
+
* - "diatonic": the key's chords with the same harmonic function
|
|
283
|
+
* (`chordsHarmonicFunction`), triads for a triad and 7th chords otherwise:
|
|
284
|
+
* Em7 and Am7 for Cmaj7 in C, Dm7 for Fmaj7, Bm7b5 for G7. Only for a chord
|
|
285
|
+
* of the key: its root a degree and its notes in the scale (the natural
|
|
286
|
+
* minor's, in a minor key);
|
|
287
|
+
* - "borrowed": the chords of `Key.borrowedChords` that replace the chord's
|
|
288
|
+
* numeral (by root, 3rd, and a dominant for "V7").
|
|
289
|
+
*
|
|
290
|
+
* The related ii of a dominant is an m7b5 when its target (a 4th up) is a
|
|
291
|
+
* minor chord of the key, unless `minor` says otherwise: Bm7b5 for E7 in C.
|
|
292
|
+
* `kinds` keeps only those kinds. It returns `[]` for an invalid key or a
|
|
293
|
+
* chord without root.
|
|
294
|
+
*
|
|
295
|
+
* @param key - a key name, like "C major" (or "C") or "A minor"
|
|
296
|
+
* @param chord - the chord symbol, like "G7"
|
|
297
|
+
* @param options - `next`: the chord after; `kinds`; `minor`
|
|
298
|
+
* @example
|
|
299
|
+
* Key.substitutes("C major", "Fmaj7").map((s) => `${s.kind}: ${s.chords}`);
|
|
300
|
+
* // => ["contained: Am", "diatonic: Dm7", "borrowed: Ebmaj7", "borrowed: Fm7", "borrowed: Fm6", "borrowed: Bbmaj7"]
|
|
301
|
+
* Key.substitutes("C major", "E7", { kinds: ["related ii"] }); // => [{ chords: ["Bm7b5", "E7"], kind: "related ii" }]
|
|
302
|
+
*/
|
|
303
|
+
declare function substitutes(key: string, chord: string, options?: KeySubstitutesOptions): KeySubstitute[];
|
|
304
|
+
/**
|
|
305
|
+
* Get the chords two keys share (pivot chords, to modulate from one to the
|
|
306
|
+
* other), with the numeral of each in both keys (as `Key.analyzeChord`
|
|
307
|
+
* writes it). Triads by default, 7th chords with `sevenths`. A minor key has
|
|
308
|
+
* the chords of its natural, harmonic and melodic forms. Chords match by
|
|
309
|
+
* root and type, whatever their spelling, and are spelled as in the second
|
|
310
|
+
* key, in the order of the first key's chords.
|
|
311
|
+
*
|
|
312
|
+
* With `chromatic`, then the chords of one key that have a functional
|
|
313
|
+
* reading in the other: the first reading of `Key.analyzeChord` that isn't
|
|
314
|
+
* "chromatic" or borrowed from a mode (borrowed from the parallel major or
|
|
315
|
+
* minor counts). D7 is V7/V in C and V7 in G. The chords of the first key
|
|
316
|
+
* come first, then the second's. `fromSource` and `toSource` say where each
|
|
317
|
+
* reading comes from. It returns `[]` for an invalid key.
|
|
318
|
+
*
|
|
319
|
+
* @param from - a key name, like "C major" (or "C") or "A minor"
|
|
320
|
+
* @param to - the other key
|
|
321
|
+
* @param options - `sevenths`, `chromatic`
|
|
322
|
+
* @example
|
|
323
|
+
* Key.pivotChords("C major", "G major").map((p) => `${p.chord}: ${p.from} ${p.to}`); // => ["C: I IV", "Em: iii vi", "G: V I", "Am: vi ii"]
|
|
324
|
+
* Key.pivotChords("C major", "G major", { sevenths: true }).map((p) => p.chord); // => ["Cmaj7", "Em7", "Am7"]
|
|
325
|
+
* Key.pivotChords("C major", "G major", { chromatic: true }).slice(4).map((p) => `${p.chord}: ${p.from} ${p.to}`); // => ["Dm: ii v", "F: IV bVII", "D: V/V V"]
|
|
326
|
+
*/
|
|
327
|
+
declare function pivotChords(from: string, to: string, options?: PivotChordsOptions): PivotChord[];
|
|
125
328
|
/** @deprecated Use the named exports instead. */
|
|
126
329
|
declare const _default: {
|
|
127
330
|
majorKey: typeof majorKey;
|
|
128
331
|
majorTonicFromKeySignature: typeof majorTonicFromKeySignature;
|
|
129
332
|
minorKey: typeof minorKey;
|
|
130
333
|
};
|
|
131
|
-
export { Key, KeyChord, KeyScale, MajorKey, MinorKey, _default as default, majorKey, majorKeyChords, majorTonicFromKeySignature, minorKey, minorKeyChords };
|
|
334
|
+
export { type AnalyzeChordOptions, type BorrowedChord, type ChordReading, type ChordSource, Key, KeyChord, KeyScale, type KeySubstitute, type KeySubstituteKind, type KeySubstitutesOptions, MajorKey, MinorKey, type PivotChord, type PivotChordsOptions, analyzeChord, borrowedChords, _default as default, majorKey, majorKeyChords, majorTonicFromKeySignature, minorKey, minorKeyChords, pivotChords, substitutes };
|
|
132
335
|
//# sourceMappingURL=index.d.ts.map
|