@libraz/libcantus 0.9.1 → 0.9.2

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 (154) hide show
  1. package/README.md +15 -0
  2. package/dist/analyze/index.cjs +1697 -0
  3. package/dist/analyze/index.cjs.map +1 -0
  4. package/dist/analyze/index.d.cts +429 -0
  5. package/dist/analyze/index.d.ts +429 -0
  6. package/dist/analyze/index.js +51 -0
  7. package/dist/analyze/index.js.map +1 -0
  8. package/dist/chunk-5HTNMQW4.js +653 -0
  9. package/dist/chunk-5HTNMQW4.js.map +1 -0
  10. package/dist/chunk-7Y7WF64D.js +410 -0
  11. package/dist/chunk-7Y7WF64D.js.map +1 -0
  12. package/dist/chunk-A4532ZFR.js +259 -0
  13. package/dist/chunk-A4532ZFR.js.map +1 -0
  14. package/dist/chunk-BHUT2S5G.js +22 -0
  15. package/dist/chunk-BHUT2S5G.js.map +1 -0
  16. package/dist/chunk-CCBLVAPK.js +42 -0
  17. package/dist/chunk-CCBLVAPK.js.map +1 -0
  18. package/dist/chunk-COKTX2G5.js +907 -0
  19. package/dist/chunk-COKTX2G5.js.map +1 -0
  20. package/dist/chunk-DYWFNC4A.js +152 -0
  21. package/dist/chunk-DYWFNC4A.js.map +1 -0
  22. package/dist/chunk-GQKN5KDT.js +159 -0
  23. package/dist/chunk-GQKN5KDT.js.map +1 -0
  24. package/dist/chunk-LN7ZZMD2.js +530 -0
  25. package/dist/chunk-LN7ZZMD2.js.map +1 -0
  26. package/dist/chunk-MSWFZF7J.js +118 -0
  27. package/dist/chunk-MSWFZF7J.js.map +1 -0
  28. package/dist/chunk-R3S2LUBH.js +2722 -0
  29. package/dist/chunk-R3S2LUBH.js.map +1 -0
  30. package/dist/chunk-SDM3VJJ5.js +41 -0
  31. package/dist/chunk-SDM3VJJ5.js.map +1 -0
  32. package/dist/chunk-XTC3X6MS.js +816 -0
  33. package/dist/chunk-XTC3X6MS.js.map +1 -0
  34. package/dist/chunk-ZXW5YIWK.js +55 -0
  35. package/dist/chunk-ZXW5YIWK.js.map +1 -0
  36. package/dist/core/index.cjs +432 -0
  37. package/dist/core/index.cjs.map +1 -0
  38. package/dist/core/index.d.cts +210 -0
  39. package/dist/core/index.d.ts +210 -0
  40. package/dist/core/index.js +73 -0
  41. package/dist/core/index.js.map +1 -0
  42. package/dist/function-2bJW1Zp_.d.ts +187 -0
  43. package/dist/function-r2sh-jOO.d.cts +187 -0
  44. package/dist/generate/index.cjs +3787 -0
  45. package/dist/generate/index.cjs.map +1 -0
  46. package/dist/generate/index.d.cts +980 -0
  47. package/dist/generate/index.d.ts +980 -0
  48. package/dist/generate/index.js +52 -0
  49. package/dist/generate/index.js.map +1 -0
  50. package/dist/index-BMPxwjwV.d.ts +151 -0
  51. package/dist/index-BOBXBNwP.d.cts +157 -0
  52. package/dist/index-BdeQ1r_p.d.cts +56 -0
  53. package/dist/index-BreoJRw0.d.ts +127 -0
  54. package/dist/index-CGMZNCx6.d.cts +140 -0
  55. package/dist/index-CGMZNCx6.d.ts +140 -0
  56. package/dist/index-CM5W4rcm.d.ts +157 -0
  57. package/dist/index-CP3wAfEH.d.ts +56 -0
  58. package/dist/index-Cl7mhOFM.d.cts +164 -0
  59. package/dist/index-Cl7mhOFM.d.ts +164 -0
  60. package/dist/index-DZ1M21do.d.cts +127 -0
  61. package/dist/index-D_ZTUNKp.d.cts +151 -0
  62. package/dist/index.cjs +3016 -2984
  63. package/dist/index.cjs.map +1 -1
  64. package/dist/index.d.cts +14 -3982
  65. package/dist/index.d.ts +14 -3982
  66. package/dist/index.js +170 -6504
  67. package/dist/index.js.map +1 -1
  68. package/dist/model/index.cjs +2435 -0
  69. package/dist/model/index.cjs.map +1 -0
  70. package/dist/model/index.d.cts +630 -0
  71. package/dist/model/index.d.ts +630 -0
  72. package/dist/model/index.js +21 -0
  73. package/dist/model/index.js.map +1 -0
  74. package/dist/styled-BjXtOFNk.d.cts +282 -0
  75. package/dist/styled-D7BAx3S3.d.ts +282 -0
  76. package/dist/theory/index.cjs +1677 -0
  77. package/dist/theory/index.cjs.map +1 -0
  78. package/dist/theory/index.d.cts +535 -0
  79. package/dist/theory/index.d.ts +535 -0
  80. package/dist/theory/index.js +149 -0
  81. package/dist/theory/index.js.map +1 -0
  82. package/dist/types-MGP29r3t.d.cts +30 -0
  83. package/dist/types-MGP29r3t.d.ts +30 -0
  84. package/package.json +27 -2
  85. package/src/analyze/arrange/index.ts +21 -0
  86. package/src/analyze/arrange/internal.ts +125 -0
  87. package/src/analyze/arrange/tension.ts +187 -0
  88. package/src/analyze/arrange/tracks.ts +279 -0
  89. package/src/{detect → analyze/detect}/index.ts +4 -4
  90. package/src/analyze/functional/borrowed.ts +84 -0
  91. package/src/analyze/functional/cadence.ts +66 -0
  92. package/src/analyze/functional/function.ts +184 -0
  93. package/src/analyze/functional/index.ts +23 -0
  94. package/src/analyze/functional/internal.ts +29 -0
  95. package/src/{functional/index.ts → analyze/functional/roman.ts} +9 -327
  96. package/src/analyze/index.ts +49 -0
  97. package/src/{timeline → analyze/timeline}/index.ts +7 -11
  98. package/src/{analysis → analyze/voice}/index.ts +8 -5
  99. package/src/core/index.ts +47 -0
  100. package/src/{bass → generate/bass}/index.ts +5 -5
  101. package/src/{countermelody → generate/countermelody}/index.ts +11 -11
  102. package/src/{drums → generate/drums}/index.ts +2 -2
  103. package/src/{drums → generate/drums}/rng.ts +2 -2
  104. package/src/{groove → generate/groove}/index.ts +3 -3
  105. package/src/{harmonize → generate/harmonize}/index.ts +13 -13
  106. package/src/generate/index.ts +59 -0
  107. package/src/{motif → generate/motif}/index.ts +7 -7
  108. package/src/{progression → generate/progression}/index.ts +11 -25
  109. package/src/{reharmony → generate/reharmony}/index.ts +11 -11
  110. package/src/{rhythm → generate/rhythm}/index.ts +2 -2
  111. package/src/index.ts +130 -117
  112. package/src/model/chord.ts +423 -0
  113. package/src/model/index.ts +5 -1096
  114. package/src/model/interval.ts +82 -0
  115. package/src/model/key.ts +266 -0
  116. package/src/model/note.ts +176 -0
  117. package/src/model/progression.ts +161 -0
  118. package/src/model/shared.ts +12 -0
  119. package/src/{chord → theory/chord}/index.ts +19 -1
  120. package/src/{counterpoint → theory/counterpoint}/index.ts +2 -2
  121. package/src/theory/index.ts +107 -0
  122. package/src/{safety → theory/safety}/index.ts +1 -1
  123. package/src/theory/scale/degrees.ts +123 -0
  124. package/src/theory/scale/index.ts +28 -0
  125. package/src/theory/scale/key.ts +56 -0
  126. package/src/theory/scale/masks.ts +153 -0
  127. package/src/{spelling → theory/spelling}/index.ts +3 -3
  128. package/src/{symbol → theory/symbol}/index.ts +8 -1
  129. package/src/theory/voicing/index.ts +5 -0
  130. package/src/theory/voicing/internal.ts +168 -0
  131. package/src/theory/voicing/leading.ts +112 -0
  132. package/src/theory/voicing/satb.ts +195 -0
  133. package/src/theory/voicing/styled.ts +176 -0
  134. package/src/arrange/index.ts +0 -571
  135. package/src/scale/index.ts +0 -331
  136. package/src/voicing/index.ts +0 -623
  137. /package/src/{interval → core/interval}/index.ts +0 -0
  138. /package/src/{meter → core/meter}/index.ts +0 -0
  139. /package/src/{pitch → core/pitch}/index.ts +0 -0
  140. /package/src/{random → core/random}/index.ts +0 -0
  141. /package/src/{tuning → core/tuning}/index.ts +0 -0
  142. /package/src/{types.ts → core/types.ts} +0 -0
  143. /package/src/{drums → generate/drums}/beat.ts +0 -0
  144. /package/src/{drums → generate/drums}/euclid.ts +0 -0
  145. /package/src/{drums → generate/drums}/fills.ts +0 -0
  146. /package/src/{drums → generate/drums}/ghost.ts +0 -0
  147. /package/src/{drums → generate/drums}/hihat.ts +0 -0
  148. /package/src/{drums → generate/drums}/hit.ts +0 -0
  149. /package/src/{drums → generate/drums}/internal.ts +0 -0
  150. /package/src/{drums → generate/drums}/kick.ts +0 -0
  151. /package/src/{drums → generate/drums}/percussion.ts +0 -0
  152. /package/src/{drums → generate/drums}/swing.ts +0 -0
  153. /package/src/{chordscale → theory/chordscale}/index.ts +0 -0
  154. /package/src/{harmony → theory/harmony}/index.ts +0 -0
@@ -0,0 +1,423 @@
1
+ import { detectChord, detectChordBest } from '../analyze/detect/index.js';
2
+ import {
3
+ analyzeChord,
4
+ type BorrowedSource,
5
+ borrowedSource,
6
+ type ChordAnalysis,
7
+ chordToRoman,
8
+ functionOf,
9
+ type HarmonicFunction,
10
+ isBorrowedChord,
11
+ } from '../analyze/functional/index.js';
12
+ import { negativeHarmonyMirror } from '../generate/reharmony/index.js';
13
+ import {
14
+ type Chord as ChordData,
15
+ type ChordQuality,
16
+ chordPitchClasses,
17
+ makeChord,
18
+ } from '../theory/chord/index.js';
19
+ import {
20
+ availableTensions,
21
+ avoidNotes,
22
+ type ChordScaleMatch,
23
+ chordScales,
24
+ } from '../theory/chordscale/index.js';
25
+ import { spellChord } from '../theory/spelling/index.js';
26
+ import { formatChordSymbol, parseChordSymbol } from '../theory/symbol/index.js';
27
+ import {
28
+ type StyledVoicingOptions,
29
+ type VoicingOptions,
30
+ voiceChord,
31
+ voiceChordStyled,
32
+ } from '../theory/voicing/index.js';
33
+ import type { Key } from './key.js';
34
+ import { Note } from './note.js';
35
+ import { Progression } from './progression.js';
36
+ import { mod12 } from './shared.js';
37
+
38
+ /**
39
+ * Defensive copy of a plain chord.
40
+ *
41
+ * Any enharmonic spelling hints (`rootSpelling`/`bassSpelling`, populated by
42
+ * `parseChordSymbol`) are carried through so a flat-named chord round-trips
43
+ * through the class API; a hint that no longer matches its pitch class is
44
+ * simply ignored by the formatter.
45
+ */
46
+ function copyChord(data: ChordData): ChordData {
47
+ const copy: ChordData = {
48
+ rootPc: data.rootPc,
49
+ quality: data.quality,
50
+ intervals: [...data.intervals],
51
+ };
52
+ if (data.bassPc !== undefined) {
53
+ copy.bassPc = data.bassPc;
54
+ }
55
+ if (data.rootSpelling !== undefined) {
56
+ copy.rootSpelling = { letter: data.rootSpelling.letter, alter: data.rootSpelling.alter };
57
+ }
58
+ if (data.bassSpelling !== undefined) {
59
+ copy.bassSpelling = { letter: data.bassSpelling.letter, alter: data.bassSpelling.alter };
60
+ }
61
+ return copy;
62
+ }
63
+
64
+ /**
65
+ * An immutable chord: a root pitch class, quality, interval template, and
66
+ * optional slash bass, optionally carrying a {@link Key} context. Analysis
67
+ * methods (`roman`, `function`, `analyze`, ...) use an explicitly passed key
68
+ * first and fall back to the carried context.
69
+ *
70
+ * @category Class API
71
+ * @example
72
+ * ```ts
73
+ * import { Chord } from '@libraz/libcantus';
74
+ * Chord.parse('Cmaj7').invert(1).symbol(); // 'Cmaj7/E' (third in the bass)
75
+ * ```
76
+ */
77
+ export class Chord {
78
+ readonly #data: ChordData;
79
+ readonly #key: Key | undefined;
80
+
81
+ /**
82
+ * Wrap a plain chord object.
83
+ *
84
+ * @param data The chord; it is copied, never retained or mutated.
85
+ * @param key Optional key context for analysis methods.
86
+ */
87
+ constructor(data: ChordData, key?: Key) {
88
+ this.#data = copyChord(data);
89
+ this.#key = key;
90
+ }
91
+
92
+ /**
93
+ * Build a chord from a root and quality.
94
+ *
95
+ * @param root Root as a note name (e.g. `'Eb'`) or a pitch class.
96
+ * @param quality The chord quality.
97
+ * @param bass Optional slash-chord bass pitch class.
98
+ * @returns The chord (without key context).
99
+ */
100
+ static of(root: string | number, quality: ChordQuality, bass?: number): Chord {
101
+ const rootPc = typeof root === 'string' ? Note.of(root).pitchClass : root;
102
+ return new Chord(makeChord(rootPc, quality, bass));
103
+ }
104
+
105
+ /**
106
+ * Wrap an existing plain chord object.
107
+ *
108
+ * @param data The plain chord.
109
+ * @returns The wrapped chord (without key context).
110
+ */
111
+ static from(data: ChordData): Chord {
112
+ return new Chord(data);
113
+ }
114
+
115
+ /**
116
+ * Parse a lead-sheet chord symbol (e.g. `'Cmaj7'`, `'F#m7b5'`, `'C/G'`).
117
+ *
118
+ * @param symbol The chord symbol.
119
+ * @returns The chord (without key context).
120
+ * @throws If the root or quality is not recognized.
121
+ */
122
+ static parse(symbol: string): Chord {
123
+ return new Chord(parseChordSymbol(symbol));
124
+ }
125
+
126
+ /**
127
+ * Identify the chords matching a set of pitches, best interpretation first.
128
+ *
129
+ * @param pitches MIDI pitches or bare pitch classes.
130
+ * @returns Ranked chord interpretations (may be empty).
131
+ */
132
+ static detect(pitches: number[]): Chord[] {
133
+ return detectChord(pitches).map(
134
+ (match) => new Chord(makeChord(match.rootPc, match.quality, match.bassPc)),
135
+ );
136
+ }
137
+
138
+ /**
139
+ * The single best chord interpretation of a pitch set.
140
+ *
141
+ * @param pitches MIDI pitches or bare pitch classes.
142
+ * @returns The top-ranked chord, or null when nothing matches.
143
+ */
144
+ static detectBest(pitches: number[]): Chord | null {
145
+ const best = detectChordBest(pitches);
146
+ return best === null ? null : new Chord(best);
147
+ }
148
+
149
+ /** The root pitch class (0..11). */
150
+ get rootPc(): number {
151
+ return this.#data.rootPc;
152
+ }
153
+
154
+ /** The chord quality. */
155
+ get quality(): ChordQuality {
156
+ return this.#data.quality;
157
+ }
158
+
159
+ /** A copy of the semitone offsets above the root. */
160
+ get intervals(): number[] {
161
+ return [...this.#data.intervals];
162
+ }
163
+
164
+ /** The slash-chord bass pitch class, or undefined in root position. */
165
+ get bassPc(): number | undefined {
166
+ return this.#data.bassPc;
167
+ }
168
+
169
+ /** A copy of the underlying plain chord object. */
170
+ get data(): ChordData {
171
+ return copyChord(this.#data);
172
+ }
173
+
174
+ /** The carried key context, if any. */
175
+ get key(): Key | undefined {
176
+ return this.#key;
177
+ }
178
+
179
+ /**
180
+ * A copy of this chord carrying the given key context.
181
+ *
182
+ * @param key The key context to attach.
183
+ * @returns The new chord.
184
+ */
185
+ withKey(key: Key): Chord {
186
+ return new Chord(this.#data, key);
187
+ }
188
+
189
+ /**
190
+ * The chord's sorted, deduplicated pitch classes.
191
+ *
192
+ * @returns Pitch classes ascending in [0, 11].
193
+ */
194
+ pitchClasses(): number[] {
195
+ return chordPitchClasses(this.#data);
196
+ }
197
+
198
+ /**
199
+ * The chord's Roman numeral in a key.
200
+ *
201
+ * @param key Key to analyze in; falls back to the carried context.
202
+ * @returns The Roman numeral string.
203
+ * @throws If no key is given and none is carried.
204
+ */
205
+ roman(key?: Key): string {
206
+ return chordToRoman(this.#data, this.#resolveKey(key).scale);
207
+ }
208
+
209
+ /**
210
+ * The chord's harmonic function (tonic / subdominant / dominant) in a key.
211
+ *
212
+ * @param key Key to analyze in; falls back to the carried context.
213
+ * @returns The harmonic function.
214
+ * @throws If no key is given and none is carried.
215
+ */
216
+ function(key?: Key): HarmonicFunction {
217
+ return functionOf(this.#data, this.#resolveKey(key).scale);
218
+ }
219
+
220
+ /**
221
+ * Full functional analysis: function, borrowing, and Roman numeral.
222
+ *
223
+ * @param key Key to analyze in; falls back to the carried context.
224
+ * @returns The chord analysis.
225
+ * @throws If no key is given and none is carried.
226
+ */
227
+ analyze(key?: Key): ChordAnalysis {
228
+ return analyzeChord(this.#data, this.#resolveKey(key).scale);
229
+ }
230
+
231
+ /**
232
+ * Whether the chord is borrowed from the parallel mode (modal interchange).
233
+ *
234
+ * @param key Key to analyze in; falls back to the carried context.
235
+ * @returns True if the chord is borrowed.
236
+ * @throws If no key is given and none is carried.
237
+ */
238
+ isBorrowed(key?: Key): boolean {
239
+ return isBorrowedChord(this.#data, this.#resolveKey(key).scale);
240
+ }
241
+
242
+ /**
243
+ * The origin of a non-diatonic chord (parallel mode or Neapolitan), or null.
244
+ *
245
+ * @param key Key to analyze in; falls back to the carried context.
246
+ * @returns The borrowing source, or null.
247
+ * @throws If no key is given and none is carried.
248
+ */
249
+ borrowedSource(key?: Key): BorrowedSource {
250
+ return borrowedSource(this.#data, this.#resolveKey(key).scale);
251
+ }
252
+
253
+ /**
254
+ * The chord rendered as a lead-sheet symbol (e.g. `'Cmaj7'`, `'F#m7'`, `'C/G'`).
255
+ *
256
+ * @param opts Set `flats: true` to spell the root/bass with flats.
257
+ * @returns The chord symbol.
258
+ */
259
+ symbol(opts?: { flats?: boolean }): string {
260
+ return formatChordSymbol(this.#data, opts);
261
+ }
262
+
263
+ /**
264
+ * Realize the chord as one MIDI pitch per voice, ascending.
265
+ *
266
+ * @param opts Voicing options; defaults to four SATB voices.
267
+ * @returns MIDI pitches, ascending, one per voice.
268
+ * @throws If no voicing fits the given ranges.
269
+ */
270
+ voice(opts?: VoicingOptions): number[] {
271
+ return voiceChord(this.#data, opts);
272
+ }
273
+
274
+ /**
275
+ * Realize the chord as a single styled voicing (`close`, `drop2`, `drop3`,
276
+ * `shell`, or `rootless`), optionally constraining the top voice.
277
+ *
278
+ * @param opts Styled-voicing options; defaults to a close-position voicing.
279
+ * @returns MIDI pitches, ascending.
280
+ */
281
+ styledVoicing(opts?: StyledVoicingOptions): number[] {
282
+ return voiceChordStyled(this.#data, opts);
283
+ }
284
+
285
+ /**
286
+ * The negative-harmony mirror of the chord about the key's tonic–dominant
287
+ * axis (major becomes minor and vice versa).
288
+ *
289
+ * @param key Key providing the reflection axis; falls back to the carried
290
+ * context.
291
+ * @returns The mirrored chord, keeping any key context.
292
+ * @throws If no key is given and none is carried.
293
+ */
294
+ negativeHarmony(key?: Key): Chord {
295
+ const resolved = this.#resolveKey(key);
296
+ // Retain the key that anchored the reflection (explicit first, then carried)
297
+ // so a later no-arg analysis method still has a key context.
298
+ return new Chord(negativeHarmonyMirror(this.#data, resolved.scale), key ?? this.#key);
299
+ }
300
+
301
+ /**
302
+ * The n-th inversion: a copy whose bass is the chord tone `n` steps above the
303
+ * root in the interval template (`invert(1)` puts the third in the bass).
304
+ * `n` wraps around the template length; negative values count backwards.
305
+ *
306
+ * `invert(0)` (and any `n` that wraps to it) is root position, so it carries
307
+ * no slash bass and equals the original chord.
308
+ *
309
+ * @param n The inversion number.
310
+ * @returns The inverted chord, keeping any key context.
311
+ * @throws If the chord has no intervals.
312
+ */
313
+ invert(n: number): Chord {
314
+ const intervals = this.#data.intervals;
315
+ const length = intervals.length;
316
+ if (length === 0) {
317
+ throw new Error('cannot invert a chord with no intervals');
318
+ }
319
+ const index = ((n % length) + length) % length;
320
+ const data = copyChord(this.#data);
321
+ if (index === 0) {
322
+ delete data.bassPc;
323
+ } else {
324
+ data.bassPc = mod12(this.#data.rootPc + (intervals[index] ?? 0));
325
+ }
326
+ return new Chord(data, this.#key);
327
+ }
328
+
329
+ /**
330
+ * The named scales that fit over this chord, best fit first, rooted on the
331
+ * chord root.
332
+ *
333
+ * @returns The matching scales.
334
+ */
335
+ scales(): ChordScaleMatch[] {
336
+ return chordScales(this.#data);
337
+ }
338
+
339
+ /**
340
+ * The available tensions (usable non-chord, non-avoid scale tones) of a
341
+ * scale over this chord.
342
+ *
343
+ * @param scaleName A named scale, rooted on the chord root.
344
+ * @returns Tension pitch classes, ascending in [0, 11].
345
+ */
346
+ tensions(scaleName: string): number[] {
347
+ return availableTensions(this.#data, scaleName);
348
+ }
349
+
350
+ /**
351
+ * The avoid notes (scale tones a semitone above a chord tone) of a scale
352
+ * over this chord.
353
+ *
354
+ * @param scaleName A named scale, rooted on the chord root.
355
+ * @returns Avoid-note pitch classes, ascending in [0, 11].
356
+ */
357
+ avoidNotes(scaleName: string): number[] {
358
+ return avoidNotes(this.#data, scaleName);
359
+ }
360
+
361
+ /**
362
+ * Spell the chord tones with letter names, root first, in the key's spelling.
363
+ *
364
+ * @param key Key providing the spelled tonic; falls back to the carried
365
+ * context.
366
+ * @returns Spelled octave-less notes in the chord's own (tertian) order.
367
+ * @throws If no key is given and none is carried.
368
+ */
369
+ spell(key?: Key): Note[] {
370
+ const resolved = this.#resolveKey(key);
371
+ return spellChord(this.#data, resolved.tonic.data, resolved.scale).map(
372
+ (note) => new Note(note),
373
+ );
374
+ }
375
+
376
+ /**
377
+ * Start a progression with this chord followed by others, carrying this
378
+ * chord's key context (if any).
379
+ *
380
+ * @param others The chords following this one.
381
+ * @returns The progression.
382
+ */
383
+ progressionTo(...others: Chord[]): Progression {
384
+ return new Progression([this, ...others], this.#key);
385
+ }
386
+
387
+ /**
388
+ * Whether another chord has the same root, quality, intervals, and bass.
389
+ * Key context is not compared.
390
+ *
391
+ * @param other The chord to compare.
392
+ * @returns True if the chord data is identical.
393
+ */
394
+ equals(other: Chord): boolean {
395
+ const a = this.#data;
396
+ const b = other.#data;
397
+ return (
398
+ a.rootPc === b.rootPc &&
399
+ a.quality === b.quality &&
400
+ a.bassPc === b.bassPc &&
401
+ a.intervals.length === b.intervals.length &&
402
+ a.intervals.every((interval, i) => interval === b.intervals[i])
403
+ );
404
+ }
405
+
406
+ /**
407
+ * The plain chord data, for JSON serialization.
408
+ *
409
+ * @returns A copy of the underlying plain chord object.
410
+ */
411
+ toJSON(): ChordData {
412
+ return this.data;
413
+ }
414
+
415
+ /** Resolve the key for an analysis method: explicit first, then carried. */
416
+ #resolveKey(key?: Key): Key {
417
+ const resolved = key ?? this.#key;
418
+ if (resolved === undefined) {
419
+ throw new Error('chord has no key context; pass a Key or attach one with withKey()');
420
+ }
421
+ return resolved;
422
+ }
423
+ }