@libraz/libcantus 0.9.5 → 1.0.1

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.
Files changed (185) hide show
  1. package/README.md +61 -270
  2. package/README_ja.md +61 -214
  3. package/dist/analyze/index.cjs +54 -7
  4. package/dist/analyze/index.cjs.map +1 -1
  5. package/dist/analyze/index.d.cts +200 -353
  6. package/dist/analyze/index.d.ts +200 -353
  7. package/dist/analyze/index.js +56 -9
  8. package/dist/chunk-2LCPM3EG.js +3224 -0
  9. package/dist/chunk-2LCPM3EG.js.map +1 -0
  10. package/dist/chunk-6XH6QZYQ.cjs +7647 -0
  11. package/dist/chunk-6XH6QZYQ.cjs.map +1 -0
  12. package/dist/chunk-6XPTBE7Y.cjs +49 -0
  13. package/dist/chunk-6XPTBE7Y.cjs.map +1 -0
  14. package/dist/chunk-AFM2ULJH.cjs +5121 -0
  15. package/dist/chunk-AFM2ULJH.cjs.map +1 -0
  16. package/dist/chunk-B6XNKWZV.cjs +3224 -0
  17. package/dist/chunk-B6XNKWZV.cjs.map +1 -0
  18. package/dist/chunk-E3F4AHAH.cjs +690 -0
  19. package/dist/chunk-E3F4AHAH.cjs.map +1 -0
  20. package/dist/{chunk-2PTFGVD7.js → chunk-ELCTZUJJ.js} +250 -132
  21. package/dist/chunk-ELCTZUJJ.js.map +1 -0
  22. package/dist/chunk-FVSI36UV.js +690 -0
  23. package/dist/chunk-FVSI36UV.js.map +1 -0
  24. package/dist/chunk-GEDTJHAC.cjs +1 -0
  25. package/dist/chunk-GEDTJHAC.cjs.map +1 -0
  26. package/dist/chunk-H3VORETI.js +2243 -0
  27. package/dist/chunk-H3VORETI.js.map +1 -0
  28. package/dist/chunk-H42UHPYW.js +1577 -0
  29. package/dist/chunk-H42UHPYW.js.map +1 -0
  30. package/dist/chunk-HFPS7JFD.js +1 -0
  31. package/dist/chunk-INHVXP6Z.js +3053 -0
  32. package/dist/chunk-INHVXP6Z.js.map +1 -0
  33. package/dist/chunk-K4ZJUGF4.cjs +379 -0
  34. package/dist/chunk-K4ZJUGF4.cjs.map +1 -0
  35. package/dist/chunk-KNJEKLKV.js +49 -0
  36. package/dist/chunk-KNJEKLKV.js.map +1 -0
  37. package/dist/chunk-MXO72PLY.cjs +211 -0
  38. package/dist/chunk-MXO72PLY.cjs.map +1 -0
  39. package/dist/chunk-NLEU4QSE.cjs +360 -0
  40. package/dist/chunk-NLEU4QSE.cjs.map +1 -0
  41. package/dist/chunk-OE6WK2Y2.cjs +1577 -0
  42. package/dist/chunk-OE6WK2Y2.cjs.map +1 -0
  43. package/dist/chunk-PKFNUHDY.js +7647 -0
  44. package/dist/chunk-PKFNUHDY.js.map +1 -0
  45. package/dist/chunk-Q2WGKJNN.cjs +1064 -0
  46. package/dist/chunk-Q2WGKJNN.cjs.map +1 -0
  47. package/dist/chunk-QYQQ5J6E.js +1 -0
  48. package/dist/chunk-QYQQ5J6E.js.map +1 -0
  49. package/dist/chunk-RHIJ3S4I.cjs +1 -0
  50. package/dist/chunk-RHIJ3S4I.cjs.map +1 -0
  51. package/dist/chunk-TTCLJX6D.js +211 -0
  52. package/dist/chunk-TTCLJX6D.js.map +1 -0
  53. package/dist/chunk-UADYAYAT.cjs +3053 -0
  54. package/dist/chunk-UADYAYAT.cjs.map +1 -0
  55. package/dist/chunk-VOHZB45S.js +5121 -0
  56. package/dist/chunk-VOHZB45S.js.map +1 -0
  57. package/dist/chunk-VTI6FOLB.js +1064 -0
  58. package/dist/chunk-VTI6FOLB.js.map +1 -0
  59. package/dist/chunk-WWURE4XT.cjs +2243 -0
  60. package/dist/chunk-WWURE4XT.cjs.map +1 -0
  61. package/dist/chunk-YH3BIKHH.js +360 -0
  62. package/dist/chunk-YH3BIKHH.js.map +1 -0
  63. package/dist/core/index.cjs +93 -6
  64. package/dist/core/index.cjs.map +1 -1
  65. package/dist/core/index.d.cts +87 -346
  66. package/dist/core/index.d.ts +87 -346
  67. package/dist/core/index.js +94 -7
  68. package/dist/generate/index.cjs +89 -10
  69. package/dist/generate/index.cjs.map +1 -1
  70. package/dist/generate/index.d.cts +436 -1094
  71. package/dist/generate/index.d.ts +436 -1094
  72. package/dist/generate/index.js +94 -15
  73. package/dist/index-9wcMhG73.d.ts +1095 -0
  74. package/dist/{index-Cfx8xgH0.d.ts → index-B4o55NDr.d.cts} +13 -9
  75. package/dist/index-B9MNZboQ.d.cts +770 -0
  76. package/dist/index-B9MNZboQ.d.ts +770 -0
  77. package/dist/index-BGFW-8P2.d.cts +2307 -0
  78. package/dist/index-BO6xE9YU.d.cts +1804 -0
  79. package/dist/index-BkGmlyI3.d.cts +470 -0
  80. package/dist/index-CCNJRG-P.d.cts +1095 -0
  81. package/dist/index-CGpRv5sl.d.cts +643 -0
  82. package/dist/index-C_8o--VE.d.cts +1242 -0
  83. package/dist/index-CgHqxdps.d.ts +2307 -0
  84. package/dist/index-Chbst3Jx.d.ts +1343 -0
  85. package/dist/index-Cj49F892.d.ts +470 -0
  86. package/dist/{index-x2vcsduE.d.cts → index-CunYKLiu.d.ts} +13 -9
  87. package/dist/index-D57QRbVn.d.ts +1804 -0
  88. package/dist/index-DInQqT8Q.d.cts +66 -0
  89. package/dist/index-DInQqT8Q.d.ts +66 -0
  90. package/dist/index-Dzr13q3d.d.cts +1343 -0
  91. package/dist/index-G1uwGGWQ.d.ts +643 -0
  92. package/dist/index-szBv3496.d.ts +1242 -0
  93. package/dist/index.cjs +348 -15
  94. package/dist/index.cjs.map +1 -1
  95. package/dist/index.d.cts +17 -15
  96. package/dist/index.d.ts +17 -15
  97. package/dist/index.js +397 -64
  98. package/dist/masks-DYbE485J.d.cts +445 -0
  99. package/dist/masks-DYbE485J.d.ts +445 -0
  100. package/dist/model/index.cjs +39 -7
  101. package/dist/model/index.cjs.map +1 -1
  102. package/dist/model/index.d.cts +4659 -249
  103. package/dist/model/index.d.ts +4659 -249
  104. package/dist/model/index.js +40 -8
  105. package/dist/positional-Cptlj-xs.d.ts +287 -0
  106. package/dist/positional-DvH_sd8u.d.cts +287 -0
  107. package/dist/theory/index.cjs +101 -7
  108. package/dist/theory/index.cjs.map +1 -1
  109. package/dist/theory/index.d.cts +511 -171
  110. package/dist/theory/index.d.ts +511 -171
  111. package/dist/theory/index.js +118 -24
  112. package/package.json +6 -4
  113. package/dist/chunk-2A2QMA74.cjs +0 -261
  114. package/dist/chunk-2A2QMA74.cjs.map +0 -1
  115. package/dist/chunk-2PTFGVD7.js.map +0 -1
  116. package/dist/chunk-357ZDPVU.cjs +0 -162
  117. package/dist/chunk-357ZDPVU.cjs.map +0 -1
  118. package/dist/chunk-3KX76RLG.js +0 -1548
  119. package/dist/chunk-3KX76RLG.js.map +0 -1
  120. package/dist/chunk-4VZ5MZAM.cjs +0 -889
  121. package/dist/chunk-4VZ5MZAM.cjs.map +0 -1
  122. package/dist/chunk-7EONYVI5.js +0 -1204
  123. package/dist/chunk-7EONYVI5.js.map +0 -1
  124. package/dist/chunk-7JEP3MFY.js +0 -162
  125. package/dist/chunk-7JEP3MFY.js.map +0 -1
  126. package/dist/chunk-AID75RN3.js +0 -3176
  127. package/dist/chunk-AID75RN3.js.map +0 -1
  128. package/dist/chunk-BSLTLGM3.cjs +0 -497
  129. package/dist/chunk-BSLTLGM3.cjs.map +0 -1
  130. package/dist/chunk-CU6VG2YM.cjs +0 -109
  131. package/dist/chunk-CU6VG2YM.cjs.map +0 -1
  132. package/dist/chunk-DZMHIGI4.js +0 -337
  133. package/dist/chunk-DZMHIGI4.js.map +0 -1
  134. package/dist/chunk-EDOTEABK.js +0 -109
  135. package/dist/chunk-EDOTEABK.js.map +0 -1
  136. package/dist/chunk-HN2OEUN2.js +0 -33
  137. package/dist/chunk-HN2OEUN2.js.map +0 -1
  138. package/dist/chunk-KBTTEX7Q.js +0 -497
  139. package/dist/chunk-KBTTEX7Q.js.map +0 -1
  140. package/dist/chunk-KQN2ZYND.cjs +0 -724
  141. package/dist/chunk-KQN2ZYND.cjs.map +0 -1
  142. package/dist/chunk-MPTVJIVG.cjs +0 -3176
  143. package/dist/chunk-MPTVJIVG.cjs.map +0 -1
  144. package/dist/chunk-MTMZTMWM.cjs +0 -53
  145. package/dist/chunk-MTMZTMWM.cjs.map +0 -1
  146. package/dist/chunk-N6IHQUOX.js +0 -1
  147. package/dist/chunk-NNB67XA2.js +0 -724
  148. package/dist/chunk-NNB67XA2.js.map +0 -1
  149. package/dist/chunk-OL3IHHSJ.cjs +0 -1204
  150. package/dist/chunk-OL3IHHSJ.cjs.map +0 -1
  151. package/dist/chunk-PI3UXRWK.cjs +0 -528
  152. package/dist/chunk-PI3UXRWK.cjs.map +0 -1
  153. package/dist/chunk-R2VVFAIN.js +0 -528
  154. package/dist/chunk-R2VVFAIN.js.map +0 -1
  155. package/dist/chunk-T64C7ZD7.cjs +0 -1
  156. package/dist/chunk-T64C7ZD7.cjs.map +0 -1
  157. package/dist/chunk-WFDXOLUB.cjs +0 -337
  158. package/dist/chunk-WFDXOLUB.cjs.map +0 -1
  159. package/dist/chunk-WTAN4ACG.cjs +0 -1548
  160. package/dist/chunk-WTAN4ACG.cjs.map +0 -1
  161. package/dist/chunk-YFJXS3AU.cjs +0 -33
  162. package/dist/chunk-YFJXS3AU.cjs.map +0 -1
  163. package/dist/chunk-YUE6TJ4M.js +0 -889
  164. package/dist/chunk-YUE6TJ4M.js.map +0 -1
  165. package/dist/chunk-ZGLJM4A4.js +0 -53
  166. package/dist/chunk-ZGLJM4A4.js.map +0 -1
  167. package/dist/function-CxixTB02.d.cts +0 -299
  168. package/dist/function-DTCt675z.d.ts +0 -299
  169. package/dist/index-B2Ulxxpo.d.cts +0 -144
  170. package/dist/index-BkYJ0xMq.d.cts +0 -152
  171. package/dist/index-BuaB-ypt.d.ts +0 -144
  172. package/dist/index-CAN7v-kw.d.ts +0 -199
  173. package/dist/index-COw1Ky9g.d.ts +0 -242
  174. package/dist/index-DRtIhlJj.d.ts +0 -152
  175. package/dist/index-DXd9JikN.d.cts +0 -246
  176. package/dist/index-DXd9JikN.d.ts +0 -246
  177. package/dist/index-alrRninU.d.cts +0 -199
  178. package/dist/index-oTQbYYIs.d.cts +0 -242
  179. package/dist/index-tR9jTn26.d.cts +0 -275
  180. package/dist/index-tR9jTn26.d.ts +0 -275
  181. package/dist/styled-Bl0ZK28h.d.ts +0 -543
  182. package/dist/styled-Crv6SA4S.d.cts +0 -543
  183. package/dist/types-BN6_Q9Kl.d.cts +0 -39
  184. package/dist/types-BN6_Q9Kl.d.ts +0 -39
  185. /package/dist/{chunk-N6IHQUOX.js.map → chunk-HFPS7JFD.js.map} +0 -0
@@ -1,724 +0,0 @@
1
- import {
2
- HARMONIC_MINOR_MASK,
3
- MAJOR_MASK,
4
- MELODIC_MINOR_MASK,
5
- NATURAL_MINOR_MASK,
6
- chordPitchClasses,
7
- chordQualities,
8
- isScaleTone,
9
- majorKey,
10
- makeChord,
11
- scaleTonesInDegreeOrder
12
- } from "./chunk-KBTTEX7Q.js";
13
- import {
14
- InvalidInputError,
15
- assertFiniteNumber,
16
- assertGenerationBudget,
17
- assertInteger,
18
- assertMidiPitch,
19
- assertNoteEvents,
20
- pitchClassOf
21
- } from "./chunk-R2VVFAIN.js";
22
-
23
- // src/analyze/detect/index.ts
24
- function uniquePitchClasses(pitches) {
25
- return [...new Set(pitches.map(pitchClassOf))].sort((a, b) => a - b);
26
- }
27
- function assertPitches(pitches, name, budget = void 0) {
28
- assertGenerationBudget(pitches.length, name, budget);
29
- for (let index = 0; index < pitches.length; index += 1) {
30
- assertMidiPitch(pitches[index] ?? Number.NaN, `pitches[${index}]`);
31
- }
32
- }
33
- function detectChord(pitches, opts = {}) {
34
- assertPitches(pitches, "chord detection pitches");
35
- if (opts.bassPc !== void 0) assertFiniteNumber(opts.bassPc, "bassPc");
36
- const input = uniquePitchClasses(pitches);
37
- if (input.length === 0) {
38
- return [];
39
- }
40
- const inputKind = opts.input === void 0 || opts.input === "auto" ? pitches.every((pitch) => Number.isInteger(pitch) && pitch >= 0 && pitch <= 11) ? "pitchClass" : "midi" : opts.input;
41
- const bassPc = opts.bassPc !== void 0 ? pitchClassOf(opts.bassPc) : inputKind === "midi" ? pitchClassOf(pitches.reduce((lowest, pitch) => Math.min(lowest, pitch), Infinity)) : void 0;
42
- const inputSet = new Set(input);
43
- const matches = [];
44
- const qualities = chordQualities();
45
- const toneCounts = new Map(
46
- qualities.map((quality) => [quality, chordPitchClasses(makeChord(0, quality)).length])
47
- );
48
- for (const rootPc of input) {
49
- for (const quality of qualities) {
50
- const chord = makeChord(rootPc, quality);
51
- const tones = chordPitchClasses(chord);
52
- const toneSet = new Set(tones);
53
- const missingPcs = tones.filter((pc) => !inputSet.has(pc));
54
- const fifthPc = pitchClassOf(rootPc + 7);
55
- if (missingPcs.length > 1 || missingPcs.length === 1 && missingPcs[0] !== fifthPc) {
56
- continue;
57
- }
58
- const extraPcs = input.filter((pc) => !toneSet.has(pc));
59
- const bassIndex = bassPc === void 0 ? -1 : chord.intervals.findIndex((iv) => pitchClassOf(rootPc + iv) === bassPc);
60
- const inversion = bassPc === void 0 || bassIndex < 0 ? null : bassIndex;
61
- const match = {
62
- rootPc,
63
- quality,
64
- missingPcs,
65
- extraPcs,
66
- exact: extraPcs.length === 0 && missingPcs.length === 0,
67
- inversion
68
- };
69
- if (bassPc !== void 0 && bassPc !== rootPc) {
70
- match.bassPc = bassPc;
71
- }
72
- matches.push(match);
73
- }
74
- }
75
- matches.sort((a, b) => {
76
- if (a.extraPcs.length !== b.extraPcs.length) {
77
- return a.extraPcs.length - b.extraPcs.length;
78
- }
79
- if (a.missingPcs.length !== b.missingPcs.length) {
80
- return a.missingPcs.length - b.missingPcs.length;
81
- }
82
- if (a.inversion === 0 !== (b.inversion === 0)) {
83
- return a.inversion === 0 ? -1 : 1;
84
- }
85
- const aSize = toneCounts.get(a.quality) ?? 0;
86
- const bSize = toneCounts.get(b.quality) ?? 0;
87
- return bSize - aSize;
88
- });
89
- return matches;
90
- }
91
- function detectChordBest(pitches, opts = {}) {
92
- const best = detectChord(pitches, opts)[0];
93
- if (!best) {
94
- return null;
95
- }
96
- return makeChord(best.rootPc, best.quality, best.bassPc);
97
- }
98
- var MINOR_VARIANTS = [
99
- { variant: "natural", mask: NATURAL_MINOR_MASK },
100
- { variant: "harmonic", mask: HARMONIC_MINOR_MASK },
101
- { variant: "melodic", mask: MELODIC_MINOR_MASK }
102
- ];
103
- var MAJOR_VARIANTS = [{ variant: "major", mask: MAJOR_MASK }];
104
- function detectKey(pitches, opts = {}) {
105
- assertPitches(pitches, "key detection pitches", opts.budget);
106
- const weights = opts.weights;
107
- if (weights !== void 0 && weights.length !== pitches.length) {
108
- throw new InvalidInputError("weights must have one entry per pitch");
109
- }
110
- const counts = /* @__PURE__ */ new Map();
111
- let total = 0;
112
- for (let index = 0; index < pitches.length; index += 1) {
113
- const weight = weights === void 0 ? 1 : weights[index] ?? 0;
114
- assertFiniteNumber(weight, `weights[${index}]`);
115
- if (weight <= 0) {
116
- continue;
117
- }
118
- const pc = pitchClassOf(pitches[index] ?? 0);
119
- counts.set(pc, (counts.get(pc) ?? 0) + weight);
120
- total += weight;
121
- }
122
- if (total === 0) {
123
- return [];
124
- }
125
- const input = [...counts.keys()];
126
- const results = [];
127
- for (let tonic = 0; tonic < 12; tonic += 1) {
128
- for (const mode of ["major", "minor"]) {
129
- const variants = mode === "major" ? MAJOR_VARIANTS : MINOR_VARIANTS;
130
- let inScale = 0;
131
- let weighted = Number.NEGATIVE_INFINITY;
132
- let best = variants[0];
133
- for (const candidate of variants) {
134
- let variantInScale = 0;
135
- let variantWeighted = 0;
136
- for (const pc of input) {
137
- const offset = (pc - tonic + 12) % 12;
138
- if (candidate.mask >> offset & 1) {
139
- variantInScale += 1;
140
- }
141
- }
142
- for (const [pc, count] of counts) {
143
- const offset = (pc - tonic + 12) % 12;
144
- if (candidate.mask >> offset & 1) {
145
- variantWeighted += count;
146
- }
147
- }
148
- if (variantWeighted > weighted) {
149
- weighted = variantWeighted;
150
- inScale = variantInScale;
151
- best = candidate;
152
- }
153
- }
154
- weighted += (counts.get(tonic) ?? 0) * 0.5;
155
- results.push({
156
- key: { rootPc: tonic, modeMask12: best.mask },
157
- mode,
158
- variant: best.variant,
159
- fit: inScale / input.length,
160
- score: weighted / total
161
- });
162
- }
163
- }
164
- results.sort((a, b) => b.score - a.score);
165
- return results;
166
- }
167
- var DEFAULT_VELOCITY = 100;
168
- function detectKeyFromNotes(notes, opts = {}) {
169
- assertNoteEvents(notes, "key detection notes", {
170
- allowNonPositiveDuration: true,
171
- budget: opts.budget
172
- });
173
- const sounding = notes.filter((note) => note.durationBeat > 0);
174
- return detectKey(
175
- sounding.map((note) => note.pitch),
176
- {
177
- weights: sounding.map((note) => note.durationBeat * (note.velocity ?? DEFAULT_VELOCITY)),
178
- budget: opts.budget
179
- }
180
- );
181
- }
182
- function detectKeyBest(pitches, opts = {}) {
183
- return detectKey(pitches, opts)[0] ?? null;
184
- }
185
-
186
- // src/analyze/functional/internal.ts
187
- function degreeRootPc(degreeNumber, key) {
188
- const tones = scaleTonesInDegreeOrder(key);
189
- if (tones.length === 0) {
190
- return pitchClassOf(key.rootPc);
191
- }
192
- const index = ((degreeNumber - 1) % tones.length + tones.length) % tones.length;
193
- return tones[index] ?? pitchClassOf(key.rootPc);
194
- }
195
- function loweredDegrees(key) {
196
- const tones = scaleTonesInDegreeOrder(key);
197
- const out = /* @__PURE__ */ new Set();
198
- if (tones.length !== 7) {
199
- return out;
200
- }
201
- const major = scaleTonesInDegreeOrder({ rootPc: pitchClassOf(key.rootPc), modeMask12: MAJOR_MASK });
202
- for (let index = 0; index < 7; index += 1) {
203
- const tone = tones[index];
204
- const majorTone = major[index];
205
- if (tone !== void 0 && majorTone !== void 0 && pitchClassOf(majorTone - tone) === 1) {
206
- out.add(index + 1);
207
- }
208
- }
209
- return out;
210
- }
211
- function romanReference(key) {
212
- return scaleTonesInDegreeOrder(key).length === 7 ? key : majorKey(pitchClassOf(key.rootPc));
213
- }
214
- function isNeapolitan(chord, key) {
215
- return pitchClassOf(chord.rootPc - key.rootPc) === 1 && chord.quality === "maj";
216
- }
217
- function isAppliedDominantSonority(chord) {
218
- const has = (semitones) => chord.intervals.some((i) => pitchClassOf(i) === semitones);
219
- return chord.quality === "maj" || has(4) && has(10);
220
- }
221
-
222
- // src/analyze/functional/roman.ts
223
- var ROMAN = ["I", "II", "III", "IV", "V", "VI", "VII"];
224
- var ROMAN_TO_DEGREE = {
225
- I: 1,
226
- II: 2,
227
- III: 3,
228
- IV: 4,
229
- V: 5,
230
- VI: 6,
231
- VII: 7
232
- };
233
- var OFFSET_SPELLING = [
234
- [1, ""],
235
- [2, "b"],
236
- [2, ""],
237
- [3, "b"],
238
- [3, ""],
239
- [4, ""],
240
- [4, "#"],
241
- [5, ""],
242
- [6, "b"],
243
- [6, ""],
244
- [7, "b"],
245
- [7, ""]
246
- ];
247
- function seventhQuality(base, halfDim) {
248
- if (halfDim) {
249
- return "m7b5";
250
- }
251
- if (base === "dim") {
252
- return "dim7";
253
- }
254
- if (base === "aug") {
255
- return "aug7";
256
- }
257
- return base === "maj" ? "dom7" : "min7";
258
- }
259
- var INVERSION_FIGURES = /* @__PURE__ */ new Set(["6", "64", "65", "43", "42", "2", "7"]);
260
- var ROMAN_STYLE = {
261
- maj: { lower: false, suffix: "" },
262
- min: { lower: true, suffix: "" },
263
- dim: { lower: true, suffix: "o" },
264
- aug: { lower: false, suffix: "+" },
265
- maj7: { lower: false, suffix: "maj7" },
266
- min7: { lower: true, suffix: "7" },
267
- dom7: { lower: false, suffix: "7" },
268
- dim7: { lower: true, suffix: "o7" },
269
- m7b5: { lower: true, suffix: "\xF87" },
270
- minMaj7: { lower: true, suffix: "maj7" },
271
- minMaj9: { lower: true, suffix: "maj9" },
272
- minMaj11: { lower: true, suffix: "maj11" },
273
- minMaj13: { lower: true, suffix: "maj13" },
274
- aug7: { lower: false, suffix: "+7" },
275
- augMaj7: { lower: false, suffix: "+maj7" },
276
- majb5: { lower: false, suffix: "b5" },
277
- "6": { lower: false, suffix: "add6" },
278
- min6: { lower: true, suffix: "add6" },
279
- "6/9": { lower: false, suffix: "69" },
280
- sus2: { lower: false, suffix: "sus2" },
281
- sus4: { lower: false, suffix: "sus4" },
282
- add9: { lower: false, suffix: "add9" },
283
- add11: { lower: false, suffix: "add11" },
284
- maj9: { lower: false, suffix: "maj9" },
285
- min9: { lower: true, suffix: "9" },
286
- dom9: { lower: false, suffix: "9" },
287
- "7b9": { lower: false, suffix: "7b9" },
288
- "7#9": { lower: false, suffix: "7#9" },
289
- "7#11": { lower: false, suffix: "7#11" },
290
- "7b13": { lower: false, suffix: "7b13" },
291
- "11": { lower: false, suffix: "11" },
292
- "13": { lower: false, suffix: "13" },
293
- "5": { lower: false, suffix: "5" },
294
- "7sus4": { lower: false, suffix: "7sus4" },
295
- "7b5": { lower: false, suffix: "7b5" },
296
- "7alt": { lower: false, suffix: "7alt" },
297
- "13b9": { lower: false, suffix: "13b9" },
298
- maj13: { lower: false, suffix: "maj13" },
299
- "maj7#11": { lower: false, suffix: "maj7#11" },
300
- min11: { lower: true, suffix: "11" },
301
- min13: { lower: true, suffix: "13" },
302
- minAdd9: { lower: true, suffix: "add9" },
303
- "min6/9": { lower: true, suffix: "69" }
304
- };
305
- var SUFFIX_QUALITY = new Map(
306
- Object.entries(ROMAN_STYLE).map(
307
- ([quality, style]) => [`${style.lower ? "l" : "u"}:${style.suffix}`, quality]
308
- )
309
- );
310
- function parseInversion(figures) {
311
- if (figures === "65") {
312
- return { inversion: 1, seventh: true };
313
- }
314
- if (figures === "43") {
315
- return { inversion: 2, seventh: true };
316
- }
317
- if (figures === "42" || figures === "2") {
318
- return { inversion: 3, seventh: true };
319
- }
320
- if (figures === "7") {
321
- return { inversion: 0, seventh: true };
322
- }
323
- if (figures === "64") {
324
- return { inversion: 2, seventh: false };
325
- }
326
- if (figures === "6") {
327
- return { inversion: 1, seventh: false };
328
- }
329
- return { inversion: 0, seventh: false };
330
- }
331
- function parseSimpleRoman(text, key) {
332
- const match = /^([b#]?)([iIvV]+)(.*)$/.exec(text.trim());
333
- if (!match) {
334
- throw new InvalidInputError(`Invalid Roman numeral: ${text}`);
335
- }
336
- const glyphText = match[2] ?? "";
337
- if (glyphText !== glyphText.toUpperCase() && glyphText !== glyphText.toLowerCase()) {
338
- throw new InvalidInputError(`Roman numeral must use one case: ${text}`);
339
- }
340
- const accidental = match[1] === "b" ? -1 : match[1] === "#" ? 1 : 0;
341
- const glyph = glyphText.toUpperCase();
342
- const degreeNumber = ROMAN_TO_DEGREE[glyph];
343
- if (degreeNumber === void 0) {
344
- throw new InvalidInputError(`Invalid Roman numeral: ${text}`);
345
- }
346
- const isUpper = glyphText[0] === glyphText[0]?.toUpperCase();
347
- const suffix = match[3] ?? "";
348
- const frame = romanReference(key);
349
- const redundantFlat = accidental === -1 && loweredDegrees(frame).has(degreeNumber);
350
- const diatonicRootPc = pitchClassOf(
351
- degreeRootPc(degreeNumber, frame) + (redundantFlat ? 0 : accidental)
352
- );
353
- const rootForQuality = (quality2) => accidental === 0 && degreeNumber === 7 && loweredDegrees(frame).has(7) && (quality2 === "dim" || quality2 === "dim7") ? pitchClassOf(diatonicRootPc + 1) : diatonicRootPc;
354
- const canonical = SUFFIX_QUALITY.get(`${isUpper ? "u" : "l"}:${suffix}`);
355
- if (canonical !== void 0) {
356
- return { rootPc: rootForQuality(canonical), quality: canonical, inversion: 0 };
357
- }
358
- const parsedSuffix = /^(o|°|dim|ø|\+|aug)?(maj7|M7)?(65|64|43|42|7|6|2)?$/.exec(suffix);
359
- if (!parsedSuffix) {
360
- throw new InvalidInputError(`Unsupported suffix "${suffix}" in Roman numeral: ${text}`);
361
- }
362
- const qualityMarker = parsedSuffix[1] ?? "";
363
- const isDim = qualityMarker === "o" || qualityMarker === "\xB0" || qualityMarker === "dim";
364
- const isAug = qualityMarker === "+" || qualityMarker === "aug";
365
- const isHalfDim = qualityMarker === "\xF8";
366
- const explicitMaj7 = parsedSuffix[2] !== void 0;
367
- const figures = parsedSuffix[3] ?? "";
368
- if (figures !== "" && !INVERSION_FIGURES.has(figures)) {
369
- throw new InvalidInputError(
370
- `Unsupported figured-bass or extension "${figures}" in Roman numeral: ${text}`
371
- );
372
- }
373
- const { inversion, seventh } = parseInversion(figures);
374
- const hasSeventh = explicitMaj7 || seventh || isHalfDim;
375
- let base;
376
- if (isDim || isHalfDim) {
377
- base = "dim";
378
- } else if (isAug) {
379
- base = "aug";
380
- } else {
381
- base = isUpper ? "maj" : "min";
382
- }
383
- let quality;
384
- if (explicitMaj7) {
385
- quality = base === "min" ? "minMaj7" : base === "aug" ? "augMaj7" : "maj7";
386
- } else if (hasSeventh) {
387
- quality = seventhQuality(base, isHalfDim);
388
- } else if (base === "dim") {
389
- quality = "dim";
390
- } else if (base === "aug") {
391
- quality = "aug";
392
- } else {
393
- quality = base;
394
- }
395
- return { rootPc: rootForQuality(quality), quality, inversion };
396
- }
397
- function chordFromParsed(parsed) {
398
- const chord = makeChord(parsed.rootPc, parsed.quality);
399
- if (parsed.inversion > 0 && parsed.inversion < chord.intervals.length) {
400
- chord.bassPc = pitchClassOf(parsed.rootPc + (chord.intervals[parsed.inversion] ?? 0));
401
- }
402
- return chord;
403
- }
404
- function romanToChord(text, key) {
405
- const trimmed = text.trim().replace(/(\d)\/(?=\d)/g, "$1");
406
- const slash = trimmed.indexOf("/");
407
- if (slash >= 0) {
408
- const applied = trimmed.slice(0, slash);
409
- const target = trimmed.slice(slash + 1);
410
- const targetRoot = parseSimpleRoman(target, key).rootPc;
411
- const localKey = majorKey(targetRoot);
412
- return chordFromParsed(parseSimpleRoman(applied, localKey));
413
- }
414
- return chordFromParsed(parseSimpleRoman(trimmed, key));
415
- }
416
- function romanStyle(quality) {
417
- return ROMAN_STYLE[quality];
418
- }
419
- function romanSpelling(rootPc, key) {
420
- const tones = scaleTonesInDegreeOrder(romanReference(key));
421
- const diatonic = tones.indexOf(pitchClassOf(rootPc));
422
- if (diatonic >= 0) {
423
- return { degreeNumber: diatonic + 1, accidental: "" };
424
- }
425
- const lowered = loweredDegrees(romanReference(key));
426
- for (let i = 0; i < tones.length; i += 1) {
427
- if (lowered.has(i + 1) && pitchClassOf((tones[i] ?? 0) + 1) === pitchClassOf(rootPc)) {
428
- return { degreeNumber: i + 1, accidental: "#" };
429
- }
430
- }
431
- for (let i = 0; i < tones.length; i += 1) {
432
- const degreeNumber2 = i + 1;
433
- if (degreeNumber2 === 1 || degreeNumber2 === 5) {
434
- continue;
435
- }
436
- if (pitchClassOf((tones[i] ?? 0) - 1) === pitchClassOf(rootPc)) {
437
- return { degreeNumber: degreeNumber2, accidental: "b" };
438
- }
439
- }
440
- for (let i = 0; i < tones.length; i += 1) {
441
- if (pitchClassOf((tones[i] ?? 0) + 1) === pitchClassOf(rootPc)) {
442
- return { degreeNumber: i + 1, accidental: "#" };
443
- }
444
- }
445
- const [degreeNumber, accidental] = OFFSET_SPELLING[pitchClassOf(rootPc - key.rootPc)] ?? [1, ""];
446
- return { degreeNumber, accidental };
447
- }
448
- function baseMarker(quality) {
449
- if (quality === "dim" || quality === "dim7") {
450
- return "o";
451
- }
452
- if (quality === "m7b5") {
453
- return "\xF8";
454
- }
455
- if (quality === "aug" || quality === "aug7") {
456
- return "+";
457
- }
458
- if (quality === "augMaj7") {
459
- return "+maj7";
460
- }
461
- if (quality === "maj7" || quality === "minMaj7") {
462
- return "maj7";
463
- }
464
- return "";
465
- }
466
- var TRIAD_FIGURES = { 1: "6", 2: "64" };
467
- var SEVENTH_FIGURES = { 1: "65", 2: "43", 3: "42" };
468
- var TRIAD_FIGURE_QUALITIES = /* @__PURE__ */ new Set(["maj", "min", "dim", "aug"]);
469
- var SEVENTH_FIGURE_QUALITIES = /* @__PURE__ */ new Set([
470
- "maj7",
471
- "min7",
472
- "dom7",
473
- "dim7",
474
- "m7b5",
475
- "minMaj7",
476
- "aug7",
477
- "augMaj7"
478
- ]);
479
- function numeralFor(degreeNumber, lower) {
480
- const glyph = ROMAN[degreeNumber - 1];
481
- if (glyph === void 0) {
482
- throw new InvalidInputError(`no Roman numeral for scale degree ${degreeNumber}`);
483
- }
484
- return lower ? glyph.toLowerCase() : glyph;
485
- }
486
- function isDiatonicChord(chord, key) {
487
- return chordPitchClasses(chord).every((pc) => isScaleTone(pc, key));
488
- }
489
- var LEADING_TONE_QUALITIES = /* @__PURE__ */ new Set(["dim", "dim7", "m7b5"]);
490
- function degreeTriad(tones, index) {
491
- const root = tones[index] ?? 0;
492
- return {
493
- third: pitchClassOf((tones[(index + 2) % tones.length] ?? 0) - root),
494
- fifth: pitchClassOf((tones[(index + 4) % tones.length] ?? 0) - root)
495
- };
496
- }
497
- function appliedTarget(chord, key) {
498
- const dominant = isAppliedDominantSonority(chord);
499
- const leadingTone = LEADING_TONE_QUALITIES.has(chord.quality);
500
- if (!dominant && !leadingTone) {
501
- return null;
502
- }
503
- const tones = scaleTonesInDegreeOrder(romanReference(key));
504
- for (let index = 1; index < tones.length; index += 1) {
505
- const targetRoot = tones[index];
506
- if (targetRoot === void 0) {
507
- continue;
508
- }
509
- const triad = degreeTriad(tones, index);
510
- const expectedRoot = pitchClassOf(targetRoot + (dominant ? 7 : -1));
511
- if (expectedRoot === pitchClassOf(chord.rootPc)) {
512
- return { degreeNumber: index + 1, rootPc: targetRoot, lower: triad.third === 3 };
513
- }
514
- }
515
- return null;
516
- }
517
- function chordToRoman(chord, key, opts = {}) {
518
- if (opts.applied === true && !isDiatonicChord(chord, key)) {
519
- const target = appliedTarget(chord, key);
520
- if (target !== null) {
521
- const local = chordToRoman(chord, majorKey(target.rootPc));
522
- return `${local}/${numeralFor(target.degreeNumber, target.lower)}`;
523
- }
524
- }
525
- const { degreeNumber, accidental: spelledAccidental } = romanSpelling(chord.rootPc, key);
526
- const { lower, suffix } = romanStyle(chord.quality);
527
- const cased = numeralFor(degreeNumber, lower);
528
- const accidental = spelledAccidental === "#" && degreeNumber === 7 && loweredDegrees(romanReference(key)).has(7) && (chord.quality === "dim" || chord.quality === "dim7") ? "" : spelledAccidental;
529
- let inversion = 0;
530
- if (chord.bassPc !== void 0) {
531
- const idx = chord.intervals.findIndex((iv) => pitchClassOf(chord.rootPc + iv) === chord.bassPc);
532
- if (idx > 0) {
533
- inversion = idx;
534
- }
535
- }
536
- if (inversion > 0) {
537
- const figure = SEVENTH_FIGURE_QUALITIES.has(chord.quality) ? SEVENTH_FIGURES[inversion] : TRIAD_FIGURE_QUALITIES.has(chord.quality) ? TRIAD_FIGURES[inversion] : void 0;
538
- if (figure !== void 0) {
539
- return `${accidental}${cased}${baseMarker(chord.quality)}${figure}`;
540
- }
541
- }
542
- return `${accidental}${cased}${suffix}`;
543
- }
544
-
545
- // src/analyze/functional/borrowed.ts
546
- function isMinorScaleAlteration(chord, key) {
547
- if (!isMinorKey(key)) return false;
548
- const alteredKey = { rootPc: pitchClassOf(key.rootPc), modeMask12: HARMONIC_MINOR_MASK };
549
- if (isDiatonic(chord, alteredKey)) return true;
550
- return pitchClassOf(chord.rootPc - key.rootPc) === 11 && isDiatonic(chord, { rootPc: pitchClassOf(key.rootPc), modeMask12: MELODIC_MINOR_MASK });
551
- }
552
- function isBorrowedChord(chord, key) {
553
- if (isDiatonic(chord, key)) {
554
- return false;
555
- }
556
- if (isNeapolitan(chord, key)) {
557
- return true;
558
- }
559
- if (isMinorScaleAlteration(chord, key)) {
560
- return false;
561
- }
562
- return isDiatonic(chord, parallelKey(key));
563
- }
564
- function borrowedSource(chord, key) {
565
- if (isDiatonic(chord, key)) {
566
- return null;
567
- }
568
- if (isNeapolitan(chord, key)) return "neapolitan";
569
- if (isBorrowedChord(chord, key)) {
570
- return isMinorKey(key) ? "parallelMajor" : "parallelMinor";
571
- }
572
- return null;
573
- }
574
-
575
- // src/analyze/functional/function.ts
576
- var FUNCTION_BY_OFFSET = [
577
- "tonic",
578
- // 0 I
579
- "subdominant",
580
- // 1 bII (Neapolitan)
581
- "subdominant",
582
- // 2 ii
583
- "tonic",
584
- // 3 bIII
585
- "tonic",
586
- // 4 iii
587
- "subdominant",
588
- // 5 IV
589
- "dominant",
590
- // 6 #IV / bV
591
- "dominant",
592
- // 7 V
593
- "subdominant",
594
- // 8 bVI
595
- "tonic",
596
- // 9 vi
597
- "subdominant",
598
- // 10 bVII
599
- "dominant"
600
- // 11 vii
601
- ];
602
- var MINOR_FUNCTION_BY_OFFSET = [
603
- "tonic",
604
- "subdominant",
605
- "subdominant",
606
- "tonic",
607
- "dominant",
608
- "subdominant",
609
- "dominant",
610
- "dominant",
611
- "tonic",
612
- "tonic",
613
- "subdominant",
614
- "dominant"
615
- ];
616
- function isMinorKey(key) {
617
- const hasMinorThird = key.modeMask12 >> 3 & 1;
618
- const hasMajorThird2 = key.modeMask12 >> 4 & 1;
619
- return Boolean(hasMinorThird) && !hasMajorThird2;
620
- }
621
- function functionOf(chord, key) {
622
- const offset = pitchClassOf(chord.rootPc - key.rootPc);
623
- if (isNeapolitan(chord, key)) {
624
- return "subdominant";
625
- }
626
- if (isAppliedDominant(chord, key)) {
627
- return "dominant";
628
- }
629
- if (!isMinorKey(key) && hasMajorThird(chord) && (offset === 8 || offset === 10)) {
630
- return "subdominant";
631
- }
632
- const functions = isMinorKey(key) ? MINOR_FUNCTION_BY_OFFSET : FUNCTION_BY_OFFSET;
633
- return functions[offset] ?? "tonic";
634
- }
635
- function isAppliedDominant(chord, key) {
636
- if (isDiatonic(chord, key)) {
637
- return false;
638
- }
639
- const root = pitchClassOf(chord.rootPc);
640
- const resolvesTo = (step) => isScaleTone(pitchClassOf(root + step), key);
641
- if (isAppliedDominantSonority(chord)) {
642
- return chord.quality === "maj" ? resolvesTo(5) : resolvesTo(5) || resolvesTo(11);
643
- }
644
- return isDiminishedQuality(chord.quality) && resolvesTo(1);
645
- }
646
- function isDiatonic(chord, key) {
647
- return chordPitchClasses(chord).every((pc) => isScaleTone(pc, key));
648
- }
649
- function parallelKey(key) {
650
- return {
651
- rootPc: pitchClassOf(key.rootPc),
652
- modeMask12: isMinorKey(key) ? MAJOR_MASK : NATURAL_MINOR_MASK
653
- };
654
- }
655
- function isDiminishedQuality(quality) {
656
- return quality === "dim" || quality === "dim7" || quality === "m7b5";
657
- }
658
- function hasMajorThird(chord) {
659
- return chord.intervals.some((interval) => pitchClassOf(interval) === 4);
660
- }
661
- function analyzeChord(chord, key, opts = {}) {
662
- const source = borrowedSource(chord, key);
663
- return {
664
- function: functionOf(chord, key),
665
- borrowed: source !== null,
666
- source,
667
- roman: chordToRoman(chord, key, opts)
668
- };
669
- }
670
- function secondaryDominant(targetDegree, key) {
671
- const degreeCount = scaleTonesInDegreeOrder(key).length;
672
- assertInteger(targetDegree, "targetDegree", 0, degreeCount - 1);
673
- const targetRoot = degreeRootPc(targetDegree + 1, key);
674
- return makeChord(pitchClassOf(targetRoot + 7), "dom7");
675
- }
676
-
677
- // src/analyze/functional/cadence.ts
678
- function hasDominantThird(chord) {
679
- return chord.intervals.some((interval) => pitchClassOf(interval) === 4);
680
- }
681
- function isLeadingToneDiminished(chord) {
682
- return chord.quality === "dim" || chord.quality === "dim7" || chord.quality === "m7b5";
683
- }
684
- function detectCadence(from, to, key) {
685
- const tonic = pitchClassOf(key.rootPc);
686
- const fromOffset = pitchClassOf(from.rootPc - tonic);
687
- const toOffset = pitchClassOf(to.rootPc - tonic);
688
- const deceptiveTargets = isMinorKey(key) ? [8] : [8, 9];
689
- const dominant = fromOffset === 7 && hasDominantThird(from);
690
- const leadingTone = fromOffset === 11 && isLeadingToneDiminished(from);
691
- if ((dominant || leadingTone) && toOffset === 0) {
692
- return "authentic";
693
- }
694
- if (fromOffset === 5 && toOffset === 0) {
695
- return "plagal";
696
- }
697
- if (dominant && deceptiveTargets.includes(toOffset)) {
698
- return "deceptive";
699
- }
700
- if (toOffset === 7 && hasDominantThird(to) && fromOffset !== 7) {
701
- return "half";
702
- }
703
- return null;
704
- }
705
-
706
- export {
707
- detectChord,
708
- detectChordBest,
709
- detectKey,
710
- detectKeyFromNotes,
711
- detectKeyBest,
712
- romanToChord,
713
- chordToRoman,
714
- isMinorKey,
715
- functionOf,
716
- isDiatonic,
717
- parallelKey,
718
- analyzeChord,
719
- secondaryDominant,
720
- isBorrowedChord,
721
- borrowedSource,
722
- detectCadence
723
- };
724
- //# sourceMappingURL=chunk-NNB67XA2.js.map