@tonaljs/key 4.11.7 → 4.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -62,6 +62,8 @@ Key.majorKey("C"); // =>
62
62
  }
63
63
  ```
64
64
 
65
+ A substitute dominant is spelled a diminished fifth above its secondary dominant (`Gb7` for `C7`), unless that needs a double flat or sharp: then it takes the simplest name, as a lead sheet writes it. So in Eb major the substitute of `Eb7` is `A7`, not `Bbb7`.
66
+
65
67
  The supertonics are the ii chords of the ii-V into each degree:
66
68
 
67
69
  - A secondary dominant's ii takes its quality from the target. Into a minor or diminished chord it's half-diminished (`Em7b5 A7 Dm`), and into a major or augmented chord it's a minor seventh (`Gm7 C7 F`).
@@ -94,8 +96,8 @@ Key.minorKey("C"); // =>
94
96
  chordScales: ["C minor", "D locrian", "Eb major", "F dorian", "G phrygian", "Ab lydian", "Bb mixolydian"],
95
97
  secondaryDominants: ["G7", "", "", "C7", "D7", "Eb7", "F7"],
96
98
  secondaryDominantSupertonics: ["Dm7b5", "", "", "Gm7b5", "Am7b5", "Bbm7", "Cm7"],
97
- substituteDominants: ["Db7", "", "", "Gb7", "Ab7", "Bbb7", "Cb7"],
98
- substituteDominantSupertonics: ["Abm7", "", "", "Dbm7", "Ebm7", "Fbm7", "Gbm7"],
99
+ substituteDominants: ["Db7", "", "", "Gb7", "Ab7", "A7", "Cb7"],
100
+ substituteDominantSupertonics: ["Abm7", "", "", "Dbm7", "Ebm7", "Em7", "Gbm7"],
99
101
  },
100
102
  harmonic: {
101
103
  tonic: "C",
@@ -105,11 +107,11 @@ Key.minorKey("C"); // =>
105
107
  triads: ["Cm", "Ddim", "Ebaug", "Fm", "G", "Ab", "Bdim"],
106
108
  chords: ["CmMaj7", "Dm7b5", "Eb+maj7", "Fm7", "G7", "Abmaj7", "Bo7"],
107
109
  chordsHarmonicFunction: ["T", "SD", "T", "SD", "D", "SD", "D"],
108
- chordScales: ["C harmonic minor", "D locrian 6", "Eb major augmented", "F lydian diminished", "G phrygian dominant", "Ab lydian #9", "B ultralocrian"],
110
+ chordScales: ["C harmonic minor", "D locrian 6", "Eb major augmented", "F dorian #4", "G phrygian dominant", "Ab lydian #9", "B ultralocrian"],
109
111
  secondaryDominants: ["", "", "", "C7", "D7", "Eb7", ""],
110
112
  secondaryDominantSupertonics: ["", "", "", "Gm7b5", "Am7", "Bbm7", ""],
111
- substituteDominants: ["", "", "", "Gb7", "Ab7", "Bbb7", ""],
112
- substituteDominantSupertonics: ["", "", "", "Dbm7", "Ebm7", "Fbm7", ""],
113
+ substituteDominants: ["", "", "", "Gb7", "Ab7", "A7", ""],
114
+ substituteDominantSupertonics: ["", "", "", "Dbm7", "Ebm7", "Em7", ""],
113
115
  },
114
116
  melodic: {
115
117
  tonic: "C",
@@ -166,7 +168,7 @@ Return a list of all available chords for a given minor key:
166
168
  Key.minorKeyChords("C")
167
169
  .map((chord) => chord.name)
168
170
  .join(", ");
169
- // => "Cm7, Dm7b5, Ebmaj7, Fm7, Gm7, Abmaj7, Bb7, G7, C7, D7, Eb7, F7, Gm7b5, Am7b5, Bbm7, Db7, Gb7, Ab7, Bbb7, Cb7, Abm7, Dbm7, Ebm7, Fbm7, Gbm7, CmMaj7, Eb+maj7, Bo7, Am7, Cm6, Dm7, Bm7b5, A7, Em7b5"
171
+ // => "Cm7, Dm7b5, Ebmaj7, Fm7, Gm7, Abmaj7, Bb7, G7, C7, D7, Eb7, F7, Gm7b5, Am7b5, Bbm7, Db7, Gb7, Ab7, A7, Cb7, Abm7, Dbm7, Ebm7, Em7, Gbm7, CmMaj7, Eb+maj7, Bo7, Am7, Cm6, Dm7, Bm7b5, Em7b5"
170
172
  ```
171
173
 
172
174
  ## How to...
package/dist/index.d.mts CHANGED
@@ -1,21 +1,35 @@
1
1
  interface Key {
2
2
  readonly type: "major" | "minor";
3
+ /** The tonic pitch class, like "F". Empty for an invalid key. */
3
4
  readonly tonic: string;
5
+ /** Number of accidentals in the key signature: positive for sharps, negative for flats. */
4
6
  readonly alteration: number;
7
+ /** The key signature as accidentals: "" (none), "bb" (two flats), "###" (three sharps). */
5
8
  readonly keySignature: string;
6
9
  }
7
10
  interface KeyScale {
8
11
  readonly tonic: string;
12
+ /** Roman numeral of each degree, like ["I", "II", "bIII", ...]. */
9
13
  readonly grades: readonly string[];
14
+ /** Interval from the tonic to each degree, like ["1P", "2M", "3M", ...]. */
10
15
  readonly intervals: readonly string[];
16
+ /** Notes of the scale, one per degree. */
11
17
  readonly scale: readonly string[];
18
+ /** Triad of each degree, like ["F", "Gm", "Am", ...]. */
12
19
  readonly triads: readonly string[];
20
+ /** Seventh chord of each degree, like ["Fmaj7", "Gm7", ...]. */
13
21
  readonly chords: readonly string[];
22
+ /** Harmonic function of each chord: "T" (tonic), "SD" (subdominant) or "D" (dominant). Empty string if none. */
14
23
  readonly chordsHarmonicFunction: readonly string[];
24
+ /** Scale that fits each chord, like ["F major", "G dorian", ...]. */
15
25
  readonly chordScales: readonly string[];
26
+ /** Dominant seventh chord that resolves to each degree ("" if the degree has none), like ["", "D7", "E7", ...] for F major. */
16
27
  readonly secondaryDominants: readonly string[];
28
+ /** The ii chord that precedes each secondary dominant ("" if none): a minor seventh, or a half-diminished chord when the target is minor. */
17
29
  readonly secondaryDominantSupertonics: readonly string[];
30
+ /** Tritone substitution of each secondary dominant ("" if none): the dominant seventh a tritone away, spelled a diminished fifth above it (Gb7 for C7) unless that needs a double flat or sharp (A7, not Bbb7, for Eb7). */
18
31
  readonly substituteDominants: readonly string[];
32
+ /** The minor seventh ii chord that precedes each substitute dominant ("" if none). */
19
33
  readonly substituteDominantSupertonics: readonly string[];
20
34
  /** @deprecated use secondaryDominantSupertonics */
21
35
  readonly secondaryDominantsMinorRelative: readonly string[];
@@ -24,6 +38,7 @@ interface KeyScale {
24
38
  }
25
39
  interface MajorKey extends Key, KeyScale {
26
40
  readonly type: "major";
41
+ /** Tonic of the relative minor key, like "D" for "F". */
27
42
  readonly minorRelative: string;
28
43
  readonly scale: readonly string[];
29
44
  readonly substituteDominants: readonly string[];
@@ -33,46 +48,81 @@ interface MajorKey extends Key, KeyScale {
33
48
  }
34
49
  interface MinorKey extends Key {
35
50
  readonly type: "minor";
51
+ /** Tonic of the relative major key, like "C" for "A". */
36
52
  readonly relativeMajor: string;
53
+ /** Natural minor (aeolian) scale and its chords. */
37
54
  readonly natural: KeyScale;
55
+ /** Harmonic minor scale and its chords. */
38
56
  readonly harmonic: KeyScale;
57
+ /** Melodic minor (ascending) scale and its chords. */
39
58
  readonly melodic: KeyScale;
40
59
  }
41
60
  type KeyChord = {
61
+ /** Chord symbol, like "Dm7". */
42
62
  name: string;
63
+ /** Functions the chord plays in the key: "T", "SD", "D", or "V/II", "ii/V", "subV/II", "subii/II" for secondary and substitute dominants. */
43
64
  roles: string[];
44
65
  };
45
66
  /**
46
- * Get a major key properties in a given tonic
47
- * @param tonic
67
+ * Get a major key: its signature, scale, triads, seventh chords, harmonic
68
+ * functions and secondary and substitute dominants. For an invalid tonic
69
+ * it returns a key with empty strings and arrays.
70
+ *
71
+ * @param tonic - the tonic note or pitch class, like "F" or "Bb"
72
+ * @example
73
+ * Key.majorKey("F").scale; // => ["F", "G", "A", "Bb", "C", "D", "E"]
74
+ * Key.majorKey("F").chords; // => ["Fmaj7", "Gm7", "Am7", "Bbmaj7", "C7", "Dm7", "Em7b5"]
75
+ * Key.majorKey("F").keySignature; // => "b"
48
76
  */
49
77
  declare function majorKey(tonic: string): MajorKey;
50
78
  /**
51
- * Get a list of available chords for a given major key
52
- * @param tonic
79
+ * Get the chords available in a major key, each with the roles it plays:
80
+ * diatonic chords ("T", "SD", "D") and secondary and substitute dominants
81
+ * with their supertonics ("V/II", "ii/V", "subV/II"...). Returns an empty
82
+ * array for an invalid tonic.
83
+ *
84
+ * @param tonic - the tonic note or pitch class, like "C"
53
85
  * @returns array of { name: string, roles: string[] }
86
+ * @example
87
+ * Key.majorKeyChords("C").slice(0, 3); // => [{ name: "Cmaj7", roles: ["T"] }, { name: "Dm7", roles: ["SD"] }, { name: "Em7", roles: ["T"] }]
54
88
  */
55
89
  declare function majorKeyChords(tonic: string): KeyChord[];
56
90
  /**
57
- * Get a list of available chords for a given major key
58
- * @param tonic
91
+ * Get the chords available in a minor key, each with the roles it plays. It
92
+ * merges the chords of the natural, harmonic and melodic scales, so a chord
93
+ * that appears in several scales has all its roles. Returns an empty array
94
+ * for an invalid tonic.
95
+ *
96
+ * @param tonic - the tonic note or pitch class, like "A"
59
97
  * @returns array of { name: string, roles: string[] }
98
+ * @example
99
+ * Key.minorKeyChords("A").slice(0, 2); // => [{ name: "Am7", roles: ["T", "ii/bVII"] }, { name: "Bm7b5", roles: ["SD", "ii/I"] }]
60
100
  */
61
101
  declare function minorKeyChords(tonic: string): KeyChord[];
62
102
  /**
63
- * Get minor key properties in a given tonic
64
- * @param tonic
103
+ * Get a minor key: its signature, relative major and the scale, chords and
104
+ * dominants of its natural, harmonic and melodic forms. For an invalid tonic
105
+ * it returns a key with empty strings and arrays.
106
+ *
107
+ * @param tnc - the tonic note or pitch class, like "A"
108
+ * @example
109
+ * Key.minorKey("A").relativeMajor; // => "C"
110
+ * Key.minorKey("A").harmonic.scale; // => ["A", "B", "C", "D", "E", "F", "G#"]
111
+ * Key.minorKey("A").natural.chords; // => ["Am7", "Bm7b5", "Cmaj7", "Dm7", "Em7", "Fmaj7", "G7"]
65
112
  */
66
113
  declare function minorKey(tnc: string): MinorKey;
67
114
  /**
68
- * Given a key signature, returns the tonic of the major key
69
- * @param signature
115
+ * Get the tonic of the major key with the given key signature, or null if
116
+ * the signature is not valid.
117
+ *
118
+ * @param sig - accidentals ("", "bb", "###") or a number of fifths (positive for sharps, negative for flats)
70
119
  * @example
71
- * majorTonicFromKeySignature('###') // => 'A'
72
- * majorTonicFromKeySignature('') // => 'C'
120
+ * Key.majorTonicFromKeySignature("###"); // => "A"
121
+ * Key.majorTonicFromKeySignature(-2); // => "Bb"
122
+ * Key.majorTonicFromKeySignature(""); // => "C"
73
123
  */
74
124
  declare function majorTonicFromKeySignature(sig: string | number): string | null;
75
- /** @deprecated */
125
+ /** @deprecated Use the named exports instead. */
76
126
  declare const _default: {
77
127
  majorKey: typeof majorKey;
78
128
  majorTonicFromKeySignature: typeof majorTonicFromKeySignature;
package/dist/index.d.ts CHANGED
@@ -1,21 +1,35 @@
1
1
  interface Key {
2
2
  readonly type: "major" | "minor";
3
+ /** The tonic pitch class, like "F". Empty for an invalid key. */
3
4
  readonly tonic: string;
5
+ /** Number of accidentals in the key signature: positive for sharps, negative for flats. */
4
6
  readonly alteration: number;
7
+ /** The key signature as accidentals: "" (none), "bb" (two flats), "###" (three sharps). */
5
8
  readonly keySignature: string;
6
9
  }
7
10
  interface KeyScale {
8
11
  readonly tonic: string;
12
+ /** Roman numeral of each degree, like ["I", "II", "bIII", ...]. */
9
13
  readonly grades: readonly string[];
14
+ /** Interval from the tonic to each degree, like ["1P", "2M", "3M", ...]. */
10
15
  readonly intervals: readonly string[];
16
+ /** Notes of the scale, one per degree. */
11
17
  readonly scale: readonly string[];
18
+ /** Triad of each degree, like ["F", "Gm", "Am", ...]. */
12
19
  readonly triads: readonly string[];
20
+ /** Seventh chord of each degree, like ["Fmaj7", "Gm7", ...]. */
13
21
  readonly chords: readonly string[];
22
+ /** Harmonic function of each chord: "T" (tonic), "SD" (subdominant) or "D" (dominant). Empty string if none. */
14
23
  readonly chordsHarmonicFunction: readonly string[];
24
+ /** Scale that fits each chord, like ["F major", "G dorian", ...]. */
15
25
  readonly chordScales: readonly string[];
26
+ /** Dominant seventh chord that resolves to each degree ("" if the degree has none), like ["", "D7", "E7", ...] for F major. */
16
27
  readonly secondaryDominants: readonly string[];
28
+ /** The ii chord that precedes each secondary dominant ("" if none): a minor seventh, or a half-diminished chord when the target is minor. */
17
29
  readonly secondaryDominantSupertonics: readonly string[];
30
+ /** Tritone substitution of each secondary dominant ("" if none): the dominant seventh a tritone away, spelled a diminished fifth above it (Gb7 for C7) unless that needs a double flat or sharp (A7, not Bbb7, for Eb7). */
18
31
  readonly substituteDominants: readonly string[];
32
+ /** The minor seventh ii chord that precedes each substitute dominant ("" if none). */
19
33
  readonly substituteDominantSupertonics: readonly string[];
20
34
  /** @deprecated use secondaryDominantSupertonics */
21
35
  readonly secondaryDominantsMinorRelative: readonly string[];
@@ -24,6 +38,7 @@ interface KeyScale {
24
38
  }
25
39
  interface MajorKey extends Key, KeyScale {
26
40
  readonly type: "major";
41
+ /** Tonic of the relative minor key, like "D" for "F". */
27
42
  readonly minorRelative: string;
28
43
  readonly scale: readonly string[];
29
44
  readonly substituteDominants: readonly string[];
@@ -33,46 +48,81 @@ interface MajorKey extends Key, KeyScale {
33
48
  }
34
49
  interface MinorKey extends Key {
35
50
  readonly type: "minor";
51
+ /** Tonic of the relative major key, like "C" for "A". */
36
52
  readonly relativeMajor: string;
53
+ /** Natural minor (aeolian) scale and its chords. */
37
54
  readonly natural: KeyScale;
55
+ /** Harmonic minor scale and its chords. */
38
56
  readonly harmonic: KeyScale;
57
+ /** Melodic minor (ascending) scale and its chords. */
39
58
  readonly melodic: KeyScale;
40
59
  }
41
60
  type KeyChord = {
61
+ /** Chord symbol, like "Dm7". */
42
62
  name: string;
63
+ /** Functions the chord plays in the key: "T", "SD", "D", or "V/II", "ii/V", "subV/II", "subii/II" for secondary and substitute dominants. */
43
64
  roles: string[];
44
65
  };
45
66
  /**
46
- * Get a major key properties in a given tonic
47
- * @param tonic
67
+ * Get a major key: its signature, scale, triads, seventh chords, harmonic
68
+ * functions and secondary and substitute dominants. For an invalid tonic
69
+ * it returns a key with empty strings and arrays.
70
+ *
71
+ * @param tonic - the tonic note or pitch class, like "F" or "Bb"
72
+ * @example
73
+ * Key.majorKey("F").scale; // => ["F", "G", "A", "Bb", "C", "D", "E"]
74
+ * Key.majorKey("F").chords; // => ["Fmaj7", "Gm7", "Am7", "Bbmaj7", "C7", "Dm7", "Em7b5"]
75
+ * Key.majorKey("F").keySignature; // => "b"
48
76
  */
49
77
  declare function majorKey(tonic: string): MajorKey;
50
78
  /**
51
- * Get a list of available chords for a given major key
52
- * @param tonic
79
+ * Get the chords available in a major key, each with the roles it plays:
80
+ * diatonic chords ("T", "SD", "D") and secondary and substitute dominants
81
+ * with their supertonics ("V/II", "ii/V", "subV/II"...). Returns an empty
82
+ * array for an invalid tonic.
83
+ *
84
+ * @param tonic - the tonic note or pitch class, like "C"
53
85
  * @returns array of { name: string, roles: string[] }
86
+ * @example
87
+ * Key.majorKeyChords("C").slice(0, 3); // => [{ name: "Cmaj7", roles: ["T"] }, { name: "Dm7", roles: ["SD"] }, { name: "Em7", roles: ["T"] }]
54
88
  */
55
89
  declare function majorKeyChords(tonic: string): KeyChord[];
56
90
  /**
57
- * Get a list of available chords for a given major key
58
- * @param tonic
91
+ * Get the chords available in a minor key, each with the roles it plays. It
92
+ * merges the chords of the natural, harmonic and melodic scales, so a chord
93
+ * that appears in several scales has all its roles. Returns an empty array
94
+ * for an invalid tonic.
95
+ *
96
+ * @param tonic - the tonic note or pitch class, like "A"
59
97
  * @returns array of { name: string, roles: string[] }
98
+ * @example
99
+ * Key.minorKeyChords("A").slice(0, 2); // => [{ name: "Am7", roles: ["T", "ii/bVII"] }, { name: "Bm7b5", roles: ["SD", "ii/I"] }]
60
100
  */
61
101
  declare function minorKeyChords(tonic: string): KeyChord[];
62
102
  /**
63
- * Get minor key properties in a given tonic
64
- * @param tonic
103
+ * Get a minor key: its signature, relative major and the scale, chords and
104
+ * dominants of its natural, harmonic and melodic forms. For an invalid tonic
105
+ * it returns a key with empty strings and arrays.
106
+ *
107
+ * @param tnc - the tonic note or pitch class, like "A"
108
+ * @example
109
+ * Key.minorKey("A").relativeMajor; // => "C"
110
+ * Key.minorKey("A").harmonic.scale; // => ["A", "B", "C", "D", "E", "F", "G#"]
111
+ * Key.minorKey("A").natural.chords; // => ["Am7", "Bm7b5", "Cmaj7", "Dm7", "Em7", "Fmaj7", "G7"]
65
112
  */
66
113
  declare function minorKey(tnc: string): MinorKey;
67
114
  /**
68
- * Given a key signature, returns the tonic of the major key
69
- * @param signature
115
+ * Get the tonic of the major key with the given key signature, or null if
116
+ * the signature is not valid.
117
+ *
118
+ * @param sig - accidentals ("", "bb", "###") or a number of fifths (positive for sharps, negative for flats)
70
119
  * @example
71
- * majorTonicFromKeySignature('###') // => 'A'
72
- * majorTonicFromKeySignature('') // => 'C'
120
+ * Key.majorTonicFromKeySignature("###"); // => "A"
121
+ * Key.majorTonicFromKeySignature(-2); // => "Bb"
122
+ * Key.majorTonicFromKeySignature(""); // => "C"
73
123
  */
74
124
  declare function majorTonicFromKeySignature(sig: string | number): string | null;
75
- /** @deprecated */
125
+ /** @deprecated Use the named exports instead. */
76
126
  declare const _default: {
77
127
  majorKey: typeof majorKey;
78
128
  majorTonicFromKeySignature: typeof majorTonicFromKeySignature;
package/dist/index.js CHANGED
@@ -55,11 +55,7 @@ function keyScale(grades, triads, chordTypes, harmonicFunctions, chordScales) {
55
55
  const chords = mapScaleToType(scale, chordTypes);
56
56
  const secondaryDominants = scale.map((note) => (0, _tonaljs_note.transpose)(note, "5P")).map((note) => scale.includes(note) && !chords.includes(note + "7") ? note + "7" : "");
57
57
  const secondaryDominantSupertonics = supertonics(secondaryDominants, triads);
58
- const substituteDominants = secondaryDominants.map((chord) => {
59
- if (!chord) return "";
60
- const domRoot = chord.slice(0, -1);
61
- return (0, _tonaljs_note.transpose)(domRoot, "5d") + "7";
62
- });
58
+ const substituteDominants = secondaryDominants.map((chord) => chord ? substituteRoot(chord.slice(0, -1)) + "7" : "");
63
59
  const substituteDominantSupertonics = substituteSupertonics(substituteDominants);
64
60
  return {
65
61
  tonic,
@@ -79,6 +75,10 @@ function keyScale(grades, triads, chordTypes, harmonicFunctions, chordScales) {
79
75
  };
80
76
  };
81
77
  }
78
+ function substituteRoot(dominantRoot) {
79
+ const root = (0, _tonaljs_note.transpose)(dominantRoot, "5d");
80
+ return (0, _tonaljs_pitch_note.note)(root).acc.length > 1 ? (0, _tonaljs_note.simplify)(root) : root;
81
+ }
82
82
  const supertonicRoot = (dominant) => (0, _tonaljs_note.transpose)(dominant.slice(0, -1), "5P");
83
83
  const supertonics = (dominants, targetTriads) => dominants.map((chord, index) => {
84
84
  if (!chord) return "";
@@ -94,11 +94,18 @@ const distInFifths = (from, to) => {
94
94
  };
95
95
  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(","));
96
96
  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(","));
97
- 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(","));
97
+ 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,dorian #4,phrygian dominant,lydian #9,ultralocrian".split(","));
98
98
  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(","));
99
99
  /**
100
- * Get a major key properties in a given tonic
101
- * @param tonic
100
+ * Get a major key: its signature, scale, triads, seventh chords, harmonic
101
+ * functions and secondary and substitute dominants. For an invalid tonic
102
+ * it returns a key with empty strings and arrays.
103
+ *
104
+ * @param tonic - the tonic note or pitch class, like "F" or "Bb"
105
+ * @example
106
+ * Key.majorKey("F").scale; // => ["F", "G", "A", "Bb", "C", "D", "E"]
107
+ * Key.majorKey("F").chords; // => ["Fmaj7", "Gm7", "Am7", "Bbmaj7", "C7", "Dm7", "Em7b5"]
108
+ * Key.majorKey("F").keySignature; // => "b"
102
109
  */
103
110
  function majorKey(tonic) {
104
111
  const pc = (0, _tonaljs_pitch_note.note)(tonic).pc;
@@ -114,9 +121,15 @@ function majorKey(tonic) {
114
121
  };
115
122
  }
116
123
  /**
117
- * Get a list of available chords for a given major key
118
- * @param tonic
124
+ * Get the chords available in a major key, each with the roles it plays:
125
+ * diatonic chords ("T", "SD", "D") and secondary and substitute dominants
126
+ * with their supertonics ("V/II", "ii/V", "subV/II"...). Returns an empty
127
+ * array for an invalid tonic.
128
+ *
129
+ * @param tonic - the tonic note or pitch class, like "C"
119
130
  * @returns array of { name: string, roles: string[] }
131
+ * @example
132
+ * Key.majorKeyChords("C").slice(0, 3); // => [{ name: "Cmaj7", roles: ["T"] }, { name: "Dm7", roles: ["SD"] }, { name: "Em7", roles: ["T"] }]
120
133
  */
121
134
  function majorKeyChords(tonic) {
122
135
  const key = majorKey(tonic);
@@ -125,9 +138,15 @@ function majorKeyChords(tonic) {
125
138
  return chords;
126
139
  }
127
140
  /**
128
- * Get a list of available chords for a given major key
129
- * @param tonic
141
+ * Get the chords available in a minor key, each with the roles it plays. It
142
+ * merges the chords of the natural, harmonic and melodic scales, so a chord
143
+ * that appears in several scales has all its roles. Returns an empty array
144
+ * for an invalid tonic.
145
+ *
146
+ * @param tonic - the tonic note or pitch class, like "A"
130
147
  * @returns array of { name: string, roles: string[] }
148
+ * @example
149
+ * Key.minorKeyChords("A").slice(0, 2); // => [{ name: "Am7", roles: ["T", "ii/bVII"] }, { name: "Bm7b5", roles: ["SD", "ii/I"] }]
131
150
  */
132
151
  function minorKeyChords(tonic) {
133
152
  const key = minorKey(tonic);
@@ -157,8 +176,15 @@ function keyChordsOf(key, chords) {
157
176
  key.substituteDominantSupertonics.forEach((chordName, index) => updateChord(chordName, `subii/${key.grades[index]}`));
158
177
  }
159
178
  /**
160
- * Get minor key properties in a given tonic
161
- * @param tonic
179
+ * Get a minor key: its signature, relative major and the scale, chords and
180
+ * dominants of its natural, harmonic and melodic forms. For an invalid tonic
181
+ * it returns a key with empty strings and arrays.
182
+ *
183
+ * @param tnc - the tonic note or pitch class, like "A"
184
+ * @example
185
+ * Key.minorKey("A").relativeMajor; // => "C"
186
+ * Key.minorKey("A").harmonic.scale; // => ["A", "B", "C", "D", "E", "F", "G#"]
187
+ * Key.minorKey("A").natural.chords; // => ["Am7", "Bm7b5", "Cmaj7", "Dm7", "Em7", "Fmaj7", "G7"]
162
188
  */
163
189
  function minorKey(tnc) {
164
190
  const pc = (0, _tonaljs_pitch_note.note)(tnc).pc;
@@ -176,18 +202,21 @@ function minorKey(tnc) {
176
202
  };
177
203
  }
178
204
  /**
179
- * Given a key signature, returns the tonic of the major key
180
- * @param signature
205
+ * Get the tonic of the major key with the given key signature, or null if
206
+ * the signature is not valid.
207
+ *
208
+ * @param sig - accidentals ("", "bb", "###") or a number of fifths (positive for sharps, negative for flats)
181
209
  * @example
182
- * majorTonicFromKeySignature('###') // => 'A'
183
- * majorTonicFromKeySignature('') // => 'C'
210
+ * Key.majorTonicFromKeySignature("###"); // => "A"
211
+ * Key.majorTonicFromKeySignature(-2); // => "Bb"
212
+ * Key.majorTonicFromKeySignature(""); // => "C"
184
213
  */
185
214
  function majorTonicFromKeySignature(sig) {
186
215
  if (typeof sig === "number") return (0, _tonaljs_note.transposeFifths)("C", sig);
187
216
  else if (typeof sig === "string" && /^(b*|#*)$/.test(sig)) return (0, _tonaljs_note.transposeFifths)("C", (0, _tonaljs_pitch_note.accToAlt)(sig));
188
217
  return null;
189
218
  }
190
- /** @deprecated */
219
+ /** @deprecated Use the named exports instead. */
191
220
  var key_default = {
192
221
  majorKey,
193
222
  majorTonicFromKeySignature,
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["roman","transpose","note","altToAcc","transposeFifths","accToAlt"],"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 secondaryDominantSupertonics */\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 substituteDominantSupertonics */\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 =\n substituteSupertonics(substituteDominants);\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 aliases\n secondaryDominantsMinorRelative: secondaryDominantSupertonics,\n substituteDominantsMinorRelative: substituteDominantSupertonics,\n };\n };\n}\n\n// The root of the ii chord of a dominant: a fifth above its root\nconst supertonicRoot = (dominant: string) =>\n transpose(dominant.slice(0, -1), \"5P\");\n\n// The ii of a secondary dominant takes its quality from the target: a ii-V\n// into a minor or diminished chord uses a half-diminished ii (Em7b5 A7 Dm),\n// and into a major or augmented chord a minor seventh ii (Gm7 C7 F)\nconst supertonics = (dominants: string[], targetTriads: string[]) =>\n dominants.map((chord, index) => {\n if (!chord) return \"\";\n const target = targetTriads[index];\n const isMinor = target === \"m\" || target === \"dim\";\n return supertonicRoot(chord) + (isMinor ? \"m7b5\" : \"m7\");\n });\n\n// A substitute dominant doesn't resolve to the key it points to (Eb7 resolves\n// to Dm, not Ab), so its ii is always a minor seventh: Bbm7 Eb7 Dm\nconst substituteSupertonics = (dominants: string[]) =>\n dominants.map((chord) => (chord ? supertonicRoot(chord) + \"m7\" : \"\"));\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 * majorTonicFromKeySignature('') // => 'C'\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,GAA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AC1C,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,GAAKD,oBAAAA,KAAAA,CAAK,GAAG,CAAC,CAAC;CACrB,IAAI,CAAC,IAAI,OAAO;CAEhB,MAAM,aAAa,aAAa,KAAK,EAAE,IAAI;CAC3C,OAAO;EACL,MAAM;EACN,OAAO;EACP,gBAAA,GAAeD,cAAAA,UAAAA,CAAU,IAAI,IAAI;EACjC;EACA,eAAA,GAAcE,oBAAAA,SAAAA,CAAS,UAAU;EACjC,SAAS,aAAa,EAAE;EACxB,UAAU,cAAc,EAAE;EAC1B,SAAS,aAAa,EAAE;CAC1B;AACF;;;;;;;;AASA,SAAgB,2BACd,KACe;CACf,IAAI,OAAO,QAAQ,UACjB,QAAA,GAAOC,cAAAA,gBAAAA,CAAgB,KAAK,GAAG;MAC1B,IAAI,OAAO,QAAQ,YAAY,YAAY,KAAK,GAAG,GACxD,QAAA,GAAOA,cAAAA,gBAAAA,CAAgB,MAAA,GAAKC,oBAAAA,SAAAA,CAAS,GAAG,CAAC;CAE3C,OAAO;AACT;;AAGA,IAAA,cAAe;CAAE;CAAU;CAA4B;AAAS"}
1
+ {"version":3,"file":"index.js","names":["roman","transpose","note","simplify","altToAcc","transposeFifths","accToAlt"],"sources":["../index.ts"],"sourcesContent":["import { simplify, 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 /** The tonic pitch class, like \"F\". Empty for an invalid key. */\n readonly tonic: string;\n /** Number of accidentals in the key signature: positive for sharps, negative for flats. */\n readonly alteration: number;\n /** The key signature as accidentals: \"\" (none), \"bb\" (two flats), \"###\" (three sharps). */\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 /** Roman numeral of each degree, like [\"I\", \"II\", \"bIII\", ...]. */\n readonly grades: readonly string[];\n /** Interval from the tonic to each degree, like [\"1P\", \"2M\", \"3M\", ...]. */\n readonly intervals: readonly string[];\n /** Notes of the scale, one per degree. */\n readonly scale: readonly string[];\n /** Triad of each degree, like [\"F\", \"Gm\", \"Am\", ...]. */\n readonly triads: readonly string[];\n /** Seventh chord of each degree, like [\"Fmaj7\", \"Gm7\", ...]. */\n readonly chords: readonly string[];\n /** Harmonic function of each chord: \"T\" (tonic), \"SD\" (subdominant) or \"D\" (dominant). Empty string if none. */\n readonly chordsHarmonicFunction: readonly string[];\n /** Scale that fits each chord, like [\"F major\", \"G dorian\", ...]. */\n readonly chordScales: readonly string[];\n /** Dominant seventh chord that resolves to each degree (\"\" if the degree has none), like [\"\", \"D7\", \"E7\", ...] for F major. */\n readonly secondaryDominants: readonly string[];\n /** The ii chord that precedes each secondary dominant (\"\" if none): a minor seventh, or a half-diminished chord when the target is minor. */\n readonly secondaryDominantSupertonics: readonly string[];\n /** Tritone substitution of each secondary dominant (\"\" if none): the dominant seventh a tritone away, spelled a diminished fifth above it (Gb7 for C7) unless that needs a double flat or sharp (A7, not Bbb7, for Eb7). */\n readonly substituteDominants: readonly string[];\n /** The minor seventh ii chord that precedes each substitute dominant (\"\" if none). */\n readonly substituteDominantSupertonics: readonly string[];\n\n /** @deprecated use secondaryDominantSupertonics */\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 /** Tonic of the relative minor key, like \"D\" for \"F\". */\n readonly minorRelative: string;\n readonly scale: readonly string[];\n readonly substituteDominants: readonly string[];\n readonly secondaryDominantSupertonics: readonly string[];\n /** @deprecated use substituteDominantSupertonics */\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 /** Tonic of the relative major key, like \"C\" for \"A\". */\n readonly relativeMajor: string;\n /** Natural minor (aeolian) scale and its chords. */\n readonly natural: KeyScale;\n /** Harmonic minor scale and its chords. */\n readonly harmonic: KeyScale;\n /** Melodic minor (ascending) scale and its chords. */\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 /** Chord symbol, like \"Dm7\". */\n name: string;\n /** Functions the chord plays in the key: \"T\", \"SD\", \"D\", or \"V/II\", \"ii/V\", \"subV/II\", \"subii/II\" for secondary and substitute dominants. */\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 chord ? substituteRoot(chord.slice(0, -1)) + \"7\" : \"\",\n );\n const substituteDominantSupertonics =\n substituteSupertonics(substituteDominants);\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 aliases\n secondaryDominantsMinorRelative: secondaryDominantSupertonics,\n substituteDominantsMinorRelative: substituteDominantSupertonics,\n };\n };\n}\n\n// The root of a substitute dominant: a diminished fifth above the dominant's\n// root (Gb for C), or its simplest enharmonic when that has a double\n// accidental, as a lead sheet writes it (A, not Bbb, for Eb)\nfunction substituteRoot(dominantRoot: string) {\n const root = transpose(dominantRoot, \"5d\");\n return note(root).acc.length > 1 ? simplify(root) : root;\n}\n\n// The root of the ii chord of a dominant: a fifth above its root\nconst supertonicRoot = (dominant: string) =>\n transpose(dominant.slice(0, -1), \"5P\");\n\n// The ii of a secondary dominant takes its quality from the target: a ii-V\n// into a minor or diminished chord uses a half-diminished ii (Em7b5 A7 Dm),\n// and into a major or augmented chord a minor seventh ii (Gm7 C7 F)\nconst supertonics = (dominants: string[], targetTriads: string[]) =>\n dominants.map((chord, index) => {\n if (!chord) return \"\";\n const target = targetTriads[index];\n const isMinor = target === \"m\" || target === \"dim\";\n return supertonicRoot(chord) + (isMinor ? \"m7b5\" : \"m7\");\n });\n\n// A substitute dominant doesn't resolve to the key it points to (Eb7 resolves\n// to Dm, not Ab), so its ii is always a minor seventh: Bbm7 Eb7 Dm\nconst substituteSupertonics = (dominants: string[]) =>\n dominants.map((chord) => (chord ? supertonicRoot(chord) + \"m7\" : \"\"));\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,dorian #4,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: its signature, scale, triads, seventh chords, harmonic\n * functions and secondary and substitute dominants. For an invalid tonic\n * it returns a key with empty strings and arrays.\n *\n * @param tonic - the tonic note or pitch class, like \"F\" or \"Bb\"\n * @example\n * Key.majorKey(\"F\").scale; // => [\"F\", \"G\", \"A\", \"Bb\", \"C\", \"D\", \"E\"]\n * Key.majorKey(\"F\").chords; // => [\"Fmaj7\", \"Gm7\", \"Am7\", \"Bbmaj7\", \"C7\", \"Dm7\", \"Em7b5\"]\n * Key.majorKey(\"F\").keySignature; // => \"b\"\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 the chords available in a major key, each with the roles it plays:\n * diatonic chords (\"T\", \"SD\", \"D\") and secondary and substitute dominants\n * with their supertonics (\"V/II\", \"ii/V\", \"subV/II\"...). Returns an empty\n * array for an invalid tonic.\n *\n * @param tonic - the tonic note or pitch class, like \"C\"\n * @returns array of { name: string, roles: string[] }\n * @example\n * Key.majorKeyChords(\"C\").slice(0, 3); // => [{ name: \"Cmaj7\", roles: [\"T\"] }, { name: \"Dm7\", roles: [\"SD\"] }, { name: \"Em7\", roles: [\"T\"] }]\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 the chords available in a minor key, each with the roles it plays. It\n * merges the chords of the natural, harmonic and melodic scales, so a chord\n * that appears in several scales has all its roles. Returns an empty array\n * for an invalid tonic.\n *\n * @param tonic - the tonic note or pitch class, like \"A\"\n * @returns array of { name: string, roles: string[] }\n * @example\n * Key.minorKeyChords(\"A\").slice(0, 2); // => [{ name: \"Am7\", roles: [\"T\", \"ii/bVII\"] }, { name: \"Bm7b5\", roles: [\"SD\", \"ii/I\"] }]\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 a minor key: its signature, relative major and the scale, chords and\n * dominants of its natural, harmonic and melodic forms. For an invalid tonic\n * it returns a key with empty strings and arrays.\n *\n * @param tnc - the tonic note or pitch class, like \"A\"\n * @example\n * Key.minorKey(\"A\").relativeMajor; // => \"C\"\n * Key.minorKey(\"A\").harmonic.scale; // => [\"A\", \"B\", \"C\", \"D\", \"E\", \"F\", \"G#\"]\n * Key.minorKey(\"A\").natural.chords; // => [\"Am7\", \"Bm7b5\", \"Cmaj7\", \"Dm7\", \"Em7\", \"Fmaj7\", \"G7\"]\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 * Get the tonic of the major key with the given key signature, or null if\n * the signature is not valid.\n *\n * @param sig - accidentals (\"\", \"bb\", \"###\") or a number of fifths (positive for sharps, negative for flats)\n * @example\n * Key.majorTonicFromKeySignature(\"###\"); // => \"A\"\n * Key.majorTonicFromKeySignature(-2); // => \"Bb\"\n * Key.majorTonicFromKeySignature(\"\"); // => \"C\"\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 Use the named exports instead. */\nexport default { majorKey, majorTonicFromKeySignature, minorKey };\n"],"mappings":";;;;;;;;AAIA,MAAM,QAA2B,OAAO,OAAO,CAAC,CAAa;AAY7D,MAAM,QAAa;CACjB,MAAM;CACN,OAAO;CACP,YAAY;CACZ,cAAc;AAChB;AAiCA,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;AAaA,MAAM,aAAuB;CAC3B,GAAG;CACH,GAAG;CACH,MAAM;CACN,eAAe;CACf,OAAO;CACP,qBAAqB;CACrB,8BAA8B;CAC9B,kCAAkC;AACpC;AAcA,MAAM,aAAuB;CAC3B,GAAG;CACH,MAAM;CACN,eAAe;CACf,SAAS;CACT,UAAU;CACV,SAAS;AACX;AASA,MAAM,kBAAkB,OAAiB,MAAgB,MAAM,OAC7D,KAAK,KAAK,MAAM,MAAM,GAAG,MAAM,KAAK,MAAM,MAAM;AAElD,SAAS,SACP,QACA,QACA,YACA,mBACA,aACA;CACA,QAAQ,UAA4B;EAClC,MAAM,YAAY,OAAO,KAAK,QAAA,GAAOA,uBAAAA,IAAAA,CAAM,EAAE,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AEhB,MAAM,aAAa,aAAa,KAAK,EAAE,IAAI;CAC3C,OAAO;EACL,MAAM;EACN,OAAO;EACP,gBAAA,GAAeD,cAAAA,UAAAA,CAAU,IAAI,IAAI;EACjC;EACA,eAAA,GAAcG,oBAAAA,SAAAA,CAAS,UAAU;EACjC,SAAS,aAAa,EAAE;EACxB,UAAU,cAAc,EAAE;EAC1B,SAAS,aAAa,EAAE;CAC1B;AACF;;;;;;;;;;;AAYA,SAAgB,2BACd,KACe;CACf,IAAI,OAAO,QAAQ,UACjB,QAAA,GAAOC,cAAAA,gBAAAA,CAAgB,KAAK,GAAG;MAC1B,IAAI,OAAO,QAAQ,YAAY,YAAY,KAAK,GAAG,GACxD,QAAA,GAAOA,cAAAA,gBAAAA,CAAgB,MAAA,GAAKC,oBAAAA,SAAAA,CAAS,GAAG,CAAC;CAE3C,OAAO;AACT;;AAGA,IAAA,cAAe;CAAE;CAAU;CAA4B;AAAS"}
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { transpose, transposeFifths } from "@tonaljs/note";
1
+ import { simplify, transpose, transposeFifths } from "@tonaljs/note";
2
2
  import { accToAlt, altToAcc, note } from "@tonaljs/pitch-note";
3
3
  import { get } from "@tonaljs/roman-numeral";
4
4
  // index.ts
@@ -51,11 +51,7 @@ function keyScale(grades, triads, chordTypes, harmonicFunctions, chordScales) {
51
51
  const chords = mapScaleToType(scale, chordTypes);
52
52
  const secondaryDominants = scale.map((note) => transpose(note, "5P")).map((note) => scale.includes(note) && !chords.includes(note + "7") ? note + "7" : "");
53
53
  const secondaryDominantSupertonics = supertonics(secondaryDominants, triads);
54
- const substituteDominants = secondaryDominants.map((chord) => {
55
- if (!chord) return "";
56
- const domRoot = chord.slice(0, -1);
57
- return transpose(domRoot, "5d") + "7";
58
- });
54
+ const substituteDominants = secondaryDominants.map((chord) => chord ? substituteRoot(chord.slice(0, -1)) + "7" : "");
59
55
  const substituteDominantSupertonics = substituteSupertonics(substituteDominants);
60
56
  return {
61
57
  tonic,
@@ -75,6 +71,10 @@ function keyScale(grades, triads, chordTypes, harmonicFunctions, chordScales) {
75
71
  };
76
72
  };
77
73
  }
74
+ function substituteRoot(dominantRoot) {
75
+ const root = transpose(dominantRoot, "5d");
76
+ return note(root).acc.length > 1 ? simplify(root) : root;
77
+ }
78
78
  const supertonicRoot = (dominant) => transpose(dominant.slice(0, -1), "5P");
79
79
  const supertonics = (dominants, targetTriads) => dominants.map((chord, index) => {
80
80
  if (!chord) return "";
@@ -90,11 +90,18 @@ const distInFifths = (from, to) => {
90
90
  };
91
91
  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(","));
92
92
  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(","));
93
- 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(","));
93
+ 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,dorian #4,phrygian dominant,lydian #9,ultralocrian".split(","));
94
94
  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(","));
95
95
  /**
96
- * Get a major key properties in a given tonic
97
- * @param tonic
96
+ * Get a major key: its signature, scale, triads, seventh chords, harmonic
97
+ * functions and secondary and substitute dominants. For an invalid tonic
98
+ * it returns a key with empty strings and arrays.
99
+ *
100
+ * @param tonic - the tonic note or pitch class, like "F" or "Bb"
101
+ * @example
102
+ * Key.majorKey("F").scale; // => ["F", "G", "A", "Bb", "C", "D", "E"]
103
+ * Key.majorKey("F").chords; // => ["Fmaj7", "Gm7", "Am7", "Bbmaj7", "C7", "Dm7", "Em7b5"]
104
+ * Key.majorKey("F").keySignature; // => "b"
98
105
  */
99
106
  function majorKey(tonic) {
100
107
  const pc = note(tonic).pc;
@@ -110,9 +117,15 @@ function majorKey(tonic) {
110
117
  };
111
118
  }
112
119
  /**
113
- * Get a list of available chords for a given major key
114
- * @param tonic
120
+ * Get the chords available in a major key, each with the roles it plays:
121
+ * diatonic chords ("T", "SD", "D") and secondary and substitute dominants
122
+ * with their supertonics ("V/II", "ii/V", "subV/II"...). Returns an empty
123
+ * array for an invalid tonic.
124
+ *
125
+ * @param tonic - the tonic note or pitch class, like "C"
115
126
  * @returns array of { name: string, roles: string[] }
127
+ * @example
128
+ * Key.majorKeyChords("C").slice(0, 3); // => [{ name: "Cmaj7", roles: ["T"] }, { name: "Dm7", roles: ["SD"] }, { name: "Em7", roles: ["T"] }]
116
129
  */
117
130
  function majorKeyChords(tonic) {
118
131
  const key = majorKey(tonic);
@@ -121,9 +134,15 @@ function majorKeyChords(tonic) {
121
134
  return chords;
122
135
  }
123
136
  /**
124
- * Get a list of available chords for a given major key
125
- * @param tonic
137
+ * Get the chords available in a minor key, each with the roles it plays. It
138
+ * merges the chords of the natural, harmonic and melodic scales, so a chord
139
+ * that appears in several scales has all its roles. Returns an empty array
140
+ * for an invalid tonic.
141
+ *
142
+ * @param tonic - the tonic note or pitch class, like "A"
126
143
  * @returns array of { name: string, roles: string[] }
144
+ * @example
145
+ * Key.minorKeyChords("A").slice(0, 2); // => [{ name: "Am7", roles: ["T", "ii/bVII"] }, { name: "Bm7b5", roles: ["SD", "ii/I"] }]
127
146
  */
128
147
  function minorKeyChords(tonic) {
129
148
  const key = minorKey(tonic);
@@ -153,8 +172,15 @@ function keyChordsOf(key, chords) {
153
172
  key.substituteDominantSupertonics.forEach((chordName, index) => updateChord(chordName, `subii/${key.grades[index]}`));
154
173
  }
155
174
  /**
156
- * Get minor key properties in a given tonic
157
- * @param tonic
175
+ * Get a minor key: its signature, relative major and the scale, chords and
176
+ * dominants of its natural, harmonic and melodic forms. For an invalid tonic
177
+ * it returns a key with empty strings and arrays.
178
+ *
179
+ * @param tnc - the tonic note or pitch class, like "A"
180
+ * @example
181
+ * Key.minorKey("A").relativeMajor; // => "C"
182
+ * Key.minorKey("A").harmonic.scale; // => ["A", "B", "C", "D", "E", "F", "G#"]
183
+ * Key.minorKey("A").natural.chords; // => ["Am7", "Bm7b5", "Cmaj7", "Dm7", "Em7", "Fmaj7", "G7"]
158
184
  */
159
185
  function minorKey(tnc) {
160
186
  const pc = note(tnc).pc;
@@ -172,18 +198,21 @@ function minorKey(tnc) {
172
198
  };
173
199
  }
174
200
  /**
175
- * Given a key signature, returns the tonic of the major key
176
- * @param signature
201
+ * Get the tonic of the major key with the given key signature, or null if
202
+ * the signature is not valid.
203
+ *
204
+ * @param sig - accidentals ("", "bb", "###") or a number of fifths (positive for sharps, negative for flats)
177
205
  * @example
178
- * majorTonicFromKeySignature('###') // => 'A'
179
- * majorTonicFromKeySignature('') // => 'C'
206
+ * Key.majorTonicFromKeySignature("###"); // => "A"
207
+ * Key.majorTonicFromKeySignature(-2); // => "Bb"
208
+ * Key.majorTonicFromKeySignature(""); // => "C"
180
209
  */
181
210
  function majorTonicFromKeySignature(sig) {
182
211
  if (typeof sig === "number") return transposeFifths("C", sig);
183
212
  else if (typeof sig === "string" && /^(b*|#*)$/.test(sig)) return transposeFifths("C", accToAlt(sig));
184
213
  return null;
185
214
  }
186
- /** @deprecated */
215
+ /** @deprecated Use the named exports instead. */
187
216
  var key_default = {
188
217
  majorKey,
189
218
  majorTonicFromKeySignature,
@@ -1 +1 @@
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 secondaryDominantSupertonics */\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 substituteDominantSupertonics */\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 =\n substituteSupertonics(substituteDominants);\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 aliases\n secondaryDominantsMinorRelative: secondaryDominantSupertonics,\n substituteDominantsMinorRelative: substituteDominantSupertonics,\n };\n };\n}\n\n// The root of the ii chord of a dominant: a fifth above its root\nconst supertonicRoot = (dominant: string) =>\n transpose(dominant.slice(0, -1), \"5P\");\n\n// The ii of a secondary dominant takes its quality from the target: a ii-V\n// into a minor or diminished chord uses a half-diminished ii (Em7b5 A7 Dm),\n// and into a major or augmented chord a minor seventh ii (Gm7 C7 F)\nconst supertonics = (dominants: string[], targetTriads: string[]) =>\n dominants.map((chord, index) => {\n if (!chord) return \"\";\n const target = targetTriads[index];\n const isMinor = target === \"m\" || target === \"dim\";\n return supertonicRoot(chord) + (isMinor ? \"m7b5\" : \"m7\");\n });\n\n// A substitute dominant doesn't resolve to the key it points to (Eb7 resolves\n// to Dm, not Ab), so its ii is always a minor seventh: Bbm7 Eb7 Dm\nconst substituteSupertonics = (dominants: string[]) =>\n dominants.map((chord) => (chord ? supertonicRoot(chord) + \"m7\" : \"\"));\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 * majorTonicFromKeySignature('') // => 'C'\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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;CACrB,IAAI,CAAC,IAAI,OAAO;CAEhB,MAAM,aAAa,aAAa,KAAK,EAAE,IAAI;CAC3C,OAAO;EACL,MAAM;EACN,OAAO;EACP,eAAe,UAAU,IAAI,IAAI;EACjC;EACA,cAAc,SAAS,UAAU;EACjC,SAAS,aAAa,EAAE;EACxB,UAAU,cAAc,EAAE;EAC1B,SAAS,aAAa,EAAE;CAC1B;AACF;;;;;;;;AASA,SAAgB,2BACd,KACe;CACf,IAAI,OAAO,QAAQ,UACjB,OAAO,gBAAgB,KAAK,GAAG;MAC1B,IAAI,OAAO,QAAQ,YAAY,YAAY,KAAK,GAAG,GACxD,OAAO,gBAAgB,KAAK,SAAS,GAAG,CAAC;CAE3C,OAAO;AACT;;AAGA,IAAA,cAAe;CAAE;CAAU;CAA4B;AAAS"}
1
+ {"version":3,"file":"index.mjs","names":["roman"],"sources":["../index.ts"],"sourcesContent":["import { simplify, 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 /** The tonic pitch class, like \"F\". Empty for an invalid key. */\n readonly tonic: string;\n /** Number of accidentals in the key signature: positive for sharps, negative for flats. */\n readonly alteration: number;\n /** The key signature as accidentals: \"\" (none), \"bb\" (two flats), \"###\" (three sharps). */\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 /** Roman numeral of each degree, like [\"I\", \"II\", \"bIII\", ...]. */\n readonly grades: readonly string[];\n /** Interval from the tonic to each degree, like [\"1P\", \"2M\", \"3M\", ...]. */\n readonly intervals: readonly string[];\n /** Notes of the scale, one per degree. */\n readonly scale: readonly string[];\n /** Triad of each degree, like [\"F\", \"Gm\", \"Am\", ...]. */\n readonly triads: readonly string[];\n /** Seventh chord of each degree, like [\"Fmaj7\", \"Gm7\", ...]. */\n readonly chords: readonly string[];\n /** Harmonic function of each chord: \"T\" (tonic), \"SD\" (subdominant) or \"D\" (dominant). Empty string if none. */\n readonly chordsHarmonicFunction: readonly string[];\n /** Scale that fits each chord, like [\"F major\", \"G dorian\", ...]. */\n readonly chordScales: readonly string[];\n /** Dominant seventh chord that resolves to each degree (\"\" if the degree has none), like [\"\", \"D7\", \"E7\", ...] for F major. */\n readonly secondaryDominants: readonly string[];\n /** The ii chord that precedes each secondary dominant (\"\" if none): a minor seventh, or a half-diminished chord when the target is minor. */\n readonly secondaryDominantSupertonics: readonly string[];\n /** Tritone substitution of each secondary dominant (\"\" if none): the dominant seventh a tritone away, spelled a diminished fifth above it (Gb7 for C7) unless that needs a double flat or sharp (A7, not Bbb7, for Eb7). */\n readonly substituteDominants: readonly string[];\n /** The minor seventh ii chord that precedes each substitute dominant (\"\" if none). */\n readonly substituteDominantSupertonics: readonly string[];\n\n /** @deprecated use secondaryDominantSupertonics */\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 /** Tonic of the relative minor key, like \"D\" for \"F\". */\n readonly minorRelative: string;\n readonly scale: readonly string[];\n readonly substituteDominants: readonly string[];\n readonly secondaryDominantSupertonics: readonly string[];\n /** @deprecated use substituteDominantSupertonics */\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 /** Tonic of the relative major key, like \"C\" for \"A\". */\n readonly relativeMajor: string;\n /** Natural minor (aeolian) scale and its chords. */\n readonly natural: KeyScale;\n /** Harmonic minor scale and its chords. */\n readonly harmonic: KeyScale;\n /** Melodic minor (ascending) scale and its chords. */\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 /** Chord symbol, like \"Dm7\". */\n name: string;\n /** Functions the chord plays in the key: \"T\", \"SD\", \"D\", or \"V/II\", \"ii/V\", \"subV/II\", \"subii/II\" for secondary and substitute dominants. */\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 chord ? substituteRoot(chord.slice(0, -1)) + \"7\" : \"\",\n );\n const substituteDominantSupertonics =\n substituteSupertonics(substituteDominants);\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 aliases\n secondaryDominantsMinorRelative: secondaryDominantSupertonics,\n substituteDominantsMinorRelative: substituteDominantSupertonics,\n };\n };\n}\n\n// The root of a substitute dominant: a diminished fifth above the dominant's\n// root (Gb for C), or its simplest enharmonic when that has a double\n// accidental, as a lead sheet writes it (A, not Bbb, for Eb)\nfunction substituteRoot(dominantRoot: string) {\n const root = transpose(dominantRoot, \"5d\");\n return note(root).acc.length > 1 ? simplify(root) : root;\n}\n\n// The root of the ii chord of a dominant: a fifth above its root\nconst supertonicRoot = (dominant: string) =>\n transpose(dominant.slice(0, -1), \"5P\");\n\n// The ii of a secondary dominant takes its quality from the target: a ii-V\n// into a minor or diminished chord uses a half-diminished ii (Em7b5 A7 Dm),\n// and into a major or augmented chord a minor seventh ii (Gm7 C7 F)\nconst supertonics = (dominants: string[], targetTriads: string[]) =>\n dominants.map((chord, index) => {\n if (!chord) return \"\";\n const target = targetTriads[index];\n const isMinor = target === \"m\" || target === \"dim\";\n return supertonicRoot(chord) + (isMinor ? \"m7b5\" : \"m7\");\n });\n\n// A substitute dominant doesn't resolve to the key it points to (Eb7 resolves\n// to Dm, not Ab), so its ii is always a minor seventh: Bbm7 Eb7 Dm\nconst substituteSupertonics = (dominants: string[]) =>\n dominants.map((chord) => (chord ? supertonicRoot(chord) + \"m7\" : \"\"));\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,dorian #4,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: its signature, scale, triads, seventh chords, harmonic\n * functions and secondary and substitute dominants. For an invalid tonic\n * it returns a key with empty strings and arrays.\n *\n * @param tonic - the tonic note or pitch class, like \"F\" or \"Bb\"\n * @example\n * Key.majorKey(\"F\").scale; // => [\"F\", \"G\", \"A\", \"Bb\", \"C\", \"D\", \"E\"]\n * Key.majorKey(\"F\").chords; // => [\"Fmaj7\", \"Gm7\", \"Am7\", \"Bbmaj7\", \"C7\", \"Dm7\", \"Em7b5\"]\n * Key.majorKey(\"F\").keySignature; // => \"b\"\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 the chords available in a major key, each with the roles it plays:\n * diatonic chords (\"T\", \"SD\", \"D\") and secondary and substitute dominants\n * with their supertonics (\"V/II\", \"ii/V\", \"subV/II\"...). Returns an empty\n * array for an invalid tonic.\n *\n * @param tonic - the tonic note or pitch class, like \"C\"\n * @returns array of { name: string, roles: string[] }\n * @example\n * Key.majorKeyChords(\"C\").slice(0, 3); // => [{ name: \"Cmaj7\", roles: [\"T\"] }, { name: \"Dm7\", roles: [\"SD\"] }, { name: \"Em7\", roles: [\"T\"] }]\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 the chords available in a minor key, each with the roles it plays. It\n * merges the chords of the natural, harmonic and melodic scales, so a chord\n * that appears in several scales has all its roles. Returns an empty array\n * for an invalid tonic.\n *\n * @param tonic - the tonic note or pitch class, like \"A\"\n * @returns array of { name: string, roles: string[] }\n * @example\n * Key.minorKeyChords(\"A\").slice(0, 2); // => [{ name: \"Am7\", roles: [\"T\", \"ii/bVII\"] }, { name: \"Bm7b5\", roles: [\"SD\", \"ii/I\"] }]\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 a minor key: its signature, relative major and the scale, chords and\n * dominants of its natural, harmonic and melodic forms. For an invalid tonic\n * it returns a key with empty strings and arrays.\n *\n * @param tnc - the tonic note or pitch class, like \"A\"\n * @example\n * Key.minorKey(\"A\").relativeMajor; // => \"C\"\n * Key.minorKey(\"A\").harmonic.scale; // => [\"A\", \"B\", \"C\", \"D\", \"E\", \"F\", \"G#\"]\n * Key.minorKey(\"A\").natural.chords; // => [\"Am7\", \"Bm7b5\", \"Cmaj7\", \"Dm7\", \"Em7\", \"Fmaj7\", \"G7\"]\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 * Get the tonic of the major key with the given key signature, or null if\n * the signature is not valid.\n *\n * @param sig - accidentals (\"\", \"bb\", \"###\") or a number of fifths (positive for sharps, negative for flats)\n * @example\n * Key.majorTonicFromKeySignature(\"###\"); // => \"A\"\n * Key.majorTonicFromKeySignature(-2); // => \"Bb\"\n * Key.majorTonicFromKeySignature(\"\"); // => \"C\"\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 Use the named exports instead. */\nexport default { majorKey, majorTonicFromKeySignature, minorKey };\n"],"mappings":";;;;AAIA,MAAM,QAA2B,OAAO,OAAO,CAAC,CAAa;AAY7D,MAAM,QAAa;CACjB,MAAM;CACN,OAAO;CACP,YAAY;CACZ,cAAc;AAChB;AAiCA,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;AAaA,MAAM,aAAuB;CAC3B,GAAG;CACH,GAAG;CACH,MAAM;CACN,eAAe;CACf,OAAO;CACP,qBAAqB;CACrB,8BAA8B;CAC9B,kCAAkC;AACpC;AAcA,MAAM,aAAuB;CAC3B,GAAG;CACH,MAAM;CACN,eAAe;CACf,SAAS;CACT,UAAU;CACV,SAAS;AACX;AASA,MAAM,kBAAkB,OAAiB,MAAgB,MAAM,OAC7D,KAAK,KAAK,MAAM,MAAM,GAAG,MAAM,KAAK,MAAM,MAAM;AAElD,SAAS,SACP,QACA,QACA,YACA,mBACA,aACA;CACA,QAAQ,UAA4B;EAClC,MAAM,YAAY,OAAO,KAAK,OAAOA,IAAM,EAAE,CAAC,CAAC,YAAY,EAAE;EAC7D,MAAM,QAAQ,UAAU,KAAK,aAAa,UAAU,OAAO,QAAQ,CAAC;EACpE,MAAM,SAAS,eAAe,OAAO,UAAU;EAC/C,MAAM,qBAAqB,MACxB,KAAK,SAAS,UAAU,MAAM,IAAI,CAAC,CAAC,CACpC,KAAK,SAIJ,MAAM,SAAS,IAAI,KAAK,CAAC,OAAO,SAAS,OAAO,GAAG,IAAI,OAAO,MAAM,EACtE;EAEF,MAAM,+BAA+B,YACnC,oBACA,MACF;EACA,MAAM,sBAAsB,mBAAmB,KAAK,UAClD,QAAQ,eAAe,MAAM,MAAM,GAAG,EAA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O,GAC7C,SAAS,MAAM,KAAK,OAAO;CAE/B;CAEA,IAAI,OAAO,SAAS,WAAW,UAC7B,YAAY,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;;;;;;;;;;;;AAaA,SAAgB,SAAS,KAAuB;CAC9C,MAAM,KAAK,KAAK,GAAG,CAAC,CAAC;CACrB,IAAI,CAAC,IAAI,OAAO;CAEhB,MAAM,aAAa,aAAa,KAAK,EAAE,IAAI;CAC3C,OAAO;EACL,MAAM;EACN,OAAO;EACP,eAAe,UAAU,IAAI,IAAI;EACjC;EACA,cAAc,SAAS,UAAU;EACjC,SAAS,aAAa,EAAE;EACxB,UAAU,cAAc,EAAE;EAC1B,SAAS,aAAa,EAAE;CAC1B;AACF;;;;;;;;;;;AAYA,SAAgB,2BACd,KACe;CACf,IAAI,OAAO,QAAQ,UACjB,OAAO,gBAAgB,KAAK,GAAG;MAC1B,IAAI,OAAO,QAAQ,YAAY,YAAY,KAAK,GAAG,GACxD,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.7",
3
+ "version": "4.12.0",
4
4
  "description": "Functions to work with musical keys",
5
5
  "keywords": [
6
6
  "key",
@@ -16,12 +16,12 @@
16
16
  "types": "dist/index.d.ts",
17
17
  "dependencies": {
18
18
  "@tonaljs/pitch-note": "6.1.3",
19
- "@tonaljs/note": "4.12.6",
19
+ "@tonaljs/note": "4.12.7",
20
20
  "@tonaljs/roman-numeral": "4.10.1"
21
21
  },
22
22
  "devDependencies": {
23
- "@tonaljs/chord": "6.3.1",
24
- "@tonaljs/scale": "4.14.1"
23
+ "@tonaljs/chord": "6.5.0",
24
+ "@tonaljs/scale": "4.15.1"
25
25
  },
26
26
  "author": "danigb@gmail.com",
27
27
  "license": "MIT",