@libraz/libcantus 0.9.0 → 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.
- package/README.md +25 -2
- package/dist/analyze/index.cjs +1697 -0
- package/dist/analyze/index.cjs.map +1 -0
- package/dist/analyze/index.d.cts +429 -0
- package/dist/analyze/index.d.ts +429 -0
- package/dist/analyze/index.js +51 -0
- package/dist/analyze/index.js.map +1 -0
- package/dist/chunk-5HTNMQW4.js +653 -0
- package/dist/chunk-5HTNMQW4.js.map +1 -0
- package/dist/chunk-7Y7WF64D.js +410 -0
- package/dist/chunk-7Y7WF64D.js.map +1 -0
- package/dist/chunk-A4532ZFR.js +259 -0
- package/dist/chunk-A4532ZFR.js.map +1 -0
- package/dist/chunk-BHUT2S5G.js +22 -0
- package/dist/chunk-BHUT2S5G.js.map +1 -0
- package/dist/chunk-CCBLVAPK.js +42 -0
- package/dist/chunk-CCBLVAPK.js.map +1 -0
- package/dist/chunk-COKTX2G5.js +907 -0
- package/dist/chunk-COKTX2G5.js.map +1 -0
- package/dist/chunk-DYWFNC4A.js +152 -0
- package/dist/chunk-DYWFNC4A.js.map +1 -0
- package/dist/chunk-GQKN5KDT.js +159 -0
- package/dist/chunk-GQKN5KDT.js.map +1 -0
- package/dist/chunk-LN7ZZMD2.js +530 -0
- package/dist/chunk-LN7ZZMD2.js.map +1 -0
- package/dist/chunk-MSWFZF7J.js +118 -0
- package/dist/chunk-MSWFZF7J.js.map +1 -0
- package/dist/chunk-R3S2LUBH.js +2722 -0
- package/dist/chunk-R3S2LUBH.js.map +1 -0
- package/dist/chunk-SDM3VJJ5.js +41 -0
- package/dist/chunk-SDM3VJJ5.js.map +1 -0
- package/dist/chunk-XTC3X6MS.js +816 -0
- package/dist/chunk-XTC3X6MS.js.map +1 -0
- package/dist/chunk-ZXW5YIWK.js +55 -0
- package/dist/chunk-ZXW5YIWK.js.map +1 -0
- package/dist/core/index.cjs +432 -0
- package/dist/core/index.cjs.map +1 -0
- package/dist/core/index.d.cts +210 -0
- package/dist/core/index.d.ts +210 -0
- package/dist/core/index.js +73 -0
- package/dist/core/index.js.map +1 -0
- package/dist/function-2bJW1Zp_.d.ts +187 -0
- package/dist/function-r2sh-jOO.d.cts +187 -0
- package/dist/generate/index.cjs +3787 -0
- package/dist/generate/index.cjs.map +1 -0
- package/dist/generate/index.d.cts +980 -0
- package/dist/generate/index.d.ts +980 -0
- package/dist/generate/index.js +52 -0
- package/dist/generate/index.js.map +1 -0
- package/dist/index-BMPxwjwV.d.ts +151 -0
- package/dist/index-BOBXBNwP.d.cts +157 -0
- package/dist/index-BdeQ1r_p.d.cts +56 -0
- package/dist/index-BreoJRw0.d.ts +127 -0
- package/dist/index-CGMZNCx6.d.cts +140 -0
- package/dist/index-CGMZNCx6.d.ts +140 -0
- package/dist/index-CM5W4rcm.d.ts +157 -0
- package/dist/index-CP3wAfEH.d.ts +56 -0
- package/dist/index-Cl7mhOFM.d.cts +164 -0
- package/dist/index-Cl7mhOFM.d.ts +164 -0
- package/dist/index-DZ1M21do.d.cts +127 -0
- package/dist/index-D_ZTUNKp.d.cts +151 -0
- package/dist/index.cjs +5277 -4893
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -2621
- package/dist/index.d.ts +14 -2621
- package/dist/index.js +170 -6152
- package/dist/index.js.map +1 -1
- package/dist/model/index.cjs +2435 -0
- package/dist/model/index.cjs.map +1 -0
- package/dist/model/index.d.cts +630 -0
- package/dist/model/index.d.ts +630 -0
- package/dist/model/index.js +21 -0
- package/dist/model/index.js.map +1 -0
- package/dist/styled-BjXtOFNk.d.cts +282 -0
- package/dist/styled-D7BAx3S3.d.ts +282 -0
- package/dist/theory/index.cjs +1677 -0
- package/dist/theory/index.cjs.map +1 -0
- package/dist/theory/index.d.cts +535 -0
- package/dist/theory/index.d.ts +535 -0
- package/dist/theory/index.js +149 -0
- package/dist/theory/index.js.map +1 -0
- package/dist/types-MGP29r3t.d.cts +30 -0
- package/dist/types-MGP29r3t.d.ts +30 -0
- package/package.json +31 -1
- package/src/analyze/arrange/index.ts +21 -0
- package/src/analyze/arrange/internal.ts +125 -0
- package/src/analyze/arrange/tension.ts +187 -0
- package/src/analyze/arrange/tracks.ts +279 -0
- package/src/{detect → analyze/detect}/index.ts +82 -23
- package/src/analyze/functional/borrowed.ts +84 -0
- package/src/analyze/functional/cadence.ts +66 -0
- package/src/analyze/functional/function.ts +184 -0
- package/src/analyze/functional/index.ts +23 -0
- package/src/analyze/functional/internal.ts +29 -0
- package/src/analyze/functional/roman.ts +393 -0
- package/src/analyze/index.ts +49 -0
- package/src/{timeline → analyze/timeline}/index.ts +87 -24
- package/src/{analysis → analyze/voice}/index.ts +81 -12
- package/src/core/index.ts +47 -0
- package/src/{interval → core/interval}/index.ts +15 -1
- package/src/{meter → core/meter}/index.ts +108 -5
- package/src/{pitch → core/pitch}/index.ts +58 -3
- package/src/{random → core/random}/index.ts +13 -1
- package/src/{tuning → core/tuning}/index.ts +28 -1
- package/src/{bass → generate/bass}/index.ts +66 -17
- package/src/{countermelody → generate/countermelody}/index.ts +54 -24
- package/src/{drums → generate/drums}/fills.ts +31 -20
- package/src/{drums → generate/drums}/index.ts +127 -9
- package/src/{drums → generate/drums}/internal.ts +7 -1
- package/src/{drums → generate/drums}/rng.ts +2 -2
- package/src/{drums → generate/drums}/swing.ts +7 -2
- package/src/{groove → generate/groove}/index.ts +118 -22
- package/src/{harmonize → generate/harmonize}/index.ts +96 -23
- package/src/generate/index.ts +59 -0
- package/src/{motif → generate/motif}/index.ts +94 -17
- package/src/{progression → generate/progression}/index.ts +61 -27
- package/src/{reharmony → generate/reharmony}/index.ts +46 -15
- package/src/{rhythm → generate/rhythm}/index.ts +47 -13
- package/src/index.ts +130 -116
- package/src/model/chord.ts +423 -0
- package/src/model/index.ts +5 -947
- package/src/model/interval.ts +82 -0
- package/src/model/key.ts +266 -0
- package/src/model/note.ts +176 -0
- package/src/model/progression.ts +161 -0
- package/src/model/shared.ts +12 -0
- package/src/{chord → theory/chord}/index.ts +85 -4
- package/src/{chordscale → theory/chordscale}/index.ts +67 -9
- package/src/{counterpoint → theory/counterpoint}/index.ts +23 -2
- package/src/{harmony → theory/harmony}/index.ts +19 -2
- package/src/theory/index.ts +107 -0
- package/src/{safety → theory/safety}/index.ts +59 -12
- package/src/theory/scale/degrees.ts +123 -0
- package/src/theory/scale/index.ts +28 -0
- package/src/theory/scale/key.ts +56 -0
- package/src/theory/scale/masks.ts +153 -0
- package/src/{spelling → theory/spelling}/index.ts +21 -3
- package/src/{symbol → theory/symbol}/index.ts +91 -36
- package/src/theory/voicing/index.ts +5 -0
- package/src/theory/voicing/internal.ts +168 -0
- package/src/theory/voicing/leading.ts +112 -0
- package/src/theory/voicing/satb.ts +195 -0
- package/src/theory/voicing/styled.ts +176 -0
- package/src/arrange/index.ts +0 -409
- package/src/functional/index.ts +0 -602
- package/src/scale/index.ts +0 -215
- package/src/voicing/index.ts +0 -523
- /package/src/{types.ts → core/types.ts} +0 -0
- /package/src/{drums → generate/drums}/beat.ts +0 -0
- /package/src/{drums → generate/drums}/euclid.ts +0 -0
- /package/src/{drums → generate/drums}/ghost.ts +0 -0
- /package/src/{drums → generate/drums}/hihat.ts +0 -0
- /package/src/{drums → generate/drums}/hit.ts +0 -0
- /package/src/{drums → generate/drums}/kick.ts +0 -0
- /package/src/{drums → generate/drums}/percussion.ts +0 -0
package/src/scale/index.ts
DELETED
|
@@ -1,215 +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
|
-
export function maskFromOffsets(offsets: readonly number[]): number {
|
|
10
|
-
let mask = 1;
|
|
11
|
-
for (const offset of offsets) {
|
|
12
|
-
mask |= 1 << (((offset % 12) + 12) % 12);
|
|
13
|
-
}
|
|
14
|
-
return mask;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/** Mode mask for the major (Ionian) scale: offsets {0, 2, 4, 5, 7, 9, 11}. */
|
|
18
|
-
export const MAJOR_MASK = 0b101010110101;
|
|
19
|
-
|
|
20
|
-
/** Mode mask for the natural minor (Aeolian) scale: offsets {0, 2, 3, 5, 7, 8, 10}. */
|
|
21
|
-
export const NATURAL_MINOR_MASK = 0b010110101101;
|
|
22
|
-
|
|
23
|
-
/** Harmonic minor: natural minor with a raised seventh — offsets {0,2,3,5,7,8,11}. */
|
|
24
|
-
export const HARMONIC_MINOR_MASK = maskFromOffsets([0, 2, 3, 5, 7, 8, 11]);
|
|
25
|
-
|
|
26
|
-
/** Ascending melodic minor: offsets {0,2,3,5,7,9,11}. */
|
|
27
|
-
export const MELODIC_MINOR_MASK = maskFromOffsets([0, 2, 3, 5, 7, 9, 11]);
|
|
28
|
-
|
|
29
|
-
/** Dorian mode: offsets {0,2,3,5,7,9,10}. */
|
|
30
|
-
export const DORIAN_MASK = maskFromOffsets([0, 2, 3, 5, 7, 9, 10]);
|
|
31
|
-
|
|
32
|
-
/** Phrygian mode: offsets {0,1,3,5,7,8,10}. */
|
|
33
|
-
export const PHRYGIAN_MASK = maskFromOffsets([0, 1, 3, 5, 7, 8, 10]);
|
|
34
|
-
|
|
35
|
-
/** Lydian mode: offsets {0,2,4,6,7,9,11}. */
|
|
36
|
-
export const LYDIAN_MASK = maskFromOffsets([0, 2, 4, 6, 7, 9, 11]);
|
|
37
|
-
|
|
38
|
-
/** Mixolydian mode: offsets {0,2,4,5,7,9,10}. */
|
|
39
|
-
export const MIXOLYDIAN_MASK = maskFromOffsets([0, 2, 4, 5, 7, 9, 10]);
|
|
40
|
-
|
|
41
|
-
/** Locrian mode: offsets {0,1,3,5,6,8,10}. */
|
|
42
|
-
export const LOCRIAN_MASK = maskFromOffsets([0, 1, 3, 5, 6, 8, 10]);
|
|
43
|
-
|
|
44
|
-
/** Major pentatonic: offsets {0,2,4,7,9}. */
|
|
45
|
-
export const MAJOR_PENTATONIC_MASK = maskFromOffsets([0, 2, 4, 7, 9]);
|
|
46
|
-
|
|
47
|
-
/** Minor pentatonic: offsets {0,3,5,7,10}. */
|
|
48
|
-
export const MINOR_PENTATONIC_MASK = maskFromOffsets([0, 3, 5, 7, 10]);
|
|
49
|
-
|
|
50
|
-
/** Hexatonic blues scale: minor pentatonic plus the flat-fifth — {0,3,5,6,7,10}. */
|
|
51
|
-
export const BLUES_MASK = maskFromOffsets([0, 3, 5, 6, 7, 10]);
|
|
52
|
-
|
|
53
|
-
/** Whole-tone scale: offsets {0,2,4,6,8,10}. */
|
|
54
|
-
export const WHOLE_TONE_MASK = maskFromOffsets([0, 2, 4, 6, 8, 10]);
|
|
55
|
-
|
|
56
|
-
/** Octatonic (half-step first): offsets {0,1,3,4,6,7,9,10}. */
|
|
57
|
-
export const OCTATONIC_HALF_WHOLE_MASK = maskFromOffsets([0, 1, 3, 4, 6, 7, 9, 10]);
|
|
58
|
-
|
|
59
|
-
/** Octatonic (whole-step first): offsets {0,2,3,5,6,8,9,11}. */
|
|
60
|
-
export const OCTATONIC_WHOLE_HALF_MASK = maskFromOffsets([0, 2, 3, 5, 6, 8, 9, 11]);
|
|
61
|
-
|
|
62
|
-
/** Chromatic scale: all twelve pitch classes. */
|
|
63
|
-
export const CHROMATIC_MASK = 0b111111111111;
|
|
64
|
-
|
|
65
|
-
/** Named scale masks addressable by {@link scaleByName}. */
|
|
66
|
-
export const NAMED_SCALES: Record<string, number> = {
|
|
67
|
-
major: MAJOR_MASK,
|
|
68
|
-
ionian: MAJOR_MASK,
|
|
69
|
-
naturalMinor: NATURAL_MINOR_MASK,
|
|
70
|
-
aeolian: NATURAL_MINOR_MASK,
|
|
71
|
-
harmonicMinor: HARMONIC_MINOR_MASK,
|
|
72
|
-
melodicMinor: MELODIC_MINOR_MASK,
|
|
73
|
-
dorian: DORIAN_MASK,
|
|
74
|
-
phrygian: PHRYGIAN_MASK,
|
|
75
|
-
lydian: LYDIAN_MASK,
|
|
76
|
-
mixolydian: MIXOLYDIAN_MASK,
|
|
77
|
-
locrian: LOCRIAN_MASK,
|
|
78
|
-
majorPentatonic: MAJOR_PENTATONIC_MASK,
|
|
79
|
-
minorPentatonic: MINOR_PENTATONIC_MASK,
|
|
80
|
-
blues: BLUES_MASK,
|
|
81
|
-
wholeTone: WHOLE_TONE_MASK,
|
|
82
|
-
octatonicHalfWhole: OCTATONIC_HALF_WHOLE_MASK,
|
|
83
|
-
octatonicWholeHalf: OCTATONIC_WHOLE_HALF_MASK,
|
|
84
|
-
chromatic: CHROMATIC_MASK,
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
/** Build a `KeyScale` for a major key on the given root pitch class. */
|
|
88
|
-
export function majorKey(rootPc: number): KeyScale {
|
|
89
|
-
return { rootPc: ((rootPc % 12) + 12) % 12, modeMask12: MAJOR_MASK };
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/** Build a `KeyScale` for a natural-minor key on the given root pitch class. */
|
|
93
|
-
export function minorKey(rootPc: number): KeyScale {
|
|
94
|
-
return { rootPc: ((rootPc % 12) + 12) % 12, modeMask12: NATURAL_MINOR_MASK };
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Build a `KeyScale` from a named scale (see {@link NAMED_SCALES}).
|
|
99
|
-
*
|
|
100
|
-
* @param name The scale name, e.g. `'dorian'` or `'harmonicMinor'`.
|
|
101
|
-
* @param rootPc The root pitch class.
|
|
102
|
-
* @returns The key/scale.
|
|
103
|
-
* @throws If the name is not a known scale.
|
|
104
|
-
*/
|
|
105
|
-
export function scaleByName(name: string, rootPc: number): KeyScale {
|
|
106
|
-
const mask = NAMED_SCALES[name];
|
|
107
|
-
if (mask === undefined) {
|
|
108
|
-
throw new Error(`Unknown scale: ${name}`);
|
|
109
|
-
}
|
|
110
|
-
return { rootPc: ((rootPc % 12) + 12) % 12, modeMask12: mask };
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/** Reduce a pitch (or pitch class) to a pitch class in [0, 11]. */
|
|
114
|
-
function pitchClass(pitch: number): number {
|
|
115
|
-
return ((Math.trunc(pitch) % 12) + 12) % 12;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/** Scale offset of a pitch relative to the key root, in [0, 11]. */
|
|
119
|
-
function scaleOffset(pitch: number, key: KeyScale): number {
|
|
120
|
-
return (pitchClass(pitch) - pitchClass(key.rootPc) + 12) % 12;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Test whether a pitch belongs to the scale.
|
|
125
|
-
*
|
|
126
|
-
* @param pitch MIDI pitch or bare pitch class.
|
|
127
|
-
* @param key The key/scale to test against.
|
|
128
|
-
* @returns True if the pitch class is a member of the scale.
|
|
129
|
-
*/
|
|
130
|
-
export function isScaleTone(pitch: number, key: KeyScale): boolean {
|
|
131
|
-
return ((key.modeMask12 >> scaleOffset(pitch, key)) & 1) === 1;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* Find the nearest MIDI pitch whose pitch class is in the scale.
|
|
136
|
-
*
|
|
137
|
-
* The search expands symmetrically outward from `pitch`. On a tie (equal
|
|
138
|
-
* distance above and below) the lower pitch is returned.
|
|
139
|
-
*
|
|
140
|
-
* @param pitch MIDI pitch to snap.
|
|
141
|
-
* @param key The key/scale to snap to.
|
|
142
|
-
* @returns The nearest in-scale MIDI pitch.
|
|
143
|
-
*/
|
|
144
|
-
export function nearestScaleTone(pitch: number, key: KeyScale): number {
|
|
145
|
-
const base = Math.round(pitch);
|
|
146
|
-
for (let distance = 0; distance < 12; distance += 1) {
|
|
147
|
-
const lower = base - distance;
|
|
148
|
-
if (isScaleTone(lower, key)) {
|
|
149
|
-
return lower;
|
|
150
|
-
}
|
|
151
|
-
const higher = base + distance;
|
|
152
|
-
if (isScaleTone(higher, key)) {
|
|
153
|
-
return higher;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
return base;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Get the 0-based scale degree of a pitch.
|
|
161
|
-
*
|
|
162
|
-
* @param pitch MIDI pitch or bare pitch class.
|
|
163
|
-
* @param key The key/scale to measure against.
|
|
164
|
-
* @returns The 0-based degree, or -1 if the pitch is not in the scale.
|
|
165
|
-
*/
|
|
166
|
-
export function pitchToScaleDegree(pitch: number, key: KeyScale): number {
|
|
167
|
-
const offset = scaleOffset(pitch, key);
|
|
168
|
-
if (((key.modeMask12 >> offset) & 1) === 0) {
|
|
169
|
-
return -1;
|
|
170
|
-
}
|
|
171
|
-
let degree = 0;
|
|
172
|
-
for (let n = 0; n < offset; n += 1) {
|
|
173
|
-
if (((key.modeMask12 >> n) & 1) === 1) {
|
|
174
|
-
degree += 1;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
return degree;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
* List the pitch classes of a key's scale.
|
|
182
|
-
*
|
|
183
|
-
* @param key The key/scale to enumerate.
|
|
184
|
-
* @returns The member pitch classes, sorted ascending in [0, 11].
|
|
185
|
-
*/
|
|
186
|
-
export function diatonicPitchClasses(key: KeyScale): number[] {
|
|
187
|
-
const root = pitchClass(key.rootPc);
|
|
188
|
-
const pcs: number[] = [];
|
|
189
|
-
for (let n = 0; n < 12; n += 1) {
|
|
190
|
-
if (((key.modeMask12 >> n) & 1) === 1) {
|
|
191
|
-
pcs.push((root + n) % 12);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
return pcs.sort((a, b) => a - b);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* List the pitch classes of a key's scale in ascending scale-degree order.
|
|
199
|
-
*
|
|
200
|
-
* Degree 0 is the root; degrees follow the mask bits in offset order rather
|
|
201
|
-
* than sorted pitch-class order.
|
|
202
|
-
*
|
|
203
|
-
* @param key The key/scale to enumerate.
|
|
204
|
-
* @returns The member pitch classes ordered by scale degree.
|
|
205
|
-
*/
|
|
206
|
-
export function scaleTonesInDegreeOrder(key: KeyScale): number[] {
|
|
207
|
-
const root = pitchClass(key.rootPc);
|
|
208
|
-
const pcs: number[] = [];
|
|
209
|
-
for (let n = 0; n < 12; n += 1) {
|
|
210
|
-
if (((key.modeMask12 >> n) & 1) === 1) {
|
|
211
|
-
pcs.push((root + n) % 12);
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
return pcs;
|
|
215
|
-
}
|