@tonaljs/key 4.11.2 → 4.11.3
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/dist/index.cjs +201 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +80 -0
- package/dist/index.d.mts +38 -36
- package/dist/index.mjs +168 -204
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
- package/dist/index.d.ts +0 -78
- package/dist/index.js +0 -257
- package/dist/index.js.map +0 -1
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
+
});
|
|
5
|
+
let _tonaljs_note = require("@tonaljs/note");
|
|
6
|
+
let _tonaljs_pitch_note = require("@tonaljs/pitch-note");
|
|
7
|
+
let _tonaljs_roman_numeral = require("@tonaljs/roman-numeral");
|
|
8
|
+
//#region index.ts
|
|
9
|
+
const Empty = Object.freeze([]);
|
|
10
|
+
const NoKey = {
|
|
11
|
+
type: "major",
|
|
12
|
+
tonic: "",
|
|
13
|
+
alteration: 0,
|
|
14
|
+
keySignature: ""
|
|
15
|
+
};
|
|
16
|
+
const NoKeyScale = {
|
|
17
|
+
tonic: "",
|
|
18
|
+
grades: Empty,
|
|
19
|
+
intervals: Empty,
|
|
20
|
+
scale: Empty,
|
|
21
|
+
triads: Empty,
|
|
22
|
+
chords: Empty,
|
|
23
|
+
chordsHarmonicFunction: Empty,
|
|
24
|
+
chordScales: Empty,
|
|
25
|
+
secondaryDominants: Empty,
|
|
26
|
+
secondaryDominantSupertonics: Empty,
|
|
27
|
+
substituteDominantsMinorRelative: Empty,
|
|
28
|
+
substituteDominants: Empty,
|
|
29
|
+
substituteDominantSupertonics: Empty,
|
|
30
|
+
secondaryDominantsMinorRelative: Empty
|
|
31
|
+
};
|
|
32
|
+
const NoMajorKey = {
|
|
33
|
+
...NoKey,
|
|
34
|
+
...NoKeyScale,
|
|
35
|
+
type: "major",
|
|
36
|
+
minorRelative: "",
|
|
37
|
+
scale: Empty,
|
|
38
|
+
substituteDominants: Empty,
|
|
39
|
+
secondaryDominantSupertonics: Empty,
|
|
40
|
+
substituteDominantsMinorRelative: Empty
|
|
41
|
+
};
|
|
42
|
+
const NoMinorKey = {
|
|
43
|
+
...NoKey,
|
|
44
|
+
type: "minor",
|
|
45
|
+
relativeMajor: "",
|
|
46
|
+
natural: NoKeyScale,
|
|
47
|
+
harmonic: NoKeyScale,
|
|
48
|
+
melodic: NoKeyScale
|
|
49
|
+
};
|
|
50
|
+
const mapScaleToType = (scale, list, sep = "") => list.map((type, i) => `${scale[i]}${sep}${type}`);
|
|
51
|
+
function keyScale(grades, triads, chordTypes, harmonicFunctions, chordScales) {
|
|
52
|
+
return (tonic) => {
|
|
53
|
+
const intervals = grades.map((gr) => (0, _tonaljs_roman_numeral.get)(gr).interval || "");
|
|
54
|
+
const scale = intervals.map((interval) => (0, _tonaljs_note.transpose)(tonic, interval));
|
|
55
|
+
const chords = mapScaleToType(scale, chordTypes);
|
|
56
|
+
const secondaryDominants = scale.map((note) => (0, _tonaljs_note.transpose)(note, "5P")).map((note) => scale.includes(note) && !chords.includes(note + "7") ? note + "7" : "");
|
|
57
|
+
const secondaryDominantSupertonics = supertonics(secondaryDominants, triads);
|
|
58
|
+
const substituteDominants = secondaryDominants.map((chord) => {
|
|
59
|
+
if (!chord) return "";
|
|
60
|
+
return (0, _tonaljs_note.transpose)(chord.slice(0, -1), "5d") + "7";
|
|
61
|
+
});
|
|
62
|
+
const substituteDominantSupertonics = supertonics(substituteDominants, triads);
|
|
63
|
+
return {
|
|
64
|
+
tonic,
|
|
65
|
+
grades,
|
|
66
|
+
intervals,
|
|
67
|
+
scale,
|
|
68
|
+
triads: mapScaleToType(scale, triads),
|
|
69
|
+
chords,
|
|
70
|
+
chordsHarmonicFunction: harmonicFunctions.slice(),
|
|
71
|
+
chordScales: mapScaleToType(scale, chordScales, " "),
|
|
72
|
+
secondaryDominants,
|
|
73
|
+
secondaryDominantSupertonics,
|
|
74
|
+
substituteDominants,
|
|
75
|
+
substituteDominantSupertonics,
|
|
76
|
+
secondaryDominantsMinorRelative: secondaryDominantSupertonics,
|
|
77
|
+
substituteDominantsMinorRelative: substituteDominantSupertonics
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
const supertonics = (dominants, targetTriads) => {
|
|
82
|
+
return dominants.map((chord, index) => {
|
|
83
|
+
if (!chord) return "";
|
|
84
|
+
const minorRoot = (0, _tonaljs_note.transpose)(chord.slice(0, -1), "5P");
|
|
85
|
+
return targetTriads[index].endsWith("m") ? minorRoot + "m7" : minorRoot + "m7b5";
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
const distInFifths = (from, to) => {
|
|
89
|
+
const f = (0, _tonaljs_pitch_note.note)(from);
|
|
90
|
+
const t = (0, _tonaljs_pitch_note.note)(to);
|
|
91
|
+
return f.empty || t.empty ? 0 : t.coord[0] - f.coord[0];
|
|
92
|
+
};
|
|
93
|
+
const MajorScale = keyScale("I II III IV V VI VII".split(" "), " m m m dim".split(" "), "maj7 m7 m7 maj7 7 m7 m7b5".split(" "), "T SD T SD D T D".split(" "), "major,dorian,phrygian,lydian,mixolydian,minor,locrian".split(","));
|
|
94
|
+
const NaturalScale = keyScale("I II bIII IV V bVI bVII".split(" "), "m dim m m ".split(" "), "m7 m7b5 maj7 m7 m7 maj7 7".split(" "), "T SD T SD D SD SD".split(" "), "minor,locrian,major,dorian,phrygian,lydian,mixolydian".split(","));
|
|
95
|
+
const HarmonicScale = keyScale("I II bIII IV V bVI VII".split(" "), "m dim aug m dim".split(" "), "mMaj7 m7b5 +maj7 m7 7 maj7 o7".split(" "), "T SD T SD D SD D".split(" "), "harmonic minor,locrian 6,major augmented,lydian diminished,phrygian dominant,lydian #9,ultralocrian".split(","));
|
|
96
|
+
const MelodicScale = keyScale("I II bIII IV V VI VII".split(" "), "m m aug dim dim".split(" "), "m6 m7 +maj7 7 7 m7b5 m7b5".split(" "), "T SD T SD D ".split(" "), "melodic minor,dorian b2,lydian augmented,lydian dominant,mixolydian b6,locrian #2,altered".split(","));
|
|
97
|
+
/**
|
|
98
|
+
* Get a major key properties in a given tonic
|
|
99
|
+
* @param tonic
|
|
100
|
+
*/
|
|
101
|
+
function majorKey(tonic) {
|
|
102
|
+
const pc = (0, _tonaljs_pitch_note.note)(tonic).pc;
|
|
103
|
+
if (!pc) return NoMajorKey;
|
|
104
|
+
const keyScale = MajorScale(pc);
|
|
105
|
+
const alteration = distInFifths("C", pc);
|
|
106
|
+
return {
|
|
107
|
+
...keyScale,
|
|
108
|
+
type: "major",
|
|
109
|
+
minorRelative: (0, _tonaljs_note.transpose)(pc, "-3m"),
|
|
110
|
+
alteration,
|
|
111
|
+
keySignature: (0, _tonaljs_pitch_note.altToAcc)(alteration)
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Get a list of available chords for a given major key
|
|
116
|
+
* @param tonic
|
|
117
|
+
* @returns array of { name: string, roles: string[] }
|
|
118
|
+
*/
|
|
119
|
+
function majorKeyChords(tonic) {
|
|
120
|
+
const key = majorKey(tonic);
|
|
121
|
+
const chords = [];
|
|
122
|
+
keyChordsOf(key, chords);
|
|
123
|
+
return chords;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Get a list of available chords for a given major key
|
|
127
|
+
* @param tonic
|
|
128
|
+
* @returns array of { name: string, roles: string[] }
|
|
129
|
+
*/
|
|
130
|
+
function minorKeyChords(tonic) {
|
|
131
|
+
const key = minorKey(tonic);
|
|
132
|
+
const chords = [];
|
|
133
|
+
keyChordsOf(key.natural, chords);
|
|
134
|
+
keyChordsOf(key.harmonic, chords);
|
|
135
|
+
keyChordsOf(key.melodic, chords);
|
|
136
|
+
return chords;
|
|
137
|
+
}
|
|
138
|
+
function keyChordsOf(key, chords) {
|
|
139
|
+
const updateChord = (name, newRole) => {
|
|
140
|
+
if (!name) return;
|
|
141
|
+
let keyChord = chords.find((chord) => chord.name === name);
|
|
142
|
+
if (!keyChord) {
|
|
143
|
+
keyChord = {
|
|
144
|
+
name,
|
|
145
|
+
roles: []
|
|
146
|
+
};
|
|
147
|
+
chords.push(keyChord);
|
|
148
|
+
}
|
|
149
|
+
if (newRole && !keyChord.roles.includes(newRole)) keyChord.roles.push(newRole);
|
|
150
|
+
};
|
|
151
|
+
key.chords.forEach((chordName, index) => updateChord(chordName, key.chordsHarmonicFunction[index]));
|
|
152
|
+
key.secondaryDominants.forEach((chordName, index) => updateChord(chordName, `V/${key.grades[index]}`));
|
|
153
|
+
key.secondaryDominantSupertonics.forEach((chordName, index) => updateChord(chordName, `ii/${key.grades[index]}`));
|
|
154
|
+
key.substituteDominants.forEach((chordName, index) => updateChord(chordName, `subV/${key.grades[index]}`));
|
|
155
|
+
key.substituteDominantSupertonics.forEach((chordName, index) => updateChord(chordName, `subii/${key.grades[index]}`));
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Get minor key properties in a given tonic
|
|
159
|
+
* @param tonic
|
|
160
|
+
*/
|
|
161
|
+
function minorKey(tnc) {
|
|
162
|
+
const pc = (0, _tonaljs_pitch_note.note)(tnc).pc;
|
|
163
|
+
if (!pc) return NoMinorKey;
|
|
164
|
+
const alteration = distInFifths("C", pc) - 3;
|
|
165
|
+
return {
|
|
166
|
+
type: "minor",
|
|
167
|
+
tonic: pc,
|
|
168
|
+
relativeMajor: (0, _tonaljs_note.transpose)(pc, "3m"),
|
|
169
|
+
alteration,
|
|
170
|
+
keySignature: (0, _tonaljs_pitch_note.altToAcc)(alteration),
|
|
171
|
+
natural: NaturalScale(pc),
|
|
172
|
+
harmonic: HarmonicScale(pc),
|
|
173
|
+
melodic: MelodicScale(pc)
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Given a key signature, returns the tonic of the major key
|
|
178
|
+
* @param signature
|
|
179
|
+
* @example
|
|
180
|
+
* majorTonicFromKeySignature('###') // => 'A'
|
|
181
|
+
*/
|
|
182
|
+
function majorTonicFromKeySignature(sig) {
|
|
183
|
+
if (typeof sig === "number") return (0, _tonaljs_note.transposeFifths)("C", sig);
|
|
184
|
+
else if (typeof sig === "string" && /^b+|#+$/.test(sig)) return (0, _tonaljs_note.transposeFifths)("C", (0, _tonaljs_pitch_note.accToAlt)(sig));
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
/** @deprecated */
|
|
188
|
+
var key_default = {
|
|
189
|
+
majorKey,
|
|
190
|
+
majorTonicFromKeySignature,
|
|
191
|
+
minorKey
|
|
192
|
+
};
|
|
193
|
+
//#endregion
|
|
194
|
+
exports.default = key_default;
|
|
195
|
+
exports.majorKey = majorKey;
|
|
196
|
+
exports.majorKeyChords = majorKeyChords;
|
|
197
|
+
exports.majorTonicFromKeySignature = majorTonicFromKeySignature;
|
|
198
|
+
exports.minorKey = minorKey;
|
|
199
|
+
exports.minorKeyChords = minorKeyChords;
|
|
200
|
+
|
|
201
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":[],"sources":["../index.ts"],"sourcesContent":["import { transpose, transposeFifths } from \"@tonaljs/note\";\nimport { accToAlt, altToAcc, note } from \"@tonaljs/pitch-note\";\nimport { get as roman } from \"@tonaljs/roman-numeral\";\n\nconst Empty: readonly string[] = Object.freeze([] as string[]);\n\nexport interface Key {\n readonly type: \"major\" | \"minor\";\n readonly tonic: string;\n readonly alteration: number;\n readonly keySignature: string;\n}\n\nconst NoKey: Key = {\n type: \"major\",\n tonic: \"\",\n alteration: 0,\n keySignature: \"\",\n};\n\nexport interface KeyScale {\n readonly tonic: string;\n readonly grades: readonly string[];\n readonly intervals: readonly string[];\n readonly scale: readonly string[];\n readonly triads: readonly string[];\n readonly chords: readonly string[];\n readonly chordsHarmonicFunction: readonly string[];\n readonly chordScales: readonly string[];\n readonly secondaryDominants: readonly string[];\n readonly secondaryDominantSupertonics: readonly string[];\n readonly substituteDominants: readonly string[];\n readonly substituteDominantSupertonics: readonly string[];\n\n // @deprecated use secondaryDominantsSupertonic\n readonly secondaryDominantsMinorRelative: readonly string[];\n // @deprecated use substituteDominantSupertonics\n readonly substituteDominantsMinorRelative: readonly string[];\n}\n\nconst NoKeyScale: KeyScale = {\n tonic: \"\",\n grades: Empty,\n intervals: Empty,\n scale: Empty,\n triads: Empty,\n chords: Empty,\n chordsHarmonicFunction: Empty,\n chordScales: Empty,\n secondaryDominants: Empty,\n secondaryDominantSupertonics: Empty,\n substituteDominantsMinorRelative: Empty,\n substituteDominants: Empty,\n substituteDominantSupertonics: Empty,\n secondaryDominantsMinorRelative: Empty,\n};\n\nexport interface MajorKey extends Key, KeyScale {\n readonly type: \"major\";\n readonly minorRelative: string;\n readonly scale: readonly string[];\n readonly substituteDominants: readonly string[];\n readonly secondaryDominantSupertonics: readonly string[];\n // @deprecated use secondaryDominantsSupertonic\n readonly substituteDominantsMinorRelative: readonly string[];\n}\n\nconst NoMajorKey: MajorKey = {\n ...NoKey,\n ...NoKeyScale,\n type: \"major\",\n minorRelative: \"\",\n scale: Empty,\n substituteDominants: Empty,\n secondaryDominantSupertonics: Empty,\n substituteDominantsMinorRelative: Empty,\n};\n\nexport interface MinorKey extends Key {\n readonly type: \"minor\";\n readonly relativeMajor: string;\n readonly natural: KeyScale;\n readonly harmonic: KeyScale;\n readonly melodic: KeyScale;\n}\n\nconst NoMinorKey: MinorKey = {\n ...NoKey,\n type: \"minor\",\n relativeMajor: \"\",\n natural: NoKeyScale,\n harmonic: NoKeyScale,\n melodic: NoKeyScale,\n};\n\nexport type KeyChord = {\n name: string;\n roles: string[];\n};\n\nconst mapScaleToType = (scale: string[], list: string[], sep = \"\") =>\n list.map((type, i) => `${scale[i]}${sep}${type}`);\n\nfunction keyScale(\n grades: string[],\n triads: string[],\n chordTypes: string[],\n harmonicFunctions: string[],\n chordScales: string[],\n) {\n return (tonic: string): KeyScale => {\n const intervals = grades.map((gr) => roman(gr).interval || \"\");\n const scale = intervals.map((interval) => transpose(tonic, interval));\n const chords = mapScaleToType(scale, chordTypes);\n const secondaryDominants = scale\n .map((note) => transpose(note, \"5P\"))\n .map((note) =>\n // A secondary dominant is a V chord which:\n // 1. is not diatonic to the key,\n // 2. it must have a diatonic root.\n scale.includes(note) && !chords.includes(note + \"7\") ? note + \"7\" : \"\",\n );\n\n const secondaryDominantSupertonics = supertonics(\n secondaryDominants,\n triads,\n );\n const substituteDominants = secondaryDominants.map((chord) => {\n if (!chord) return \"\";\n const domRoot = chord.slice(0, -1);\n const subRoot = transpose(domRoot, \"5d\");\n return subRoot + \"7\";\n });\n const substituteDominantSupertonics = supertonics(\n substituteDominants,\n triads,\n );\n\n return {\n tonic,\n grades,\n intervals,\n scale,\n triads: mapScaleToType(scale, triads),\n chords,\n chordsHarmonicFunction: harmonicFunctions.slice(),\n chordScales: mapScaleToType(scale, chordScales, \" \"),\n secondaryDominants,\n secondaryDominantSupertonics,\n substituteDominants,\n substituteDominantSupertonics,\n\n // @deprecated use secondaryDominantsSupertonic\n secondaryDominantsMinorRelative: secondaryDominantSupertonics,\n // @deprecated use secondaryDominantsSupertonic\n substituteDominantsMinorRelative: substituteDominantSupertonics,\n };\n };\n}\n\nconst supertonics = (dominants: string[], targetTriads: string[]) => {\n return dominants.map((chord, index) => {\n if (!chord) return \"\";\n const domRoot = chord.slice(0, -1);\n const minorRoot = transpose(domRoot, \"5P\");\n const target = targetTriads[index];\n const isMinor = target.endsWith(\"m\");\n return isMinor ? minorRoot + \"m7\" : minorRoot + \"m7b5\";\n });\n};\n\nconst distInFifths = (from: string, to: string) => {\n const f = note(from);\n const t = note(to);\n return f.empty || t.empty ? 0 : t.coord[0] - f.coord[0];\n};\n\nconst MajorScale = keyScale(\n \"I II III IV V VI VII\".split(\" \"),\n \" m m m dim\".split(\" \"),\n \"maj7 m7 m7 maj7 7 m7 m7b5\".split(\" \"),\n \"T SD T SD D T D\".split(\" \"),\n \"major,dorian,phrygian,lydian,mixolydian,minor,locrian\".split(\",\"),\n);\nconst NaturalScale = keyScale(\n \"I II bIII IV V bVI bVII\".split(\" \"),\n \"m dim m m \".split(\" \"),\n \"m7 m7b5 maj7 m7 m7 maj7 7\".split(\" \"),\n \"T SD T SD D SD SD\".split(\" \"),\n \"minor,locrian,major,dorian,phrygian,lydian,mixolydian\".split(\",\"),\n);\nconst HarmonicScale = keyScale(\n \"I II bIII IV V bVI VII\".split(\" \"),\n \"m dim aug m dim\".split(\" \"),\n \"mMaj7 m7b5 +maj7 m7 7 maj7 o7\".split(\" \"),\n \"T SD T SD D SD D\".split(\" \"),\n \"harmonic minor,locrian 6,major augmented,lydian diminished,phrygian dominant,lydian #9,ultralocrian\".split(\n \",\",\n ),\n);\nconst MelodicScale = keyScale(\n \"I II bIII IV V VI VII\".split(\" \"),\n \"m m aug dim dim\".split(\" \"),\n \"m6 m7 +maj7 7 7 m7b5 m7b5\".split(\" \"),\n \"T SD T SD D \".split(\" \"),\n \"melodic minor,dorian b2,lydian augmented,lydian dominant,mixolydian b6,locrian #2,altered\".split(\n \",\",\n ),\n);\n\n/**\n * Get a major key properties in a given tonic\n * @param tonic\n */\nexport function majorKey(tonic: string): MajorKey {\n const pc = note(tonic).pc;\n if (!pc) return NoMajorKey;\n\n const keyScale = MajorScale(pc);\n const alteration = distInFifths(\"C\", pc);\n\n return {\n ...keyScale,\n type: \"major\",\n minorRelative: transpose(pc, \"-3m\"),\n alteration,\n keySignature: altToAcc(alteration),\n };\n}\n\n/**\n * Get a list of available chords for a given major key\n * @param tonic\n * @returns array of { name: string, roles: string[] }\n */\nexport function majorKeyChords(tonic: string): KeyChord[] {\n const key = majorKey(tonic);\n const chords: KeyChord[] = [];\n keyChordsOf(key, chords);\n return chords;\n}\n\n/**\n * Get a list of available chords for a given major key\n * @param tonic\n * @returns array of { name: string, roles: string[] }\n */\nexport function minorKeyChords(tonic: string): KeyChord[] {\n const key = minorKey(tonic);\n const chords: KeyChord[] = [];\n keyChordsOf(key.natural, chords);\n keyChordsOf(key.harmonic, chords);\n keyChordsOf(key.melodic, chords);\n return chords;\n}\n\nfunction keyChordsOf(key: KeyScale, chords: KeyChord[]) {\n const updateChord = (name: string, newRole: string) => {\n if (!name) return;\n let keyChord = chords.find((chord) => chord.name === name);\n if (!keyChord) {\n keyChord = { name, roles: [] };\n chords.push(keyChord);\n }\n if (newRole && !keyChord.roles.includes(newRole)) {\n keyChord.roles.push(newRole);\n }\n };\n\n key.chords.forEach((chordName, index) =>\n updateChord(chordName, key.chordsHarmonicFunction[index]),\n );\n key.secondaryDominants.forEach((chordName, index) =>\n updateChord(chordName, `V/${key.grades[index]}`),\n );\n key.secondaryDominantSupertonics.forEach((chordName, index) =>\n updateChord(chordName, `ii/${key.grades[index]}`),\n );\n key.substituteDominants.forEach((chordName, index) =>\n updateChord(chordName, `subV/${key.grades[index]}`),\n );\n key.substituteDominantSupertonics.forEach((chordName, index) =>\n updateChord(chordName, `subii/${key.grades[index]}`),\n );\n}\n\n/**\n * Get minor key properties in a given tonic\n * @param tonic\n */\nexport function minorKey(tnc: string): MinorKey {\n const pc = note(tnc).pc;\n if (!pc) return NoMinorKey;\n\n const alteration = distInFifths(\"C\", pc) - 3;\n return {\n type: \"minor\",\n tonic: pc,\n relativeMajor: transpose(pc, \"3m\"),\n alteration,\n keySignature: altToAcc(alteration),\n natural: NaturalScale(pc),\n harmonic: HarmonicScale(pc),\n melodic: MelodicScale(pc),\n };\n}\n\n/**\n * Given a key signature, returns the tonic of the major key\n * @param signature\n * @example\n * majorTonicFromKeySignature('###') // => 'A'\n */\nexport function majorTonicFromKeySignature(\n sig: string | number,\n): string | null {\n if (typeof sig === \"number\") {\n return transposeFifths(\"C\", sig);\n } else if (typeof sig === \"string\" && /^b+|#+$/.test(sig)) {\n return transposeFifths(\"C\", accToAlt(sig));\n }\n return null;\n}\n\n/** @deprecated */\nexport default { majorKey, majorTonic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WAAW,IAAI,uBAAuB,MAAM,CAC1D;CACA,IAAI,mBAAmB,SAAS,WAAW,UACzC,YAAY,WAAW,KAAK,IAAI,OAAO,QAAQ,CACjD;CACA,IAAI,6BAA6B,SAAS,WAAW,UACnD,YAAY,WAAW,MAAM,IAAI,OAAO,QAAQ,CAClD;CACA,IAAI,oBAAoB,SAAS,WAAW,UAC1C,YAAY,WAAW,QAAQ,IAAI,OAAO,QAAQ,CACpD;CACA,IAAI,8BAA8B,SAAS,WAAW,UACpD,YAAY,WAAW,SAAS,IAAI,OAAO,QAAQ,CACrD;AACF;;;;;AAMA,SAAgB,SAAS,KAAuB;CAC9C,MAAM,MAAA,GAAA,oBAAA,KAAA,CAAU,GAAG,CAAC,CAAC;CACrB,IAAI,CAAC,IAAI,OAAO;CAEhB,MAAM,aAAa,aAAa,KAAK,EAAE,IAAI;CAC3C,OAAO;EACL,MAAM;EACN,OAAO;EACP,gBAAA,GAAA,cAAA,UAAA,CAAyB,IAAI,IAAI;EACjC;EACA,eAAA,GAAA,oBAAA,SAAA,CAAuB,UAAU;EACjC,SAAS,aAAa,EAAE;EACxB,UAAU,cAAc,EAAE;EAC1B,SAAS,aAAa,EAAE;CAC1B;AACF;;;;;;;AAQA,SAAgB,2BACd,KACe;CACf,IAAI,OAAO,QAAQ,UACjB,QAAA,GAAA,cAAA,gBAAA,CAAuB,KAAK,GAAG;MAC1B,IAAI,OAAO,QAAQ,YAAY,UAAU,KAAK,GAAG,GACtD,QAAA,GAAA,cAAA,gBAAA,CAAuB,MAAA,GAAA,oBAAA,SAAA,CAAc,GAAG,CAAC;CAE3C,OAAO;AACT;;AAGA,IAAA,cAAe;CAAE;CAAU;CAA4B;AAAS"}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
//#region index.d.ts
|
|
2
|
+
interface Key {
|
|
3
|
+
readonly type: "major" | "minor";
|
|
4
|
+
readonly tonic: string;
|
|
5
|
+
readonly alteration: number;
|
|
6
|
+
readonly keySignature: string;
|
|
7
|
+
}
|
|
8
|
+
interface KeyScale {
|
|
9
|
+
readonly tonic: string;
|
|
10
|
+
readonly grades: readonly string[];
|
|
11
|
+
readonly intervals: readonly string[];
|
|
12
|
+
readonly scale: readonly string[];
|
|
13
|
+
readonly triads: readonly string[];
|
|
14
|
+
readonly chords: readonly string[];
|
|
15
|
+
readonly chordsHarmonicFunction: readonly string[];
|
|
16
|
+
readonly chordScales: readonly string[];
|
|
17
|
+
readonly secondaryDominants: readonly string[];
|
|
18
|
+
readonly secondaryDominantSupertonics: readonly string[];
|
|
19
|
+
readonly substituteDominants: readonly string[];
|
|
20
|
+
readonly substituteDominantSupertonics: readonly string[];
|
|
21
|
+
readonly secondaryDominantsMinorRelative: readonly string[];
|
|
22
|
+
readonly substituteDominantsMinorRelative: readonly string[];
|
|
23
|
+
}
|
|
24
|
+
interface MajorKey extends Key, KeyScale {
|
|
25
|
+
readonly type: "major";
|
|
26
|
+
readonly minorRelative: string;
|
|
27
|
+
readonly scale: readonly string[];
|
|
28
|
+
readonly substituteDominants: readonly string[];
|
|
29
|
+
readonly secondaryDominantSupertonics: readonly string[];
|
|
30
|
+
readonly substituteDominantsMinorRelative: readonly string[];
|
|
31
|
+
}
|
|
32
|
+
interface MinorKey extends Key {
|
|
33
|
+
readonly type: "minor";
|
|
34
|
+
readonly relativeMajor: string;
|
|
35
|
+
readonly natural: KeyScale;
|
|
36
|
+
readonly harmonic: KeyScale;
|
|
37
|
+
readonly melodic: KeyScale;
|
|
38
|
+
}
|
|
39
|
+
type KeyChord = {
|
|
40
|
+
name: string;
|
|
41
|
+
roles: string[];
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Get a major key properties in a given tonic
|
|
45
|
+
* @param tonic
|
|
46
|
+
*/
|
|
47
|
+
declare function majorKey(tonic: string): MajorKey;
|
|
48
|
+
/**
|
|
49
|
+
* Get a list of available chords for a given major key
|
|
50
|
+
* @param tonic
|
|
51
|
+
* @returns array of { name: string, roles: string[] }
|
|
52
|
+
*/
|
|
53
|
+
declare function majorKeyChords(tonic: string): KeyChord[];
|
|
54
|
+
/**
|
|
55
|
+
* Get a list of available chords for a given major key
|
|
56
|
+
* @param tonic
|
|
57
|
+
* @returns array of { name: string, roles: string[] }
|
|
58
|
+
*/
|
|
59
|
+
declare function minorKeyChords(tonic: string): KeyChord[];
|
|
60
|
+
/**
|
|
61
|
+
* Get minor key properties in a given tonic
|
|
62
|
+
* @param tonic
|
|
63
|
+
*/
|
|
64
|
+
declare function minorKey(tnc: string): MinorKey;
|
|
65
|
+
/**
|
|
66
|
+
* Given a key signature, returns the tonic of the major key
|
|
67
|
+
* @param signature
|
|
68
|
+
* @example
|
|
69
|
+
* majorTonicFromKeySignature('###') // => 'A'
|
|
70
|
+
*/
|
|
71
|
+
declare function majorTonicFromKeySignature(sig: string | number): string | null;
|
|
72
|
+
/** @deprecated */
|
|
73
|
+
declare const _default: {
|
|
74
|
+
majorKey: typeof majorKey;
|
|
75
|
+
majorTonicFromKeySignature: typeof majorTonicFromKeySignature;
|
|
76
|
+
minorKey: typeof minorKey;
|
|
77
|
+
};
|
|
78
|
+
//#endregion
|
|
79
|
+
export { Key, KeyChord, KeyScale, MajorKey, MinorKey, _default as default, majorKey, majorKeyChords, majorTonicFromKeySignature, minorKey, minorKeyChords };
|
|
80
|
+
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.mts
CHANGED
|
@@ -1,43 +1,44 @@
|
|
|
1
|
+
//#region index.d.ts
|
|
1
2
|
interface Key {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
readonly type: "major" | "minor";
|
|
4
|
+
readonly tonic: string;
|
|
5
|
+
readonly alteration: number;
|
|
6
|
+
readonly keySignature: string;
|
|
6
7
|
}
|
|
7
8
|
interface KeyScale {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
9
|
+
readonly tonic: string;
|
|
10
|
+
readonly grades: readonly string[];
|
|
11
|
+
readonly intervals: readonly string[];
|
|
12
|
+
readonly scale: readonly string[];
|
|
13
|
+
readonly triads: readonly string[];
|
|
14
|
+
readonly chords: readonly string[];
|
|
15
|
+
readonly chordsHarmonicFunction: readonly string[];
|
|
16
|
+
readonly chordScales: readonly string[];
|
|
17
|
+
readonly secondaryDominants: readonly string[];
|
|
18
|
+
readonly secondaryDominantSupertonics: readonly string[];
|
|
19
|
+
readonly substituteDominants: readonly string[];
|
|
20
|
+
readonly substituteDominantSupertonics: readonly string[];
|
|
21
|
+
readonly secondaryDominantsMinorRelative: readonly string[];
|
|
22
|
+
readonly substituteDominantsMinorRelative: readonly string[];
|
|
22
23
|
}
|
|
23
24
|
interface MajorKey extends Key, KeyScale {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
readonly type: "major";
|
|
26
|
+
readonly minorRelative: string;
|
|
27
|
+
readonly scale: readonly string[];
|
|
28
|
+
readonly substituteDominants: readonly string[];
|
|
29
|
+
readonly secondaryDominantSupertonics: readonly string[];
|
|
30
|
+
readonly substituteDominantsMinorRelative: readonly string[];
|
|
30
31
|
}
|
|
31
32
|
interface MinorKey extends Key {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
readonly type: "minor";
|
|
34
|
+
readonly relativeMajor: string;
|
|
35
|
+
readonly natural: KeyScale;
|
|
36
|
+
readonly harmonic: KeyScale;
|
|
37
|
+
readonly melodic: KeyScale;
|
|
37
38
|
}
|
|
38
39
|
type KeyChord = {
|
|
39
|
-
|
|
40
|
-
|
|
40
|
+
name: string;
|
|
41
|
+
roles: string[];
|
|
41
42
|
};
|
|
42
43
|
/**
|
|
43
44
|
* Get a major key properties in a given tonic
|
|
@@ -70,9 +71,10 @@ declare function minorKey(tnc: string): MinorKey;
|
|
|
70
71
|
declare function majorTonicFromKeySignature(sig: string | number): string | null;
|
|
71
72
|
/** @deprecated */
|
|
72
73
|
declare const _default: {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
majorKey: typeof majorKey;
|
|
75
|
+
majorTonicFromKeySignature: typeof majorTonicFromKeySignature;
|
|
76
|
+
minorKey: typeof minorKey;
|
|
76
77
|
};
|
|
77
|
-
|
|
78
|
-
export {
|
|
78
|
+
//#endregion
|
|
79
|
+
export { Key, KeyChord, KeyScale, MajorKey, MinorKey, _default as default, majorKey, majorKeyChords, majorTonicFromKeySignature, minorKey, minorKeyChords };
|
|
80
|
+
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.mjs
CHANGED
|
@@ -1,228 +1,192 @@
|
|
|
1
|
-
// index.ts
|
|
2
1
|
import { transpose, transposeFifths } from "@tonaljs/note";
|
|
3
2
|
import { accToAlt, altToAcc, note } from "@tonaljs/pitch-note";
|
|
4
|
-
import { get
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
import { get } from "@tonaljs/roman-numeral";
|
|
4
|
+
//#region index.ts
|
|
5
|
+
const Empty = Object.freeze([]);
|
|
6
|
+
const NoKey = {
|
|
7
|
+
type: "major",
|
|
8
|
+
tonic: "",
|
|
9
|
+
alteration: 0,
|
|
10
|
+
keySignature: ""
|
|
11
11
|
};
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
12
|
+
const NoKeyScale = {
|
|
13
|
+
tonic: "",
|
|
14
|
+
grades: Empty,
|
|
15
|
+
intervals: Empty,
|
|
16
|
+
scale: Empty,
|
|
17
|
+
triads: Empty,
|
|
18
|
+
chords: Empty,
|
|
19
|
+
chordsHarmonicFunction: Empty,
|
|
20
|
+
chordScales: Empty,
|
|
21
|
+
secondaryDominants: Empty,
|
|
22
|
+
secondaryDominantSupertonics: Empty,
|
|
23
|
+
substituteDominantsMinorRelative: Empty,
|
|
24
|
+
substituteDominants: Empty,
|
|
25
|
+
substituteDominantSupertonics: Empty,
|
|
26
|
+
secondaryDominantsMinorRelative: Empty
|
|
27
27
|
};
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
28
|
+
const NoMajorKey = {
|
|
29
|
+
...NoKey,
|
|
30
|
+
...NoKeyScale,
|
|
31
|
+
type: "major",
|
|
32
|
+
minorRelative: "",
|
|
33
|
+
scale: Empty,
|
|
34
|
+
substituteDominants: Empty,
|
|
35
|
+
secondaryDominantSupertonics: Empty,
|
|
36
|
+
substituteDominantsMinorRelative: Empty
|
|
37
37
|
};
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
38
|
+
const NoMinorKey = {
|
|
39
|
+
...NoKey,
|
|
40
|
+
type: "minor",
|
|
41
|
+
relativeMajor: "",
|
|
42
|
+
natural: NoKeyScale,
|
|
43
|
+
harmonic: NoKeyScale,
|
|
44
|
+
melodic: NoKeyScale
|
|
45
45
|
};
|
|
46
|
-
|
|
46
|
+
const mapScaleToType = (scale, list, sep = "") => list.map((type, i) => `${scale[i]}${sep}${type}`);
|
|
47
47
|
function keyScale(grades, triads, chordTypes, harmonicFunctions, chordScales) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
grades,
|
|
77
|
-
intervals,
|
|
78
|
-
scale,
|
|
79
|
-
triads: mapScaleToType(scale, triads),
|
|
80
|
-
chords,
|
|
81
|
-
chordsHarmonicFunction: harmonicFunctions.slice(),
|
|
82
|
-
chordScales: mapScaleToType(scale, chordScales, " "),
|
|
83
|
-
secondaryDominants,
|
|
84
|
-
secondaryDominantSupertonics,
|
|
85
|
-
substituteDominants,
|
|
86
|
-
substituteDominantSupertonics,
|
|
87
|
-
// @deprecated use secondaryDominantsSupertonic
|
|
88
|
-
secondaryDominantsMinorRelative: secondaryDominantSupertonics,
|
|
89
|
-
// @deprecated use secondaryDominantsSupertonic
|
|
90
|
-
substituteDominantsMinorRelative: substituteDominantSupertonics
|
|
91
|
-
};
|
|
92
|
-
};
|
|
48
|
+
return (tonic) => {
|
|
49
|
+
const intervals = grades.map((gr) => get(gr).interval || "");
|
|
50
|
+
const scale = intervals.map((interval) => transpose(tonic, interval));
|
|
51
|
+
const chords = mapScaleToType(scale, chordTypes);
|
|
52
|
+
const secondaryDominants = scale.map((note) => transpose(note, "5P")).map((note) => scale.includes(note) && !chords.includes(note + "7") ? note + "7" : "");
|
|
53
|
+
const secondaryDominantSupertonics = supertonics(secondaryDominants, triads);
|
|
54
|
+
const substituteDominants = secondaryDominants.map((chord) => {
|
|
55
|
+
if (!chord) return "";
|
|
56
|
+
return transpose(chord.slice(0, -1), "5d") + "7";
|
|
57
|
+
});
|
|
58
|
+
const substituteDominantSupertonics = supertonics(substituteDominants, triads);
|
|
59
|
+
return {
|
|
60
|
+
tonic,
|
|
61
|
+
grades,
|
|
62
|
+
intervals,
|
|
63
|
+
scale,
|
|
64
|
+
triads: mapScaleToType(scale, triads),
|
|
65
|
+
chords,
|
|
66
|
+
chordsHarmonicFunction: harmonicFunctions.slice(),
|
|
67
|
+
chordScales: mapScaleToType(scale, chordScales, " "),
|
|
68
|
+
secondaryDominants,
|
|
69
|
+
secondaryDominantSupertonics,
|
|
70
|
+
substituteDominants,
|
|
71
|
+
substituteDominantSupertonics,
|
|
72
|
+
secondaryDominantsMinorRelative: secondaryDominantSupertonics,
|
|
73
|
+
substituteDominantsMinorRelative: substituteDominantSupertonics
|
|
74
|
+
};
|
|
75
|
+
};
|
|
93
76
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const isMinor = target.endsWith("m");
|
|
101
|
-
return isMinor ? minorRoot + "m7" : minorRoot + "m7b5";
|
|
102
|
-
});
|
|
77
|
+
const supertonics = (dominants, targetTriads) => {
|
|
78
|
+
return dominants.map((chord, index) => {
|
|
79
|
+
if (!chord) return "";
|
|
80
|
+
const minorRoot = transpose(chord.slice(0, -1), "5P");
|
|
81
|
+
return targetTriads[index].endsWith("m") ? minorRoot + "m7" : minorRoot + "m7b5";
|
|
82
|
+
});
|
|
103
83
|
};
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
84
|
+
const distInFifths = (from, to) => {
|
|
85
|
+
const f = note(from);
|
|
86
|
+
const t = note(to);
|
|
87
|
+
return f.empty || t.empty ? 0 : t.coord[0] - f.coord[0];
|
|
108
88
|
};
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
"I II bIII IV V bVI bVII".split(" "),
|
|
118
|
-
"m dim m m ".split(" "),
|
|
119
|
-
"m7 m7b5 maj7 m7 m7 maj7 7".split(" "),
|
|
120
|
-
"T SD T SD D SD SD".split(" "),
|
|
121
|
-
"minor,locrian,major,dorian,phrygian,lydian,mixolydian".split(",")
|
|
122
|
-
);
|
|
123
|
-
var HarmonicScale = keyScale(
|
|
124
|
-
"I II bIII IV V bVI VII".split(" "),
|
|
125
|
-
"m dim aug m dim".split(" "),
|
|
126
|
-
"mMaj7 m7b5 +maj7 m7 7 maj7 o7".split(" "),
|
|
127
|
-
"T SD T SD D SD D".split(" "),
|
|
128
|
-
"harmonic minor,locrian 6,major augmented,lydian diminished,phrygian dominant,lydian #9,ultralocrian".split(
|
|
129
|
-
","
|
|
130
|
-
)
|
|
131
|
-
);
|
|
132
|
-
var MelodicScale = keyScale(
|
|
133
|
-
"I II bIII IV V VI VII".split(" "),
|
|
134
|
-
"m m aug dim dim".split(" "),
|
|
135
|
-
"m6 m7 +maj7 7 7 m7b5 m7b5".split(" "),
|
|
136
|
-
"T SD T SD D ".split(" "),
|
|
137
|
-
"melodic minor,dorian b2,lydian augmented,lydian dominant,mixolydian b6,locrian #2,altered".split(
|
|
138
|
-
","
|
|
139
|
-
)
|
|
140
|
-
);
|
|
89
|
+
const MajorScale = keyScale("I II III IV V VI VII".split(" "), " m m m dim".split(" "), "maj7 m7 m7 maj7 7 m7 m7b5".split(" "), "T SD T SD D T D".split(" "), "major,dorian,phrygian,lydian,mixolydian,minor,locrian".split(","));
|
|
90
|
+
const NaturalScale = keyScale("I II bIII IV V bVI bVII".split(" "), "m dim m m ".split(" "), "m7 m7b5 maj7 m7 m7 maj7 7".split(" "), "T SD T SD D SD SD".split(" "), "minor,locrian,major,dorian,phrygian,lydian,mixolydian".split(","));
|
|
91
|
+
const HarmonicScale = keyScale("I II bIII IV V bVI VII".split(" "), "m dim aug m dim".split(" "), "mMaj7 m7b5 +maj7 m7 7 maj7 o7".split(" "), "T SD T SD D SD D".split(" "), "harmonic minor,locrian 6,major augmented,lydian diminished,phrygian dominant,lydian #9,ultralocrian".split(","));
|
|
92
|
+
const MelodicScale = keyScale("I II bIII IV V VI VII".split(" "), "m m aug dim dim".split(" "), "m6 m7 +maj7 7 7 m7b5 m7b5".split(" "), "T SD T SD D ".split(" "), "melodic minor,dorian b2,lydian augmented,lydian dominant,mixolydian b6,locrian #2,altered".split(","));
|
|
93
|
+
/**
|
|
94
|
+
* Get a major key properties in a given tonic
|
|
95
|
+
* @param tonic
|
|
96
|
+
*/
|
|
141
97
|
function majorKey(tonic) {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
98
|
+
const pc = note(tonic).pc;
|
|
99
|
+
if (!pc) return NoMajorKey;
|
|
100
|
+
const keyScale = MajorScale(pc);
|
|
101
|
+
const alteration = distInFifths("C", pc);
|
|
102
|
+
return {
|
|
103
|
+
...keyScale,
|
|
104
|
+
type: "major",
|
|
105
|
+
minorRelative: transpose(pc, "-3m"),
|
|
106
|
+
alteration,
|
|
107
|
+
keySignature: altToAcc(alteration)
|
|
108
|
+
};
|
|
153
109
|
}
|
|
110
|
+
/**
|
|
111
|
+
* Get a list of available chords for a given major key
|
|
112
|
+
* @param tonic
|
|
113
|
+
* @returns array of { name: string, roles: string[] }
|
|
114
|
+
*/
|
|
154
115
|
function majorKeyChords(tonic) {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
116
|
+
const key = majorKey(tonic);
|
|
117
|
+
const chords = [];
|
|
118
|
+
keyChordsOf(key, chords);
|
|
119
|
+
return chords;
|
|
159
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* Get a list of available chords for a given major key
|
|
123
|
+
* @param tonic
|
|
124
|
+
* @returns array of { name: string, roles: string[] }
|
|
125
|
+
*/
|
|
160
126
|
function minorKeyChords(tonic) {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
127
|
+
const key = minorKey(tonic);
|
|
128
|
+
const chords = [];
|
|
129
|
+
keyChordsOf(key.natural, chords);
|
|
130
|
+
keyChordsOf(key.harmonic, chords);
|
|
131
|
+
keyChordsOf(key.melodic, chords);
|
|
132
|
+
return chords;
|
|
167
133
|
}
|
|
168
134
|
function keyChordsOf(key, chords) {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
key.secondaryDominantSupertonics.forEach(
|
|
187
|
-
(chordName, index) => updateChord(chordName, `ii/${key.grades[index]}`)
|
|
188
|
-
);
|
|
189
|
-
key.substituteDominants.forEach(
|
|
190
|
-
(chordName, index) => updateChord(chordName, `subV/${key.grades[index]}`)
|
|
191
|
-
);
|
|
192
|
-
key.substituteDominantSupertonics.forEach(
|
|
193
|
-
(chordName, index) => updateChord(chordName, `subii/${key.grades[index]}`)
|
|
194
|
-
);
|
|
135
|
+
const updateChord = (name, newRole) => {
|
|
136
|
+
if (!name) return;
|
|
137
|
+
let keyChord = chords.find((chord) => chord.name === name);
|
|
138
|
+
if (!keyChord) {
|
|
139
|
+
keyChord = {
|
|
140
|
+
name,
|
|
141
|
+
roles: []
|
|
142
|
+
};
|
|
143
|
+
chords.push(keyChord);
|
|
144
|
+
}
|
|
145
|
+
if (newRole && !keyChord.roles.includes(newRole)) keyChord.roles.push(newRole);
|
|
146
|
+
};
|
|
147
|
+
key.chords.forEach((chordName, index) => updateChord(chordName, key.chordsHarmonicFunction[index]));
|
|
148
|
+
key.secondaryDominants.forEach((chordName, index) => updateChord(chordName, `V/${key.grades[index]}`));
|
|
149
|
+
key.secondaryDominantSupertonics.forEach((chordName, index) => updateChord(chordName, `ii/${key.grades[index]}`));
|
|
150
|
+
key.substituteDominants.forEach((chordName, index) => updateChord(chordName, `subV/${key.grades[index]}`));
|
|
151
|
+
key.substituteDominantSupertonics.forEach((chordName, index) => updateChord(chordName, `subii/${key.grades[index]}`));
|
|
195
152
|
}
|
|
153
|
+
/**
|
|
154
|
+
* Get minor key properties in a given tonic
|
|
155
|
+
* @param tonic
|
|
156
|
+
*/
|
|
196
157
|
function minorKey(tnc) {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
158
|
+
const pc = note(tnc).pc;
|
|
159
|
+
if (!pc) return NoMinorKey;
|
|
160
|
+
const alteration = distInFifths("C", pc) - 3;
|
|
161
|
+
return {
|
|
162
|
+
type: "minor",
|
|
163
|
+
tonic: pc,
|
|
164
|
+
relativeMajor: transpose(pc, "3m"),
|
|
165
|
+
alteration,
|
|
166
|
+
keySignature: altToAcc(alteration),
|
|
167
|
+
natural: NaturalScale(pc),
|
|
168
|
+
harmonic: HarmonicScale(pc),
|
|
169
|
+
melodic: MelodicScale(pc)
|
|
170
|
+
};
|
|
210
171
|
}
|
|
172
|
+
/**
|
|
173
|
+
* Given a key signature, returns the tonic of the major key
|
|
174
|
+
* @param signature
|
|
175
|
+
* @example
|
|
176
|
+
* majorTonicFromKeySignature('###') // => 'A'
|
|
177
|
+
*/
|
|
211
178
|
function majorTonicFromKeySignature(sig) {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
return transposeFifths("C", accToAlt(sig));
|
|
216
|
-
}
|
|
217
|
-
return null;
|
|
179
|
+
if (typeof sig === "number") return transposeFifths("C", sig);
|
|
180
|
+
else if (typeof sig === "string" && /^b+|#+$/.test(sig)) return transposeFifths("C", accToAlt(sig));
|
|
181
|
+
return null;
|
|
218
182
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
majorTonicFromKeySignature,
|
|
225
|
-
minorKey,
|
|
226
|
-
minorKeyChords
|
|
183
|
+
/** @deprecated */
|
|
184
|
+
var key_default = {
|
|
185
|
+
majorKey,
|
|
186
|
+
majorTonicFromKeySignature,
|
|
187
|
+
minorKey
|
|
227
188
|
};
|
|
189
|
+
//#endregion
|
|
190
|
+
export { key_default as default, majorKey, majorKeyChords, majorTonicFromKeySignature, minorKey, minorKeyChords };
|
|
191
|
+
|
|
228
192
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../index.ts"],"sourcesContent":["import { transpose, transposeFifths } from \"@tonaljs/note\";\nimport { accToAlt, altToAcc, note } from \"@tonaljs/pitch-note\";\nimport { get as roman } from \"@tonaljs/roman-numeral\";\n\nconst Empty: readonly string[] = Object.freeze([] as string[]);\n\nexport interface Key {\n readonly type: \"major\" | \"minor\";\n readonly tonic: string;\n readonly alteration: number;\n readonly keySignature: string;\n}\n\nconst NoKey: Key = {\n type: \"major\",\n tonic: \"\",\n alteration: 0,\n keySignature: \"\",\n};\n\nexport interface KeyScale {\n readonly tonic: string;\n readonly grades: readonly string[];\n readonly intervals: readonly string[];\n readonly scale: readonly string[];\n readonly triads: readonly string[];\n readonly chords: readonly string[];\n readonly chordsHarmonicFunction: readonly string[];\n readonly chordScales: readonly string[];\n readonly secondaryDominants: readonly string[];\n readonly secondaryDominantSupertonics: readonly string[];\n readonly substituteDominants: readonly string[];\n readonly substituteDominantSupertonics: readonly string[];\n\n // @deprecated use secondaryDominantsSupertonic\n readonly secondaryDominantsMinorRelative: readonly string[];\n // @deprecated use substituteDominantSupertonics\n readonly substituteDominantsMinorRelative: readonly string[];\n}\n\nconst NoKeyScale: KeyScale = {\n tonic: \"\",\n grades: Empty,\n intervals: Empty,\n scale: Empty,\n triads: Empty,\n chords: Empty,\n chordsHarmonicFunction: Empty,\n chordScales: Empty,\n secondaryDominants: Empty,\n secondaryDominantSupertonics: Empty,\n substituteDominantsMinorRelative: Empty,\n substituteDominants: Empty,\n substituteDominantSupertonics: Empty,\n secondaryDominantsMinorRelative: Empty,\n};\n\nexport interface MajorKey extends Key, KeyScale {\n readonly type: \"major\";\n readonly minorRelative: string;\n readonly scale: readonly string[];\n readonly substituteDominants: readonly string[];\n readonly secondaryDominantSupertonics: readonly string[];\n // @deprecated use secondaryDominantsSupertonic\n readonly substituteDominantsMinorRelative: readonly string[];\n}\n\nconst NoMajorKey: MajorKey = {\n ...NoKey,\n ...NoKeyScale,\n type: \"major\",\n minorRelative: \"\",\n scale: Empty,\n substituteDominants: Empty,\n secondaryDominantSupertonics: Empty,\n substituteDominantsMinorRelative: Empty,\n};\n\nexport interface MinorKey extends Key {\n readonly type: \"minor\";\n readonly relativeMajor: string;\n readonly natural: KeyScale;\n readonly harmonic: KeyScale;\n readonly melodic: KeyScale;\n}\n\nconst NoMinorKey: MinorKey = {\n ...NoKey,\n type: \"minor\",\n relativeMajor: \"\",\n natural: NoKeyScale,\n harmonic: NoKeyScale,\n melodic: NoKeyScale,\n};\n\nexport type KeyChord = {\n name: string;\n roles: string[];\n};\n\nconst mapScaleToType = (scale: string[], list: string[], sep = \"\") =>\n list.map((type, i) => `${scale[i]}${sep}${type}`);\n\nfunction keyScale(\n grades: string[],\n triads: string[],\n chordTypes: string[],\n harmonicFunctions: string[],\n chordScales: string[],\n) {\n return (tonic: string): KeyScale => {\n const intervals = grades.map((gr) => roman(gr).interval || \"\");\n const scale = intervals.map((interval) => transpose(tonic, interval));\n const chords = mapScaleToType(scale, chordTypes);\n const secondaryDominants = scale\n .map((note) => transpose(note, \"5P\"))\n .map((note) =>\n // A secondary dominant is a V chord which:\n // 1. is not diatonic to the key,\n // 2. it must have a diatonic root.\n scale.includes(note) && !chords.includes(note + \"7\") ? note + \"7\" : \"\",\n );\n\n const secondaryDominantSupertonics = supertonics(\n secondaryDominants,\n triads,\n );\n const substituteDominants = secondaryDominants.map((chord) => {\n if (!chord) return \"\";\n const domRoot = chord.slice(0, -1);\n const subRoot = transpose(domRoot, \"5d\");\n return subRoot + \"7\";\n });\n const substituteDominantSupertonics = supertonics(\n substituteDominants,\n triads,\n );\n\n return {\n tonic,\n grades,\n intervals,\n scale,\n triads: mapScaleToType(scale, triads),\n chords,\n chordsHarmonicFunction: harmonicFunctions.slice(),\n chordScales: mapScaleToType(scale, chordScales, \" \"),\n secondaryDominants,\n secondaryDominantSupertonics,\n substituteDominants,\n substituteDominantSupertonics,\n\n // @deprecated use secondaryDominantsSupertonic\n secondaryDominantsMinorRelative: secondaryDominantSupertonics,\n // @deprecated use secondaryDominantsSupertonic\n substituteDominantsMinorRelative: substituteDominantSupertonics,\n };\n };\n}\n\nconst supertonics = (dominants: string[], targetTriads: string[]) => {\n return dominants.map((chord, index) => {\n if (!chord) return \"\";\n const domRoot = chord.slice(0, -1);\n const minorRoot = transpose(domRoot, \"5P\");\n const target = targetTriads[index];\n const isMinor = target.endsWith(\"m\");\n return isMinor ? minorRoot + \"m7\" : minorRoot + \"m7b5\";\n });\n};\n\nconst distInFifths = (from: string, to: string) => {\n const f = note(from);\n const t = note(to);\n return f.empty || t.empty ? 0 : t.coord[0] - f.coord[0];\n};\n\nconst MajorScale = keyScale(\n \"I II III IV V VI VII\".split(\" \"),\n \" m m m dim\".split(\" \"),\n \"maj7 m7 m7 maj7 7 m7 m7b5\".split(\" \"),\n \"T SD T SD D T D\".split(\" \"),\n \"major,dorian,phrygian,lydian,mixolydian,minor,locrian\".split(\",\"),\n);\nconst NaturalScale = keyScale(\n \"I II bIII IV V bVI bVII\".split(\" \"),\n \"m dim m m \".split(\" \"),\n \"m7 m7b5 maj7 m7 m7 maj7 7\".split(\" \"),\n \"T SD T SD D SD SD\".split(\" \"),\n \"minor,locrian,major,dorian,phrygian,lydian,mixolydian\".split(\",\"),\n);\nconst HarmonicScale = keyScale(\n \"I II bIII IV V bVI VII\".split(\" \"),\n \"m dim aug m dim\".split(\" \"),\n \"mMaj7 m7b5 +maj7 m7 7 maj7 o7\".split(\" \"),\n \"T SD T SD D SD D\".split(\" \"),\n \"harmonic minor,locrian 6,major augmented,lydian diminished,phrygian dominant,lydian #9,ultralocrian\".split(\n \",\",\n ),\n);\nconst MelodicScale = keyScale(\n \"I II bIII IV V VI VII\".split(\" \"),\n \"m m aug dim dim\".split(\" \"),\n \"m6 m7 +maj7 7 7 m7b5 m7b5\".split(\" \"),\n \"T SD T SD D \".split(\" \"),\n \"melodic minor,dorian b2,lydian augmented,lydian dominant,mixolydian b6,locrian #2,altered\".split(\n \",\",\n ),\n);\n\n/**\n * Get a major key properties in a given tonic\n * @param tonic\n */\nexport function majorKey(tonic: string): MajorKey {\n const pc = note(tonic).pc;\n if (!pc) return NoMajorKey;\n\n const keyScale = MajorScale(pc);\n const alteration = distInFifths(\"C\", pc);\n\n return {\n ...keyScale,\n type: \"major\",\n minorRelative: transpose(pc, \"-3m\"),\n alteration,\n keySignature: altToAcc(alteration),\n };\n}\n\n/**\n * Get a list of available chords for a given major key\n * @param tonic\n * @returns array of { name: string, roles: string[] }\n */\nexport function majorKeyChords(tonic: string): KeyChord[] {\n const key = majorKey(tonic);\n const chords: KeyChord[] = [];\n keyChordsOf(key, chords);\n return chords;\n}\n\n/**\n * Get a list of available chords for a given major key\n * @param tonic\n * @returns array of { name: string, roles: string[] }\n */\nexport function minorKeyChords(tonic: string): KeyChord[] {\n const key = minorKey(tonic);\n const chords: KeyChord[] = [];\n keyChordsOf(key.natural, chords);\n keyChordsOf(key.harmonic, chords);\n keyChordsOf(key.melodic, chords);\n return chords;\n}\n\nfunction keyChordsOf(key: KeyScale, chords: KeyChord[]) {\n const updateChord = (name: string, newRole: string) => {\n if (!name) return;\n let keyChord = chords.find((chord) => chord.name === name);\n if (!keyChord) {\n keyChord = { name, roles: [] };\n chords.push(keyChord);\n }\n if (newRole && !keyChord.roles.includes(newRole)) {\n keyChord.roles.push(newRole);\n }\n };\n\n key.chords.forEach((chordName, index) =>\n updateChord(chordName, key.chordsHarmonicFunction[index]),\n );\n key.secondaryDominants.forEach((chordName, index) =>\n updateChord(chordName, `V/${key.grades[index]}`),\n );\n key.secondaryDominantSupertonics.forEach((chordName, index) =>\n updateChord(chordName, `ii/${key.grades[index]}`),\n );\n key.substituteDominants.forEach((chordName, index) =>\n updateChord(chordName, `subV/${key.grades[index]}`),\n );\n key.substituteDominantSupertonics.forEach((chordName, index) =>\n updateChord(chordName, `subii/${key.grades[index]}`),\n );\n}\n\n/**\n * Get minor key properties in a given tonic\n * @param tonic\n */\nexport function minorKey(tnc: string): MinorKey {\n const pc = note(tnc).pc;\n if (!pc) return NoMinorKey;\n\n const alteration = distInFifths(\"C\", pc) - 3;\n return {\n type: \"minor\",\n tonic: pc,\n relativeMajor: transpose(pc, \"3m\"),\n alteration,\n keySignature: altToAcc(alteration),\n natural: NaturalScale(pc),\n harmonic: HarmonicScale(pc),\n melodic: MelodicScale(pc),\n };\n}\n\n/**\n * Given a key signature, returns the tonic of the major key\n * @param signature\n * @example\n * majorTonicFromKeySignature('###') // => 'A'\n */\nexport function majorTonicFromKeySignature(\n sig: string | number,\n): string | null {\n if (typeof sig === \"number\") {\n return transposeFifths(\"C\", sig);\n } else if (typeof sig === \"string\" && /^b+|#+$/.test(sig)) {\n return transposeFifths(\"C\", accToAlt(sig));\n }\n return null;\n}\n\n/** @deprecated */\nexport default { majorKey, majorTonicFromKeySignature, minorKey };\n"],"mappings":";AAAA,SAAS,WAAW,uBAAuB;AAC3C,SAAS,UAAU,UAAU,YAAY;AACzC,SAAS,OAAO,aAAa;AAE7B,IAAM,QAA2B,OAAO,OAAO,CAAC,CAAa;AAS7D,IAAM,QAAa;AAAA,EACjB,MAAM;AAAA,EACN,OAAO;AAAA,EACP,YAAY;AAAA,EACZ,cAAc;AAChB;AAsBA,IAAM,aAAuB;AAAA,EAC3B,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,WAAW;AAAA,EACX,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,wBAAwB;AAAA,EACxB,aAAa;AAAA,EACb,oBAAoB;AAAA,EACpB,8BAA8B;AAAA,EAC9B,kC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AS,GAAG,CAAC;AAAA,EAC3C;AACA,SAAO;AACT;AAGA,IAAO,gBAAQ,EAAE,UAAU,4BAA4B,SAAS;","names":["note","keyScale"]}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["roman"],"sources":["../index.ts"],"sourcesContent":["import { transpose, transposeFifths } from \"@tonaljs/note\";\nimport { accToAlt, altToAcc, note } from \"@tonaljs/pitch-note\";\nimport { get as roman } from \"@tonaljs/roman-numeral\";\n\nconst Empty: readonly string[] = Object.freeze([] as string[]);\n\nexport interface Key {\n readonly type: \"major\" | \"minor\";\n readonly tonic: string;\n readonly alteration: number;\n readonly keySignature: string;\n}\n\nconst NoKey: Key = {\n type: \"major\",\n tonic: \"\",\n alteration: 0,\n keySignature: \"\",\n};\n\nexport interface KeyScale {\n readonly tonic: string;\n readonly grades: readonly string[];\n readonly intervals: readonly string[];\n readonly scale: readonly string[];\n readonly triads: readonly string[];\n readonly chords: readonly string[];\n readonly chordsHarmonicFunction: readonly string[];\n readonly chordScales: readonly string[];\n readonly secondaryDominants: readonly string[];\n readonly secondaryDominantSupertonics: readonly string[];\n readonly substituteDominants: readonly string[];\n readonly substituteDominantSupertonics: readonly string[];\n\n // @deprecated use secondaryDominantsSupertonic\n readonly secondaryDominantsMinorRelative: readonly string[];\n // @deprecated use substituteDominantSupertonics\n readonly substituteDominantsMinorRelative: readonly string[];\n}\n\nconst NoKeyScale: KeyScale = {\n tonic: \"\",\n grades: Empty,\n intervals: Empty,\n scale: Empty,\n triads: Empty,\n chords: Empty,\n chordsHarmonicFunction: Empty,\n chordScales: Empty,\n secondaryDominants: Empty,\n secondaryDominantSupertonics: Empty,\n substituteDominantsMinorRelative: Empty,\n substituteDominants: Empty,\n substituteDominantSupertonics: Empty,\n secondaryDominantsMinorRelative: Empty,\n};\n\nexport interface MajorKey extends Key, KeyScale {\n readonly type: \"major\";\n readonly minorRelative: string;\n readonly scale: readonly string[];\n readonly substituteDominants: readonly string[];\n readonly secondaryDominantSupertonics: readonly string[];\n // @deprecated use secondaryDominantsSupertonic\n readonly substituteDominantsMinorRelative: readonly string[];\n}\n\nconst NoMajorKey: MajorKey = {\n ...NoKey,\n ...NoKeyScale,\n type: \"major\",\n minorRelative: \"\",\n scale: Empty,\n substituteDominants: Empty,\n secondaryDominantSupertonics: Empty,\n substituteDominantsMinorRelative: Empty,\n};\n\nexport interface MinorKey extends Key {\n readonly type: \"minor\";\n readonly relativeMajor: string;\n readonly natural: KeyScale;\n readonly harmonic: KeyScale;\n readonly melodic: KeyScale;\n}\n\nconst NoMinorKey: MinorKey = {\n ...NoKey,\n type: \"minor\",\n relativeMajor: \"\",\n natural: NoKeyScale,\n harmonic: NoKeyScale,\n melodic: NoKeyScale,\n};\n\nexport type KeyChord = {\n name: string;\n roles: string[];\n};\n\nconst mapScaleToType = (scale: string[], list: string[], sep = \"\") =>\n list.map((type, i) => `${scale[i]}${sep}${type}`);\n\nfunction keyScale(\n grades: string[],\n triads: string[],\n chordTypes: string[],\n harmonicFunctions: string[],\n chordScales: string[],\n) {\n return (tonic: string): KeyScale => {\n const intervals = grades.map((gr) => roman(gr).interval || \"\");\n const scale = intervals.map((interval) => transpose(tonic, interval));\n const chords = mapScaleToType(scale, chordTypes);\n const secondaryDominants = scale\n .map((note) => transpose(note, \"5P\"))\n .map((note) =>\n // A secondary dominant is a V chord which:\n // 1. is not diatonic to the key,\n // 2. it must have a diatonic root.\n scale.includes(note) && !chords.includes(note + \"7\") ? note + \"7\" : \"\",\n );\n\n const secondaryDominantSupertonics = supertonics(\n secondaryDominants,\n triads,\n );\n const substituteDominants = secondaryDominants.map((chord) => {\n if (!chord) return \"\";\n const domRoot = chord.slice(0, -1);\n const subRoot = transpose(domRoot, \"5d\");\n return subRoot + \"7\";\n });\n const substituteDominantSupertonics = supertonics(\n substituteDominants,\n triads,\n );\n\n return {\n tonic,\n grades,\n intervals,\n scale,\n triads: mapScaleToType(scale, triads),\n chords,\n chordsHarmonicFunction: harmonicFunctions.slice(),\n chordScales: mapScaleToType(scale, chordScales, \" \"),\n secondaryDominants,\n secondaryDominantSupertonics,\n substituteDominants,\n substituteDominantSupertonics,\n\n // @deprecated use secondaryDominantsSupertonic\n secondaryDominantsMinorRelative: secondaryDominantSupertonics,\n // @deprecated use secondaryDominantsSupertonic\n substituteDominantsMinorRelative: substituteDominantSupertonics,\n };\n };\n}\n\nconst supertonics = (dominants: string[], targetTriads: string[]) => {\n return dominants.map((chord, index) => {\n if (!chord) return \"\";\n const domRoot = chord.slice(0, -1);\n const minorRoot = transpose(domRoot, \"5P\");\n const target = targetTriads[index];\n const isMinor = target.endsWith(\"m\");\n return isMinor ? minorRoot + \"m7\" : minorRoot + \"m7b5\";\n });\n};\n\nconst distInFifths = (from: string, to: string) => {\n const f = note(from);\n const t = note(to);\n return f.empty || t.empty ? 0 : t.coord[0] - f.coord[0];\n};\n\nconst MajorScale = keyScale(\n \"I II III IV V VI VII\".split(\" \"),\n \" m m m dim\".split(\" \"),\n \"maj7 m7 m7 maj7 7 m7 m7b5\".split(\" \"),\n \"T SD T SD D T D\".split(\" \"),\n \"major,dorian,phrygian,lydian,mixolydian,minor,locrian\".split(\",\"),\n);\nconst NaturalScale = keyScale(\n \"I II bIII IV V bVI bVII\".split(\" \"),\n \"m dim m m \".split(\" \"),\n \"m7 m7b5 maj7 m7 m7 maj7 7\".split(\" \"),\n \"T SD T SD D SD SD\".split(\" \"),\n \"minor,locrian,major,dorian,phrygian,lydian,mixolydian\".split(\",\"),\n);\nconst HarmonicScale = keyScale(\n \"I II bIII IV V bVI VII\".split(\" \"),\n \"m dim aug m dim\".split(\" \"),\n \"mMaj7 m7b5 +maj7 m7 7 maj7 o7\".split(\" \"),\n \"T SD T SD D SD D\".split(\" \"),\n \"harmonic minor,locrian 6,major augmented,lydian diminished,phrygian dominant,lydian #9,ultralocrian\".split(\n \",\",\n ),\n);\nconst MelodicScale = keyScale(\n \"I II bIII IV V VI VII\".split(\" \"),\n \"m m aug dim dim\".split(\" \"),\n \"m6 m7 +maj7 7 7 m7b5 m7b5\".split(\" \"),\n \"T SD T SD D \".split(\" \"),\n \"melodic minor,dorian b2,lydian augmented,lydian dominant,mixolydian b6,locrian #2,altered\".split(\n \",\",\n ),\n);\n\n/**\n * Get a major key properties in a given tonic\n * @param tonic\n */\nexport function majorKey(tonic: string): MajorKey {\n const pc = note(tonic).pc;\n if (!pc) return NoMajorKey;\n\n const keyScale = MajorScale(pc);\n const alteration = distInFifths(\"C\", pc);\n\n return {\n ...keyScale,\n type: \"major\",\n minorRelative: transpose(pc, \"-3m\"),\n alteration,\n keySignature: altToAcc(alteration),\n };\n}\n\n/**\n * Get a list of available chords for a given major key\n * @param tonic\n * @returns array of { name: string, roles: string[] }\n */\nexport function majorKeyChords(tonic: string): KeyChord[] {\n const key = majorKey(tonic);\n const chords: KeyChord[] = [];\n keyChordsOf(key, chords);\n return chords;\n}\n\n/**\n * Get a list of available chords for a given major key\n * @param tonic\n * @returns array of { name: string, roles: string[] }\n */\nexport function minorKeyChords(tonic: string): KeyChord[] {\n const key = minorKey(tonic);\n const chords: KeyChord[] = [];\n keyChordsOf(key.natural, chords);\n keyChordsOf(key.harmonic, chords);\n keyChordsOf(key.melodic, chords);\n return chords;\n}\n\nfunction keyChordsOf(key: KeyScale, chords: KeyChord[]) {\n const updateChord = (name: string, newRole: string) => {\n if (!name) return;\n let keyChord = chords.find((chord) => chord.name === name);\n if (!keyChord) {\n keyChord = { name, roles: [] };\n chords.push(keyChord);\n }\n if (newRole && !keyChord.roles.includes(newRole)) {\n keyChord.roles.push(newRole);\n }\n };\n\n key.chords.forEach((chordName, index) =>\n updateChord(chordName, key.chordsHarmonicFunction[index]),\n );\n key.secondaryDominants.forEach((chordName, index) =>\n updateChord(chordName, `V/${key.grades[index]}`),\n );\n key.secondaryDominantSupertonics.forEach((chordName, index) =>\n updateChord(chordName, `ii/${key.grades[index]}`),\n );\n key.substituteDominants.forEach((chordName, index) =>\n updateChord(chordName, `subV/${key.grades[index]}`),\n );\n key.substituteDominantSupertonics.forEach((chordName, index) =>\n updateChord(chordName, `subii/${key.grades[index]}`),\n );\n}\n\n/**\n * Get minor key properties in a given tonic\n * @param tonic\n */\nexport function minorKey(tnc: string): MinorKey {\n const pc = note(tnc).pc;\n if (!pc) return NoMinorKey;\n\n const alteration = distInFifths(\"C\", pc) - 3;\n return {\n type: \"minor\",\n tonic: pc,\n relativeMajor: transpose(pc, \"3m\"),\n alteration,\n keySignature: altToAcc(alteration),\n natural: NaturalScale(pc),\n harmonic: HarmonicScale(pc),\n melodic: MelodicScale(pc),\n };\n}\n\n/**\n * Given a key signature, returns the tonic of the major key\n * @param signature\n * @example\n * majorTonicFromKeySignature('###') // => 'A'\n */\nexport function majorTonicFromKeySignature(\n sig: string | number,\n): string | null {\n if (typeof sig === \"number\") {\n return transposeFifths(\"C\", sig);\n } else if (typeof sig === \"string\" && /^b+|#+$/.test(sig)) {\n return transposeFifths(\"C\", accToAlt(sig));\n }\n return null;\n}\n\n/** @deprecated */\nexport default { majorKey, majorTonicFromKeySignature, minorKey };\n"],"mappings":";;;;AAIA,MAAM,QAA2B,OAAO,OAAO,CAAC,CAAa;AAS7D,MAAM,QAAa;CACjB,MAAM;CACN,OAAO;CACP,YAAY;CACZ,cAAc;AAChB;AAsBA,MAAM,aAAuB;CAC3B,OAAO;CACP,QAAQ;CACR,WAAW;CACX,OAAO;CACP,QAAQ;CACR,QAAQ;CACR,wBAAwB;CACxB,aAAa;CACb,oBAAoB;CACpB,8BAA8B;CAC9B,kCAAkC;CAClC,qBAAqB;CACrB,+BAA+B;CAC/B,iCAAiC;AACnC;AAYA,MAAM,aAAuB;CAC3B,GAAG;CACH,GAAG;CACH,MAAM;CACN,eAAe;CACf,OAAO;CACP,qBAAqB;CACrB,8BAA8B;CAC9B,kCAAkC;AACpC;AAUA,MAAM,aAAuB;CAC3B,GAAG;CACH,MAAM;CACN,eAAe;CACf,SAAS;CACT,UAAU;CACV,SAAS;AACX;AAOA,MAAM,kBAAkB,OAAiB,MAAgB,MA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,UAAU,KAAK,GAAG,GACtD,OAAO,gBAAgB,KAAK,SAAS,GAAG,CAAC;CAE3C,OAAO;AACT;;AAGA,IAAA,cAAe;CAAE;CAAU;CAA4B;AAAS"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tonaljs/key",
|
|
3
|
-
"version": "4.11.
|
|
3
|
+
"version": "4.11.3",
|
|
4
4
|
"description": "Functions to work with musical keys",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"key",
|
|
@@ -15,13 +15,13 @@
|
|
|
15
15
|
],
|
|
16
16
|
"types": "dist/index.d.ts",
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@tonaljs/pitch-note": "6.1.
|
|
19
|
-
"@tonaljs/note": "4.12.
|
|
20
|
-
"@tonaljs/roman-numeral": "4.9.
|
|
18
|
+
"@tonaljs/pitch-note": "6.1.1",
|
|
19
|
+
"@tonaljs/note": "4.12.2",
|
|
20
|
+
"@tonaljs/roman-numeral": "4.9.2"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@tonaljs/chord": "6.
|
|
24
|
-
"@tonaljs/scale": "4.13.
|
|
23
|
+
"@tonaljs/chord": "6.2.0",
|
|
24
|
+
"@tonaljs/scale": "4.13.5"
|
|
25
25
|
},
|
|
26
26
|
"author": "danigb@gmail.com",
|
|
27
27
|
"license": "MIT",
|
|
@@ -29,6 +29,6 @@
|
|
|
29
29
|
"access": "public"
|
|
30
30
|
},
|
|
31
31
|
"scripts": {
|
|
32
|
-
"build": "
|
|
32
|
+
"build": "tsdown index.ts --sourcemap --dts --format esm,cjs"
|
|
33
33
|
}
|
|
34
34
|
}
|
package/dist/index.d.ts
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
interface Key {
|
|
2
|
-
readonly type: "major" | "minor";
|
|
3
|
-
readonly tonic: string;
|
|
4
|
-
readonly alteration: number;
|
|
5
|
-
readonly keySignature: string;
|
|
6
|
-
}
|
|
7
|
-
interface KeyScale {
|
|
8
|
-
readonly tonic: string;
|
|
9
|
-
readonly grades: readonly string[];
|
|
10
|
-
readonly intervals: readonly string[];
|
|
11
|
-
readonly scale: readonly string[];
|
|
12
|
-
readonly triads: readonly string[];
|
|
13
|
-
readonly chords: readonly string[];
|
|
14
|
-
readonly chordsHarmonicFunction: readonly string[];
|
|
15
|
-
readonly chordScales: readonly string[];
|
|
16
|
-
readonly secondaryDominants: readonly string[];
|
|
17
|
-
readonly secondaryDominantSupertonics: readonly string[];
|
|
18
|
-
readonly substituteDominants: readonly string[];
|
|
19
|
-
readonly substituteDominantSupertonics: readonly string[];
|
|
20
|
-
readonly secondaryDominantsMinorRelative: readonly string[];
|
|
21
|
-
readonly substituteDominantsMinorRelative: readonly string[];
|
|
22
|
-
}
|
|
23
|
-
interface MajorKey extends Key, KeyScale {
|
|
24
|
-
readonly type: "major";
|
|
25
|
-
readonly minorRelative: string;
|
|
26
|
-
readonly scale: readonly string[];
|
|
27
|
-
readonly substituteDominants: readonly string[];
|
|
28
|
-
readonly secondaryDominantSupertonics: readonly string[];
|
|
29
|
-
readonly substituteDominantsMinorRelative: readonly string[];
|
|
30
|
-
}
|
|
31
|
-
interface MinorKey extends Key {
|
|
32
|
-
readonly type: "minor";
|
|
33
|
-
readonly relativeMajor: string;
|
|
34
|
-
readonly natural: KeyScale;
|
|
35
|
-
readonly harmonic: KeyScale;
|
|
36
|
-
readonly melodic: KeyScale;
|
|
37
|
-
}
|
|
38
|
-
type KeyChord = {
|
|
39
|
-
name: string;
|
|
40
|
-
roles: string[];
|
|
41
|
-
};
|
|
42
|
-
/**
|
|
43
|
-
* Get a major key properties in a given tonic
|
|
44
|
-
* @param tonic
|
|
45
|
-
*/
|
|
46
|
-
declare function majorKey(tonic: string): MajorKey;
|
|
47
|
-
/**
|
|
48
|
-
* Get a list of available chords for a given major key
|
|
49
|
-
* @param tonic
|
|
50
|
-
* @returns array of { name: string, roles: string[] }
|
|
51
|
-
*/
|
|
52
|
-
declare function majorKeyChords(tonic: string): KeyChord[];
|
|
53
|
-
/**
|
|
54
|
-
* Get a list of available chords for a given major key
|
|
55
|
-
* @param tonic
|
|
56
|
-
* @returns array of { name: string, roles: string[] }
|
|
57
|
-
*/
|
|
58
|
-
declare function minorKeyChords(tonic: string): KeyChord[];
|
|
59
|
-
/**
|
|
60
|
-
* Get minor key properties in a given tonic
|
|
61
|
-
* @param tonic
|
|
62
|
-
*/
|
|
63
|
-
declare function minorKey(tnc: string): MinorKey;
|
|
64
|
-
/**
|
|
65
|
-
* Given a key signature, returns the tonic of the major key
|
|
66
|
-
* @param signature
|
|
67
|
-
* @example
|
|
68
|
-
* majorTonicFromKeySignature('###') // => 'A'
|
|
69
|
-
*/
|
|
70
|
-
declare function majorTonicFromKeySignature(sig: string | number): string | null;
|
|
71
|
-
/** @deprecated */
|
|
72
|
-
declare const _default: {
|
|
73
|
-
majorKey: typeof majorKey;
|
|
74
|
-
majorTonicFromKeySignature: typeof majorTonicFromKeySignature;
|
|
75
|
-
minorKey: typeof minorKey;
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
export { type Key, type KeyChord, type KeyScale, type MajorKey, type MinorKey, _default as default, majorKey, majorKeyChords, majorTonicFromKeySignature, minorKey, minorKeyChords };
|
package/dist/index.js
DELETED
|
@@ -1,257 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// index.ts
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
default: () => index_default,
|
|
24
|
-
majorKey: () => majorKey,
|
|
25
|
-
majorKeyChords: () => majorKeyChords,
|
|
26
|
-
majorTonicFromKeySignature: () => majorTonicFromKeySignature,
|
|
27
|
-
minorKey: () => minorKey,
|
|
28
|
-
minorKeyChords: () => minorKeyChords
|
|
29
|
-
});
|
|
30
|
-
module.exports = __toCommonJS(index_exports);
|
|
31
|
-
var import_note = require("@tonaljs/note");
|
|
32
|
-
var import_pitch_note = require("@tonaljs/pitch-note");
|
|
33
|
-
var import_roman_numeral = require("@tonaljs/roman-numeral");
|
|
34
|
-
var Empty = Object.freeze([]);
|
|
35
|
-
var NoKey = {
|
|
36
|
-
type: "major",
|
|
37
|
-
tonic: "",
|
|
38
|
-
alteration: 0,
|
|
39
|
-
keySignature: ""
|
|
40
|
-
};
|
|
41
|
-
var NoKeyScale = {
|
|
42
|
-
tonic: "",
|
|
43
|
-
grades: Empty,
|
|
44
|
-
intervals: Empty,
|
|
45
|
-
scale: Empty,
|
|
46
|
-
triads: Empty,
|
|
47
|
-
chords: Empty,
|
|
48
|
-
chordsHarmonicFunction: Empty,
|
|
49
|
-
chordScales: Empty,
|
|
50
|
-
secondaryDominants: Empty,
|
|
51
|
-
secondaryDominantSupertonics: Empty,
|
|
52
|
-
substituteDominantsMinorRelative: Empty,
|
|
53
|
-
substituteDominants: Empty,
|
|
54
|
-
substituteDominantSupertonics: Empty,
|
|
55
|
-
secondaryDominantsMinorRelative: Empty
|
|
56
|
-
};
|
|
57
|
-
var NoMajorKey = {
|
|
58
|
-
...NoKey,
|
|
59
|
-
...NoKeyScale,
|
|
60
|
-
type: "major",
|
|
61
|
-
minorRelative: "",
|
|
62
|
-
scale: Empty,
|
|
63
|
-
substituteDominants: Empty,
|
|
64
|
-
secondaryDominantSupertonics: Empty,
|
|
65
|
-
substituteDominantsMinorRelative: Empty
|
|
66
|
-
};
|
|
67
|
-
var NoMinorKey = {
|
|
68
|
-
...NoKey,
|
|
69
|
-
type: "minor",
|
|
70
|
-
relativeMajor: "",
|
|
71
|
-
natural: NoKeyScale,
|
|
72
|
-
harmonic: NoKeyScale,
|
|
73
|
-
melodic: NoKeyScale
|
|
74
|
-
};
|
|
75
|
-
var mapScaleToType = (scale, list, sep = "") => list.map((type, i) => `${scale[i]}${sep}${type}`);
|
|
76
|
-
function keyScale(grades, triads, chordTypes, harmonicFunctions, chordScales) {
|
|
77
|
-
return (tonic) => {
|
|
78
|
-
const intervals = grades.map((gr) => (0, import_roman_numeral.get)(gr).interval || "");
|
|
79
|
-
const scale = intervals.map((interval) => (0, import_note.transpose)(tonic, interval));
|
|
80
|
-
const chords = mapScaleToType(scale, chordTypes);
|
|
81
|
-
const secondaryDominants = scale.map((note2) => (0, import_note.transpose)(note2, "5P")).map(
|
|
82
|
-
(note2) => (
|
|
83
|
-
// A secondary dominant is a V chord which:
|
|
84
|
-
// 1. is not diatonic to the key,
|
|
85
|
-
// 2. it must have a diatonic root.
|
|
86
|
-
scale.includes(note2) && !chords.includes(note2 + "7") ? note2 + "7" : ""
|
|
87
|
-
)
|
|
88
|
-
);
|
|
89
|
-
const secondaryDominantSupertonics = supertonics(
|
|
90
|
-
secondaryDominants,
|
|
91
|
-
triads
|
|
92
|
-
);
|
|
93
|
-
const substituteDominants = secondaryDominants.map((chord) => {
|
|
94
|
-
if (!chord) return "";
|
|
95
|
-
const domRoot = chord.slice(0, -1);
|
|
96
|
-
const subRoot = (0, import_note.transpose)(domRoot, "5d");
|
|
97
|
-
return subRoot + "7";
|
|
98
|
-
});
|
|
99
|
-
const substituteDominantSupertonics = supertonics(
|
|
100
|
-
substituteDominants,
|
|
101
|
-
triads
|
|
102
|
-
);
|
|
103
|
-
return {
|
|
104
|
-
tonic,
|
|
105
|
-
grades,
|
|
106
|
-
intervals,
|
|
107
|
-
scale,
|
|
108
|
-
triads: mapScaleToType(scale, triads),
|
|
109
|
-
chords,
|
|
110
|
-
chordsHarmonicFunction: harmonicFunctions.slice(),
|
|
111
|
-
chordScales: mapScaleToType(scale, chordScales, " "),
|
|
112
|
-
secondaryDominants,
|
|
113
|
-
secondaryDominantSupertonics,
|
|
114
|
-
substituteDominants,
|
|
115
|
-
substituteDominantSupertonics,
|
|
116
|
-
// @deprecated use secondaryDominantsSupertonic
|
|
117
|
-
secondaryDominantsMinorRelative: secondaryDominantSupertonics,
|
|
118
|
-
// @deprecated use secondaryDominantsSupertonic
|
|
119
|
-
substituteDominantsMinorRelative: substituteDominantSupertonics
|
|
120
|
-
};
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
var supertonics = (dominants, targetTriads) => {
|
|
124
|
-
return dominants.map((chord, index) => {
|
|
125
|
-
if (!chord) return "";
|
|
126
|
-
const domRoot = chord.slice(0, -1);
|
|
127
|
-
const minorRoot = (0, import_note.transpose)(domRoot, "5P");
|
|
128
|
-
const target = targetTriads[index];
|
|
129
|
-
const isMinor = target.endsWith("m");
|
|
130
|
-
return isMinor ? minorRoot + "m7" : minorRoot + "m7b5";
|
|
131
|
-
});
|
|
132
|
-
};
|
|
133
|
-
var distInFifths = (from, to) => {
|
|
134
|
-
const f = (0, import_pitch_note.note)(from);
|
|
135
|
-
const t = (0, import_pitch_note.note)(to);
|
|
136
|
-
return f.empty || t.empty ? 0 : t.coord[0] - f.coord[0];
|
|
137
|
-
};
|
|
138
|
-
var MajorScale = keyScale(
|
|
139
|
-
"I II III IV V VI VII".split(" "),
|
|
140
|
-
" m m m dim".split(" "),
|
|
141
|
-
"maj7 m7 m7 maj7 7 m7 m7b5".split(" "),
|
|
142
|
-
"T SD T SD D T D".split(" "),
|
|
143
|
-
"major,dorian,phrygian,lydian,mixolydian,minor,locrian".split(",")
|
|
144
|
-
);
|
|
145
|
-
var NaturalScale = keyScale(
|
|
146
|
-
"I II bIII IV V bVI bVII".split(" "),
|
|
147
|
-
"m dim m m ".split(" "),
|
|
148
|
-
"m7 m7b5 maj7 m7 m7 maj7 7".split(" "),
|
|
149
|
-
"T SD T SD D SD SD".split(" "),
|
|
150
|
-
"minor,locrian,major,dorian,phrygian,lydian,mixolydian".split(",")
|
|
151
|
-
);
|
|
152
|
-
var HarmonicScale = keyScale(
|
|
153
|
-
"I II bIII IV V bVI VII".split(" "),
|
|
154
|
-
"m dim aug m dim".split(" "),
|
|
155
|
-
"mMaj7 m7b5 +maj7 m7 7 maj7 o7".split(" "),
|
|
156
|
-
"T SD T SD D SD D".split(" "),
|
|
157
|
-
"harmonic minor,locrian 6,major augmented,lydian diminished,phrygian dominant,lydian #9,ultralocrian".split(
|
|
158
|
-
","
|
|
159
|
-
)
|
|
160
|
-
);
|
|
161
|
-
var MelodicScale = keyScale(
|
|
162
|
-
"I II bIII IV V VI VII".split(" "),
|
|
163
|
-
"m m aug dim dim".split(" "),
|
|
164
|
-
"m6 m7 +maj7 7 7 m7b5 m7b5".split(" "),
|
|
165
|
-
"T SD T SD D ".split(" "),
|
|
166
|
-
"melodic minor,dorian b2,lydian augmented,lydian dominant,mixolydian b6,locrian #2,altered".split(
|
|
167
|
-
","
|
|
168
|
-
)
|
|
169
|
-
);
|
|
170
|
-
function majorKey(tonic) {
|
|
171
|
-
const pc = (0, import_pitch_note.note)(tonic).pc;
|
|
172
|
-
if (!pc) return NoMajorKey;
|
|
173
|
-
const keyScale2 = MajorScale(pc);
|
|
174
|
-
const alteration = distInFifths("C", pc);
|
|
175
|
-
return {
|
|
176
|
-
...keyScale2,
|
|
177
|
-
type: "major",
|
|
178
|
-
minorRelative: (0, import_note.transpose)(pc, "-3m"),
|
|
179
|
-
alteration,
|
|
180
|
-
keySignature: (0, import_pitch_note.altToAcc)(alteration)
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
function majorKeyChords(tonic) {
|
|
184
|
-
const key = majorKey(tonic);
|
|
185
|
-
const chords = [];
|
|
186
|
-
keyChordsOf(key, chords);
|
|
187
|
-
return chords;
|
|
188
|
-
}
|
|
189
|
-
function minorKeyChords(tonic) {
|
|
190
|
-
const key = minorKey(tonic);
|
|
191
|
-
const chords = [];
|
|
192
|
-
keyChordsOf(key.natural, chords);
|
|
193
|
-
keyChordsOf(key.harmonic, chords);
|
|
194
|
-
keyChordsOf(key.melodic, chords);
|
|
195
|
-
return chords;
|
|
196
|
-
}
|
|
197
|
-
function keyChordsOf(key, chords) {
|
|
198
|
-
const updateChord = (name, newRole) => {
|
|
199
|
-
if (!name) return;
|
|
200
|
-
let keyChord = chords.find((chord) => chord.name === name);
|
|
201
|
-
if (!keyChord) {
|
|
202
|
-
keyChord = { name, roles: [] };
|
|
203
|
-
chords.push(keyChord);
|
|
204
|
-
}
|
|
205
|
-
if (newRole && !keyChord.roles.includes(newRole)) {
|
|
206
|
-
keyChord.roles.push(newRole);
|
|
207
|
-
}
|
|
208
|
-
};
|
|
209
|
-
key.chords.forEach(
|
|
210
|
-
(chordName, index) => updateChord(chordName, key.chordsHarmonicFunction[index])
|
|
211
|
-
);
|
|
212
|
-
key.secondaryDominants.forEach(
|
|
213
|
-
(chordName, index) => updateChord(chordName, `V/${key.grades[index]}`)
|
|
214
|
-
);
|
|
215
|
-
key.secondaryDominantSupertonics.forEach(
|
|
216
|
-
(chordName, index) => updateChord(chordName, `ii/${key.grades[index]}`)
|
|
217
|
-
);
|
|
218
|
-
key.substituteDominants.forEach(
|
|
219
|
-
(chordName, index) => updateChord(chordName, `subV/${key.grades[index]}`)
|
|
220
|
-
);
|
|
221
|
-
key.substituteDominantSupertonics.forEach(
|
|
222
|
-
(chordName, index) => updateChord(chordName, `subii/${key.grades[index]}`)
|
|
223
|
-
);
|
|
224
|
-
}
|
|
225
|
-
function minorKey(tnc) {
|
|
226
|
-
const pc = (0, import_pitch_note.note)(tnc).pc;
|
|
227
|
-
if (!pc) return NoMinorKey;
|
|
228
|
-
const alteration = distInFifths("C", pc) - 3;
|
|
229
|
-
return {
|
|
230
|
-
type: "minor",
|
|
231
|
-
tonic: pc,
|
|
232
|
-
relativeMajor: (0, import_note.transpose)(pc, "3m"),
|
|
233
|
-
alteration,
|
|
234
|
-
keySignature: (0, import_pitch_note.altToAcc)(alteration),
|
|
235
|
-
natural: NaturalScale(pc),
|
|
236
|
-
harmonic: HarmonicScale(pc),
|
|
237
|
-
melodic: MelodicScale(pc)
|
|
238
|
-
};
|
|
239
|
-
}
|
|
240
|
-
function majorTonicFromKeySignature(sig) {
|
|
241
|
-
if (typeof sig === "number") {
|
|
242
|
-
return (0, import_note.transposeFifths)("C", sig);
|
|
243
|
-
} else if (typeof sig === "string" && /^b+|#+$/.test(sig)) {
|
|
244
|
-
return (0, import_note.transposeFifths)("C", (0, import_pitch_note.accToAlt)(sig));
|
|
245
|
-
}
|
|
246
|
-
return null;
|
|
247
|
-
}
|
|
248
|
-
var index_default = { majorKey, majorTonicFromKeySignature, minorKey };
|
|
249
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
250
|
-
0 && (module.exports = {
|
|
251
|
-
majorKey,
|
|
252
|
-
majorKeyChords,
|
|
253
|
-
majorTonicFromKeySignature,
|
|
254
|
-
minorKey,
|
|
255
|
-
minorKeyChords
|
|
256
|
-
});
|
|
257
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../index.ts"],"sourcesContent":["import { transpose, transposeFifths } from \"@tonaljs/note\";\nimport { accToAlt, altToAcc, note } from \"@tonaljs/pitch-note\";\nimport { get as roman } from \"@tonaljs/roman-numeral\";\n\nconst Empty: readonly string[] = Object.freeze([] as string[]);\n\nexport interface Key {\n readonly type: \"major\" | \"minor\";\n readonly tonic: string;\n readonly alteration: number;\n readonly keySignature: string;\n}\n\nconst NoKey: Key = {\n type: \"major\",\n tonic: \"\",\n alteration: 0,\n keySignature: \"\",\n};\n\nexport interface KeyScale {\n readonly tonic: string;\n readonly grades: readonly string[];\n readonly intervals: readonly string[];\n readonly scale: readonly string[];\n readonly triads: readonly string[];\n readonly chords: readonly string[];\n readonly chordsHarmonicFunction: readonly string[];\n readonly chordScales: readonly string[];\n readonly secondaryDominants: readonly string[];\n readonly secondaryDominantSupertonics: readonly string[];\n readonly substituteDominants: readonly string[];\n readonly substituteDominantSupertonics: readonly string[];\n\n // @deprecated use secondaryDominantsSupertonic\n readonly secondaryDominantsMinorRelative: readonly string[];\n // @deprecated use substituteDominantSupertonics\n readonly substituteDominantsMinorRelative: readonly string[];\n}\n\nconst NoKeyScale: KeyScale = {\n tonic: \"\",\n grades: Empty,\n intervals: Empty,\n scale: Empty,\n triads: Empty,\n chords: Empty,\n chordsHarmonicFunction: Empty,\n chordScales: Empty,\n secondaryDominants: Empty,\n secondaryDominantSupertonics: Empty,\n substituteDominantsMinorRelative: Empty,\n substituteDominants: Empty,\n substituteDominantSupertonics: Empty,\n secondaryDominantsMinorRelative: Empty,\n};\n\nexport interface MajorKey extends Key, KeyScale {\n readonly type: \"major\";\n readonly minorRelative: string;\n readonly scale: readonly string[];\n readonly substituteDominants: readonly string[];\n readonly secondaryDominantSupertonics: readonly string[];\n // @deprecated use secondaryDominantsSupertonic\n readonly substituteDominantsMinorRelative: readonly string[];\n}\n\nconst NoMajorKey: MajorKey = {\n ...NoKey,\n ...NoKeyScale,\n type: \"major\",\n minorRelative: \"\",\n scale: Empty,\n substituteDominants: Empty,\n secondaryDominantSupertonics: Empty,\n substituteDominantsMinorRelative: Empty,\n};\n\nexport interface MinorKey extends Key {\n readonly type: \"minor\";\n readonly relativeMajor: string;\n readonly natural: KeyScale;\n readonly harmonic: KeyScale;\n readonly melodic: KeyScale;\n}\n\nconst NoMinorKey: MinorKey = {\n ...NoKey,\n type: \"minor\",\n relativeMajor: \"\",\n natural: NoKeyScale,\n harmonic: NoKeyScale,\n melodic: NoKeyScale,\n};\n\nexport type KeyChord = {\n name: string;\n roles: string[];\n};\n\nconst mapScaleToType = (scale: string[], list: string[], sep = \"\") =>\n list.map((type, i) => `${scale[i]}${sep}${type}`);\n\nfunction keyScale(\n grades: string[],\n triads: string[],\n chordTypes: string[],\n harmonicFunctions: string[],\n chordScales: string[],\n) {\n return (tonic: string): KeyScale => {\n const intervals = grades.map((gr) => roman(gr).interval || \"\");\n const scale = intervals.map((interval) => transpose(tonic, interval));\n const chords = mapScaleToType(scale, chordTypes);\n const secondaryDominants = scale\n .map((note) => transpose(note, \"5P\"))\n .map((note) =>\n // A secondary dominant is a V chord which:\n // 1. is not diatonic to the key,\n // 2. it must have a diatonic root.\n scale.includes(note) && !chords.includes(note + \"7\") ? note + \"7\" : \"\",\n );\n\n const secondaryDominantSupertonics = supertonics(\n secondaryDominants,\n triads,\n );\n const substituteDominants = secondaryDominants.map((chord) => {\n if (!chord) return \"\";\n const domRoot = chord.slice(0, -1);\n const subRoot = transpose(domRoot, \"5d\");\n return subRoot + \"7\";\n });\n const substituteDominantSupertonics = supertonics(\n substituteDominants,\n triads,\n );\n\n return {\n tonic,\n grades,\n intervals,\n scale,\n triads: mapScaleToType(scale, triads),\n chords,\n chordsHarmonicFunction: harmonicFunctions.slice(),\n chordScales: mapScaleToType(scale, chordScales, \" \"),\n secondaryDominants,\n secondaryDominantSupertonics,\n substituteDominants,\n substituteDominantSupertonics,\n\n // @deprecated use secondaryDominantsSupertonic\n secondaryDominantsMinorRelative: secondaryDominantSupertonics,\n // @deprecated use secondaryDominantsSupertonic\n substituteDominantsMinorRelative: substituteDominantSupertonics,\n };\n };\n}\n\nconst supertonics = (dominants: string[], targetTriads: string[]) => {\n return dominants.map((chord, index) => {\n if (!chord) return \"\";\n const domRoot = chord.slice(0, -1);\n const minorRoot = transpose(domRoot, \"5P\");\n const target = targetTriads[index];\n const isMinor = target.endsWith(\"m\");\n return isMinor ? minorRoot + \"m7\" : minorRoot + \"m7b5\";\n });\n};\n\nconst distInFifths = (from: string, to: string) => {\n const f = note(from);\n const t = note(to);\n return f.empty || t.empty ? 0 : t.coord[0] - f.coord[0];\n};\n\nconst MajorScale = keyScale(\n \"I II III IV V VI VII\".split(\" \"),\n \" m m m dim\".split(\" \"),\n \"maj7 m7 m7 maj7 7 m7 m7b5\".split(\" \"),\n \"T SD T SD D T D\".split(\" \"),\n \"major,dorian,phrygian,lydian,mixolydian,minor,locrian\".split(\",\"),\n);\nconst NaturalScale = keyScale(\n \"I II bIII IV V bVI bVII\".split(\" \"),\n \"m dim m m \".split(\" \"),\n \"m7 m7b5 maj7 m7 m7 maj7 7\".split(\" \"),\n \"T SD T SD D SD SD\".split(\" \"),\n \"minor,locrian,major,dorian,phrygian,lydian,mixolydian\".split(\",\"),\n);\nconst HarmonicScale = keyScale(\n \"I II bIII IV V bVI VII\".split(\" \"),\n \"m dim aug m dim\".split(\" \"),\n \"mMaj7 m7b5 +maj7 m7 7 maj7 o7\".split(\" \"),\n \"T SD T SD D SD D\".split(\" \"),\n \"harmonic minor,locrian 6,major augmented,lydian diminished,phrygian dominant,lydian #9,ultralocrian\".split(\n \",\",\n ),\n);\nconst MelodicScale = keyScale(\n \"I II bIII IV V VI VII\".split(\" \"),\n \"m m aug dim dim\".split(\" \"),\n \"m6 m7 +maj7 7 7 m7b5 m7b5\".split(\" \"),\n \"T SD T SD D \".split(\" \"),\n \"melodic minor,dorian b2,lydian augmented,lydian dominant,mixolydian b6,locrian #2,altered\".split(\n \",\",\n ),\n);\n\n/**\n * Get a major key properties in a given tonic\n * @param tonic\n */\nexport function majorKey(tonic: string): MajorKey {\n const pc = note(tonic).pc;\n if (!pc) return NoMajorKey;\n\n const keyScale = MajorScale(pc);\n const alteration = distInFifths(\"C\", pc);\n\n return {\n ...keyScale,\n type: \"major\",\n minorRelative: transpose(pc, \"-3m\"),\n alteration,\n keySignature: altToAcc(alteration),\n };\n}\n\n/**\n * Get a list of available chords for a given major key\n * @param tonic\n * @returns array of { name: string, roles: string[] }\n */\nexport function majorKeyChords(tonic: string): KeyChord[] {\n const key = majorKey(tonic);\n const chords: KeyChord[] = [];\n keyChordsOf(key, chords);\n return chords;\n}\n\n/**\n * Get a list of available chords for a given major key\n * @param tonic\n * @returns array of { name: string, roles: string[] }\n */\nexport function minorKeyChords(tonic: string): KeyChord[] {\n const key = minorKey(tonic);\n const chords: KeyChord[] = [];\n keyChordsOf(key.natural, chords);\n keyChordsOf(key.harmonic, chords);\n keyChordsOf(key.melodic, chords);\n return chords;\n}\n\nfunction keyChordsOf(key: KeyScale, chords: KeyChord[]) {\n const updateChord = (name: string, newRole: string) => {\n if (!name) return;\n let keyChord = chords.find((chord) => chord.name === name);\n if (!keyChord) {\n keyChord = { name, roles: [] };\n chords.push(keyChord);\n }\n if (newRole && !keyChord.roles.includes(newRole)) {\n keyChord.roles.push(newRole);\n }\n };\n\n key.chords.forEach((chordName, index) =>\n updateChord(chordName, key.chordsHarmonicFunction[index]),\n );\n key.secondaryDominants.forEach((chordName, index) =>\n updateChord(chordName, `V/${key.grades[index]}`),\n );\n key.secondaryDominantSupertonics.forEach((chordName, index) =>\n updateChord(chordName, `ii/${key.grades[index]}`),\n );\n key.substituteDominants.forEach((chordName, index) =>\n updateChord(chordName, `subV/${key.grades[index]}`),\n );\n key.substituteDominantSupertonics.forEach((chordName, index) =>\n updateChord(chordName, `subii/${key.grades[index]}`),\n );\n}\n\n/**\n * Get minor key properties in a given tonic\n * @param tonic\n */\nexport function minorKey(tnc: string): MinorKey {\n const pc = note(tnc).pc;\n if (!pc) return NoMinorKey;\n\n const alteration = distInFifths(\"C\", pc) - 3;\n return {\n type: \"minor\",\n tonic: pc,\n relativeMajor: transpose(pc, \"3m\"),\n alteration,\n keySignature: altToAcc(alteration),\n natural: NaturalScale(pc),\n harmonic: HarmonicScale(pc),\n melodic: MelodicScale(pc),\n };\n}\n\n/**\n * Given a key signature, returns the tonic of the major key\n * @param signature\n * @example\n * majorTonicFromKeySignature('###') // => 'A'\n */\nexport function majorTonicFromKeySignature(\n sig: string | number,\n): string | null {\n if (typeof sig === \"number\") {\n return transposeFifths(\"C\", sig);\n } else if (typeof sig === \"string\" && /^b+|#+$/.test(sig)) {\n return transposeFifths(\"C\", accToAlt(sig));\n }\n return null;\n}\n\n/** @deprecated */\nexport default { majorKey, majorTonicFromKeySignature, minorKey };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA2C;AAC3C,wBAAyC;AACzC,2BAA6B;AAE7B,IAAM,QAA2B,OAAO,OAAO,CAAC,CAAa;AAS7D,IAAM,QAAa;AAAA,EACjB,MAAM;AAAA,EACN,OAAO;AAAA,EACP,YAAY;AAAA,EACZ,cAAc;AAChB;AAsBA,IAAM,aAAuB;AAAA,EAC3B,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,WAAW;AAAA,EACX,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,wBAAwB;AAAA,EACxB,aAAa;AAAA,EACb,oBAAoB;AAAA,EACpB,8BAA8B;AAAA,EAC9B,kCAAkC;AAAA,EAClC,qBAAqB;AAAA,EACrB,+BAA+B;AAAA,EAC/B,iCAAiC;AACnC;AAYA,IAAM,aAAuB;AAAA,EAC3B,GAAG;AAAA,EACH,GAAG;AAAA,EACH,MAAM;AAAA,EACN,eAAe;AAAA,EACf,OAAO;AAAA,EACP,qBAAqB;AAAA,EACrB,8BAA8B;AAAA,EAC9B,kCAAkC;AACpC;AAUA,IAAM,aAAuB;AAAA,EAC3B,GAAG;AAAA,EACH,MAAM;AAAA,EACN,eAAe;AAAA,EACf,SAAS;AAAA,EACT,UAAU;AAAA,EACV,SAAS;AACX;AAOA,IAAM,iBAAiB,CAAC,OAAiB,MAAgB,MAAM,OAC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