@tonaljs/key 4.6.4 → 4.6.10

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.d.ts CHANGED
@@ -1,54 +1,55 @@
1
- export 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 chords: readonly string[];
13
- readonly chordsHarmonicFunction: readonly string[];
14
- readonly chordScales: readonly string[];
15
- }
16
- export interface MajorKey extends Key, KeyScale {
17
- readonly type: "major";
18
- readonly minorRelative: string;
19
- readonly scale: readonly string[];
20
- readonly secondaryDominants: readonly string[];
21
- readonly secondaryDominantsMinorRelative: readonly string[];
22
- readonly substituteDominants: readonly string[];
23
- readonly substituteDominantsMinorRelative: readonly string[];
24
- }
25
- export interface MinorKey extends Key {
26
- readonly type: "minor";
27
- readonly relativeMajor: string;
28
- readonly natural: KeyScale;
29
- readonly harmonic: KeyScale;
30
- readonly melodic: KeyScale;
31
- }
32
- /**
33
- * Get a major key properties in a given tonic
34
- * @param tonic
35
- */
36
- export declare function majorKey(tonic: string): MajorKey;
37
- /**
38
- * Get minor key properties in a given tonic
39
- * @param tonic
40
- */
41
- export declare function minorKey(tnc: string): MinorKey;
42
- /**
43
- * Given a key signature, returns the tonic of the major key
44
- * @param sigature
45
- * @example
46
- * majorTonicFromKeySignature('###') // => 'A'
47
- */
48
- export declare function majorTonicFromKeySignature(sig: string | number): string | null;
49
- declare const _default: {
50
- majorKey: typeof majorKey;
51
- majorTonicFromKeySignature: typeof majorTonicFromKeySignature;
52
- minorKey: typeof minorKey;
53
- };
54
- export default _default;
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 chords: readonly string[];
13
+ readonly chordsHarmonicFunction: readonly string[];
14
+ readonly chordScales: readonly string[];
15
+ }
16
+ interface MajorKey extends Key, KeyScale {
17
+ readonly type: "major";
18
+ readonly minorRelative: string;
19
+ readonly scale: readonly string[];
20
+ readonly secondaryDominants: readonly string[];
21
+ readonly secondaryDominantsMinorRelative: readonly string[];
22
+ readonly substituteDominants: readonly string[];
23
+ readonly substituteDominantsMinorRelative: readonly string[];
24
+ }
25
+ interface MinorKey extends Key {
26
+ readonly type: "minor";
27
+ readonly relativeMajor: string;
28
+ readonly natural: KeyScale;
29
+ readonly harmonic: KeyScale;
30
+ readonly melodic: KeyScale;
31
+ }
32
+ /**
33
+ * Get a major key properties in a given tonic
34
+ * @param tonic
35
+ */
36
+ declare function majorKey(tonic: string): MajorKey;
37
+ /**
38
+ * Get minor key properties in a given tonic
39
+ * @param tonic
40
+ */
41
+ declare function minorKey(tnc: string): MinorKey;
42
+ /**
43
+ * Given a key signature, returns the tonic of the major key
44
+ * @param sigature
45
+ * @example
46
+ * majorTonicFromKeySignature('###') // => 'A'
47
+ */
48
+ declare function majorTonicFromKeySignature(sig: string | number): string | null;
49
+ declare const _default: {
50
+ majorKey: typeof majorKey;
51
+ majorTonicFromKeySignature: typeof majorTonicFromKeySignature;
52
+ minorKey: typeof minorKey;
53
+ };
54
+
55
+ export { Key, KeyScale, MajorKey, MinorKey, _default as default, majorKey, majorTonicFromKeySignature, minorKey };
package/dist/index.js CHANGED
@@ -1,148 +1,171 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@tonaljs/core'), require('@tonaljs/note'), require('@tonaljs/roman-numeral')) :
3
- typeof define === 'function' && define.amd ? define(['exports', '@tonaljs/core', '@tonaljs/note', '@tonaljs/roman-numeral'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Key = {}, global.core, global.note, global.romanNumeral));
5
- }(this, (function (exports, core, note, romanNumeral) { 'use strict';
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);
6
19
 
7
- /*! *****************************************************************************
8
- Copyright (c) Microsoft Corporation.
9
-
10
- Permission to use, copy, modify, and/or distribute this software for any
11
- purpose with or without fee is hereby granted.
12
-
13
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
14
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
15
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
16
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
17
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
18
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19
- PERFORMANCE OF THIS SOFTWARE.
20
- ***************************************************************************** */
21
-
22
- var __assign = function() {
23
- __assign = Object.assign || function __assign(t) {
24
- for (var s, i = 1, n = arguments.length; i < n; i++) {
25
- s = arguments[i];
26
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
27
- }
28
- return t;
29
- };
30
- return __assign.apply(this, arguments);
20
+ // index.ts
21
+ var key_exports = {};
22
+ __export(key_exports, {
23
+ default: () => key_default,
24
+ majorKey: () => majorKey,
25
+ majorTonicFromKeySignature: () => majorTonicFromKeySignature,
26
+ minorKey: () => minorKey
27
+ });
28
+ module.exports = __toCommonJS(key_exports);
29
+ var import_core = require("@tonaljs/core");
30
+ var import_note = require("@tonaljs/note");
31
+ var import_roman_numeral = require("@tonaljs/roman-numeral");
32
+ var Empty = Object.freeze([]);
33
+ var NoKey = {
34
+ type: "major",
35
+ tonic: "",
36
+ alteration: 0,
37
+ keySignature: ""
38
+ };
39
+ var NoKeyScale = {
40
+ tonic: "",
41
+ grades: Empty,
42
+ intervals: Empty,
43
+ scale: Empty,
44
+ chords: Empty,
45
+ chordsHarmonicFunction: Empty,
46
+ chordScales: Empty
47
+ };
48
+ var NoMajorKey = {
49
+ ...NoKey,
50
+ ...NoKeyScale,
51
+ type: "major",
52
+ minorRelative: "",
53
+ scale: Empty,
54
+ secondaryDominants: Empty,
55
+ secondaryDominantsMinorRelative: Empty,
56
+ substituteDominants: Empty,
57
+ substituteDominantsMinorRelative: Empty
58
+ };
59
+ var NoMinorKey = {
60
+ ...NoKey,
61
+ type: "minor",
62
+ relativeMajor: "",
63
+ natural: NoKeyScale,
64
+ harmonic: NoKeyScale,
65
+ melodic: NoKeyScale
66
+ };
67
+ var mapScaleToType = (scale, list, sep = "") => list.map((type, i) => `${scale[i]}${sep}${type}`);
68
+ function keyScale(grades, chords, harmonicFunctions, chordScales) {
69
+ return (tonic) => {
70
+ const intervals = grades.map((gr) => (0, import_roman_numeral.get)(gr).interval || "");
71
+ const scale = intervals.map((interval) => (0, import_core.transpose)(tonic, interval));
72
+ return {
73
+ tonic,
74
+ grades,
75
+ intervals,
76
+ scale,
77
+ chords: mapScaleToType(scale, chords),
78
+ chordsHarmonicFunction: harmonicFunctions.slice(),
79
+ chordScales: mapScaleToType(scale, chordScales, " ")
31
80
  };
32
-
33
- var Empty = Object.freeze([]);
34
- var NoKey = {
35
- type: "major",
36
- tonic: "",
37
- alteration: 0,
38
- keySignature: "",
39
- };
40
- var NoKeyScale = {
41
- tonic: "",
42
- grades: Empty,
43
- intervals: Empty,
44
- scale: Empty,
45
- chords: Empty,
46
- chordsHarmonicFunction: Empty,
47
- chordScales: Empty,
48
- };
49
- var NoMajorKey = __assign(__assign(__assign({}, NoKey), NoKeyScale), { type: "major", minorRelative: "", scale: Empty, secondaryDominants: Empty, secondaryDominantsMinorRelative: Empty, substituteDominants: Empty, substituteDominantsMinorRelative: Empty });
50
- var NoMinorKey = __assign(__assign({}, NoKey), { type: "minor", relativeMajor: "", natural: NoKeyScale, harmonic: NoKeyScale, melodic: NoKeyScale });
51
- var mapScaleToType = function (scale, list, sep) {
52
- if (sep === void 0) { sep = ""; }
53
- return list.map(function (type, i) { return "" + scale[i] + sep + type; });
54
- };
55
- function keyScale(grades, chords, harmonicFunctions, chordScales) {
56
- return function (tonic) {
57
- var intervals = grades.map(function (gr) { return romanNumeral.get(gr).interval || ""; });
58
- var scale = intervals.map(function (interval) { return core.transpose(tonic, interval); });
59
- return {
60
- tonic: tonic,
61
- grades: grades,
62
- intervals: intervals,
63
- scale: scale,
64
- chords: mapScaleToType(scale, chords),
65
- chordsHarmonicFunction: harmonicFunctions.slice(),
66
- chordScales: mapScaleToType(scale, chordScales, " "),
67
- };
68
- };
69
- }
70
- var distInFifths = function (from, to) {
71
- var f = core.note(from);
72
- var t = core.note(to);
73
- return f.empty || t.empty ? 0 : t.coord[0] - f.coord[0];
74
- };
75
- var MajorScale = keyScale("I II III IV V VI VII".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(","));
76
- var NaturalScale = keyScale("I II bIII IV V bVI bVII".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(","));
77
- var HarmonicScale = keyScale("I II bIII IV V bVI VII".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(","));
78
- var MelodicScale = keyScale("I II bIII IV V VI VII".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(","));
79
- /**
80
- * Get a major key properties in a given tonic
81
- * @param tonic
82
- */
83
- function majorKey(tonic) {
84
- var pc = core.note(tonic).pc;
85
- if (!pc)
86
- return NoMajorKey;
87
- var keyScale = MajorScale(pc);
88
- var alteration = distInFifths("C", pc);
89
- var romanInTonic = function (src) {
90
- var r = romanNumeral.get(src);
91
- if (r.empty)
92
- return "";
93
- return core.transpose(tonic, r.interval) + r.chordType;
94
- };
95
- return __assign(__assign({}, keyScale), { type: "major", minorRelative: core.transpose(pc, "-3m"), alteration: alteration, keySignature: core.altToAcc(alteration), secondaryDominants: "- VI7 VII7 I7 II7 III7 -".split(" ").map(romanInTonic), secondaryDominantsMinorRelative: "- IIIm7b5 IV#m7 Vm7 VIm7 VIIm7b5 -"
96
- .split(" ")
97
- .map(romanInTonic), substituteDominants: "- bIII7 IV7 bV7 bVI7 bVII7 -"
98
- .split(" ")
99
- .map(romanInTonic), substituteDominantsMinorRelative: "- IIIm7 Im7 IIbm7 VIm7 IVm7 -"
100
- .split(" ")
101
- .map(romanInTonic) });
102
- }
103
- /**
104
- * Get minor key properties in a given tonic
105
- * @param tonic
106
- */
107
- function minorKey(tnc) {
108
- var pc = core.note(tnc).pc;
109
- if (!pc)
110
- return NoMinorKey;
111
- var alteration = distInFifths("C", pc) - 3;
112
- return {
113
- type: "minor",
114
- tonic: pc,
115
- relativeMajor: core.transpose(pc, "3m"),
116
- alteration: alteration,
117
- keySignature: core.altToAcc(alteration),
118
- natural: NaturalScale(pc),
119
- harmonic: HarmonicScale(pc),
120
- melodic: MelodicScale(pc),
121
- };
122
- }
123
- /**
124
- * Given a key signature, returns the tonic of the major key
125
- * @param sigature
126
- * @example
127
- * majorTonicFromKeySignature('###') // => 'A'
128
- */
129
- function majorTonicFromKeySignature(sig) {
130
- if (typeof sig === "number") {
131
- return note.transposeFifths("C", sig);
132
- }
133
- else if (typeof sig === "string" && /^b+|#+$/.test(sig)) {
134
- return note.transposeFifths("C", core.accToAlt(sig));
135
- }
136
- return null;
137
- }
138
- var index = { majorKey: majorKey, majorTonicFromKeySignature: majorTonicFromKeySignature, minorKey: minorKey };
139
-
140
- exports['default'] = index;
141
- exports.majorKey = majorKey;
142
- exports.majorTonicFromKeySignature = majorTonicFromKeySignature;
143
- exports.minorKey = minorKey;
144
-
145
- Object.defineProperty(exports, '__esModule', { value: true });
146
-
147
- })));
148
- //# sourceMappingURL=index.js.map
81
+ };
82
+ }
83
+ var distInFifths = (from, to) => {
84
+ const f = (0, import_core.note)(from);
85
+ const t = (0, import_core.note)(to);
86
+ return f.empty || t.empty ? 0 : t.coord[0] - f.coord[0];
87
+ };
88
+ var MajorScale = keyScale(
89
+ "I II III IV V VI VII".split(" "),
90
+ "maj7 m7 m7 maj7 7 m7 m7b5".split(" "),
91
+ "T SD T SD D T D".split(" "),
92
+ "major,dorian,phrygian,lydian,mixolydian,minor,locrian".split(",")
93
+ );
94
+ var NaturalScale = keyScale(
95
+ "I II bIII IV V bVI bVII".split(" "),
96
+ "m7 m7b5 maj7 m7 m7 maj7 7".split(" "),
97
+ "T SD T SD D SD SD".split(" "),
98
+ "minor,locrian,major,dorian,phrygian,lydian,mixolydian".split(",")
99
+ );
100
+ var HarmonicScale = keyScale(
101
+ "I II bIII IV V bVI VII".split(" "),
102
+ "mMaj7 m7b5 +maj7 m7 7 maj7 o7".split(" "),
103
+ "T SD T SD D SD D".split(" "),
104
+ "harmonic minor,locrian 6,major augmented,lydian diminished,phrygian dominant,lydian #9,ultralocrian".split(
105
+ ","
106
+ )
107
+ );
108
+ var MelodicScale = keyScale(
109
+ "I II bIII IV V VI VII".split(" "),
110
+ "m6 m7 +maj7 7 7 m7b5 m7b5".split(" "),
111
+ "T SD T SD D ".split(" "),
112
+ "melodic minor,dorian b2,lydian augmented,lydian dominant,mixolydian b6,locrian #2,altered".split(
113
+ ","
114
+ )
115
+ );
116
+ function majorKey(tonic) {
117
+ const pc = (0, import_core.note)(tonic).pc;
118
+ if (!pc)
119
+ return NoMajorKey;
120
+ const keyScale2 = MajorScale(pc);
121
+ const alteration = distInFifths("C", pc);
122
+ const romanInTonic = (src) => {
123
+ const r = (0, import_roman_numeral.get)(src);
124
+ if (r.empty)
125
+ return "";
126
+ return (0, import_core.transpose)(tonic, r.interval) + r.chordType;
127
+ };
128
+ return {
129
+ ...keyScale2,
130
+ type: "major",
131
+ minorRelative: (0, import_core.transpose)(pc, "-3m"),
132
+ alteration,
133
+ keySignature: (0, import_core.altToAcc)(alteration),
134
+ secondaryDominants: "- VI7 VII7 I7 II7 III7 -".split(" ").map(romanInTonic),
135
+ secondaryDominantsMinorRelative: "- IIIm7b5 IV#m7 Vm7 VIm7 VIIm7b5 -".split(" ").map(romanInTonic),
136
+ substituteDominants: "- bIII7 IV7 bV7 bVI7 bVII7 -".split(" ").map(romanInTonic),
137
+ substituteDominantsMinorRelative: "- IIIm7 Im7 IIbm7 VIm7 IVm7 -".split(" ").map(romanInTonic)
138
+ };
139
+ }
140
+ function minorKey(tnc) {
141
+ const pc = (0, import_core.note)(tnc).pc;
142
+ if (!pc)
143
+ return NoMinorKey;
144
+ const alteration = distInFifths("C", pc) - 3;
145
+ return {
146
+ type: "minor",
147
+ tonic: pc,
148
+ relativeMajor: (0, import_core.transpose)(pc, "3m"),
149
+ alteration,
150
+ keySignature: (0, import_core.altToAcc)(alteration),
151
+ natural: NaturalScale(pc),
152
+ harmonic: HarmonicScale(pc),
153
+ melodic: MelodicScale(pc)
154
+ };
155
+ }
156
+ function majorTonicFromKeySignature(sig) {
157
+ if (typeof sig === "number") {
158
+ return (0, import_note.transposeFifths)("C", sig);
159
+ } else if (typeof sig === "string" && /^b+|#+$/.test(sig)) {
160
+ return (0, import_note.transposeFifths)("C", (0, import_core.accToAlt)(sig));
161
+ }
162
+ return null;
163
+ }
164
+ var key_default = { majorKey, majorTonicFromKeySignature, minorKey };
165
+ // Annotate the CommonJS export names for ESM import in node:
166
+ 0 && (module.exports = {
167
+ majorKey,
168
+ majorTonicFromKeySignature,
169
+ minorKey
170
+ });
171
+ //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"sources":["../index.ts"],"sourcesContent":["import { accToAlt, altToAcc, note, transpose } from \"@tonaljs/core\";\nimport { transposeFifths } from \"@tonaljs/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 chords: readonly string[];\n readonly chordsHarmonicFunction: readonly string[];\n readonly chordScales: readonly string[];\n}\n\nconst NoKeyScale: KeyScale = {\n tonic: \"\",\n grades: Empty,\n intervals: Empty,\n scale: Empty,\n chords: Empty,\n chordsHarmonicFunction: Empty,\n chordScales: Empty,\n};\n\nexport interface MajorKey extends Key, KeyScale {\n readonly type: \"major\";\n readonly minorRelative: string;\n readonly scale: readonly string[];\n readonly secondaryDominants: readonly string[];\n readonly secondaryDominantsMinorRelative: readonly string[];\n readonly substituteDominants: readonly string[];\n readonly substituteDominantsMinorRelative: readonly string[];\n}\n\nconst NoMajorKey: MajorKey = {\n ...NoKey,\n ...NoKeyScale,\n type: \"major\",\n minorRelative: \"\",\n scale: Empty,\n secondaryDominants: Empty,\n secondaryDominantsMinorRelative: Empty,\n substituteDominants: 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\nconst mapScaleToType = (scale: string[], list: string[], sep = \"\") =>\n list.map((type, i) => `${scale[i]}${sep}${type}`);\n\nfunction keyScale(\n grades: string[],\n chords: 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\n return {\n tonic,\n grades,\n intervals,\n scale,\n chords: mapScaleToType(scale, chords),\n chordsHarmonicFunction: harmonicFunctions.slice(),\n chordScales: mapScaleToType(scale, chordScales, \" \"),\n };\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 \"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 \"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 \"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 \"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 const romanInTonic = (src: string) => {\n const r = roman(src);\n if (r.empty) return \"\";\n\n return transpose(tonic, r.interval) + r.chordType;\n };\n\n return {\n ...keyScale,\n type: \"major\",\n minorRelative: transpose(pc, \"-3m\"),\n alteration,\n keySignature: altToAcc(alteration),\n secondaryDominants: \"- VI7 VII7 I7 II7 III7 -\".split(\" \").map(romanInTonic),\n secondaryDominantsMinorRelative: \"- IIIm7b5 IV#m7 Vm7 VIm7 VIIm7b5 -\"\n .split(\" \")\n .map(romanInTonic),\n substituteDominants: \"- bIII7 IV7 bV7 bVI7 bVII7 -\"\n .split(\" \")\n .map(romanInTonic),\n substituteDominantsMinorRelative: \"- IIIm7 Im7 IIbm7 VIm7 IVm7 -\"\n .split(\" \")\n .map(romanInTonic),\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 sigature\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\nexport default { majorKey, majorTonicFromKeySignature, minorKey };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAoD;AACpD,kBAAgC;AAChC,2BAA6B;AAE7B,IAAM,QAA2B,OAAO,OAAO,CAAC,CAAa;AAS7D,IAAM,QAAa;AAAA,EACjB,MAAM;AAAA,EACN,OAAO;AAAA,EACP,YAAY;AAAA,EACZ,cAAc;AAChB;AAYA,IAAM,aAAuB;AAAA,EAC3B,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,WAAW;AAAA,EACX,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,wBAAwB;AAAA,EACxB,aAAa;AACf;AAYA,IAAM,aAAuB;AAAA,EAC3B,GAAG;AAAA,EACH,GAAG;AAAA,EACH,MAAM;AAAA,EACN,eAAe;AAAA,EACf,OAAO;AAAA,EACP,oBAAoB;AAAA,EACpB,iCAAiC;AAAA,EACjC,qBAAqB;AAAA,EACrB,kCAAkC;AACpC;AAUA,IAAM,aAAuB;AAAA,EAC3B,GAAG;AA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IAC1B,SAAS,aAAa,EAAE;AAAA,EAC1B;AACF;AAQO,SAAS,2BACd,KACe;AACf,MAAI,OAAO,QAAQ,UAAU;AAC3B,eAAO,6BAAgB,KAAK,GAAG;AAAA,EACjC,WAAW,OAAO,QAAQ,YAAY,UAAU,KAAK,GAAG,GAAG;AACzD,eAAO,6BAAgB,SAAK,sBAAS,GAAG,CAAC;AAAA,EAC3C;AACA,SAAO;AACT;AAEA,IAAO,cAAQ,EAAE,UAAU,4BAA4B,SAAS;","names":["roman","keyScale"]}
package/dist/index.mjs ADDED
@@ -0,0 +1,144 @@
1
+ // index.ts
2
+ import { accToAlt, altToAcc, note, transpose } from "@tonaljs/core";
3
+ import { transposeFifths } from "@tonaljs/note";
4
+ import { get as roman } from "@tonaljs/roman-numeral";
5
+ var Empty = Object.freeze([]);
6
+ var NoKey = {
7
+ type: "major",
8
+ tonic: "",
9
+ alteration: 0,
10
+ keySignature: ""
11
+ };
12
+ var NoKeyScale = {
13
+ tonic: "",
14
+ grades: Empty,
15
+ intervals: Empty,
16
+ scale: Empty,
17
+ chords: Empty,
18
+ chordsHarmonicFunction: Empty,
19
+ chordScales: Empty
20
+ };
21
+ var NoMajorKey = {
22
+ ...NoKey,
23
+ ...NoKeyScale,
24
+ type: "major",
25
+ minorRelative: "",
26
+ scale: Empty,
27
+ secondaryDominants: Empty,
28
+ secondaryDominantsMinorRelative: Empty,
29
+ substituteDominants: Empty,
30
+ substituteDominantsMinorRelative: Empty
31
+ };
32
+ var NoMinorKey = {
33
+ ...NoKey,
34
+ type: "minor",
35
+ relativeMajor: "",
36
+ natural: NoKeyScale,
37
+ harmonic: NoKeyScale,
38
+ melodic: NoKeyScale
39
+ };
40
+ var mapScaleToType = (scale, list, sep = "") => list.map((type, i) => `${scale[i]}${sep}${type}`);
41
+ function keyScale(grades, chords, harmonicFunctions, chordScales) {
42
+ return (tonic) => {
43
+ const intervals = grades.map((gr) => roman(gr).interval || "");
44
+ const scale = intervals.map((interval) => transpose(tonic, interval));
45
+ return {
46
+ tonic,
47
+ grades,
48
+ intervals,
49
+ scale,
50
+ chords: mapScaleToType(scale, chords),
51
+ chordsHarmonicFunction: harmonicFunctions.slice(),
52
+ chordScales: mapScaleToType(scale, chordScales, " ")
53
+ };
54
+ };
55
+ }
56
+ var distInFifths = (from, to) => {
57
+ const f = note(from);
58
+ const t = note(to);
59
+ return f.empty || t.empty ? 0 : t.coord[0] - f.coord[0];
60
+ };
61
+ var MajorScale = keyScale(
62
+ "I II III IV V VI VII".split(" "),
63
+ "maj7 m7 m7 maj7 7 m7 m7b5".split(" "),
64
+ "T SD T SD D T D".split(" "),
65
+ "major,dorian,phrygian,lydian,mixolydian,minor,locrian".split(",")
66
+ );
67
+ var NaturalScale = keyScale(
68
+ "I II bIII IV V bVI bVII".split(" "),
69
+ "m7 m7b5 maj7 m7 m7 maj7 7".split(" "),
70
+ "T SD T SD D SD SD".split(" "),
71
+ "minor,locrian,major,dorian,phrygian,lydian,mixolydian".split(",")
72
+ );
73
+ var HarmonicScale = keyScale(
74
+ "I II bIII IV V bVI VII".split(" "),
75
+ "mMaj7 m7b5 +maj7 m7 7 maj7 o7".split(" "),
76
+ "T SD T SD D SD D".split(" "),
77
+ "harmonic minor,locrian 6,major augmented,lydian diminished,phrygian dominant,lydian #9,ultralocrian".split(
78
+ ","
79
+ )
80
+ );
81
+ var MelodicScale = keyScale(
82
+ "I II bIII IV V VI VII".split(" "),
83
+ "m6 m7 +maj7 7 7 m7b5 m7b5".split(" "),
84
+ "T SD T SD D ".split(" "),
85
+ "melodic minor,dorian b2,lydian augmented,lydian dominant,mixolydian b6,locrian #2,altered".split(
86
+ ","
87
+ )
88
+ );
89
+ function majorKey(tonic) {
90
+ const pc = note(tonic).pc;
91
+ if (!pc)
92
+ return NoMajorKey;
93
+ const keyScale2 = MajorScale(pc);
94
+ const alteration = distInFifths("C", pc);
95
+ const romanInTonic = (src) => {
96
+ const r = roman(src);
97
+ if (r.empty)
98
+ return "";
99
+ return transpose(tonic, r.interval) + r.chordType;
100
+ };
101
+ return {
102
+ ...keyScale2,
103
+ type: "major",
104
+ minorRelative: transpose(pc, "-3m"),
105
+ alteration,
106
+ keySignature: altToAcc(alteration),
107
+ secondaryDominants: "- VI7 VII7 I7 II7 III7 -".split(" ").map(romanInTonic),
108
+ secondaryDominantsMinorRelative: "- IIIm7b5 IV#m7 Vm7 VIm7 VIIm7b5 -".split(" ").map(romanInTonic),
109
+ substituteDominants: "- bIII7 IV7 bV7 bVI7 bVII7 -".split(" ").map(romanInTonic),
110
+ substituteDominantsMinorRelative: "- IIIm7 Im7 IIbm7 VIm7 IVm7 -".split(" ").map(romanInTonic)
111
+ };
112
+ }
113
+ function minorKey(tnc) {
114
+ const pc = note(tnc).pc;
115
+ if (!pc)
116
+ return NoMinorKey;
117
+ const alteration = distInFifths("C", pc) - 3;
118
+ return {
119
+ type: "minor",
120
+ tonic: pc,
121
+ relativeMajor: transpose(pc, "3m"),
122
+ alteration,
123
+ keySignature: altToAcc(alteration),
124
+ natural: NaturalScale(pc),
125
+ harmonic: HarmonicScale(pc),
126
+ melodic: MelodicScale(pc)
127
+ };
128
+ }
129
+ function majorTonicFromKeySignature(sig) {
130
+ if (typeof sig === "number") {
131
+ return transposeFifths("C", sig);
132
+ } else if (typeof sig === "string" && /^b+|#+$/.test(sig)) {
133
+ return transposeFifths("C", accToAlt(sig));
134
+ }
135
+ return null;
136
+ }
137
+ var key_default = { majorKey, majorTonicFromKeySignature, minorKey };
138
+ export {
139
+ key_default as default,
140
+ majorKey,
141
+ majorTonicFromKeySignature,
142
+ minorKey
143
+ };
144
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../index.ts"],"sourcesContent":["import { accToAlt, altToAcc, note, transpose } from \"@tonaljs/core\";\nimport { transposeFifths } from \"@tonaljs/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 chords: readonly string[];\n readonly chordsHarmonicFunction: readonly string[];\n readonly chordScales: readonly string[];\n}\n\nconst NoKeyScale: KeyScale = {\n tonic: \"\",\n grades: Empty,\n intervals: Empty,\n scale: Empty,\n chords: Empty,\n chordsHarmonicFunction: Empty,\n chordScales: Empty,\n};\n\nexport interface MajorKey extends Key, KeyScale {\n readonly type: \"major\";\n readonly minorRelative: string;\n readonly scale: readonly string[];\n readonly secondaryDominants: readonly string[];\n readonly secondaryDominantsMinorRelative: readonly string[];\n readonly substituteDominants: readonly string[];\n readonly substituteDominantsMinorRelative: readonly string[];\n}\n\nconst NoMajorKey: MajorKey = {\n ...NoKey,\n ...NoKeyScale,\n type: \"major\",\n minorRelative: \"\",\n scale: Empty,\n secondaryDominants: Empty,\n secondaryDominantsMinorRelative: Empty,\n substituteDominants: 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\nconst mapScaleToType = (scale: string[], list: string[], sep = \"\") =>\n list.map((type, i) => `${scale[i]}${sep}${type}`);\n\nfunction keyScale(\n grades: string[],\n chords: 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\n return {\n tonic,\n grades,\n intervals,\n scale,\n chords: mapScaleToType(scale, chords),\n chordsHarmonicFunction: harmonicFunctions.slice(),\n chordScales: mapScaleToType(scale, chordScales, \" \"),\n };\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 \"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 \"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 \"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 \"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 const romanInTonic = (src: string) => {\n const r = roman(src);\n if (r.empty) return \"\";\n\n return transpose(tonic, r.interval) + r.chordType;\n };\n\n return {\n ...keyScale,\n type: \"major\",\n minorRelative: transpose(pc, \"-3m\"),\n alteration,\n keySignature: altToAcc(alteration),\n secondaryDominants: \"- VI7 VII7 I7 II7 III7 -\".split(\" \").map(romanInTonic),\n secondaryDominantsMinorRelative: \"- IIIm7b5 IV#m7 Vm7 VIm7 VIIm7b5 -\"\n .split(\" \")\n .map(romanInTonic),\n substituteDominants: \"- bIII7 IV7 bV7 bVI7 bVII7 -\"\n .split(\" \")\n .map(romanInTonic),\n substituteDominantsMinorRelative: \"- IIIm7 Im7 IIbm7 VIm7 IVm7 -\"\n .split(\" \")\n .map(romanInTonic),\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 sigature\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\nexport default { majorKey, majorTonicFromKeySignature, minorKey };\n"],"mappings":";AAAA,SAAS,UAAU,UAAU,MAAM,iBAAiB;AACpD,SAAS,uBAAuB;AAChC,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;AAYA,IAAM,aAAuB;AAAA,EAC3B,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,WAAW;AAAA,EACX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AE;AACrB,MAAI,CAAC;AAAI,WAAO;AAEhB,QAAM,aAAa,aAAa,KAAK,EAAE,IAAI;AAC3C,SAAO;AAAA,IACL,MAAM;AAAA,IACN,OAAO;AAAA,IACP,eAAe,UAAU,IAAI,IAAI;AAAA,IACjC;AAAA,IACA,cAAc,SAAS,UAAU;AAAA,IACjC,SAAS,aAAa,EAAE;AAAA,IACxB,UAAU,cAAc,EAAE;AAAA,IAC1B,SAAS,aAAa,EAAE;AAAA,EAC1B;AACF;AAQO,SAAS,2BACd,KACe;AACf,MAAI,OAAO,QAAQ,UAAU;AAC3B,WAAO,gBAAgB,KAAK,GAAG;AAAA,EACjC,WAAW,OAAO,QAAQ,YAAY,UAAU,KAAK,GAAG,GAAG;AACzD,WAAO,gBAAgB,KAAK,SAAS,GAAG,CAAC;AAAA,EAC3C;AACA,SAAO;AACT;AAEA,IAAO,cAAQ,EAAE,UAAU,4BAA4B,SAAS;","names":["keyScale"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tonaljs/key",
3
- "version": "4.6.4",
3
+ "version": "4.6.10",
4
4
  "description": "Functions to work with musical keys",
5
5
  "keywords": [
6
6
  "key",
@@ -9,24 +9,26 @@
9
9
  "@tonaljs/core"
10
10
  ],
11
11
  "main": "dist/index.js",
12
- "module": "dist/index.es.js",
12
+ "module": "dist/index.mjs",
13
13
  "files": [
14
14
  "dist"
15
15
  ],
16
16
  "types": "dist/index.d.ts",
17
17
  "dependencies": {
18
- "@tonaljs/core": "^4.6.2",
19
- "@tonaljs/note": "^4.6.2",
20
- "@tonaljs/roman-numeral": "^4.6.2"
18
+ "@tonaljs/core": "^4.6.10",
19
+ "@tonaljs/note": "^4.6.10",
20
+ "@tonaljs/roman-numeral": "^4.6.10"
21
21
  },
22
22
  "devDependencies": {
23
- "@tonaljs/chord": "^4.6.4",
24
- "@tonaljs/scale": "^4.6.4"
23
+ "@tonaljs/chord": "^4.6.10",
24
+ "@tonaljs/scale": "^4.6.10"
25
25
  },
26
26
  "author": "danigb@gmail.com",
27
27
  "license": "MIT",
28
28
  "publishConfig": {
29
29
  "access": "public"
30
30
  },
31
- "gitHead": "7bb82dd7ce7d97b6a8768041fc4abceeb2542211"
31
+ "scripts": {
32
+ "build": "tsup index.ts --sourcemap --dts --format esm,cjs"
33
+ }
32
34
  }
package/dist/index.es.js DELETED
@@ -1,137 +0,0 @@
1
- import { note, transpose, altToAcc, accToAlt } from '@tonaljs/core';
2
- import { transposeFifths } from '@tonaljs/note';
3
- import { get } from '@tonaljs/roman-numeral';
4
-
5
- const Empty = Object.freeze([]);
6
- const NoKey = {
7
- type: "major",
8
- tonic: "",
9
- alteration: 0,
10
- keySignature: "",
11
- };
12
- const NoKeyScale = {
13
- tonic: "",
14
- grades: Empty,
15
- intervals: Empty,
16
- scale: Empty,
17
- chords: Empty,
18
- chordsHarmonicFunction: Empty,
19
- chordScales: Empty,
20
- };
21
- const NoMajorKey = {
22
- ...NoKey,
23
- ...NoKeyScale,
24
- type: "major",
25
- minorRelative: "",
26
- scale: Empty,
27
- secondaryDominants: Empty,
28
- secondaryDominantsMinorRelative: Empty,
29
- substituteDominants: Empty,
30
- substituteDominantsMinorRelative: Empty,
31
- };
32
- const NoMinorKey = {
33
- ...NoKey,
34
- type: "minor",
35
- relativeMajor: "",
36
- natural: NoKeyScale,
37
- harmonic: NoKeyScale,
38
- melodic: NoKeyScale,
39
- };
40
- const mapScaleToType = (scale, list, sep = "") => list.map((type, i) => `${scale[i]}${sep}${type}`);
41
- function keyScale(grades, chords, harmonicFunctions, chordScales) {
42
- return (tonic) => {
43
- const intervals = grades.map((gr) => get(gr).interval || "");
44
- const scale = intervals.map((interval) => transpose(tonic, interval));
45
- return {
46
- tonic,
47
- grades,
48
- intervals,
49
- scale,
50
- chords: mapScaleToType(scale, chords),
51
- chordsHarmonicFunction: harmonicFunctions.slice(),
52
- chordScales: mapScaleToType(scale, chordScales, " "),
53
- };
54
- };
55
- }
56
- const distInFifths = (from, to) => {
57
- const f = note(from);
58
- const t = note(to);
59
- return f.empty || t.empty ? 0 : t.coord[0] - f.coord[0];
60
- };
61
- const MajorScale = keyScale("I II III IV V VI VII".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(","));
62
- const NaturalScale = keyScale("I II bIII IV V bVI bVII".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(","));
63
- const HarmonicScale = keyScale("I II bIII IV V bVI VII".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(","));
64
- const MelodicScale = keyScale("I II bIII IV V VI VII".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(","));
65
- /**
66
- * Get a major key properties in a given tonic
67
- * @param tonic
68
- */
69
- function majorKey(tonic) {
70
- const pc = note(tonic).pc;
71
- if (!pc)
72
- return NoMajorKey;
73
- const keyScale = MajorScale(pc);
74
- const alteration = distInFifths("C", pc);
75
- const romanInTonic = (src) => {
76
- const r = get(src);
77
- if (r.empty)
78
- return "";
79
- return transpose(tonic, r.interval) + r.chordType;
80
- };
81
- return {
82
- ...keyScale,
83
- type: "major",
84
- minorRelative: transpose(pc, "-3m"),
85
- alteration,
86
- keySignature: altToAcc(alteration),
87
- secondaryDominants: "- VI7 VII7 I7 II7 III7 -".split(" ").map(romanInTonic),
88
- secondaryDominantsMinorRelative: "- IIIm7b5 IV#m7 Vm7 VIm7 VIIm7b5 -"
89
- .split(" ")
90
- .map(romanInTonic),
91
- substituteDominants: "- bIII7 IV7 bV7 bVI7 bVII7 -"
92
- .split(" ")
93
- .map(romanInTonic),
94
- substituteDominantsMinorRelative: "- IIIm7 Im7 IIbm7 VIm7 IVm7 -"
95
- .split(" ")
96
- .map(romanInTonic),
97
- };
98
- }
99
- /**
100
- * Get minor key properties in a given tonic
101
- * @param tonic
102
- */
103
- function minorKey(tnc) {
104
- const pc = note(tnc).pc;
105
- if (!pc)
106
- return NoMinorKey;
107
- const alteration = distInFifths("C", pc) - 3;
108
- return {
109
- type: "minor",
110
- tonic: pc,
111
- relativeMajor: transpose(pc, "3m"),
112
- alteration,
113
- keySignature: altToAcc(alteration),
114
- natural: NaturalScale(pc),
115
- harmonic: HarmonicScale(pc),
116
- melodic: MelodicScale(pc),
117
- };
118
- }
119
- /**
120
- * Given a key signature, returns the tonic of the major key
121
- * @param sigature
122
- * @example
123
- * majorTonicFromKeySignature('###') // => 'A'
124
- */
125
- function majorTonicFromKeySignature(sig) {
126
- if (typeof sig === "number") {
127
- return transposeFifths("C", sig);
128
- }
129
- else if (typeof sig === "string" && /^b+|#+$/.test(sig)) {
130
- return transposeFifths("C", accToAlt(sig));
131
- }
132
- return null;
133
- }
134
- var index = { majorKey, majorTonicFromKeySignature, minorKey };
135
-
136
- export { index as default, majorKey, majorTonicFromKeySignature, minorKey };
137
- //# sourceMappingURL=index.es.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.es.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}