@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
@@ -1,331 +0,0 @@
1
- import type { KeyScale } from '../types.js';
2
-
3
- /**
4
- * Build a 12-bit mode mask from a list of semitone offsets above the root.
5
- *
6
- * Bit 0 (the root) is always set, enforcing the `KeyScale` invariant that the
7
- * root is a scale tone even when the offset list omits 0.
8
- *
9
- * @category Scales
10
- */
11
- export function maskFromOffsets(offsets: readonly number[]): number {
12
- let mask = 1;
13
- for (const offset of offsets) {
14
- mask |= 1 << (((offset % 12) + 12) % 12);
15
- }
16
- return mask;
17
- }
18
-
19
- /**
20
- * Mode mask for the major (Ionian) scale: offsets {0, 2, 4, 5, 7, 9, 11}.
21
- *
22
- * @category Scales
23
- */
24
- export const MAJOR_MASK = 0b101010110101;
25
-
26
- /**
27
- * Mode mask for the natural minor (Aeolian) scale: offsets {0, 2, 3, 5, 7, 8, 10}.
28
- *
29
- * @category Scales
30
- */
31
- export const NATURAL_MINOR_MASK = 0b010110101101;
32
-
33
- /**
34
- * Harmonic minor: natural minor with a raised seventh — offsets {0,2,3,5,7,8,11}.
35
- *
36
- * @category Scales
37
- */
38
- export const HARMONIC_MINOR_MASK = maskFromOffsets([0, 2, 3, 5, 7, 8, 11]);
39
-
40
- /**
41
- * Ascending melodic minor: offsets {0,2,3,5,7,9,11}.
42
- *
43
- * @category Scales
44
- */
45
- export const MELODIC_MINOR_MASK = maskFromOffsets([0, 2, 3, 5, 7, 9, 11]);
46
-
47
- /**
48
- * Dorian mode: offsets {0,2,3,5,7,9,10}.
49
- *
50
- * @category Scales
51
- */
52
- export const DORIAN_MASK = maskFromOffsets([0, 2, 3, 5, 7, 9, 10]);
53
-
54
- /**
55
- * Phrygian mode: offsets {0,1,3,5,7,8,10}.
56
- *
57
- * @category Scales
58
- */
59
- export const PHRYGIAN_MASK = maskFromOffsets([0, 1, 3, 5, 7, 8, 10]);
60
-
61
- /**
62
- * Lydian mode: offsets {0,2,4,6,7,9,11}.
63
- *
64
- * @category Scales
65
- */
66
- export const LYDIAN_MASK = maskFromOffsets([0, 2, 4, 6, 7, 9, 11]);
67
-
68
- /**
69
- * Mixolydian mode: offsets {0,2,4,5,7,9,10}.
70
- *
71
- * @category Scales
72
- */
73
- export const MIXOLYDIAN_MASK = maskFromOffsets([0, 2, 4, 5, 7, 9, 10]);
74
-
75
- /**
76
- * Locrian mode: offsets {0,1,3,5,6,8,10}.
77
- *
78
- * @category Scales
79
- */
80
- export const LOCRIAN_MASK = maskFromOffsets([0, 1, 3, 5, 6, 8, 10]);
81
-
82
- /**
83
- * Major pentatonic: offsets {0,2,4,7,9}.
84
- *
85
- * @category Scales
86
- */
87
- export const MAJOR_PENTATONIC_MASK = maskFromOffsets([0, 2, 4, 7, 9]);
88
-
89
- /**
90
- * Minor pentatonic: offsets {0,3,5,7,10}.
91
- *
92
- * @category Scales
93
- */
94
- export const MINOR_PENTATONIC_MASK = maskFromOffsets([0, 3, 5, 7, 10]);
95
-
96
- /**
97
- * Hexatonic blues scale: minor pentatonic plus the flat-fifth — {0,3,5,6,7,10}.
98
- *
99
- * @category Scales
100
- */
101
- export const BLUES_MASK = maskFromOffsets([0, 3, 5, 6, 7, 10]);
102
-
103
- /**
104
- * Whole-tone scale: offsets {0,2,4,6,8,10}.
105
- *
106
- * @category Scales
107
- */
108
- export const WHOLE_TONE_MASK = maskFromOffsets([0, 2, 4, 6, 8, 10]);
109
-
110
- /**
111
- * Octatonic (half-step first): offsets {0,1,3,4,6,7,9,10}.
112
- *
113
- * @category Scales
114
- */
115
- export const OCTATONIC_HALF_WHOLE_MASK = maskFromOffsets([0, 1, 3, 4, 6, 7, 9, 10]);
116
-
117
- /**
118
- * Octatonic (whole-step first): offsets {0,2,3,5,6,8,9,11}.
119
- *
120
- * @category Scales
121
- */
122
- export const OCTATONIC_WHOLE_HALF_MASK = maskFromOffsets([0, 2, 3, 5, 6, 8, 9, 11]);
123
-
124
- /**
125
- * Chromatic scale: all twelve pitch classes.
126
- *
127
- * @category Scales
128
- */
129
- export const CHROMATIC_MASK = 0b111111111111;
130
-
131
- /**
132
- * Named scale masks addressable by {@link scaleByName}.
133
- *
134
- * @category Scales
135
- */
136
- export const NAMED_SCALES: Record<string, number> = {
137
- major: MAJOR_MASK,
138
- ionian: MAJOR_MASK,
139
- naturalMinor: NATURAL_MINOR_MASK,
140
- aeolian: NATURAL_MINOR_MASK,
141
- harmonicMinor: HARMONIC_MINOR_MASK,
142
- melodicMinor: MELODIC_MINOR_MASK,
143
- dorian: DORIAN_MASK,
144
- phrygian: PHRYGIAN_MASK,
145
- lydian: LYDIAN_MASK,
146
- mixolydian: MIXOLYDIAN_MASK,
147
- locrian: LOCRIAN_MASK,
148
- majorPentatonic: MAJOR_PENTATONIC_MASK,
149
- minorPentatonic: MINOR_PENTATONIC_MASK,
150
- blues: BLUES_MASK,
151
- wholeTone: WHOLE_TONE_MASK,
152
- octatonicHalfWhole: OCTATONIC_HALF_WHOLE_MASK,
153
- octatonicWholeHalf: OCTATONIC_WHOLE_HALF_MASK,
154
- chromatic: CHROMATIC_MASK,
155
- };
156
-
157
- /**
158
- * Build a `KeyScale` for a major key on the given root pitch class.
159
- *
160
- * @example
161
- * ```ts
162
- * import { majorKey } from '@libraz/libcantus';
163
- * const cMajor = majorKey(0); // C major: { rootPc: 0, modeMask12: MAJOR_MASK }
164
- * ```
165
- *
166
- * @category Scales
167
- */
168
- export function majorKey(rootPc: number): KeyScale {
169
- return { rootPc: ((rootPc % 12) + 12) % 12, modeMask12: MAJOR_MASK };
170
- }
171
-
172
- /**
173
- * Build a `KeyScale` for a natural-minor key on the given root pitch class.
174
- *
175
- * @example
176
- * ```ts
177
- * import { minorKey } from '@libraz/libcantus';
178
- * const aMinor = minorKey(9); // A natural minor: { rootPc: 9, modeMask12: NATURAL_MINOR_MASK }
179
- * ```
180
- *
181
- * @category Scales
182
- */
183
- export function minorKey(rootPc: number): KeyScale {
184
- return { rootPc: ((rootPc % 12) + 12) % 12, modeMask12: NATURAL_MINOR_MASK };
185
- }
186
-
187
- /**
188
- * Build a `KeyScale` from a named scale (see {@link NAMED_SCALES}).
189
- *
190
- * @param name The scale name, e.g. `'dorian'` or `'harmonicMinor'`.
191
- * @param rootPc The root pitch class.
192
- * @returns The key/scale.
193
- * @throws If the name is not a known scale.
194
- *
195
- * @example
196
- * ```ts
197
- * import { scaleByName } from '@libraz/libcantus';
198
- * const dDorian = scaleByName('dorian', 2); // D Dorian, rootPc 2
199
- * ```
200
- *
201
- * @category Scales
202
- */
203
- export function scaleByName(name: string, rootPc: number): KeyScale {
204
- const mask = NAMED_SCALES[name];
205
- if (mask === undefined) {
206
- throw new Error(`Unknown scale: ${name}`);
207
- }
208
- return { rootPc: ((rootPc % 12) + 12) % 12, modeMask12: mask };
209
- }
210
-
211
- /** Reduce a pitch (or pitch class) to a pitch class in [0, 11]. */
212
- function pitchClass(pitch: number): number {
213
- return ((Math.trunc(pitch) % 12) + 12) % 12;
214
- }
215
-
216
- /** Scale offset of a pitch relative to the key root, in [0, 11]. */
217
- function scaleOffset(pitch: number, key: KeyScale): number {
218
- return (pitchClass(pitch) - pitchClass(key.rootPc) + 12) % 12;
219
- }
220
-
221
- /**
222
- * Test whether a pitch belongs to the scale.
223
- *
224
- * @param pitch MIDI pitch or bare pitch class.
225
- * @param key The key/scale to test against.
226
- * @returns True if the pitch class is a member of the scale.
227
- *
228
- * @example
229
- * ```ts
230
- * import { majorKey, isScaleTone } from '@libraz/libcantus';
231
- * const key = majorKey(0); // C major
232
- * isScaleTone(64, key); // true — E is in C major
233
- * isScaleTone(61, key); // false — C# is not
234
- * ```
235
- *
236
- * @category Scales
237
- */
238
- export function isScaleTone(pitch: number, key: KeyScale): boolean {
239
- return ((key.modeMask12 >> scaleOffset(pitch, key)) & 1) === 1;
240
- }
241
-
242
- /**
243
- * Find the nearest MIDI pitch whose pitch class is in the scale.
244
- *
245
- * The search expands symmetrically outward from `pitch`. On a tie (equal
246
- * distance above and below) the lower pitch is returned.
247
- *
248
- * @param pitch MIDI pitch to snap.
249
- * @param key The key/scale to snap to.
250
- * @returns The nearest in-scale MIDI pitch.
251
- *
252
- * @category Scales
253
- */
254
- export function nearestScaleTone(pitch: number, key: KeyScale): number {
255
- const base = Math.round(pitch);
256
- for (let distance = 0; distance < 12; distance += 1) {
257
- const lower = base - distance;
258
- if (isScaleTone(lower, key)) {
259
- return lower;
260
- }
261
- const higher = base + distance;
262
- if (isScaleTone(higher, key)) {
263
- return higher;
264
- }
265
- }
266
- return base;
267
- }
268
-
269
- /**
270
- * Get the 0-based scale degree of a pitch.
271
- *
272
- * @param pitch MIDI pitch or bare pitch class.
273
- * @param key The key/scale to measure against.
274
- * @returns The 0-based degree, or -1 if the pitch is not in the scale.
275
- *
276
- * @category Scales
277
- */
278
- export function pitchToScaleDegree(pitch: number, key: KeyScale): number {
279
- const offset = scaleOffset(pitch, key);
280
- if (((key.modeMask12 >> offset) & 1) === 0) {
281
- return -1;
282
- }
283
- let degree = 0;
284
- for (let n = 0; n < offset; n += 1) {
285
- if (((key.modeMask12 >> n) & 1) === 1) {
286
- degree += 1;
287
- }
288
- }
289
- return degree;
290
- }
291
-
292
- /**
293
- * List the pitch classes of a key's scale.
294
- *
295
- * @param key The key/scale to enumerate.
296
- * @returns The member pitch classes, sorted ascending in [0, 11].
297
- *
298
- * @category Scales
299
- */
300
- export function diatonicPitchClasses(key: KeyScale): number[] {
301
- const root = pitchClass(key.rootPc);
302
- const pcs: number[] = [];
303
- for (let n = 0; n < 12; n += 1) {
304
- if (((key.modeMask12 >> n) & 1) === 1) {
305
- pcs.push((root + n) % 12);
306
- }
307
- }
308
- return pcs.sort((a, b) => a - b);
309
- }
310
-
311
- /**
312
- * List the pitch classes of a key's scale in ascending scale-degree order.
313
- *
314
- * Degree 0 is the root; degrees follow the mask bits in offset order rather
315
- * than sorted pitch-class order.
316
- *
317
- * @param key The key/scale to enumerate.
318
- * @returns The member pitch classes ordered by scale degree.
319
- *
320
- * @category Scales
321
- */
322
- export function scaleTonesInDegreeOrder(key: KeyScale): number[] {
323
- const root = pitchClass(key.rootPc);
324
- const pcs: number[] = [];
325
- for (let n = 0; n < 12; n += 1) {
326
- if (((key.modeMask12 >> n) & 1) === 1) {
327
- pcs.push((root + n) % 12);
328
- }
329
- }
330
- return pcs;
331
- }