@libraz/libcantus 0.9.3 → 0.9.5

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 (201) hide show
  1. package/README.md +29 -20
  2. package/README_ja.md +268 -0
  3. package/dist/analyze/index.cjs +39 -1947
  4. package/dist/analyze/index.cjs.map +1 -1
  5. package/dist/analyze/index.d.cts +161 -91
  6. package/dist/analyze/index.d.ts +161 -91
  7. package/dist/analyze/index.js +19 -8
  8. package/dist/chunk-2A2QMA74.cjs +261 -0
  9. package/dist/chunk-2A2QMA74.cjs.map +1 -0
  10. package/dist/chunk-2PTFGVD7.js +261 -0
  11. package/dist/chunk-2PTFGVD7.js.map +1 -0
  12. package/dist/chunk-357ZDPVU.cjs +162 -0
  13. package/dist/chunk-357ZDPVU.cjs.map +1 -0
  14. package/dist/chunk-3KX76RLG.js +1548 -0
  15. package/dist/chunk-3KX76RLG.js.map +1 -0
  16. package/dist/chunk-4VZ5MZAM.cjs +889 -0
  17. package/dist/chunk-4VZ5MZAM.cjs.map +1 -0
  18. package/dist/{chunk-C5XYKUVG.js → chunk-7EONYVI5.js} +471 -171
  19. package/dist/chunk-7EONYVI5.js.map +1 -0
  20. package/dist/{chunk-IT2O4XFE.js → chunk-7JEP3MFY.js} +42 -34
  21. package/dist/chunk-7JEP3MFY.js.map +1 -0
  22. package/dist/{chunk-4MHA432G.js → chunk-AID75RN3.js} +572 -250
  23. package/dist/chunk-AID75RN3.js.map +1 -0
  24. package/dist/chunk-BSLTLGM3.cjs +497 -0
  25. package/dist/chunk-BSLTLGM3.cjs.map +1 -0
  26. package/dist/chunk-CU6VG2YM.cjs +109 -0
  27. package/dist/chunk-CU6VG2YM.cjs.map +1 -0
  28. package/dist/{chunk-EH6EM37U.js → chunk-DZMHIGI4.js} +81 -59
  29. package/dist/chunk-DZMHIGI4.js.map +1 -0
  30. package/dist/{chunk-AKLYPWIN.js → chunk-EDOTEABK.js} +45 -19
  31. package/dist/chunk-EDOTEABK.js.map +1 -0
  32. package/dist/{chunk-2ZWMSJH6.js → chunk-HN2OEUN2.js} +7 -4
  33. package/dist/chunk-HN2OEUN2.js.map +1 -0
  34. package/dist/{chunk-MIWO425M.js → chunk-KBTTEX7Q.js} +128 -43
  35. package/dist/chunk-KBTTEX7Q.js.map +1 -0
  36. package/dist/chunk-KQN2ZYND.cjs +724 -0
  37. package/dist/chunk-KQN2ZYND.cjs.map +1 -0
  38. package/dist/chunk-MPTVJIVG.cjs +3176 -0
  39. package/dist/chunk-MPTVJIVG.cjs.map +1 -0
  40. package/dist/chunk-MTMZTMWM.cjs +53 -0
  41. package/dist/chunk-MTMZTMWM.cjs.map +1 -0
  42. package/dist/{chunk-CHMXELDS.js → chunk-NNB67XA2.js} +372 -197
  43. package/dist/chunk-NNB67XA2.js.map +1 -0
  44. package/dist/chunk-OL3IHHSJ.cjs +1204 -0
  45. package/dist/chunk-OL3IHHSJ.cjs.map +1 -0
  46. package/dist/chunk-PI3UXRWK.cjs +528 -0
  47. package/dist/chunk-PI3UXRWK.cjs.map +1 -0
  48. package/dist/chunk-R2VVFAIN.js +528 -0
  49. package/dist/chunk-R2VVFAIN.js.map +1 -0
  50. package/dist/chunk-T64C7ZD7.cjs +1 -0
  51. package/dist/chunk-T64C7ZD7.cjs.map +1 -0
  52. package/dist/chunk-WFDXOLUB.cjs +337 -0
  53. package/dist/chunk-WFDXOLUB.cjs.map +1 -0
  54. package/dist/chunk-WTAN4ACG.cjs +1548 -0
  55. package/dist/chunk-WTAN4ACG.cjs.map +1 -0
  56. package/dist/chunk-YFJXS3AU.cjs +33 -0
  57. package/dist/chunk-YFJXS3AU.cjs.map +1 -0
  58. package/dist/{chunk-GOAW4VYL.js → chunk-YUE6TJ4M.js} +315 -145
  59. package/dist/chunk-YUE6TJ4M.js.map +1 -0
  60. package/dist/{chunk-62QZKCJQ.js → chunk-ZGLJM4A4.js} +10 -6
  61. package/dist/chunk-ZGLJM4A4.js.map +1 -0
  62. package/dist/core/index.cjs +140 -647
  63. package/dist/core/index.cjs.map +1 -1
  64. package/dist/core/index.d.cts +313 -41
  65. package/dist/core/index.d.ts +313 -41
  66. package/dist/core/index.js +64 -16
  67. package/dist/{function-DVH4Eusr.d.ts → function-CxixTB02.d.cts} +122 -10
  68. package/dist/{function-DYt4iKsn.d.cts → function-DTCt675z.d.ts} +122 -10
  69. package/dist/generate/index.cjs +28 -4085
  70. package/dist/generate/index.cjs.map +1 -1
  71. package/dist/generate/index.d.cts +374 -66
  72. package/dist/generate/index.d.ts +374 -66
  73. package/dist/generate/index.js +23 -9
  74. package/dist/{index-Jc0Ryi79.d.ts → index-B2Ulxxpo.d.cts} +21 -5
  75. package/dist/{index-CpOsP1y9.d.cts → index-BkYJ0xMq.d.cts} +18 -17
  76. package/dist/{index-CxqBQtH1.d.cts → index-BuaB-ypt.d.ts} +21 -5
  77. package/dist/index-CAN7v-kw.d.ts +199 -0
  78. package/dist/{index-Bt4tOUD9.d.ts → index-COw1Ky9g.d.ts} +93 -8
  79. package/dist/{index-Dikst44v.d.cts → index-Cfx8xgH0.d.ts} +14 -11
  80. package/dist/{index-DxvARIP2.d.ts → index-DRtIhlJj.d.ts} +18 -17
  81. package/dist/{index-Cl7mhOFM.d.cts → index-DXd9JikN.d.cts} +92 -10
  82. package/dist/{index-Cl7mhOFM.d.ts → index-DXd9JikN.d.ts} +92 -10
  83. package/dist/index-alrRninU.d.cts +199 -0
  84. package/dist/{index-BNlGP86A.d.cts → index-oTQbYYIs.d.cts} +93 -8
  85. package/dist/index-tR9jTn26.d.cts +275 -0
  86. package/dist/index-tR9jTn26.d.ts +275 -0
  87. package/dist/{index-Bg5dYMmZ.d.ts → index-x2vcsduE.d.cts} +14 -11
  88. package/dist/index.cjs +429 -7383
  89. package/dist/index.cjs.map +1 -1
  90. package/dist/index.d.cts +15 -15
  91. package/dist/index.d.ts +15 -15
  92. package/dist/index.js +121 -27
  93. package/dist/model/index.cjs +8 -2562
  94. package/dist/model/index.cjs.map +1 -1
  95. package/dist/model/index.d.cts +471 -81
  96. package/dist/model/index.d.ts +471 -81
  97. package/dist/model/index.js +6 -7
  98. package/dist/styled-Bl0ZK28h.d.ts +543 -0
  99. package/dist/styled-Crv6SA4S.d.cts +543 -0
  100. package/dist/theory/index.cjs +172 -1822
  101. package/dist/theory/index.cjs.map +1 -1
  102. package/dist/theory/index.d.cts +151 -233
  103. package/dist/theory/index.d.ts +151 -233
  104. package/dist/theory/index.js +30 -7
  105. package/dist/{types-MGP29r3t.d.cts → types-BN6_Q9Kl.d.cts} +11 -2
  106. package/dist/{types-MGP29r3t.d.ts → types-BN6_Q9Kl.d.ts} +11 -2
  107. package/package.json +34 -13
  108. package/dist/chunk-2ZWMSJH6.js.map +0 -1
  109. package/dist/chunk-4MHA432G.js.map +0 -1
  110. package/dist/chunk-62QZKCJQ.js.map +0 -1
  111. package/dist/chunk-AKLYPWIN.js.map +0 -1
  112. package/dist/chunk-C5XYKUVG.js.map +0 -1
  113. package/dist/chunk-CHMXELDS.js.map +0 -1
  114. package/dist/chunk-DYWFNC4A.js +0 -152
  115. package/dist/chunk-DYWFNC4A.js.map +0 -1
  116. package/dist/chunk-EH6EM37U.js.map +0 -1
  117. package/dist/chunk-FBQK3ZQN.js +0 -131
  118. package/dist/chunk-FBQK3ZQN.js.map +0 -1
  119. package/dist/chunk-GOAW4VYL.js.map +0 -1
  120. package/dist/chunk-I5R7ZBJS.js +0 -202
  121. package/dist/chunk-I5R7ZBJS.js.map +0 -1
  122. package/dist/chunk-IT2O4XFE.js.map +0 -1
  123. package/dist/chunk-MIWO425M.js.map +0 -1
  124. package/dist/chunk-SGU7SPLK.js +0 -924
  125. package/dist/chunk-SGU7SPLK.js.map +0 -1
  126. package/dist/index-CGMZNCx6.d.cts +0 -140
  127. package/dist/index-CGMZNCx6.d.ts +0 -140
  128. package/dist/index-CnZCo29u.d.cts +0 -108
  129. package/dist/index-JnF4v9bx.d.ts +0 -108
  130. package/dist/styled-DZ7GjShb.d.ts +0 -282
  131. package/dist/styled-ZTbdaVFM.d.cts +0 -282
  132. package/src/analyze/arrange/index.ts +0 -21
  133. package/src/analyze/arrange/internal.ts +0 -127
  134. package/src/analyze/arrange/tension.ts +0 -199
  135. package/src/analyze/arrange/tracks.ts +0 -312
  136. package/src/analyze/detect/index.ts +0 -272
  137. package/src/analyze/functional/borrowed.ts +0 -84
  138. package/src/analyze/functional/cadence.ts +0 -66
  139. package/src/analyze/functional/function.ts +0 -184
  140. package/src/analyze/functional/index.ts +0 -23
  141. package/src/analyze/functional/internal.ts +0 -29
  142. package/src/analyze/functional/roman.ts +0 -402
  143. package/src/analyze/index.ts +0 -49
  144. package/src/analyze/timeline/index.ts +0 -451
  145. package/src/analyze/voice/index.ts +0 -339
  146. package/src/core/event-index/index.ts +0 -104
  147. package/src/core/index.ts +0 -61
  148. package/src/core/interval/index.ts +0 -81
  149. package/src/core/meter/index.ts +0 -302
  150. package/src/core/pitch/index.ts +0 -311
  151. package/src/core/random/index.ts +0 -76
  152. package/src/core/tuning/index.ts +0 -186
  153. package/src/core/types.ts +0 -29
  154. package/src/core/validation/index.ts +0 -119
  155. package/src/generate/bass/index.ts +0 -373
  156. package/src/generate/countermelody/index.ts +0 -470
  157. package/src/generate/drums/beat.ts +0 -266
  158. package/src/generate/drums/euclid.ts +0 -65
  159. package/src/generate/drums/fills.ts +0 -356
  160. package/src/generate/drums/ghost.ts +0 -119
  161. package/src/generate/drums/hihat.ts +0 -285
  162. package/src/generate/drums/hit.ts +0 -31
  163. package/src/generate/drums/index.ts +0 -361
  164. package/src/generate/drums/internal.ts +0 -257
  165. package/src/generate/drums/kick.ts +0 -160
  166. package/src/generate/drums/percussion.ts +0 -121
  167. package/src/generate/drums/rng.ts +0 -7
  168. package/src/generate/drums/swing.ts +0 -71
  169. package/src/generate/groove/index.ts +0 -351
  170. package/src/generate/harmonize/index.ts +0 -451
  171. package/src/generate/index.ts +0 -58
  172. package/src/generate/motif/index.ts +0 -422
  173. package/src/generate/progression/index.ts +0 -362
  174. package/src/generate/reharmony/index.ts +0 -323
  175. package/src/generate/rhythm/index.ts +0 -175
  176. package/src/index.ts +0 -13
  177. package/src/model/chord.ts +0 -442
  178. package/src/model/index.ts +0 -15
  179. package/src/model/interval.ts +0 -82
  180. package/src/model/key.ts +0 -266
  181. package/src/model/note.ts +0 -176
  182. package/src/model/progression.ts +0 -161
  183. package/src/model/shared.ts +0 -12
  184. package/src/theory/chord/index.ts +0 -375
  185. package/src/theory/chordscale/index.ts +0 -374
  186. package/src/theory/counterpoint/index.ts +0 -230
  187. package/src/theory/harmony/index.ts +0 -77
  188. package/src/theory/index.ts +0 -112
  189. package/src/theory/safety/index.ts +0 -488
  190. package/src/theory/scale/degrees.ts +0 -123
  191. package/src/theory/scale/index.ts +0 -28
  192. package/src/theory/scale/key.ts +0 -56
  193. package/src/theory/scale/masks.ts +0 -153
  194. package/src/theory/spelling/index.ts +0 -249
  195. package/src/theory/symbol/index.ts +0 -268
  196. package/src/theory/voicing/index.ts +0 -5
  197. package/src/theory/voicing/internal.ts +0 -168
  198. package/src/theory/voicing/leading.ts +0 -112
  199. package/src/theory/voicing/satb.ts +0 -216
  200. package/src/theory/voicing/styled.ts +0 -199
  201. package/tsconfig.json +0 -23
@@ -1,924 +0,0 @@
1
- import {
2
- negativeHarmonyMirror
3
- } from "./chunk-IT2O4XFE.js";
4
- import {
5
- analyzeChord,
6
- borrowedSource,
7
- chordToRoman,
8
- detectCadence,
9
- detectChord,
10
- detectChordBest,
11
- functionOf,
12
- isBorrowedChord,
13
- isMinorKey,
14
- romanToChord
15
- } from "./chunk-CHMXELDS.js";
16
- import {
17
- availableTensions,
18
- avoidNotes,
19
- chordScales,
20
- formatChordSymbol,
21
- parseChordSymbol,
22
- spellChord,
23
- spellChordFromRoot,
24
- spellPitchClass,
25
- spellScale,
26
- voiceChord,
27
- voiceChordStyled,
28
- voiceProgression
29
- } from "./chunk-C5XYKUVG.js";
30
- import {
31
- formatNote,
32
- midiToNote,
33
- noteToMidi,
34
- noteToPitchClass,
35
- parseNote,
36
- spelledInterval
37
- } from "./chunk-DYWFNC4A.js";
38
- import {
39
- chordFromDegree,
40
- chordPitchClasses,
41
- diatonicSeventh,
42
- diatonicTriad,
43
- isScaleTone,
44
- majorKey,
45
- makeChord,
46
- minorKey,
47
- scaleByName,
48
- scaleTonesInDegreeOrder
49
- } from "./chunk-MIWO425M.js";
50
-
51
- // src/model/shared.ts
52
- function mod12(n) {
53
- return (n % 12 + 12) % 12;
54
- }
55
- function spellPitchClassBare(pc, spelling) {
56
- const spelled = midiToNote(60 + mod12(pc), spelling);
57
- return { letter: spelled.letter, alter: spelled.alter };
58
- }
59
-
60
- // src/model/note.ts
61
- function copyNote(data) {
62
- const copy = { letter: data.letter, alter: data.alter };
63
- if (data.octave !== void 0) {
64
- copy.octave = data.octave;
65
- }
66
- return copy;
67
- }
68
- var Note = class _Note {
69
- #data;
70
- /**
71
- * Wrap a plain note object.
72
- *
73
- * @param data The spelled note; it is copied, never retained or mutated.
74
- */
75
- constructor(data) {
76
- this.#data = copyNote(data);
77
- }
78
- /**
79
- * Parse scientific pitch notation (e.g. `'C#4'`, `'Bb'`, `'F##3'`).
80
- *
81
- * @param name The note text.
82
- * @returns The parsed note.
83
- * @throws If the text is not a valid note.
84
- */
85
- static of(name) {
86
- return new _Note(parseNote(name));
87
- }
88
- /**
89
- * Name a MIDI number (middle C = C4 = 60) as a note.
90
- *
91
- * @param midi The MIDI number.
92
- * @param spelling Whether to prefer sharps or flats for black keys.
93
- * @returns The spelled note, with octave.
94
- */
95
- static fromMidi(midi, spelling = "sharp") {
96
- return new _Note(midiToNote(midi, spelling));
97
- }
98
- /**
99
- * Wrap an existing plain note object.
100
- *
101
- * @param data The plain note.
102
- * @returns The wrapped note.
103
- */
104
- static fromData(data) {
105
- return new _Note(data);
106
- }
107
- /** The note rendered as scientific pitch notation, e.g. `'G4'` or `'Bb'`. */
108
- get name() {
109
- return formatNote(this.#data);
110
- }
111
- /** The pitch class (0..11), ignoring octave. */
112
- get pitchClass() {
113
- return noteToPitchClass(this.#data);
114
- }
115
- /**
116
- * The MIDI number (middle C = C4 = 60).
117
- *
118
- * @throws If the note has no octave and therefore no fixed pitch.
119
- */
120
- get midi() {
121
- if (this.#data.octave === void 0) {
122
- throw new Error(`note ${this.name} has no octave, so it has no MIDI number`);
123
- }
124
- return noteToMidi(this.#data);
125
- }
126
- /** The diatonic letter number: 0..6 for C..B. */
127
- get letter() {
128
- return this.#data.letter;
129
- }
130
- /** The chromatic alteration in semitones: -1 flat, 0 natural, +1 sharp, ... */
131
- get alter() {
132
- return this.#data.alter;
133
- }
134
- /** The octave (scientific pitch notation), or undefined for a bare pitch class. */
135
- get octave() {
136
- return this.#data.octave;
137
- }
138
- /** A copy of the underlying plain note object. */
139
- get data() {
140
- return copyNote(this.#data);
141
- }
142
- /**
143
- * Transpose by a signed number of semitones.
144
- *
145
- * When the note carries an octave the transposition happens in MIDI space and
146
- * the result is spelled with a sharp preference. An octave-less note stays
147
- * octave-less: only its pitch class is moved. Transposing by zero is the
148
- * identity: the original spelling is preserved (no enharmonic respelling).
149
- *
150
- * @param semitones The signed semitone offset.
151
- * @returns The transposed note.
152
- */
153
- transpose(semitones) {
154
- if (semitones === 0) {
155
- return new _Note(this.#data);
156
- }
157
- if (this.#data.octave !== void 0) {
158
- return _Note.fromMidi(this.midi + semitones);
159
- }
160
- return new _Note(spellPitchClassBare(this.pitchClass + semitones, "sharp"));
161
- }
162
- /**
163
- * The spelled interval from this note to another.
164
- *
165
- * @param other The second note.
166
- * @returns The diatonic number, quality, and semitone span.
167
- */
168
- intervalTo(other) {
169
- return spelledInterval(this.#data, other.#data);
170
- }
171
- /**
172
- * Whether another note has the same letter, alteration, and octave.
173
- *
174
- * @param other The note to compare.
175
- * @returns True if the spellings are identical.
176
- */
177
- equals(other) {
178
- return this.#data.letter === other.#data.letter && this.#data.alter === other.#data.alter && this.#data.octave === other.#data.octave;
179
- }
180
- /**
181
- * The plain note data, for JSON serialization.
182
- *
183
- * Private class fields do not serialize, so an explicit `toJSON` keeps
184
- * `JSON.stringify(note)` from collapsing to `{}`.
185
- *
186
- * @returns A copy of the underlying plain note object.
187
- */
188
- toJSON() {
189
- return this.data;
190
- }
191
- };
192
-
193
- // src/model/progression.ts
194
- var Progression = class _Progression {
195
- #chords;
196
- #key;
197
- /**
198
- * Wrap a chord sequence.
199
- *
200
- * @param chords The chords in order; the array is copied.
201
- * @param key Optional key context for analysis methods.
202
- */
203
- constructor(chords, key) {
204
- this.#chords = [...chords];
205
- this.#key = key;
206
- }
207
- /** A copy of the chord sequence. */
208
- get chords() {
209
- return [...this.#chords];
210
- }
211
- /** The carried key context, if any. */
212
- get key() {
213
- return this.#key;
214
- }
215
- /** The number of chords. */
216
- get length() {
217
- return this.#chords.length;
218
- }
219
- /**
220
- * A copy of this progression with a chord appended.
221
- *
222
- * @param chord The chord to append.
223
- * @returns The new progression.
224
- */
225
- add(chord) {
226
- return new _Progression([...this.#chords, chord], this.#key);
227
- }
228
- /**
229
- * A copy of this progression carrying the given key context.
230
- *
231
- * @param key The key context to attach.
232
- * @returns The new progression.
233
- */
234
- withKey(key) {
235
- return new _Progression(this.#chords, key);
236
- }
237
- /**
238
- * Voice the progression with smooth voice leading.
239
- *
240
- * @param opts Voicing options; defaults to four SATB voices.
241
- * @returns One ascending voicing (MIDI pitches) per chord.
242
- * @throws If any chord admits no voicing within the given ranges.
243
- */
244
- voice(opts) {
245
- return voiceProgression(
246
- this.#chords.map((chord) => chord.data),
247
- opts
248
- );
249
- }
250
- /**
251
- * The Roman numeral of each chord in a key.
252
- *
253
- * @param key Key to analyze in; falls back to the carried context.
254
- * @returns One numeral per chord.
255
- * @throws If no key is given and none is carried.
256
- */
257
- roman(key) {
258
- const resolved = this.#resolveKey(key);
259
- return this.#chords.map((chord) => chord.roman(resolved));
260
- }
261
- /**
262
- * The harmonic function of each chord in a key.
263
- *
264
- * @param key Key to analyze in; falls back to the carried context.
265
- * @returns One function per chord.
266
- * @throws If no key is given and none is carried.
267
- */
268
- functions(key) {
269
- const resolved = this.#resolveKey(key);
270
- return this.#chords.map((chord) => chord.function(resolved));
271
- }
272
- /**
273
- * Analyze every chord and classify the closing cadence.
274
- *
275
- * The cadence is detected on the final chord pair and is null when the
276
- * progression has fewer than two chords.
277
- *
278
- * @param key Key to analyze in; falls back to the carried context.
279
- * @returns Per-chord analyses and the closing cadence.
280
- * @throws If no key is given and none is carried.
281
- */
282
- analyze(key) {
283
- const resolved = this.#resolveKey(key);
284
- const chords = this.#chords.map((chord) => chord.analyze(resolved));
285
- const from = this.#chords[this.#chords.length - 2];
286
- const to = this.#chords[this.#chords.length - 1];
287
- const cadence = from !== void 0 && to !== void 0 ? detectCadence(from.data, to.data, resolved.scale) : null;
288
- return { chords, cadence };
289
- }
290
- /**
291
- * The plain progression data, for JSON serialization.
292
- *
293
- * Private class fields do not serialize, so an explicit `toJSON` keeps
294
- * `JSON.stringify(progression)` from collapsing to `{}`. The chords are
295
- * emitted as plain data and the carried key, when present, as its own data.
296
- *
297
- * @returns The chord data sequence and the carried key, if any.
298
- */
299
- toJSON() {
300
- return {
301
- chords: this.#chords.map((chord) => chord.data),
302
- key: this.#key?.toJSON()
303
- };
304
- }
305
- /** Resolve the key for an analysis method: explicit first, then carried. */
306
- #resolveKey(key) {
307
- const resolved = key ?? this.#key;
308
- if (resolved === void 0) {
309
- throw new Error("progression has no key context; pass a Key or attach one with withKey()");
310
- }
311
- return resolved;
312
- }
313
- };
314
-
315
- // src/model/chord.ts
316
- function copyChord(data) {
317
- const copy = {
318
- rootPc: data.rootPc,
319
- quality: data.quality,
320
- intervals: [...data.intervals]
321
- };
322
- if (data.bassPc !== void 0) {
323
- copy.bassPc = data.bassPc;
324
- }
325
- if (data.rootSpelling !== void 0) {
326
- copy.rootSpelling = { letter: data.rootSpelling.letter, alter: data.rootSpelling.alter };
327
- }
328
- if (data.bassSpelling !== void 0) {
329
- copy.bassSpelling = { letter: data.bassSpelling.letter, alter: data.bassSpelling.alter };
330
- }
331
- return copy;
332
- }
333
- var Chord = class _Chord {
334
- #data;
335
- #key;
336
- /**
337
- * Wrap a plain chord object.
338
- *
339
- * @param data The chord; it is copied, never retained or mutated.
340
- * @param key Optional key context for analysis methods.
341
- */
342
- constructor(data, key) {
343
- const copy = copyChord(data);
344
- if (copy.rootSpelling === void 0 && key !== void 0) {
345
- copy.rootSpelling = spellPitchClass(copy.rootPc, key.tonic.data, key.scale);
346
- }
347
- this.#data = copy;
348
- this.#key = key;
349
- }
350
- /**
351
- * Build a chord from a root and quality.
352
- *
353
- * @param root Root as a note name (e.g. `'Eb'`) or a pitch class.
354
- * @param quality The chord quality.
355
- * @param bass Optional slash-chord bass pitch class.
356
- * @returns The chord (without key context).
357
- */
358
- static of(root, quality, bass) {
359
- if (typeof root === "string") {
360
- const rootNote = Note.of(root);
361
- const data = makeChord(rootNote.pitchClass, quality, bass);
362
- data.rootSpelling = { letter: rootNote.letter, alter: rootNote.alter };
363
- return new _Chord(data);
364
- }
365
- return new _Chord(makeChord(root, quality, bass));
366
- }
367
- /**
368
- * Wrap an existing plain chord object.
369
- *
370
- * @param data The plain chord.
371
- * @returns The wrapped chord (without key context).
372
- */
373
- static from(data) {
374
- return new _Chord(data);
375
- }
376
- /**
377
- * Parse a lead-sheet chord symbol (e.g. `'Cmaj7'`, `'F#m7b5'`, `'C/G'`).
378
- *
379
- * @param symbol The chord symbol.
380
- * @returns The chord (without key context).
381
- * @throws If the root or quality is not recognized.
382
- */
383
- static parse(symbol) {
384
- return new _Chord(parseChordSymbol(symbol));
385
- }
386
- /**
387
- * Identify the chords matching a set of pitches, best interpretation first.
388
- *
389
- * @param pitches MIDI pitches or bare pitch classes.
390
- * @returns Ranked chord interpretations (may be empty).
391
- */
392
- static detect(pitches, opts) {
393
- return detectChord(pitches, opts).map(
394
- (match) => new _Chord(makeChord(match.rootPc, match.quality, match.bassPc))
395
- );
396
- }
397
- /**
398
- * The single best chord interpretation of a pitch set.
399
- *
400
- * @param pitches MIDI pitches or bare pitch classes.
401
- * @returns The top-ranked chord, or null when nothing matches.
402
- */
403
- static detectBest(pitches, opts) {
404
- const best = detectChordBest(pitches, opts);
405
- return best === null ? null : new _Chord(best);
406
- }
407
- /** The root pitch class (0..11). */
408
- get rootPc() {
409
- return this.#data.rootPc;
410
- }
411
- /** The chord quality. */
412
- get quality() {
413
- return this.#data.quality;
414
- }
415
- /** A copy of the semitone offsets above the root. */
416
- get intervals() {
417
- return [...this.#data.intervals];
418
- }
419
- /** The slash-chord bass pitch class, or undefined in root position. */
420
- get bassPc() {
421
- return this.#data.bassPc;
422
- }
423
- /** A copy of the underlying plain chord object. */
424
- get data() {
425
- return copyChord(this.#data);
426
- }
427
- /** The carried key context, if any. */
428
- get key() {
429
- return this.#key;
430
- }
431
- /**
432
- * A copy of this chord carrying the given key context.
433
- *
434
- * @param key The key context to attach.
435
- * @returns The new chord.
436
- */
437
- withKey(key) {
438
- return new _Chord(this.#data, key);
439
- }
440
- /**
441
- * The chord's sorted, deduplicated pitch classes.
442
- *
443
- * @returns Pitch classes ascending in [0, 11].
444
- */
445
- pitchClasses() {
446
- return chordPitchClasses(this.#data);
447
- }
448
- /**
449
- * The chord's Roman numeral in a key.
450
- *
451
- * @param key Key to analyze in; falls back to the carried context.
452
- * @returns The Roman numeral string.
453
- * @throws If no key is given and none is carried.
454
- */
455
- roman(key) {
456
- return chordToRoman(this.#data, this.#resolveKey(key).scale);
457
- }
458
- /**
459
- * The chord's harmonic function (tonic / subdominant / dominant) in a key.
460
- *
461
- * @param key Key to analyze in; falls back to the carried context.
462
- * @returns The harmonic function.
463
- * @throws If no key is given and none is carried.
464
- */
465
- function(key) {
466
- return functionOf(this.#data, this.#resolveKey(key).scale);
467
- }
468
- /**
469
- * Full functional analysis: function, borrowing, and Roman numeral.
470
- *
471
- * @param key Key to analyze in; falls back to the carried context.
472
- * @returns The chord analysis.
473
- * @throws If no key is given and none is carried.
474
- */
475
- analyze(key) {
476
- return analyzeChord(this.#data, this.#resolveKey(key).scale);
477
- }
478
- /**
479
- * Whether the chord is borrowed from the parallel mode (modal interchange).
480
- *
481
- * @param key Key to analyze in; falls back to the carried context.
482
- * @returns True if the chord is borrowed.
483
- * @throws If no key is given and none is carried.
484
- */
485
- isBorrowed(key) {
486
- return isBorrowedChord(this.#data, this.#resolveKey(key).scale);
487
- }
488
- /**
489
- * The origin of a non-diatonic chord (parallel mode or Neapolitan), or null.
490
- *
491
- * @param key Key to analyze in; falls back to the carried context.
492
- * @returns The borrowing source, or null.
493
- * @throws If no key is given and none is carried.
494
- */
495
- borrowedSource(key) {
496
- return borrowedSource(this.#data, this.#resolveKey(key).scale);
497
- }
498
- /**
499
- * The chord rendered as a lead-sheet symbol (e.g. `'Cmaj7'`, `'F#m7'`, `'C/G'`).
500
- *
501
- * @param opts Set `flats: true` to spell the root/bass with flats.
502
- * @returns The chord symbol.
503
- */
504
- symbol(opts) {
505
- return formatChordSymbol(this.#data, opts);
506
- }
507
- /**
508
- * Realize the chord as one MIDI pitch per voice, ascending.
509
- *
510
- * @param opts Voicing options; defaults to four SATB voices.
511
- * @returns MIDI pitches, ascending, one per voice.
512
- * @throws If no voicing fits the given ranges.
513
- */
514
- voice(opts) {
515
- return voiceChord(this.#data, opts);
516
- }
517
- /**
518
- * Realize the chord as a single styled voicing (`close`, `drop2`, `drop3`,
519
- * `shell`, or `rootless`), optionally constraining the top voice.
520
- *
521
- * @param opts Styled-voicing options; defaults to a close-position voicing.
522
- * @returns MIDI pitches, ascending.
523
- */
524
- styledVoicing(opts) {
525
- return voiceChordStyled(this.#data, opts);
526
- }
527
- /**
528
- * The negative-harmony mirror of the chord about the key's tonic–dominant
529
- * axis (major becomes minor and vice versa).
530
- *
531
- * @param key Key providing the reflection axis; falls back to the carried
532
- * context.
533
- * @returns The mirrored chord, keeping any key context.
534
- * @throws If no key is given and none is carried.
535
- */
536
- negativeHarmony(key) {
537
- const resolved = this.#resolveKey(key);
538
- return new _Chord(negativeHarmonyMirror(this.#data, resolved.scale), key ?? this.#key);
539
- }
540
- /**
541
- * The n-th inversion: a copy whose bass is the chord tone `n` steps above the
542
- * root in the interval template (`invert(1)` puts the third in the bass).
543
- * `n` wraps around the template length; negative values count backwards.
544
- *
545
- * `invert(0)` (and any `n` that wraps to it) is root position, so it carries
546
- * no slash bass and equals the original chord.
547
- *
548
- * @param n The inversion number.
549
- * @returns The inverted chord, keeping any key context.
550
- * @throws If the chord has no intervals.
551
- */
552
- invert(n) {
553
- const intervals = this.#data.intervals;
554
- const length = intervals.length;
555
- if (length === 0) {
556
- throw new Error("cannot invert a chord with no intervals");
557
- }
558
- const index = (n % length + length) % length;
559
- const data = copyChord(this.#data);
560
- if (index === 0) {
561
- delete data.bassPc;
562
- delete data.bassSpelling;
563
- } else {
564
- data.bassPc = mod12(this.#data.rootPc + (intervals[index] ?? 0));
565
- const rootSpelling = data.rootSpelling ?? (this.#key ? spellPitchClass(data.rootPc, this.#key.tonic.data, this.#key.scale) : spellPitchClassBare(data.rootPc, "sharp"));
566
- const bassSpelling = spellChordFromRoot(data, rootSpelling)[index];
567
- if (bassSpelling !== void 0) {
568
- data.bassSpelling = bassSpelling;
569
- }
570
- }
571
- return new _Chord(data, this.#key);
572
- }
573
- /**
574
- * The named scales that fit over this chord, best fit first, rooted on the
575
- * chord root.
576
- *
577
- * @returns The matching scales.
578
- */
579
- scales() {
580
- return chordScales(this.#data);
581
- }
582
- /**
583
- * The available tensions (usable non-chord, non-avoid scale tones) of a
584
- * scale over this chord.
585
- *
586
- * @param scaleName A named scale, rooted on the chord root.
587
- * @returns Tension pitch classes, ascending in [0, 11].
588
- */
589
- tensions(scaleName) {
590
- return availableTensions(this.#data, scaleName);
591
- }
592
- /**
593
- * The avoid notes (scale tones a semitone above a chord tone) of a scale
594
- * over this chord.
595
- *
596
- * @param scaleName A named scale, rooted on the chord root.
597
- * @returns Avoid-note pitch classes, ascending in [0, 11].
598
- */
599
- avoidNotes(scaleName) {
600
- return avoidNotes(this.#data, scaleName);
601
- }
602
- /**
603
- * Spell the chord tones with letter names, root first, in the key's spelling.
604
- *
605
- * @param key Key providing the spelled tonic; falls back to the carried
606
- * context.
607
- * @returns Spelled octave-less notes in the chord's own (tertian) order.
608
- * @throws If no key is given and none is carried.
609
- */
610
- spell(key) {
611
- const resolved = this.#resolveKey(key);
612
- return spellChord(this.#data, resolved.tonic.data, resolved.scale).map(
613
- (note) => new Note(note)
614
- );
615
- }
616
- /**
617
- * Start a progression with this chord followed by others, carrying this
618
- * chord's key context (if any).
619
- *
620
- * @param others The chords following this one.
621
- * @returns The progression.
622
- */
623
- progressionTo(...others) {
624
- return new Progression([this, ...others], this.#key);
625
- }
626
- /**
627
- * Whether another chord has the same root, quality, intervals, and bass.
628
- * Key context is not compared.
629
- *
630
- * @param other The chord to compare.
631
- * @returns True if the chord data is identical.
632
- */
633
- equals(other) {
634
- const a = this.#data;
635
- const b = other.#data;
636
- return a.rootPc === b.rootPc && a.quality === b.quality && a.bassPc === b.bassPc && a.intervals.length === b.intervals.length && a.intervals.every((interval, i) => interval === b.intervals[i]);
637
- }
638
- /**
639
- * The plain chord data, for JSON serialization.
640
- *
641
- * @returns A copy of the underlying plain chord object.
642
- */
643
- toJSON() {
644
- return this.data;
645
- }
646
- /** Resolve the key for an analysis method: explicit first, then carried. */
647
- #resolveKey(key) {
648
- const resolved = key ?? this.#key;
649
- if (resolved === void 0) {
650
- throw new Error("chord has no key context; pass a Key or attach one with withKey()");
651
- }
652
- return resolved;
653
- }
654
- };
655
-
656
- // src/model/interval.ts
657
- var Interval = class _Interval {
658
- #number;
659
- #quality;
660
- #semitones;
661
- constructor(numberValue, quality, semitones) {
662
- this.#number = numberValue;
663
- this.#quality = quality;
664
- this.#semitones = semitones;
665
- }
666
- /**
667
- * The spelled interval between two notes.
668
- *
669
- * @param a The first note.
670
- * @param b The second note.
671
- * @returns The interval from `a` to `b`.
672
- */
673
- static between(a, b) {
674
- const spelled = a.intervalTo(b);
675
- return new _Interval(spelled.number, spelled.quality, spelled.semitones);
676
- }
677
- /**
678
- * Build an interval from explicit components.
679
- *
680
- * @param numberValue Diatonic size: 1 = unison, 2 = second, ... 8 = octave.
681
- * @param quality Quality label: `'P'`, `'M'`, `'m'`, or repeated `'A'`/`'d'`.
682
- * @param semitones Signed semitone span.
683
- * @returns The interval.
684
- */
685
- static of(numberValue, quality, semitones) {
686
- return new _Interval(numberValue, quality, semitones);
687
- }
688
- /** Diatonic size: 1 = unison, 2 = second, ... 8 = octave, and beyond. */
689
- get number() {
690
- return this.#number;
691
- }
692
- /** Quality label: `'P'`, `'M'`, `'m'`, or repeated `'A'`/`'d'`. */
693
- get quality() {
694
- return this.#quality;
695
- }
696
- /** Signed semitone span. */
697
- get semitones() {
698
- return this.#semitones;
699
- }
700
- /** A readable label composed of quality and number, e.g. `'P5'` or `'M3'`. */
701
- get name() {
702
- return `${this.#quality}${this.#number}`;
703
- }
704
- /**
705
- * The plain interval data, for JSON serialization.
706
- *
707
- * Private class fields do not serialize, so an explicit `toJSON` keeps
708
- * `JSON.stringify(interval)` from collapsing to `{}`.
709
- *
710
- * @returns The diatonic number, quality, and semitone span.
711
- */
712
- toJSON() {
713
- return { number: this.#number, quality: this.#quality, semitones: this.#semitones };
714
- }
715
- };
716
-
717
- // src/model/key.ts
718
- function resolveTonic(root, spelling) {
719
- return typeof root === "string" ? Note.of(root) : new Note(spellPitchClassBare(root, spelling));
720
- }
721
- function accidentalLoad(tonic, scale) {
722
- return spellScale(tonic, scale).reduce((sum, note) => sum + Math.abs(note.alter), 0);
723
- }
724
- function bestTonicForScale(rootPc, scale) {
725
- const sharp = spellPitchClassBare(rootPc, "sharp");
726
- const flat = spellPitchClassBare(rootPc, "flat");
727
- if (sharp.letter === flat.letter && sharp.alter === flat.alter) {
728
- return new Note(sharp);
729
- }
730
- return accidentalLoad(flat, scale) <= accidentalLoad(sharp, scale) ? new Note(flat) : new Note(sharp);
731
- }
732
- var Key = class _Key {
733
- #scale;
734
- #tonic;
735
- /**
736
- * Wrap a key/scale and its spelled tonic.
737
- *
738
- * @param scale The key/scale; its root is normalized to a pitch class.
739
- * @param tonic The spelled tonic anchoring letter-name spelling.
740
- */
741
- constructor(scale, tonic) {
742
- this.#scale = { rootPc: mod12(scale.rootPc), modeMask12: scale.modeMask12 };
743
- this.#tonic = tonic;
744
- }
745
- /**
746
- * A major key.
747
- *
748
- * @param root Tonic as a note name (e.g. `'Eb'`) or a pitch class; a numeric
749
- * root is spelled with whichever accidental side yields the fewest
750
- * accidentals across the scale.
751
- * @returns The major key.
752
- */
753
- static major(root) {
754
- if (typeof root === "string") {
755
- const tonic = Note.of(root);
756
- return new _Key(majorKey(tonic.pitchClass), tonic);
757
- }
758
- const scale = majorKey(root);
759
- return new _Key(scale, bestTonicForScale(root, scale));
760
- }
761
- /**
762
- * A natural-minor key.
763
- *
764
- * @param root Tonic as a note name or a pitch class; a numeric root is
765
- * spelled with whichever accidental side yields the fewest accidentals
766
- * across the scale.
767
- * @returns The minor key.
768
- */
769
- static minor(root) {
770
- if (typeof root === "string") {
771
- const tonic = Note.of(root);
772
- return new _Key(minorKey(tonic.pitchClass), tonic);
773
- }
774
- const scale = minorKey(root);
775
- return new _Key(scale, bestTonicForScale(root, scale));
776
- }
777
- /**
778
- * A key on a named scale (e.g. `'dorian'`, `'harmonicMinor'`).
779
- *
780
- * @param name The scale name, a key of the scale module's named-scale table.
781
- * @param root Tonic as a note name or a pitch class.
782
- * @returns The key.
783
- * @throws If the name is not a known scale.
784
- */
785
- static named(name, root) {
786
- const tonic = resolveTonic(root, "sharp");
787
- return new _Key(scaleByName(name, tonic.pitchClass), tonic);
788
- }
789
- /**
790
- * Wrap an existing `KeyScale`, synthesizing a spelled tonic when none is
791
- * given (flat-preferred for minor-third scales, sharp-preferred otherwise).
792
- *
793
- * @param scale The key/scale to wrap.
794
- * @param tonic Optional spelled tonic.
795
- * @returns The key.
796
- */
797
- static of(scale, tonic) {
798
- const spelled = tonic ?? new Note(spellPitchClassBare(scale.rootPc, isMinorKey(scale) ? "flat" : "sharp"));
799
- return new _Key(scale, spelled);
800
- }
801
- /** A copy of the underlying plain `KeyScale`. */
802
- get scale() {
803
- return { rootPc: this.#scale.rootPc, modeMask12: this.#scale.modeMask12 };
804
- }
805
- /** The spelled tonic. */
806
- get tonic() {
807
- return this.#tonic;
808
- }
809
- /** The tonic pitch class (0..11). */
810
- get rootPc() {
811
- return this.#scale.rootPc;
812
- }
813
- /** Whether the scale has a minor third and no major third. */
814
- get isMinor() {
815
- return isMinorKey(this.#scale);
816
- }
817
- /**
818
- * The scale's pitch classes in ascending scale-degree order (degree 0 first).
819
- *
820
- * @returns One pitch class per scale degree.
821
- */
822
- pitchClasses() {
823
- return scaleTonesInDegreeOrder(this.#scale);
824
- }
825
- /**
826
- * The spelled scale, one note per degree (e.g. C D E F G A B for C major).
827
- *
828
- * @returns Spelled octave-less notes in scale-degree order.
829
- */
830
- notes() {
831
- return spellScale(this.#tonic.data, this.#scale).map((note) => new Note(note));
832
- }
833
- /**
834
- * Alias of {@link Key.notes}.
835
- *
836
- * @returns Spelled octave-less notes in scale-degree order.
837
- */
838
- spell() {
839
- return this.notes();
840
- }
841
- /**
842
- * The spelled scale as letter-name strings.
843
- *
844
- * @returns One name per scale degree.
845
- */
846
- noteNames() {
847
- return this.notes().map((note) => note.name);
848
- }
849
- /**
850
- * Build a chord on a scale degree, carrying this key as context.
851
- *
852
- * With an explicit quality the quality's interval template is attached to the
853
- * degree's diatonic root; without one the scale-correct diatonic triad is
854
- * stacked (e.g. a diminished triad on the leading tone of a major key).
855
- *
856
- * @param degree 0-based scale degree of the chord root.
857
- * @param quality Optional chord quality.
858
- * @returns The chord, with this key attached.
859
- */
860
- chord(degree, quality) {
861
- const data = quality === void 0 ? diatonicTriad(degree, this.#scale) : chordFromDegree(degree, quality, this.#scale);
862
- return new Chord(data, this);
863
- }
864
- /**
865
- * The diatonic triad on a scale degree, carrying this key as context.
866
- *
867
- * @param degree 0-based scale degree of the chord root.
868
- * @returns The triad, with this key attached.
869
- */
870
- diatonicTriad(degree) {
871
- return new Chord(diatonicTriad(degree, this.#scale), this);
872
- }
873
- /**
874
- * The diatonic seventh chord on a scale degree, carrying this key as context.
875
- *
876
- * @param degree 0-based scale degree of the chord root.
877
- * @returns The seventh chord, with this key attached.
878
- */
879
- diatonicSeventh(degree) {
880
- return new Chord(diatonicSeventh(degree, this.#scale), this);
881
- }
882
- /**
883
- * Build the chord denoted by a Roman numeral in this key (including applied
884
- * chords such as `'V7/V'`), carrying this key as context.
885
- *
886
- * @param text The Roman numeral.
887
- * @returns The chord, with this key attached.
888
- * @throws If the numeral is not valid.
889
- */
890
- roman(text) {
891
- return new Chord(romanToChord(text, this.#scale), this);
892
- }
893
- /**
894
- * Whether a pitch belongs to the scale.
895
- *
896
- * @param x A MIDI pitch, bare pitch class, or note.
897
- * @returns True if the pitch class is a scale tone.
898
- */
899
- contains(x) {
900
- return isScaleTone(typeof x === "number" ? x : x.pitchClass, this.#scale);
901
- }
902
- /**
903
- * The plain key data, for JSON serialization.
904
- *
905
- * Private class fields do not serialize, so an explicit `toJSON` keeps
906
- * `JSON.stringify(key)` from collapsing to `{}`. The result pairs the
907
- * `KeyScale` with the spelled tonic, enough to reconstruct the key via
908
- * {@link Key.of}.
909
- *
910
- * @returns The key/scale and its spelled tonic.
911
- */
912
- toJSON() {
913
- return { scale: this.scale, tonic: this.#tonic.data };
914
- }
915
- };
916
-
917
- export {
918
- Note,
919
- Progression,
920
- Chord,
921
- Interval,
922
- Key
923
- };
924
- //# sourceMappingURL=chunk-SGU7SPLK.js.map