@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.
- package/README.md +15 -0
- 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 +3016 -2984
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -3982
- package/dist/index.d.ts +14 -3982
- package/dist/index.js +170 -6504
- 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 +27 -2
- 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 +4 -4
- 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/{functional/index.ts → analyze/functional/roman.ts} +9 -327
- package/src/analyze/index.ts +49 -0
- package/src/{timeline → analyze/timeline}/index.ts +7 -11
- package/src/{analysis → analyze/voice}/index.ts +8 -5
- package/src/core/index.ts +47 -0
- package/src/{bass → generate/bass}/index.ts +5 -5
- package/src/{countermelody → generate/countermelody}/index.ts +11 -11
- package/src/{drums → generate/drums}/index.ts +2 -2
- package/src/{drums → generate/drums}/rng.ts +2 -2
- package/src/{groove → generate/groove}/index.ts +3 -3
- package/src/{harmonize → generate/harmonize}/index.ts +13 -13
- package/src/generate/index.ts +59 -0
- package/src/{motif → generate/motif}/index.ts +7 -7
- package/src/{progression → generate/progression}/index.ts +11 -25
- package/src/{reharmony → generate/reharmony}/index.ts +11 -11
- package/src/{rhythm → generate/rhythm}/index.ts +2 -2
- package/src/index.ts +130 -117
- package/src/model/chord.ts +423 -0
- package/src/model/index.ts +5 -1096
- 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 +19 -1
- package/src/{counterpoint → theory/counterpoint}/index.ts +2 -2
- package/src/theory/index.ts +107 -0
- package/src/{safety → theory/safety}/index.ts +1 -1
- 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 +3 -3
- package/src/{symbol → theory/symbol}/index.ts +8 -1
- 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 -571
- package/src/scale/index.ts +0 -331
- package/src/voicing/index.ts +0 -623
- /package/src/{interval → core/interval}/index.ts +0 -0
- /package/src/{meter → core/meter}/index.ts +0 -0
- /package/src/{pitch → core/pitch}/index.ts +0 -0
- /package/src/{random → core/random}/index.ts +0 -0
- /package/src/{tuning → core/tuning}/index.ts +0 -0
- /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}/fills.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}/internal.ts +0 -0
- /package/src/{drums → generate/drums}/kick.ts +0 -0
- /package/src/{drums → generate/drums}/percussion.ts +0 -0
- /package/src/{drums → generate/drums}/swing.ts +0 -0
- /package/src/{chordscale → theory/chordscale}/index.ts +0 -0
- /package/src/{harmony → theory/harmony}/index.ts +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,3982 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
* velocity. This is the library-wide interchange shape for note events read
|
|
16
|
-
* from or written to a DAW/MIDI track; the harmonizer's `MelodyNote` and the
|
|
17
|
-
* analysis `VoiceNote` are specializations of it.
|
|
18
|
-
*/
|
|
19
|
-
type NoteEvent = {
|
|
20
|
-
/** MIDI pitch (middle C = 60). */
|
|
21
|
-
pitch: number;
|
|
22
|
-
/** Onset in quarter-note beats, absolute from the start of the timeline. */
|
|
23
|
-
startBeat: number;
|
|
24
|
-
/** Duration in quarter-note beats. */
|
|
25
|
-
durationBeat: number;
|
|
26
|
-
/** MIDI velocity in [0, 127], when known. */
|
|
27
|
-
velocity?: number;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Chord quality identifiers understood by the chord builder.
|
|
32
|
-
*
|
|
33
|
-
* @category Chords
|
|
34
|
-
*/
|
|
35
|
-
type ChordQuality = 'maj' | 'min' | 'dim' | 'aug' | 'maj7' | 'min7' | 'dom7' | 'dim7' | 'm7b5' | 'minMaj7' | 'aug7' | 'augMaj7' | 'majb5' | '6' | 'min6' | '6/9' | 'sus2' | 'sus4' | 'add9' | 'add11' | 'maj9' | 'min9' | 'dom9' | '7b9' | '7#9' | '7#11' | '7b13' | '11' | '13' | '5';
|
|
36
|
-
/**
|
|
37
|
-
* A bare spelled pitch used as an enharmonic hint: a diatonic letter
|
|
38
|
-
* (0..6 = C..B) plus a chromatic alteration (-2 double-flat .. +2 double-sharp).
|
|
39
|
-
* Mirrors the letter/alter half of the pitch module's `Note` without an octave.
|
|
40
|
-
*
|
|
41
|
-
* @category Chords
|
|
42
|
-
*/
|
|
43
|
-
type PitchSpelling = {
|
|
44
|
-
letter: number;
|
|
45
|
-
alter: number;
|
|
46
|
-
};
|
|
47
|
-
/**
|
|
48
|
-
* A chord expressed as a root pitch class plus semitone offsets.
|
|
49
|
-
*
|
|
50
|
-
* `rootSpelling`/`bassSpelling` are optional enharmonic hints recorded by
|
|
51
|
-
* parsers (e.g. `parseChordSymbol('Bb7')`) so formatters can reproduce the
|
|
52
|
-
* original spelling instead of defaulting to sharps. Consumers may ignore
|
|
53
|
-
* them; a hint is only trusted when its pitch class still matches the
|
|
54
|
-
* corresponding `rootPc`/`bassPc`.
|
|
55
|
-
*
|
|
56
|
-
* @category Chords
|
|
57
|
-
*/
|
|
58
|
-
type Chord$1 = {
|
|
59
|
-
rootPc: number;
|
|
60
|
-
quality: ChordQuality;
|
|
61
|
-
intervals: number[];
|
|
62
|
-
bassPc?: number;
|
|
63
|
-
rootSpelling?: PitchSpelling;
|
|
64
|
-
bassSpelling?: PitchSpelling;
|
|
65
|
-
};
|
|
66
|
-
/**
|
|
67
|
-
* All chord qualities the builder understands, longest templates last.
|
|
68
|
-
*
|
|
69
|
-
* @category Chords
|
|
70
|
-
*/
|
|
71
|
-
declare function chordQualities(): ChordQuality[];
|
|
72
|
-
/**
|
|
73
|
-
* Build a chord rooted on a diatonic scale degree.
|
|
74
|
-
*
|
|
75
|
-
* The root pitch class is the degree's diatonic pitch class in `key`; the
|
|
76
|
-
* quality's interval template is attached unchanged. Degrees beyond the scale
|
|
77
|
-
* length wrap around.
|
|
78
|
-
*
|
|
79
|
-
* @param degree 0-based scale degree of the chord root.
|
|
80
|
-
* @param ext Chord quality to apply.
|
|
81
|
-
* @param key Key context supplying the diatonic root.
|
|
82
|
-
* @returns The constructed chord.
|
|
83
|
-
*
|
|
84
|
-
* @category Chords
|
|
85
|
-
*/
|
|
86
|
-
declare function chordFromDegree(degree: number, ext: ChordQuality, key: KeyScale): Chord$1;
|
|
87
|
-
/**
|
|
88
|
-
* Build a chord from an explicit root pitch class and quality.
|
|
89
|
-
*
|
|
90
|
-
* @param rootPc Root pitch class (0..11).
|
|
91
|
-
* @param quality Chord quality supplying the interval template.
|
|
92
|
-
* @param bassPc Optional slash-chord bass pitch class.
|
|
93
|
-
* @returns The constructed chord.
|
|
94
|
-
*
|
|
95
|
-
* @example
|
|
96
|
-
* ```ts
|
|
97
|
-
* import { makeChord } from '@libraz/libcantus';
|
|
98
|
-
* const cmaj7 = makeChord(0, 'maj7');
|
|
99
|
-
* // { rootPc: 0, quality: 'maj7', intervals: [0, 4, 7, 11] }
|
|
100
|
-
* ```
|
|
101
|
-
*
|
|
102
|
-
* @category Chords
|
|
103
|
-
*/
|
|
104
|
-
declare function makeChord(rootPc: number, quality: ChordQuality, bassPc?: number): Chord$1;
|
|
105
|
-
/**
|
|
106
|
-
* Get the sorted, deduplicated pitch classes of a chord.
|
|
107
|
-
*
|
|
108
|
-
* @param chord The chord to enumerate.
|
|
109
|
-
* @returns The chord's pitch classes, sorted ascending in [0, 11].
|
|
110
|
-
*
|
|
111
|
-
* @example
|
|
112
|
-
* ```ts
|
|
113
|
-
* import { makeChord, chordPitchClasses } from '@libraz/libcantus';
|
|
114
|
-
* chordPitchClasses(makeChord(0, 'maj7')); // [0, 4, 7, 11]
|
|
115
|
-
* ```
|
|
116
|
-
*
|
|
117
|
-
* @category Chords
|
|
118
|
-
*/
|
|
119
|
-
declare function chordPitchClasses(chord: Chord$1): number[];
|
|
120
|
-
/**
|
|
121
|
-
* Determine a pitch's harmonic role within a chord.
|
|
122
|
-
*
|
|
123
|
-
* The role is derived from the pitch's interval above the chord root, reduced
|
|
124
|
-
* modulo 12. A major sixth (9) reads as a `sixth` for sixth chords but as a
|
|
125
|
-
* `seventh` for a diminished-seventh chord; ninths and other tensions have no
|
|
126
|
-
* basic role and return null.
|
|
127
|
-
*
|
|
128
|
-
* @param pitch MIDI pitch or bare pitch class.
|
|
129
|
-
* @param chord The chord providing the root reference.
|
|
130
|
-
* @returns The chord-tone role, or null if the pitch has no basic role.
|
|
131
|
-
*
|
|
132
|
-
* @category Chords
|
|
133
|
-
*/
|
|
134
|
-
declare function chordToneRole(pitch: number, chord: Chord$1): 'root' | 'third' | 'fifth' | 'sixth' | 'seventh' | null;
|
|
135
|
-
/**
|
|
136
|
-
* Build the diatonic triad rooted on a scale degree by stacking scale thirds.
|
|
137
|
-
*
|
|
138
|
-
* Unlike {@link chordFromDegree}, the chord quality is derived from the scale
|
|
139
|
-
* rather than supplied, so degrees yield their scale-correct triads (e.g. a
|
|
140
|
-
* diminished triad on the leading tone of a major key). Intended for heptatonic
|
|
141
|
-
* scales; other scales stack by scale step regardless.
|
|
142
|
-
*
|
|
143
|
-
* @param degree 0-based scale degree of the chord root.
|
|
144
|
-
* @param key Key/scale context.
|
|
145
|
-
* @returns The diatonic triad.
|
|
146
|
-
*
|
|
147
|
-
* @example
|
|
148
|
-
* ```ts
|
|
149
|
-
* import { majorKey, diatonicTriad } from '@libraz/libcantus';
|
|
150
|
-
* const tonic = diatonicTriad(0, majorKey(0)); // C major triad (degree 0 of C major)
|
|
151
|
-
* ```
|
|
152
|
-
*
|
|
153
|
-
* @category Chords
|
|
154
|
-
*/
|
|
155
|
-
declare function diatonicTriad(degree: number, key: KeyScale): Chord$1;
|
|
156
|
-
/**
|
|
157
|
-
* Build the diatonic seventh chord rooted on a scale degree.
|
|
158
|
-
*
|
|
159
|
-
* @param degree 0-based scale degree of the chord root.
|
|
160
|
-
* @param key Key/scale context.
|
|
161
|
-
* @returns The diatonic seventh chord.
|
|
162
|
-
*
|
|
163
|
-
* @category Chords
|
|
164
|
-
*/
|
|
165
|
-
declare function diatonicSeventh(degree: number, key: KeyScale): Chord$1;
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* Severity policy: `strict` counterpoint vs. lenient `pop` voice-leading.
|
|
169
|
-
*
|
|
170
|
-
* @category Arrangement & Analysis
|
|
171
|
-
*/
|
|
172
|
-
type SafetyProfile = 'strict' | 'pop';
|
|
173
|
-
/**
|
|
174
|
-
* Overall placeability verdict for a candidate pitch.
|
|
175
|
-
*
|
|
176
|
-
* @category Arrangement & Analysis
|
|
177
|
-
*/
|
|
178
|
-
declare enum NoteSafety {
|
|
179
|
-
Safe = 0,
|
|
180
|
-
Warning = 1,
|
|
181
|
-
Dissonant = 2
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* Bit flags describing why a pitch received its verdict.
|
|
185
|
-
*
|
|
186
|
-
* @category Arrangement & Analysis
|
|
187
|
-
*/
|
|
188
|
-
declare enum ReasonFlag {
|
|
189
|
-
ChordTone = 1,
|
|
190
|
-
Tension = 2,
|
|
191
|
-
AvoidNote = 4,
|
|
192
|
-
ScaleTone = 8,
|
|
193
|
-
NonScale = 16,
|
|
194
|
-
OutOfRange = 32,
|
|
195
|
-
Tritone = 64,
|
|
196
|
-
LargeLeap = 128,
|
|
197
|
-
MinorSecond = 256,
|
|
198
|
-
MajorSeventh = 512,
|
|
199
|
-
VerticalDissonance = 1024,
|
|
200
|
-
ParallelPerfect = 2048,
|
|
201
|
-
HiddenParallel = 4096,
|
|
202
|
-
VoiceCrossing = 8192,
|
|
203
|
-
Suspension = 16384,
|
|
204
|
-
NeedsResolution = 32768
|
|
205
|
-
}
|
|
206
|
-
/**
|
|
207
|
-
* A neighbouring voice's current and previous pitch.
|
|
208
|
-
*
|
|
209
|
-
* @category Arrangement & Analysis
|
|
210
|
-
*/
|
|
211
|
-
type VoiceSnapshot = {
|
|
212
|
-
pitch: number;
|
|
213
|
-
prevPitch?: number;
|
|
214
|
-
};
|
|
215
|
-
/**
|
|
216
|
-
* Everything needed to evaluate one candidate pitch.
|
|
217
|
-
*
|
|
218
|
-
* @category Arrangement & Analysis
|
|
219
|
-
*/
|
|
220
|
-
type SafetyQuery = {
|
|
221
|
-
profile: SafetyProfile;
|
|
222
|
-
candidatePitch: number;
|
|
223
|
-
prevPitch?: number;
|
|
224
|
-
chord: Chord$1 | null;
|
|
225
|
-
key: KeyScale;
|
|
226
|
-
otherVoices: VoiceSnapshot[];
|
|
227
|
-
strongBeat: boolean;
|
|
228
|
-
vocalLow?: number;
|
|
229
|
-
vocalHigh?: number;
|
|
230
|
-
};
|
|
231
|
-
/**
|
|
232
|
-
* The verdict, reason flags, and optional resolution guidance.
|
|
233
|
-
*
|
|
234
|
-
* @category Arrangement & Analysis
|
|
235
|
-
*/
|
|
236
|
-
type SafetyResult = {
|
|
237
|
-
safety: NoteSafety;
|
|
238
|
-
reasons: number;
|
|
239
|
-
resolveTo?: number;
|
|
240
|
-
suggestions?: number[];
|
|
241
|
-
rationale?: string;
|
|
242
|
-
};
|
|
243
|
-
/**
|
|
244
|
-
* Evaluate the safety of placing a candidate pitch in a voice.
|
|
245
|
-
*
|
|
246
|
-
* Reasons are merged from harmonic context (chord tone / tension / avoid / scale)
|
|
247
|
-
* and counterpoint (vertical dissonance, parallels, voice crossing). The `strict`
|
|
248
|
-
* profile treats avoid notes and parallels as dissonant; `pop` treats them as
|
|
249
|
-
* warnings. The final verdict is the worst severity among the reasons.
|
|
250
|
-
*
|
|
251
|
-
* @param q The candidate and its harmonic/voice-leading context.
|
|
252
|
-
* @returns The verdict, reason bitmask, and optional resolution guidance.
|
|
253
|
-
* @example
|
|
254
|
-
* ```ts
|
|
255
|
-
* import { evaluateSafety, makeChord, majorKey, NoteSafety } from '@libraz/libcantus';
|
|
256
|
-
* const result = evaluateSafety({
|
|
257
|
-
* profile: 'pop',
|
|
258
|
-
* candidatePitch: 60, // C over a C major chord
|
|
259
|
-
* chord: makeChord(0, 'maj'),
|
|
260
|
-
* key: majorKey(0),
|
|
261
|
-
* otherVoices: [],
|
|
262
|
-
* strongBeat: true,
|
|
263
|
-
* });
|
|
264
|
-
* result.safety === NoteSafety.Safe; // true — C is a chord tone
|
|
265
|
-
* ```
|
|
266
|
-
* @category Arrangement & Analysis
|
|
267
|
-
*/
|
|
268
|
-
declare function evaluateSafety(q: SafetyQuery): SafetyResult;
|
|
269
|
-
/**
|
|
270
|
-
* Enumerate placeable pitches in a range, chord tones first, descending.
|
|
271
|
-
*
|
|
272
|
-
* @param q The safety context minus the candidate pitch.
|
|
273
|
-
* @param pitchLow Lowest MIDI pitch to consider (inclusive).
|
|
274
|
-
* @param pitchHigh Highest MIDI pitch to consider (inclusive).
|
|
275
|
-
* @returns Placeable pitches (non-dissonant), chord tones before others, each group descending.
|
|
276
|
-
* @example
|
|
277
|
-
* ```ts
|
|
278
|
-
* import { enumerateSafePitches, makeChord, majorKey } from '@libraz/libcantus';
|
|
279
|
-
* const pitches = enumerateSafePitches(
|
|
280
|
-
* { profile: 'pop', chord: makeChord(0, 'maj'), key: majorKey(0), otherVoices: [], strongBeat: true },
|
|
281
|
-
* 60,
|
|
282
|
-
* 72,
|
|
283
|
-
* );
|
|
284
|
-
* pitches; // placeable pitches in [60, 72], chord tones first, each group descending
|
|
285
|
-
* ```
|
|
286
|
-
* @category Arrangement & Analysis
|
|
287
|
-
*/
|
|
288
|
-
declare function enumerateSafePitches(q: Omit<SafetyQuery, 'candidatePitch'>, pitchLow: number, pitchHigh: number): number[];
|
|
289
|
-
|
|
290
|
-
/**
|
|
291
|
-
* A theory annotation attached to a note.
|
|
292
|
-
*
|
|
293
|
-
* @category Arrangement & Analysis
|
|
294
|
-
*/
|
|
295
|
-
type TheoryLabel = {
|
|
296
|
-
kind: 'chordTone';
|
|
297
|
-
role: 'root' | 'third' | 'fifth' | 'sixth' | 'seventh';
|
|
298
|
-
} | {
|
|
299
|
-
kind: 'tension';
|
|
300
|
-
degree: 9 | 11 | 13;
|
|
301
|
-
} | {
|
|
302
|
-
kind: 'avoid';
|
|
303
|
-
} | {
|
|
304
|
-
kind: 'passing';
|
|
305
|
-
} | {
|
|
306
|
-
kind: 'neighbor';
|
|
307
|
-
} | {
|
|
308
|
-
kind: 'suspension';
|
|
309
|
-
type: 'sus4-3' | 'sus7-6' | 'sus9-8' | 'sus2-3';
|
|
310
|
-
resolveTo: number;
|
|
311
|
-
} | {
|
|
312
|
-
kind: 'anticipation';
|
|
313
|
-
} | {
|
|
314
|
-
kind: 'escape';
|
|
315
|
-
} | {
|
|
316
|
-
kind: 'needsResolution';
|
|
317
|
-
resolveTo: number;
|
|
318
|
-
} | {
|
|
319
|
-
kind: 'leadingTone';
|
|
320
|
-
resolveTo: number;
|
|
321
|
-
};
|
|
322
|
-
/**
|
|
323
|
-
* A note with its theory labels and a short rationale.
|
|
324
|
-
*
|
|
325
|
-
* @category Arrangement & Analysis
|
|
326
|
-
*/
|
|
327
|
-
type AnalyzedNote = {
|
|
328
|
-
noteId: number;
|
|
329
|
-
labels: TheoryLabel[];
|
|
330
|
-
rationale?: string;
|
|
331
|
-
};
|
|
332
|
-
/**
|
|
333
|
-
* A single note in a monophonic voice: a {@link NoteEvent} with a stable id.
|
|
334
|
-
*
|
|
335
|
-
* @category Arrangement & Analysis
|
|
336
|
-
*/
|
|
337
|
-
type VoiceNote = NoteEvent & {
|
|
338
|
-
id: number;
|
|
339
|
-
};
|
|
340
|
-
/**
|
|
341
|
-
* Label every note of a voice with its theory roles.
|
|
342
|
-
*
|
|
343
|
-
* Each note is classified against the chord sounding at its beat. Chord tones
|
|
344
|
-
* get a role label; non-chord tones are matched, in order, as suspensions
|
|
345
|
-
* (prepared by an identical consonant pitch and resolving by step), passing
|
|
346
|
-
* tones, neighbors, anticipations, and escape tones, then fall back to tension,
|
|
347
|
-
* avoid, or an unresolved-dissonance label. Leading-tone resolutions are noted
|
|
348
|
-
* additionally.
|
|
349
|
-
*
|
|
350
|
-
* The voice is expected to be monophonic (one note at a time). Notes sharing an
|
|
351
|
-
* onset are treated as simultaneous cluster members, not melodic neighbors, so
|
|
352
|
-
* they receive no melodic labels (suspension, passing, neighbor, anticipation,
|
|
353
|
-
* escape) — only harmonic ones. Callers with truly polyphonic material should
|
|
354
|
-
* split it into monophonic sub-voices first, as `analyzeArrangement` does.
|
|
355
|
-
*
|
|
356
|
-
* @param voice The monophonic voice, in time order.
|
|
357
|
-
* @param chordAtBeat Chord sounding at a given beat, or null.
|
|
358
|
-
* @param key Key context for leading-tone detection.
|
|
359
|
-
* @param otherVoicesAtBeat Other sounding voices at a given beat.
|
|
360
|
-
* @returns One annotation per input note.
|
|
361
|
-
* @example
|
|
362
|
-
* ```ts
|
|
363
|
-
* import { analyzeVoice, makeChord, majorKey } from '@libraz/libcantus';
|
|
364
|
-
* const voice = [
|
|
365
|
-
* { id: 0, pitch: 60, startBeat: 0, durationBeat: 1 },
|
|
366
|
-
* { id: 1, pitch: 62, startBeat: 1, durationBeat: 1 },
|
|
367
|
-
* { id: 2, pitch: 64, startBeat: 2, durationBeat: 1 },
|
|
368
|
-
* ];
|
|
369
|
-
* const cMajor = makeChord(0, 'maj');
|
|
370
|
-
* const labels = analyzeVoice(voice, () => cMajor, majorKey(0), () => []);
|
|
371
|
-
* labels; // one AnalyzedNote per input note, in the same order
|
|
372
|
-
* ```
|
|
373
|
-
* @category Arrangement & Analysis
|
|
374
|
-
*/
|
|
375
|
-
declare function analyzeVoice(voice: VoiceNote[], chordAtBeat: (beat: number) => Chord$1 | null, key: KeyScale, otherVoicesAtBeat: (beat: number) => VoiceSnapshot[]): AnalyzedNote[];
|
|
376
|
-
|
|
377
|
-
/**
|
|
378
|
-
* Meter and time signatures: bar/beat arithmetic, simple vs. compound meters,
|
|
379
|
-
* metric-accent hierarchy, and tuplet subdivision.
|
|
380
|
-
*
|
|
381
|
-
* Positions and durations are measured in quarter-note beats, matching the rest
|
|
382
|
-
* of the library's beat convention (four quarter-note beats per bar in 4/4).
|
|
383
|
-
*/
|
|
384
|
-
/**
|
|
385
|
-
* A time signature as a numerator over a note-value denominator.
|
|
386
|
-
*
|
|
387
|
-
* @category Rhythm & Meter
|
|
388
|
-
*/
|
|
389
|
-
type TimeSignature = {
|
|
390
|
-
numerator: number;
|
|
391
|
-
denominator: number;
|
|
392
|
-
/**
|
|
393
|
-
* Optional additive grouping of the bar's main pulses, as the felt-beat
|
|
394
|
-
* lengths in pulses — e.g. `[2, 2, 3]` for a 2+2+3 reading of 7/8, or
|
|
395
|
-
* `[3, 2]` for 5/8. The entries must be positive integers summing to
|
|
396
|
-
* {@link pulsesPerBar}. When present, the head pulse of each group (other
|
|
397
|
-
* than the downbeat) is treated as a secondary strong pulse by
|
|
398
|
-
* {@link metricWeight}/{@link isStrongBeat}; when absent, all main pulses
|
|
399
|
-
* are weighted equally as flat, evenly divided pulses.
|
|
400
|
-
*/
|
|
401
|
-
grouping?: number[];
|
|
402
|
-
};
|
|
403
|
-
/**
|
|
404
|
-
* A position expressed as a bar index and a quarter-note offset within the bar.
|
|
405
|
-
*
|
|
406
|
-
* @category Rhythm & Meter
|
|
407
|
-
*/
|
|
408
|
-
type BarPosition = {
|
|
409
|
-
bar: number;
|
|
410
|
-
/** Quarter-note offset from the start of the bar. */
|
|
411
|
-
beat: number;
|
|
412
|
-
};
|
|
413
|
-
/**
|
|
414
|
-
* Parse a time signature such as `"4/4"` or `"6/8"`.
|
|
415
|
-
*
|
|
416
|
-
* @param text The signature text.
|
|
417
|
-
* @returns The parsed time signature.
|
|
418
|
-
* @throws If the text is not `n/d` with positive integers.
|
|
419
|
-
* @example
|
|
420
|
-
* ```ts
|
|
421
|
-
* import { parseTimeSignature } from '@libraz/libcantus';
|
|
422
|
-
* parseTimeSignature('6/8'); // { numerator: 6, denominator: 8 }
|
|
423
|
-
* ```
|
|
424
|
-
* @category Rhythm & Meter
|
|
425
|
-
*/
|
|
426
|
-
declare function parseTimeSignature(text: string): TimeSignature;
|
|
427
|
-
/**
|
|
428
|
-
* Render a time signature as `"n/d"`.
|
|
429
|
-
*
|
|
430
|
-
* @category Rhythm & Meter
|
|
431
|
-
*/
|
|
432
|
-
declare function formatTimeSignature(ts: TimeSignature): string;
|
|
433
|
-
/**
|
|
434
|
-
* Whether a meter is compound: its main pulses each divide into three, as in
|
|
435
|
-
* 6/8, 9/8, 12/8, or 6/4. Compound meters are those whose numerator is a
|
|
436
|
-
* multiple of three greater than three, independent of the denominator. Meters
|
|
437
|
-
* like 3/8 and 3/4 (simple triples, numerator 3) are not compound.
|
|
438
|
-
*
|
|
439
|
-
* @param ts The time signature.
|
|
440
|
-
* @returns True for compound meters.
|
|
441
|
-
* @category Rhythm & Meter
|
|
442
|
-
*/
|
|
443
|
-
declare function isCompound(ts: TimeSignature): boolean;
|
|
444
|
-
/**
|
|
445
|
-
* Length of a bar in quarter-note beats.
|
|
446
|
-
*
|
|
447
|
-
* @param ts The time signature.
|
|
448
|
-
* @returns The bar length in quarter notes.
|
|
449
|
-
* @category Rhythm & Meter
|
|
450
|
-
*/
|
|
451
|
-
declare function beatsPerBar(ts: TimeSignature): number;
|
|
452
|
-
/**
|
|
453
|
-
* Number of main pulses (felt beats) per bar: the numerator for simple meters,
|
|
454
|
-
* a third of it for compound meters.
|
|
455
|
-
*
|
|
456
|
-
* For additive/irregular meters such as 7/8 or 5/8 this counts the raw pulses
|
|
457
|
-
* (7 and 5 respectively), which are otherwise felt as flat, evenly divided and
|
|
458
|
-
* equally accented pulses. To recover a 2+2+3 or 3+2 felt-beat grouping, set
|
|
459
|
-
* {@link TimeSignature.grouping}; {@link metricWeight} then accents each
|
|
460
|
-
* group's head pulse.
|
|
461
|
-
*
|
|
462
|
-
* @param ts The time signature.
|
|
463
|
-
* @returns The pulse count per bar.
|
|
464
|
-
* @category Rhythm & Meter
|
|
465
|
-
*/
|
|
466
|
-
declare function pulsesPerBar(ts: TimeSignature): number;
|
|
467
|
-
/**
|
|
468
|
-
* Convert an absolute quarter-note position to a bar index and in-bar offset.
|
|
469
|
-
*
|
|
470
|
-
* @param beatInQuarters Absolute position in quarter-note beats.
|
|
471
|
-
* @param ts The time signature.
|
|
472
|
-
* @returns The bar and in-bar quarter-note offset.
|
|
473
|
-
* @example
|
|
474
|
-
* ```ts
|
|
475
|
-
* import { parseTimeSignature, beatToBarPosition } from '@libraz/libcantus';
|
|
476
|
-
* const ts = parseTimeSignature('4/4');
|
|
477
|
-
* beatToBarPosition(5, ts); // { bar: 1, beat: 1 }
|
|
478
|
-
* ```
|
|
479
|
-
* @category Rhythm & Meter
|
|
480
|
-
*/
|
|
481
|
-
declare function beatToBarPosition(beatInQuarters: number, ts: TimeSignature): BarPosition;
|
|
482
|
-
/**
|
|
483
|
-
* Convert a bar index and in-bar offset back to an absolute quarter-note
|
|
484
|
-
* position.
|
|
485
|
-
*
|
|
486
|
-
* @param pos The bar position.
|
|
487
|
-
* @param ts The time signature.
|
|
488
|
-
* @returns The absolute position in quarter-note beats.
|
|
489
|
-
* @category Rhythm & Meter
|
|
490
|
-
*/
|
|
491
|
-
declare function barPositionToBeat(pos: BarPosition, ts: TimeSignature): number;
|
|
492
|
-
/**
|
|
493
|
-
* Metric weight of a position within its bar, on a 0–3 scale:
|
|
494
|
-
* 3 the downbeat, 2 a secondary strong pulse, 1 any other main pulse, and 0 an
|
|
495
|
-
* off-pulse subdivision.
|
|
496
|
-
*
|
|
497
|
-
* The secondary strong pulse is the bar's midpoint in even simple/compound
|
|
498
|
-
* meters. For an additive/irregular meter with {@link TimeSignature.grouping}
|
|
499
|
-
* set (e.g. `[2, 2, 3]` for 7/8), each group's head pulse other than the
|
|
500
|
-
* downbeat is the secondary strong pulse instead; without a grouping every
|
|
501
|
-
* non-downbeat main pulse of such a meter weighs 1 (flat, evenly divided
|
|
502
|
-
* pulses).
|
|
503
|
-
*
|
|
504
|
-
* @param beatInQuarters Absolute or in-bar quarter-note position.
|
|
505
|
-
* @param ts The time signature.
|
|
506
|
-
* @returns The metric weight (0–3).
|
|
507
|
-
* @throws If `ts.grouping` is present but is not a positive-integer list
|
|
508
|
-
* summing to {@link pulsesPerBar}.
|
|
509
|
-
* @example
|
|
510
|
-
* ```ts
|
|
511
|
-
* import { parseTimeSignature, metricWeight } from '@libraz/libcantus';
|
|
512
|
-
* const ts = parseTimeSignature('4/4');
|
|
513
|
-
* metricWeight(0, ts); // 3 (the downbeat)
|
|
514
|
-
* ```
|
|
515
|
-
* @category Rhythm & Meter
|
|
516
|
-
*/
|
|
517
|
-
declare function metricWeight(beatInQuarters: number, ts: TimeSignature): number;
|
|
518
|
-
/**
|
|
519
|
-
* Whether a position is metrically accented (weight 2 or more — a downbeat or a
|
|
520
|
-
* secondary strong pulse).
|
|
521
|
-
*
|
|
522
|
-
* @param beatInQuarters Absolute or in-bar quarter-note position.
|
|
523
|
-
* @param ts The time signature.
|
|
524
|
-
* @returns True on strong beats.
|
|
525
|
-
* @category Rhythm & Meter
|
|
526
|
-
*/
|
|
527
|
-
declare function isStrongBeat(beatInQuarters: number, ts: TimeSignature): boolean;
|
|
528
|
-
/**
|
|
529
|
-
* Subdivide a span into `count` equal tuplet durations (e.g. an eighth-note
|
|
530
|
-
* triplet is `tuplet(1, 3)`).
|
|
531
|
-
*
|
|
532
|
-
* @param totalBeats Total span in quarter-note beats.
|
|
533
|
-
* @param count Number of equal parts.
|
|
534
|
-
* @returns `count` equal durations summing to `totalBeats`.
|
|
535
|
-
* @throws If `count` is not a positive integer.
|
|
536
|
-
* @category Rhythm & Meter
|
|
537
|
-
*/
|
|
538
|
-
declare function tuplet(totalBeats: number, count: number): number[];
|
|
539
|
-
|
|
540
|
-
/**
|
|
541
|
-
* Functional harmony: Roman-numeral parsing and formatting, harmonic function
|
|
542
|
-
* (tonic / subdominant / dominant), and cadence detection.
|
|
543
|
-
*
|
|
544
|
-
* Roots are pitch classes measured against the key tonic, so borrowed and
|
|
545
|
-
* chromatic chords are handled by their semitone offset rather than requiring a
|
|
546
|
-
* spelled key signature.
|
|
547
|
-
*/
|
|
548
|
-
|
|
549
|
-
/**
|
|
550
|
-
* The three broad harmonic functions of tonal music.
|
|
551
|
-
*
|
|
552
|
-
* @category Functional Harmony
|
|
553
|
-
*/
|
|
554
|
-
type HarmonicFunction = 'tonic' | 'subdominant' | 'dominant';
|
|
555
|
-
/**
|
|
556
|
-
* A recognized cadence type, or null when a chord pair forms none.
|
|
557
|
-
*
|
|
558
|
-
* @category Functional Harmony
|
|
559
|
-
*/
|
|
560
|
-
type Cadence = 'authentic' | 'plagal' | 'half' | 'deceptive' | null;
|
|
561
|
-
/**
|
|
562
|
-
* Whether a key's scale has a minor third and no major third (a minor key).
|
|
563
|
-
*
|
|
564
|
-
* @category Functional Harmony
|
|
565
|
-
*/
|
|
566
|
-
declare function isMinorKey(key: KeyScale): boolean;
|
|
567
|
-
/**
|
|
568
|
-
* Build the chord denoted by a Roman numeral in a key.
|
|
569
|
-
*
|
|
570
|
-
* Supports accidentals (`bVII`, `#iv`), case-based triad quality, the `o`/`ø`/`+`
|
|
571
|
-
* suffixes, sevenths (`V7`, `viio7`, `Imaj7`), figured-bass inversions
|
|
572
|
-
* (`V6`, `V64`, `V65`, `V43`, `V42`), and applied/secondary chords via a slash
|
|
573
|
-
* (`V7/V`, `viio/ii`). The target after the slash is read as a scale degree
|
|
574
|
-
* whose root becomes a local major tonic for the applied chord. Inverted chords
|
|
575
|
-
* carry a `bassPc`.
|
|
576
|
-
*
|
|
577
|
-
* The `ø` glyph always denotes the half-diminished seventh (`iiø` == `iiø7` ==
|
|
578
|
-
* `m7b5`), since no half-diminished triad exists. Extension and added-tone
|
|
579
|
-
* suffixes are the canonical case-sensitive forms emitted by
|
|
580
|
-
* {@link chordToRoman} and honor the numeral case: `V9` -> `dom9`, `ii9` ->
|
|
581
|
-
* `min9`, `Imaj9` -> `maj9`, `V11` -> `11`, `V13` -> `13`, `Iadd6`/`iadd6` ->
|
|
582
|
-
* `6`/`min6`, `I69` -> `6/9`, `Isus2`/`Isus4`, `Iadd9`/`Iadd11`, `Ib5` ->
|
|
583
|
-
* `majb5`, `I5` -> `5`, and the altered dominants `V7b9`/`V7#9`/`V7#11`/`V7b13`.
|
|
584
|
-
* A figure string that is neither a recognized inversion nor a supported
|
|
585
|
-
* quality suffix throws rather than silently degrading to a triad.
|
|
586
|
-
*
|
|
587
|
-
* @param text The Roman numeral.
|
|
588
|
-
* @param key The prevailing key.
|
|
589
|
-
* @returns The chord.
|
|
590
|
-
* @example
|
|
591
|
-
* ```ts
|
|
592
|
-
* import { romanToChord, majorKey } from '@libraz/libcantus';
|
|
593
|
-
* romanToChord('V7', majorKey(0)); // G7 in C major: { rootPc: 7, quality: 'dom7', ... }
|
|
594
|
-
* ```
|
|
595
|
-
* @category Functional Harmony
|
|
596
|
-
*/
|
|
597
|
-
declare function romanToChord(text: string, key: KeyScale): Chord$1;
|
|
598
|
-
/**
|
|
599
|
-
* Render a chord as a Roman numeral relative to a key.
|
|
600
|
-
*
|
|
601
|
-
* Diatonic roots take their scale-degree numeral directly, so numerals are
|
|
602
|
-
* correct in both major and minor keys (and any custom scale). The quality
|
|
603
|
-
* selects the case and suffix; chromatic roots receive a flat/sharp spelling by
|
|
604
|
-
* convention. When the chord carries a `bassPc` on a chord tone, a figured-bass
|
|
605
|
-
* inversion (`6`, `64`, `65`, `43`, `42`) is emitted for plain triads and true
|
|
606
|
-
* seventh chords; added-tone and extended qualities have no lossless figure and
|
|
607
|
-
* render in root position instead (the bass is dropped, pitch classes are
|
|
608
|
-
* preserved).
|
|
609
|
-
*
|
|
610
|
-
* @param chord The chord to name.
|
|
611
|
-
* @param key The prevailing key.
|
|
612
|
-
* @returns The Roman numeral string.
|
|
613
|
-
* @example
|
|
614
|
-
* ```ts
|
|
615
|
-
* import { chordToRoman, makeChord, majorKey } from '@libraz/libcantus';
|
|
616
|
-
* chordToRoman(makeChord(7, 'dom7'), majorKey(0)); // => 'V7' (G7 in C major)
|
|
617
|
-
* ```
|
|
618
|
-
* @category Functional Harmony
|
|
619
|
-
*/
|
|
620
|
-
declare function chordToRoman(chord: Chord$1, key: KeyScale): string;
|
|
621
|
-
/**
|
|
622
|
-
* The harmonic function of a chord in a key, from its root's offset above the
|
|
623
|
-
* tonic. The mapping follows common-practice major-key function and is a useful
|
|
624
|
-
* approximation in minor and for borrowed chords.
|
|
625
|
-
*
|
|
626
|
-
* @param chord The chord.
|
|
627
|
-
* @param key The prevailing key.
|
|
628
|
-
* @returns The harmonic function.
|
|
629
|
-
* @category Functional Harmony
|
|
630
|
-
*/
|
|
631
|
-
declare function functionOf(chord: Chord$1, key: KeyScale): HarmonicFunction;
|
|
632
|
-
/**
|
|
633
|
-
* The origin of a recognized non-diatonic chord, or null when none applies.
|
|
634
|
-
*
|
|
635
|
-
* @category Functional Harmony
|
|
636
|
-
*/
|
|
637
|
-
type BorrowedSource = 'parallel-minor' | 'parallel-major' | 'neapolitan' | null;
|
|
638
|
-
/**
|
|
639
|
-
* The result of {@link analyzeChord}: function, borrowing, and Roman numeral.
|
|
640
|
-
*
|
|
641
|
-
* @category Functional Harmony
|
|
642
|
-
*/
|
|
643
|
-
type ChordAnalysis = {
|
|
644
|
-
function: HarmonicFunction;
|
|
645
|
-
borrowed: boolean;
|
|
646
|
-
source: BorrowedSource;
|
|
647
|
-
roman: string;
|
|
648
|
-
};
|
|
649
|
-
/**
|
|
650
|
-
* Whether every pitch class of a chord belongs to the key's scale.
|
|
651
|
-
*
|
|
652
|
-
* The test is strict against the key's own mode mask: in a natural-minor key
|
|
653
|
-
* the harmonic-minor dominant (major V) is *not* diatonic, since the raised
|
|
654
|
-
* leading tone lies outside the mask. Borrowing predicates treat that case as
|
|
655
|
-
* an in-key alteration separately (see {@link isBorrowedChord}).
|
|
656
|
-
*
|
|
657
|
-
* @param chord The chord to test.
|
|
658
|
-
* @param key The prevailing key.
|
|
659
|
-
* @returns True if all chord pitch classes are scale tones.
|
|
660
|
-
* @category Functional Harmony
|
|
661
|
-
*/
|
|
662
|
-
declare function isDiatonic(chord: Chord$1, key: KeyScale): boolean;
|
|
663
|
-
/**
|
|
664
|
-
* The parallel key: same tonic, opposite mode.
|
|
665
|
-
*
|
|
666
|
-
* A key with a minor third (natural/harmonic/melodic minor, dorian, phrygian)
|
|
667
|
-
* maps to the parallel major; any other key maps to the parallel natural minor.
|
|
668
|
-
*
|
|
669
|
-
* @param key The key to mirror.
|
|
670
|
-
* @returns The parallel major or natural-minor key on the same tonic.
|
|
671
|
-
* @category Functional Harmony
|
|
672
|
-
*/
|
|
673
|
-
declare function parallelKey(key: KeyScale): KeyScale;
|
|
674
|
-
/**
|
|
675
|
-
* Whether a chord is borrowed from the parallel mode (modal interchange).
|
|
676
|
-
*
|
|
677
|
-
* True when the chord is not diatonic to `key` but is diatonic to its
|
|
678
|
-
* {@link parallelKey} — e.g. iv, bVI, or bVII in a major key, or the Picardy
|
|
679
|
-
* tonic and major IV in a minor key. Two non-diatonic families are excluded:
|
|
680
|
-
* chords diatonic to neither mode (they are chromatic, not borrowed), and, in
|
|
681
|
-
* a minor key, chords explained by the harmonic minor scale (the major
|
|
682
|
-
* dominant and raised-leading-tone chords), which are in-key alterations
|
|
683
|
-
* rather than interchange even though they happen to fit the parallel major.
|
|
684
|
-
*
|
|
685
|
-
* @param chord The chord to test.
|
|
686
|
-
* @param key The prevailing key.
|
|
687
|
-
* @returns True if the chord is borrowed from the parallel mode.
|
|
688
|
-
* @category Functional Harmony
|
|
689
|
-
*/
|
|
690
|
-
declare function isBorrowedChord(chord: Chord$1, key: KeyScale): boolean;
|
|
691
|
-
/**
|
|
692
|
-
* Identify where a non-diatonic chord comes from.
|
|
693
|
-
*
|
|
694
|
-
* The Neapolitan (major triad on b2) is recognized first, since it sits
|
|
695
|
-
* outside both parallel modes; parallel-mode borrowing follows the
|
|
696
|
-
* {@link isBorrowedChord} rules. Diatonic chords, harmonic-minor alterations,
|
|
697
|
-
* and unrecognized chromatic chords all yield null.
|
|
698
|
-
*
|
|
699
|
-
* @param chord The chord to classify.
|
|
700
|
-
* @param key The prevailing key.
|
|
701
|
-
* @returns The borrowing source, or null.
|
|
702
|
-
* @category Functional Harmony
|
|
703
|
-
*/
|
|
704
|
-
declare function borrowedSource(chord: Chord$1, key: KeyScale): BorrowedSource;
|
|
705
|
-
/**
|
|
706
|
-
* Analyze a chord in a key: harmonic function, borrowing, and Roman numeral.
|
|
707
|
-
*
|
|
708
|
-
* The function is quality-aware (see the predicates behind it), the source
|
|
709
|
-
* follows {@link borrowedSource}, and the numeral comes from
|
|
710
|
-
* {@link chordToRoman}. `borrowed` is true whenever a source is identified —
|
|
711
|
-
* including the Neapolitan, which the stricter parallel-mode predicate
|
|
712
|
-
* {@link isBorrowedChord} does not count.
|
|
713
|
-
*
|
|
714
|
-
* @param chord The chord to analyze.
|
|
715
|
-
* @param key The prevailing key.
|
|
716
|
-
* @returns The chord analysis.
|
|
717
|
-
* @example
|
|
718
|
-
* ```ts
|
|
719
|
-
* import { analyzeChord, makeChord, majorKey } from '@libraz/libcantus';
|
|
720
|
-
* analyzeChord(makeChord(7, 'dom7'), majorKey(0));
|
|
721
|
-
* // { function: 'dominant', borrowed: false, source: null, roman: 'V7' }
|
|
722
|
-
* ```
|
|
723
|
-
* @category Functional Harmony
|
|
724
|
-
*/
|
|
725
|
-
declare function analyzeChord(chord: Chord$1, key: KeyScale): ChordAnalysis;
|
|
726
|
-
/**
|
|
727
|
-
* Classify the cadence formed by moving from one chord to the next.
|
|
728
|
-
*
|
|
729
|
-
* - authentic: V (dominant a fifth above the tonic) to I
|
|
730
|
-
* - plagal: IV (a fourth above the tonic) to I
|
|
731
|
-
* - deceptive: V to the submediant (diatonic vi or borrowed bVI in major, VI in
|
|
732
|
-
* minor)
|
|
733
|
-
* - half: any chord other than the dominant itself to V
|
|
734
|
-
*
|
|
735
|
-
* A static V-to-V repeat with no root motion is not a cadence and yields null.
|
|
736
|
-
*
|
|
737
|
-
* @param from The penultimate chord.
|
|
738
|
-
* @param to The final chord.
|
|
739
|
-
* @param key The prevailing key.
|
|
740
|
-
* @returns The cadence type, or null.
|
|
741
|
-
* @example
|
|
742
|
-
* ```ts
|
|
743
|
-
* import { detectCadence, makeChord, majorKey } from '@libraz/libcantus';
|
|
744
|
-
* detectCadence(makeChord(7, 'maj'), makeChord(0, 'maj'), majorKey(0)); // => 'authentic'
|
|
745
|
-
* ```
|
|
746
|
-
* @category Functional Harmony
|
|
747
|
-
*/
|
|
748
|
-
declare function detectCadence(from: Chord$1, to: Chord$1, key: KeyScale): Cadence;
|
|
749
|
-
/**
|
|
750
|
-
* The secondary dominant (V7) that tonicizes a scale degree.
|
|
751
|
-
*
|
|
752
|
-
* @param targetDegree 0-based scale degree to tonicize.
|
|
753
|
-
* @param key The prevailing key.
|
|
754
|
-
* @returns A dominant-seventh chord a fifth above the target's root.
|
|
755
|
-
* @category Functional Harmony
|
|
756
|
-
*/
|
|
757
|
-
declare function secondaryDominant(targetDegree: number, key: KeyScale): Chord$1;
|
|
758
|
-
|
|
759
|
-
/**
|
|
760
|
-
* Broad production style a progression preset suits.
|
|
761
|
-
*
|
|
762
|
-
* @category Composition
|
|
763
|
-
*/
|
|
764
|
-
type ProgStyle = 'minimal' | 'dance' | 'idol' | 'rock';
|
|
765
|
-
/**
|
|
766
|
-
* Harmonic-function role of a progression as a whole.
|
|
767
|
-
*
|
|
768
|
-
* @category Composition
|
|
769
|
-
*/
|
|
770
|
-
type ProgFunction = 'loop' | 'tensionBuild' | 'cadenceStrong' | 'stable';
|
|
771
|
-
/**
|
|
772
|
-
* A named chord-progression preset expressed in scale degrees.
|
|
773
|
-
*
|
|
774
|
-
* @category Composition
|
|
775
|
-
*/
|
|
776
|
-
type ProgressionPreset = {
|
|
777
|
-
id: string;
|
|
778
|
-
name: string;
|
|
779
|
-
degrees: number[];
|
|
780
|
-
functional: ProgFunction;
|
|
781
|
-
styles: ProgStyle[];
|
|
782
|
-
};
|
|
783
|
-
/**
|
|
784
|
-
* A chord placed on the timeline by {@link generateProgression}.
|
|
785
|
-
*
|
|
786
|
-
* @category Composition
|
|
787
|
-
*/
|
|
788
|
-
type GeneratedChord = {
|
|
789
|
-
rootPc: number;
|
|
790
|
-
quality: ChordQuality;
|
|
791
|
-
startBeat: number;
|
|
792
|
-
bassPc?: number;
|
|
793
|
-
/** 0-based scale degree of the chord root, when known. */
|
|
794
|
-
degree?: number;
|
|
795
|
-
/** True when the chord is a secondary dominant tonicizing another degree. */
|
|
796
|
-
secondaryDominant?: boolean;
|
|
797
|
-
};
|
|
798
|
-
/**
|
|
799
|
-
* Options controlling {@link generateProgression}.
|
|
800
|
-
*
|
|
801
|
-
* @category Composition
|
|
802
|
-
*/
|
|
803
|
-
type GenerateProgressionOptions = {
|
|
804
|
-
key: KeyScale;
|
|
805
|
-
style: ProgStyle;
|
|
806
|
-
bars: number;
|
|
807
|
-
presetId?: string;
|
|
808
|
-
ext?: ChordQuality | 'auto';
|
|
809
|
-
reharmonize?: boolean;
|
|
810
|
-
/**
|
|
811
|
-
* Seed for the deterministic preset choice and reharmonization.
|
|
812
|
-
*
|
|
813
|
-
* @defaultValue 0
|
|
814
|
-
*/
|
|
815
|
-
seed?: number;
|
|
816
|
-
};
|
|
817
|
-
/**
|
|
818
|
-
* All built-in progression presets.
|
|
819
|
-
*
|
|
820
|
-
* @category Composition
|
|
821
|
-
*/
|
|
822
|
-
declare function progressions(): ProgressionPreset[];
|
|
823
|
-
/**
|
|
824
|
-
* Presets whose style list includes the given style.
|
|
825
|
-
*
|
|
826
|
-
* @category Composition
|
|
827
|
-
*/
|
|
828
|
-
declare function progressionsByStyle(style: ProgStyle): ProgressionPreset[];
|
|
829
|
-
/**
|
|
830
|
-
* Generate a chord progression laid out one chord per bar.
|
|
831
|
-
*
|
|
832
|
-
* A preset is chosen by `presetId` when given, otherwise deterministically from
|
|
833
|
-
* the presets matching `style`, seeded by `seed`. An unknown `presetId` is a
|
|
834
|
-
* caller error and throws rather than silently falling back to a random preset.
|
|
835
|
-
* The preset's degrees cycle to
|
|
836
|
-
* fill `bars`; each bar is four beats, so `startBeat` is `barIndex * 4`. Chord
|
|
837
|
-
* roots come from the key's diatonic scale-degree mapping. When `ext` is
|
|
838
|
-
* omitted or `'auto'`, each chord takes its diatonic triad quality; otherwise
|
|
839
|
-
* `ext` is forced on every chord. When `reharmonize` is set, some chords are
|
|
840
|
-
* deterministically replaced with the secondary dominant (V7) of the following
|
|
841
|
-
* chord, flagged with `secondaryDominant`.
|
|
842
|
-
*
|
|
843
|
-
* @param opts Generation options.
|
|
844
|
-
* @returns One chord per bar in timeline order.
|
|
845
|
-
* @throws If `presetId` is given but does not match any built-in preset.
|
|
846
|
-
*
|
|
847
|
-
* @example
|
|
848
|
-
* ```ts
|
|
849
|
-
* import { generateProgression, majorKey } from '@libraz/libcantus';
|
|
850
|
-
* const chords = generateProgression({ key: majorKey(0), style: 'dance', bars: 4 });
|
|
851
|
-
* // Deterministic for a given seed (defaults to 0); one GeneratedChord per bar.
|
|
852
|
-
* ```
|
|
853
|
-
*
|
|
854
|
-
* @category Composition
|
|
855
|
-
*/
|
|
856
|
-
declare function generateProgression(opts: GenerateProgressionOptions): GeneratedChord[];
|
|
857
|
-
|
|
858
|
-
/**
|
|
859
|
-
* A chord occupying a half-open beat span.
|
|
860
|
-
*
|
|
861
|
-
* @category Arrangement & Analysis
|
|
862
|
-
*/
|
|
863
|
-
type ChordSegment = {
|
|
864
|
-
startBeat: number;
|
|
865
|
-
endBeat: number;
|
|
866
|
-
chord: Chord$1;
|
|
867
|
-
};
|
|
868
|
-
/**
|
|
869
|
-
* A beat-indexed sequence of chord segments.
|
|
870
|
-
*
|
|
871
|
-
* @category Arrangement & Analysis
|
|
872
|
-
*/
|
|
873
|
-
type ChordTimeline = {
|
|
874
|
-
/** The chord sounding at a beat, or null when no segment covers it. */
|
|
875
|
-
at: (beat: number) => Chord$1 | null;
|
|
876
|
-
segments: ChordSegment[];
|
|
877
|
-
};
|
|
878
|
-
/**
|
|
879
|
-
* Build a chord timeline from placed chords.
|
|
880
|
-
*
|
|
881
|
-
* Each chord spans from its `startBeat` to the next chord's `startBeat`; the last
|
|
882
|
-
* chord runs to `totalBeats`. Segments with no positive length (from duplicate
|
|
883
|
-
* onsets or a last chord at or past `totalBeats`) are dropped. `at(beat)` returns
|
|
884
|
-
* the covering segment's chord, or null when the beat lies outside every segment.
|
|
885
|
-
*
|
|
886
|
-
* @param chords Placed chords in time order.
|
|
887
|
-
* @param totalBeats End of the timeline in beats.
|
|
888
|
-
* @returns A queryable chord timeline.
|
|
889
|
-
* @category Arrangement & Analysis
|
|
890
|
-
*/
|
|
891
|
-
declare function chordTimelineFromChords(chords: GeneratedChord[], totalBeats: number): ChordTimeline;
|
|
892
|
-
/**
|
|
893
|
-
* Options controlling {@link chordTimelineFromNotes}.
|
|
894
|
-
*
|
|
895
|
-
* @category Arrangement & Analysis
|
|
896
|
-
*/
|
|
897
|
-
type ChordTimelineOptions = {
|
|
898
|
-
/** Key context; inferred from the notes with {@link detectKey} when omitted. */
|
|
899
|
-
key?: KeyScale;
|
|
900
|
-
/**
|
|
901
|
-
* Time signature used for metric accents; defaults to 4/4.
|
|
902
|
-
*
|
|
903
|
-
* @defaultValue `4/4`
|
|
904
|
-
*/
|
|
905
|
-
ts?: TimeSignature;
|
|
906
|
-
/**
|
|
907
|
-
* Window length in beats per chord slot; defaults to one bar of `ts`.
|
|
908
|
-
*
|
|
909
|
-
* @defaultValue one bar of `ts`
|
|
910
|
-
*/
|
|
911
|
-
harmonicRhythm?: number;
|
|
912
|
-
/**
|
|
913
|
-
* End of the analyzed span in beats; defaults to the end of the last note.
|
|
914
|
-
*
|
|
915
|
-
* @defaultValue the end of the last note
|
|
916
|
-
*/
|
|
917
|
-
totalBeats?: number;
|
|
918
|
-
};
|
|
919
|
-
/**
|
|
920
|
-
* The result of {@link chordTimelineFromNotes}.
|
|
921
|
-
*
|
|
922
|
-
* @category Arrangement & Analysis
|
|
923
|
-
*/
|
|
924
|
-
type ChordTimelineResult = {
|
|
925
|
-
/** The inferred timeline, with adjacent identical chords merged. */
|
|
926
|
-
timeline: ChordTimeline;
|
|
927
|
-
/** The key used for the analysis (given or inferred). */
|
|
928
|
-
key: KeyScale;
|
|
929
|
-
/** One confidence value in [0, 1] per segment, in segment order. */
|
|
930
|
-
segmentConfidence: number[];
|
|
931
|
-
};
|
|
932
|
-
/**
|
|
933
|
-
* Infer a chord timeline from raw multi-track notes.
|
|
934
|
-
*
|
|
935
|
-
* The span `[0, totalBeats)` is sliced into `harmonicRhythm`-beat windows; each
|
|
936
|
-
* window's chord is inferred from a pitch-class weight histogram of the notes
|
|
937
|
-
* overlapping it (weight = overlap duration x velocity x metric-accent bonus
|
|
938
|
-
* for onsets in the window). Adjacent windows carrying the identical chord are
|
|
939
|
-
* merged into one segment; windows with no notes produce no segment, so
|
|
940
|
-
* `at(beat)` returns null there. Each segment carries a confidence in [0, 1]:
|
|
941
|
-
* the fraction of the window weight explained by chord tones, reduced when the
|
|
942
|
-
* match is inexact, and duration-weighted across merged windows.
|
|
943
|
-
*
|
|
944
|
-
* Notes with a zero or negative duration never sound, so they are dropped at
|
|
945
|
-
* ingest: they contribute to neither the key inference, the span, nor any
|
|
946
|
-
* window's histogram.
|
|
947
|
-
*
|
|
948
|
-
* @param notes The notes to analyze (any number of tracks, flattened).
|
|
949
|
-
* @param opts Analysis options; see {@link ChordTimelineOptions}.
|
|
950
|
-
* @returns The inferred timeline, the key used, and per-segment confidences.
|
|
951
|
-
* @throws If `harmonicRhythm` is not positive.
|
|
952
|
-
* @example
|
|
953
|
-
* ```ts
|
|
954
|
-
* import { chordTimelineFromNotes } from '@libraz/libcantus';
|
|
955
|
-
* const notes = [
|
|
956
|
-
* { pitch: 60, startBeat: 0, durationBeat: 2 }, // C
|
|
957
|
-
* { pitch: 64, startBeat: 0, durationBeat: 2 }, // E
|
|
958
|
-
* { pitch: 67, startBeat: 0, durationBeat: 2 }, // G
|
|
959
|
-
* ];
|
|
960
|
-
* const { timeline, key } = chordTimelineFromNotes(notes);
|
|
961
|
-
* timeline.at(0); // the chord inferred over beat 0, or null
|
|
962
|
-
* ```
|
|
963
|
-
* @category Arrangement & Analysis
|
|
964
|
-
*/
|
|
965
|
-
declare function chordTimelineFromNotes(notes: NoteEvent[], opts?: ChordTimelineOptions): ChordTimelineResult;
|
|
966
|
-
/**
|
|
967
|
-
* A cadence found between two consecutive timeline segments.
|
|
968
|
-
*
|
|
969
|
-
* @category Arrangement & Analysis
|
|
970
|
-
*/
|
|
971
|
-
type CadenceHit = {
|
|
972
|
-
/** The beat where the cadence arrives (the second chord's onset). */
|
|
973
|
-
atBeat: number;
|
|
974
|
-
type: Exclude<Cadence, null>;
|
|
975
|
-
from: Chord$1;
|
|
976
|
-
to: Chord$1;
|
|
977
|
-
};
|
|
978
|
-
/**
|
|
979
|
-
* Find cadences between consecutive segments of a chord timeline.
|
|
980
|
-
*
|
|
981
|
-
* Each temporally adjacent segment pair is classified with
|
|
982
|
-
* {@link detectCadence}; pairs forming no cadence are skipped. Segments
|
|
983
|
-
* separated by a gap (a rest in the timeline) are not a chord-to-chord
|
|
984
|
-
* progression, so they are never paired.
|
|
985
|
-
*
|
|
986
|
-
* @param timeline The chord timeline to scan.
|
|
987
|
-
* @param key The prevailing key.
|
|
988
|
-
* @returns The cadences found, in time order.
|
|
989
|
-
* @example
|
|
990
|
-
* ```ts
|
|
991
|
-
* import { chordTimelineFromNotes, detectCadences } from '@libraz/libcantus';
|
|
992
|
-
* const notes = [
|
|
993
|
-
* { pitch: 67, startBeat: 0, durationBeat: 4 }, // G, a dominant
|
|
994
|
-
* { pitch: 60, startBeat: 4, durationBeat: 4 }, // C, the tonic
|
|
995
|
-
* ];
|
|
996
|
-
* const { timeline, key } = chordTimelineFromNotes(notes);
|
|
997
|
-
* const cadences = detectCadences(timeline, key);
|
|
998
|
-
* ```
|
|
999
|
-
* @category Arrangement & Analysis
|
|
1000
|
-
*/
|
|
1001
|
-
declare function detectCadences(timeline: ChordTimeline, key: KeyScale): CadenceHit[];
|
|
1002
|
-
|
|
1003
|
-
/**
|
|
1004
|
-
* Arrangement analysis: the capstone that ties the timeline, per-voice analysis,
|
|
1005
|
-
* functional harmony, and safety modules together for a whole multi-track piece.
|
|
1006
|
-
*
|
|
1007
|
-
* A chord timeline and key are inferred once from every track's notes pooled
|
|
1008
|
-
* together; each track is then analysed against that shared harmony, notes that
|
|
1009
|
-
* clash with the sounding chord are collected as conflicts, and a coarse tension
|
|
1010
|
-
* curve is sampled across the piece.
|
|
1011
|
-
*/
|
|
1012
|
-
|
|
1013
|
-
/**
|
|
1014
|
-
* The musical role a track plays in the arrangement.
|
|
1015
|
-
*
|
|
1016
|
-
* @category Arrangement & Analysis
|
|
1017
|
-
*/
|
|
1018
|
-
type TrackRole = 'melody' | 'harmony' | 'bass' | 'other';
|
|
1019
|
-
/**
|
|
1020
|
-
* One input track: its notes plus optional name and role.
|
|
1021
|
-
*
|
|
1022
|
-
* @category Arrangement & Analysis
|
|
1023
|
-
*/
|
|
1024
|
-
type ArrangementTrack = {
|
|
1025
|
-
name?: string;
|
|
1026
|
-
role?: TrackRole;
|
|
1027
|
-
notes: NoteEvent[];
|
|
1028
|
-
};
|
|
1029
|
-
/**
|
|
1030
|
-
* A track after analysis: its resolved name, role, and per-note annotations.
|
|
1031
|
-
*
|
|
1032
|
-
* @category Arrangement & Analysis
|
|
1033
|
-
*/
|
|
1034
|
-
type TrackAnalysis = {
|
|
1035
|
-
name: string;
|
|
1036
|
-
role: TrackRole;
|
|
1037
|
-
/** One {@link AnalyzedNote} per note, labelled against the inferred chords. */
|
|
1038
|
-
notes: AnalyzedNote[];
|
|
1039
|
-
};
|
|
1040
|
-
/**
|
|
1041
|
-
* A note that clashes with the harmony sounding beneath it.
|
|
1042
|
-
*
|
|
1043
|
-
* @category Arrangement & Analysis
|
|
1044
|
-
*/
|
|
1045
|
-
type Conflict = {
|
|
1046
|
-
beat: number;
|
|
1047
|
-
trackName: string;
|
|
1048
|
-
pitch: number;
|
|
1049
|
-
/** The clash severity: {@link NoteSafety.Warning} or {@link NoteSafety.Dissonant}. */
|
|
1050
|
-
safety: NoteSafety;
|
|
1051
|
-
/** {@link import('../safety/index.js').SafetyResult.reasons} bitmask. */
|
|
1052
|
-
reasons: number;
|
|
1053
|
-
rationale?: string;
|
|
1054
|
-
};
|
|
1055
|
-
/**
|
|
1056
|
-
* The full result of {@link analyzeArrangement}.
|
|
1057
|
-
*
|
|
1058
|
-
* @category Arrangement & Analysis
|
|
1059
|
-
*/
|
|
1060
|
-
type ArrangementAnalysis = {
|
|
1061
|
-
key: KeyScale;
|
|
1062
|
-
timeline: ChordTimeline;
|
|
1063
|
-
segmentConfidence: number[];
|
|
1064
|
-
cadences: CadenceHit[];
|
|
1065
|
-
tracks: TrackAnalysis[];
|
|
1066
|
-
/** Notes clashing with the sounding harmony, worst severity first. */
|
|
1067
|
-
conflicts: Conflict[];
|
|
1068
|
-
};
|
|
1069
|
-
/**
|
|
1070
|
-
* Options controlling {@link analyzeArrangement} and {@link tensionCurve}.
|
|
1071
|
-
*
|
|
1072
|
-
* @category Arrangement & Analysis
|
|
1073
|
-
*/
|
|
1074
|
-
type ArrangementOptions = {
|
|
1075
|
-
/** Key context; inferred from the pooled notes when omitted. */
|
|
1076
|
-
key?: KeyScale;
|
|
1077
|
-
/**
|
|
1078
|
-
* Time signature; defaults to 4/4.
|
|
1079
|
-
*
|
|
1080
|
-
* @defaultValue `4/4`
|
|
1081
|
-
*/
|
|
1082
|
-
ts?: TimeSignature;
|
|
1083
|
-
/**
|
|
1084
|
-
* Chord-slot length in beats; defaults to one bar of `ts`.
|
|
1085
|
-
*
|
|
1086
|
-
* @defaultValue one bar of `ts`
|
|
1087
|
-
*/
|
|
1088
|
-
harmonicRhythm?: number;
|
|
1089
|
-
/**
|
|
1090
|
-
* Safety profile used for conflict detection; defaults to `pop`.
|
|
1091
|
-
*
|
|
1092
|
-
* @defaultValue `'pop'`
|
|
1093
|
-
*/
|
|
1094
|
-
profile?: SafetyProfile;
|
|
1095
|
-
};
|
|
1096
|
-
/**
|
|
1097
|
-
* Analyse a whole arrangement against a single inferred harmony.
|
|
1098
|
-
*
|
|
1099
|
-
* The chord timeline and key are inferred from the pooled notes of every track
|
|
1100
|
-
* (see {@link chordTimelineFromNotes}); pooling all voices is robust even when
|
|
1101
|
-
* roles are absent or a track doubles the harmony, so it is preferred over
|
|
1102
|
-
* deriving the harmony from a subset. Zero- and negative-length notes never
|
|
1103
|
-
* sound, so they are dropped at ingest and appear in neither the annotations
|
|
1104
|
-
* nor the conflicts.
|
|
1105
|
-
*
|
|
1106
|
-
* Voice analysis assumes one monophonic voice at a time, so each track is
|
|
1107
|
-
* first partitioned into monophonic sub-voices (a polyphonic block-chord track
|
|
1108
|
-
* fans out into one sub-voice per simultaneous note; a monophonic track is
|
|
1109
|
-
* unaffected). Each sub-voice is labelled note-by-note against the harmony
|
|
1110
|
-
* with {@link analyzeVoice}, seeing every other sub-voice — including siblings
|
|
1111
|
-
* within the same track — as its accompaniment. Every note is then re-checked
|
|
1112
|
-
* with {@link evaluateSafety} at its onset and again at each chord change it
|
|
1113
|
-
* sustains across, so a held note that clashes with a later chord is caught:
|
|
1114
|
-
* evaluations that are not {@link NoteSafety.Safe} become conflicts, one per
|
|
1115
|
-
* clashing beat, sorted worst severity first and then by beat.
|
|
1116
|
-
*
|
|
1117
|
-
* @param tracks The tracks to analyse.
|
|
1118
|
-
* @param opts Analysis options; see {@link ArrangementOptions}.
|
|
1119
|
-
* @returns The inferred harmony, per-track annotations, cadences, and conflicts.
|
|
1120
|
-
* @example
|
|
1121
|
-
* ```ts
|
|
1122
|
-
* import { analyzeArrangement } from '@libraz/libcantus';
|
|
1123
|
-
* const melody = [
|
|
1124
|
-
* { pitch: 60, startBeat: 0, durationBeat: 2 },
|
|
1125
|
-
* { pitch: 67, startBeat: 2, durationBeat: 2 },
|
|
1126
|
-
* ];
|
|
1127
|
-
* const { key, conflicts } = analyzeArrangement([{ role: 'melody', notes: melody }]);
|
|
1128
|
-
* conflicts; // notes clashing with the inferred harmony, worst severity first
|
|
1129
|
-
* ```
|
|
1130
|
-
* @category Arrangement & Analysis
|
|
1131
|
-
*/
|
|
1132
|
-
declare function analyzeArrangement(tracks: ArrangementTrack[], opts?: ArrangementOptions): ArrangementAnalysis;
|
|
1133
|
-
/**
|
|
1134
|
-
* A tension reading sampled at a beat.
|
|
1135
|
-
*
|
|
1136
|
-
* @category Arrangement & Analysis
|
|
1137
|
-
*/
|
|
1138
|
-
type TensionPoint = {
|
|
1139
|
-
beat: number;
|
|
1140
|
-
/** Combined tension in [0, 1]. */
|
|
1141
|
-
tension: number;
|
|
1142
|
-
};
|
|
1143
|
-
/**
|
|
1144
|
-
* Sample the harmonic tension of an arrangement at regular beats.
|
|
1145
|
-
*
|
|
1146
|
-
* At each sample beat the tension combines three normalized terms:
|
|
1147
|
-
* - the sounding chord's harmonic function (dominant `1`, subdominant `0.5`,
|
|
1148
|
-
* tonic or no chord `0`), weighted {@link FUNCTION_WEIGHT};
|
|
1149
|
-
* - the dissonance of the sounding notes — the larger of the share of sounding
|
|
1150
|
-
* pitches that are not chord tones and the share that {@link evaluateSafety}
|
|
1151
|
-
* rates {@link NoteSafety.Dissonant} — weighted {@link DISSONANCE_WEIGHT};
|
|
1152
|
-
* - the registral span of the sounding notes, saturating at
|
|
1153
|
-
* {@link SPAN_SATURATION} semitones, weighted {@link SPAN_WEIGHT}.
|
|
1154
|
-
*
|
|
1155
|
-
* The weighted sum is clamped to [0, 1]. The harmony is inferred from all tracks
|
|
1156
|
-
* pooled together, so the result is deterministic and self-contained.
|
|
1157
|
-
*
|
|
1158
|
-
* @param tracks The tracks to sample.
|
|
1159
|
-
* @param opts Analysis options plus an optional `step` (default one beat).
|
|
1160
|
-
* @returns One {@link TensionPoint} per sampled beat, in beat order.
|
|
1161
|
-
* @throws If `step` is not positive.
|
|
1162
|
-
* @example
|
|
1163
|
-
* ```ts
|
|
1164
|
-
* import { tensionCurve } from '@libraz/libcantus';
|
|
1165
|
-
* const notes = [{ pitch: 60, startBeat: 0, durationBeat: 4 }];
|
|
1166
|
-
* const curve = tensionCurve([{ notes }], { step: 1 });
|
|
1167
|
-
* curve; // one { beat, tension } sample per beat, in beat order
|
|
1168
|
-
* ```
|
|
1169
|
-
* @category Arrangement & Analysis
|
|
1170
|
-
*/
|
|
1171
|
-
declare function tensionCurve(tracks: ArrangementTrack[], opts?: ArrangementOptions & {
|
|
1172
|
-
step?: number;
|
|
1173
|
-
}): TensionPoint[];
|
|
1174
|
-
|
|
1175
|
-
/**
|
|
1176
|
-
* Deterministic bass-line generation over a chord placement.
|
|
1177
|
-
*
|
|
1178
|
-
* Given a sequence of chord segments and a key, this builds a monophonic bass
|
|
1179
|
-
* line in a chosen low register. Several idiomatic styles are supported, from a
|
|
1180
|
-
* single held root per segment to a quarter-note walking line that leads by
|
|
1181
|
-
* step into each chord change. All pitches are kept in a narrow bass band and
|
|
1182
|
-
* consecutive notes move by small intervals; given a seed the output is fully
|
|
1183
|
-
* reproducible.
|
|
1184
|
-
*
|
|
1185
|
-
* Positions and durations are measured in quarter-note beats, matching the
|
|
1186
|
-
* library-wide convention.
|
|
1187
|
-
*/
|
|
1188
|
-
|
|
1189
|
-
/**
|
|
1190
|
-
* A chord sounding over a half-open beat span `[startBeat, endBeat)`.
|
|
1191
|
-
*
|
|
1192
|
-
* @category Composition
|
|
1193
|
-
*/
|
|
1194
|
-
type BassSegment = {
|
|
1195
|
-
startBeat: number;
|
|
1196
|
-
endBeat: number;
|
|
1197
|
-
chord: Chord$1;
|
|
1198
|
-
};
|
|
1199
|
-
/**
|
|
1200
|
-
* The bass-line idiom to generate.
|
|
1201
|
-
*
|
|
1202
|
-
* @category Composition
|
|
1203
|
-
*/
|
|
1204
|
-
type BassStyle = 'root' | 'rootFifth' | 'pop' | 'walking' | 'arpeggio';
|
|
1205
|
-
/**
|
|
1206
|
-
* Options controlling {@link generateBassLine}.
|
|
1207
|
-
*
|
|
1208
|
-
* @category Composition
|
|
1209
|
-
*/
|
|
1210
|
-
type BassLineOptions = {
|
|
1211
|
-
/** Chord placement to follow; need not be pre-sorted. */
|
|
1212
|
-
segments: BassSegment[];
|
|
1213
|
-
/** Key/scale context, used for diatonic approach tones in `walking`. */
|
|
1214
|
-
key: KeyScale;
|
|
1215
|
-
/**
|
|
1216
|
-
* Time signature; used for metric accents.
|
|
1217
|
-
*
|
|
1218
|
-
* @defaultValue `{ numerator: 4, denominator: 4 }`
|
|
1219
|
-
*/
|
|
1220
|
-
ts?: TimeSignature;
|
|
1221
|
-
/**
|
|
1222
|
-
* Bass-line idiom.
|
|
1223
|
-
*
|
|
1224
|
-
* @defaultValue `'root'`
|
|
1225
|
-
*/
|
|
1226
|
-
style?: BassStyle;
|
|
1227
|
-
/**
|
|
1228
|
-
* Target register as a base MIDI octave; roots land around `octave*12+12`.
|
|
1229
|
-
*
|
|
1230
|
-
* @defaultValue 2
|
|
1231
|
-
*/
|
|
1232
|
-
octave?: number;
|
|
1233
|
-
/**
|
|
1234
|
-
* Seed for the deterministic PRNG.
|
|
1235
|
-
*
|
|
1236
|
-
* @defaultValue 0
|
|
1237
|
-
*/
|
|
1238
|
-
seed?: number;
|
|
1239
|
-
};
|
|
1240
|
-
/**
|
|
1241
|
-
* Generate a bass line following a chord placement.
|
|
1242
|
-
*
|
|
1243
|
-
* Each segment contributes notes in the chosen bass register per the selected
|
|
1244
|
-
* style; consecutive notes are kept within roughly a fifth. Every note's
|
|
1245
|
-
* duration extends to the next onset (the final note extends to the last
|
|
1246
|
-
* segment's end). Given a seed the output is fully reproducible.
|
|
1247
|
-
*
|
|
1248
|
-
* @param opts Segments, key, and generation options.
|
|
1249
|
-
* @returns Bass notes sorted by onset, non-overlapping.
|
|
1250
|
-
*
|
|
1251
|
-
* @example
|
|
1252
|
-
* ```ts
|
|
1253
|
-
* import { generateBassLine, makeChord, majorKey } from '@libraz/libcantus';
|
|
1254
|
-
* const segments = [
|
|
1255
|
-
* { startBeat: 0, endBeat: 4, chord: makeChord(0, 'maj') },
|
|
1256
|
-
* { startBeat: 4, endBeat: 8, chord: makeChord(7, 'maj') },
|
|
1257
|
-
* ];
|
|
1258
|
-
* const notes = generateBassLine({ segments, key: majorKey(0), style: 'walking' });
|
|
1259
|
-
* ```
|
|
1260
|
-
*
|
|
1261
|
-
* @category Composition
|
|
1262
|
-
*/
|
|
1263
|
-
declare function generateBassLine(opts: BassLineOptions): NoteEvent[];
|
|
1264
|
-
|
|
1265
|
-
/**
|
|
1266
|
-
* Test whether every chord pitch class is contained in a scale.
|
|
1267
|
-
*
|
|
1268
|
-
* @param chordPcs The chord's pitch classes (0..11).
|
|
1269
|
-
* @param scaleMask The scale's 12-bit mode mask.
|
|
1270
|
-
* @param scaleRootPc The pitch class the mask is rooted on.
|
|
1271
|
-
* @returns True if the scale is a superset of the chord.
|
|
1272
|
-
*
|
|
1273
|
-
* @category Scales
|
|
1274
|
-
*/
|
|
1275
|
-
declare function scaleMatchesChord(chordPcs: number[], scaleMask: number, scaleRootPc: number): boolean;
|
|
1276
|
-
/**
|
|
1277
|
-
* A named scale rooted on a pitch class that fits over a chord.
|
|
1278
|
-
*
|
|
1279
|
-
* @category Scales
|
|
1280
|
-
*/
|
|
1281
|
-
type ChordScaleMatch = {
|
|
1282
|
-
name: string;
|
|
1283
|
-
rootPc: number;
|
|
1284
|
-
};
|
|
1285
|
-
/**
|
|
1286
|
-
* List the scales that fit over a chord, best fit first.
|
|
1287
|
-
*
|
|
1288
|
-
* Only the chord root is considered as the scale root, matching the
|
|
1289
|
-
* conventional chord-scale relationship. Every entry of {@link NAMED_SCALES}
|
|
1290
|
-
* whose pitch-class set is a superset of the chord's is returned once per
|
|
1291
|
-
* distinct pitch-class set (aliased masks such as major/ionian report only the
|
|
1292
|
-
* modal name), ranked by fewest extra scale tones beyond the chord, then by
|
|
1293
|
-
* scale size (heptatonic before larger scales), then by scale name. For bare
|
|
1294
|
-
* triads and smaller chords, heptatonic scales rank before pentatonics and
|
|
1295
|
-
* other sizes: a pentatonic adds no modal color over a triad, so the seven-note
|
|
1296
|
-
* modes are the more useful answer. The chromatic scale is only returned as a
|
|
1297
|
-
* fallback when no other scale contains the chord.
|
|
1298
|
-
*
|
|
1299
|
-
* @param chord The chord to fit scales over.
|
|
1300
|
-
* @returns The matching scales rooted on the chord root, best fit first.
|
|
1301
|
-
*
|
|
1302
|
-
* @example
|
|
1303
|
-
* ```ts
|
|
1304
|
-
* import { makeChord, chordScales } from '@libraz/libcantus';
|
|
1305
|
-
* const scales = chordScales(makeChord(0, 'maj7'));
|
|
1306
|
-
* // scales for Cmaj7, best fit first; each is { name, rootPc: 0 }
|
|
1307
|
-
* ```
|
|
1308
|
-
*
|
|
1309
|
-
* @category Scales
|
|
1310
|
-
*/
|
|
1311
|
-
declare function chordScales(chord: Chord$1): ChordScaleMatch[];
|
|
1312
|
-
/**
|
|
1313
|
-
* List a scale's avoid notes over a chord.
|
|
1314
|
-
*
|
|
1315
|
-
* An avoid note is a non-chord scale tone that lies a semitone directly above a
|
|
1316
|
-
* chord tone; sounding it against the chord clashes. The scale is rooted on the
|
|
1317
|
-
* chord root. If the scale does not contain the chord, no avoid notes exist.
|
|
1318
|
-
*
|
|
1319
|
-
* @param chord The chord providing the chord tones.
|
|
1320
|
-
* @param scaleName A key of {@link NAMED_SCALES}.
|
|
1321
|
-
* @returns The avoid-note pitch classes, sorted ascending in [0, 11].
|
|
1322
|
-
*
|
|
1323
|
-
* @category Scales
|
|
1324
|
-
*/
|
|
1325
|
-
declare function avoidNotes(chord: Chord$1, scaleName: string): number[];
|
|
1326
|
-
/**
|
|
1327
|
-
* List a scale's available tensions over a chord.
|
|
1328
|
-
*
|
|
1329
|
-
* Available tensions are scale tones that are neither chord tones nor avoid
|
|
1330
|
-
* notes, i.e. the usable color tones (typically the 9/11/13 region). The scale
|
|
1331
|
-
* is rooted on the chord root. If the scale does not contain the chord, there
|
|
1332
|
-
* are no available tensions.
|
|
1333
|
-
*
|
|
1334
|
-
* @param chord The chord providing the chord tones.
|
|
1335
|
-
* @param scaleName A key of {@link NAMED_SCALES}.
|
|
1336
|
-
* @returns The available-tension pitch classes, sorted ascending in [0, 11].
|
|
1337
|
-
*
|
|
1338
|
-
* @example
|
|
1339
|
-
* ```ts
|
|
1340
|
-
* import { makeChord, availableTensions } from '@libraz/libcantus';
|
|
1341
|
-
* availableTensions(makeChord(0, 'maj7'), 'ionian'); // [2, 9] — color tones over Cmaj7
|
|
1342
|
-
* ```
|
|
1343
|
-
*
|
|
1344
|
-
* @category Scales
|
|
1345
|
-
*/
|
|
1346
|
-
declare function availableTensions(chord: Chord$1, scaleName: string): number[];
|
|
1347
|
-
/**
|
|
1348
|
-
* A scale fit over a chord together with its avoid notes and tensions.
|
|
1349
|
-
*
|
|
1350
|
-
* @category Scales
|
|
1351
|
-
*/
|
|
1352
|
-
type ChordScaleReportEntry = {
|
|
1353
|
-
name: string;
|
|
1354
|
-
rootPc: number;
|
|
1355
|
-
avoid: number[];
|
|
1356
|
-
tensions: number[];
|
|
1357
|
-
};
|
|
1358
|
-
/**
|
|
1359
|
-
* Report the best-fitting scales for a chord with their avoid notes and tensions.
|
|
1360
|
-
*
|
|
1361
|
-
* Combines {@link chordScales}, {@link avoidNotes}, and {@link availableTensions}
|
|
1362
|
-
* into a single ergonomic result, ordered best fit first.
|
|
1363
|
-
*
|
|
1364
|
-
* @param chord The chord to analyze.
|
|
1365
|
-
* @param limit Optional maximum number of scales to report; all by default.
|
|
1366
|
-
* @returns One entry per reported scale, best fit first.
|
|
1367
|
-
*
|
|
1368
|
-
* @category Scales
|
|
1369
|
-
*/
|
|
1370
|
-
declare function chordScaleReport(chord: Chord$1, limit?: number): ChordScaleReportEntry[];
|
|
1371
|
-
/**
|
|
1372
|
-
* A chord paired with the scale chosen for it by {@link scalesForChanges}.
|
|
1373
|
-
*
|
|
1374
|
-
* @category Scales
|
|
1375
|
-
*/
|
|
1376
|
-
type ScaleChoice = {
|
|
1377
|
-
chord: Chord$1;
|
|
1378
|
-
scale: ChordScaleMatch;
|
|
1379
|
-
};
|
|
1380
|
-
/**
|
|
1381
|
-
* Choose one scale per chord across a progression, favoring continuity.
|
|
1382
|
-
*
|
|
1383
|
-
* Each chord's {@link chordScales} candidates form a stage in a Viterbi-style
|
|
1384
|
-
* dynamic program. The transition cost between adjacent choices is the number
|
|
1385
|
-
* of pitch classes that differ between their pitch-class sets (the symmetric
|
|
1386
|
-
* difference), plus a small penalty for straying from a chord's best-fit scale
|
|
1387
|
-
* so that ties break toward the tighter fit. The minimum-total-cost path is
|
|
1388
|
-
* returned, one {@link ScaleChoice} per input chord in the original order.
|
|
1389
|
-
*
|
|
1390
|
-
* @param chords The chord sequence to choose scales for.
|
|
1391
|
-
* @returns One scale choice per chord, in input order.
|
|
1392
|
-
*
|
|
1393
|
-
* @category Scales
|
|
1394
|
-
*/
|
|
1395
|
-
declare function scalesForChanges(chords: Chord$1[]): ScaleChoice[];
|
|
1396
|
-
|
|
1397
|
-
/**
|
|
1398
|
-
* Options controlling {@link generateCounterMelody}.
|
|
1399
|
-
*
|
|
1400
|
-
* @category Voicing & Counterpoint
|
|
1401
|
-
*/
|
|
1402
|
-
type CounterMelodyOptions = {
|
|
1403
|
-
/** The lead line to write against, in ascending onset order. */
|
|
1404
|
-
melody: NoteEvent[];
|
|
1405
|
-
/** Chord sounding at an absolute beat position, or null when none applies. */
|
|
1406
|
-
chordAt: (beat: number) => Chord$1 | null;
|
|
1407
|
-
/** Key/scale context for scale-tone decisions. */
|
|
1408
|
-
key: KeyScale;
|
|
1409
|
-
/**
|
|
1410
|
-
* Meter used for strong-beat decisions.
|
|
1411
|
-
*
|
|
1412
|
-
* @defaultValue 4/4
|
|
1413
|
-
*/
|
|
1414
|
-
ts?: TimeSignature;
|
|
1415
|
-
/**
|
|
1416
|
-
* Which side of the melody the counter line occupies.
|
|
1417
|
-
*
|
|
1418
|
-
* @defaultValue 'below'
|
|
1419
|
-
*/
|
|
1420
|
-
register?: 'above' | 'below';
|
|
1421
|
-
/**
|
|
1422
|
-
* Onset strategy: `'complement'` moves where the melody holds or rests and
|
|
1423
|
-
* reinforces some strong beats; `'follow'` mirrors melody onsets.
|
|
1424
|
-
*
|
|
1425
|
-
* @defaultValue 'complement'
|
|
1426
|
-
*/
|
|
1427
|
-
rhythm?: 'complement' | 'follow';
|
|
1428
|
-
/**
|
|
1429
|
-
* Safety profile applied to candidate pitches.
|
|
1430
|
-
*
|
|
1431
|
-
* @defaultValue 'pop'
|
|
1432
|
-
*/
|
|
1433
|
-
profile?: 'strict' | 'pop';
|
|
1434
|
-
/** Lowest MIDI pitch the counter line may use (default derived from `register`). */
|
|
1435
|
-
pitchLow?: number;
|
|
1436
|
-
/** Highest MIDI pitch the counter line may use (default derived from `register`). */
|
|
1437
|
-
pitchHigh?: number;
|
|
1438
|
-
/**
|
|
1439
|
-
* PRNG seed; the same seed always yields the same line.
|
|
1440
|
-
*
|
|
1441
|
-
* @defaultValue 0
|
|
1442
|
-
*/
|
|
1443
|
-
seed?: number;
|
|
1444
|
-
};
|
|
1445
|
-
/**
|
|
1446
|
-
* Generate a counter melody against a lead line.
|
|
1447
|
-
*
|
|
1448
|
-
* Onsets are chosen per `rhythm`: `'follow'` places one counter note on each
|
|
1449
|
-
* melody onset; `'complement'` fills melody rests and sustains and reinforces
|
|
1450
|
-
* an occasional strong beat, spaced at least a beat apart. Each onset's pitch
|
|
1451
|
-
* is picked from the safe pitches in the counter register (chord tones and
|
|
1452
|
-
* consonant tensions against the sounding melody note), rejecting candidates
|
|
1453
|
-
* that would form a parallel perfect interval with the melody or sit on the
|
|
1454
|
-
* wrong side of it, then scored to favour contrary or oblique motion, imperfect
|
|
1455
|
-
* consonance, and stepwise movement. Ties break toward the lower pitch, so a
|
|
1456
|
-
* given seed always yields the same line. Notes extend to the next counter
|
|
1457
|
-
* onset (the last to the melody's end) at a velocity slightly under the melody.
|
|
1458
|
-
*
|
|
1459
|
-
* @param opts The lead line, chord context callback, key, and generation knobs.
|
|
1460
|
-
* @returns The counter line as note events sorted by onset; `[]` for an empty melody.
|
|
1461
|
-
* @example
|
|
1462
|
-
* ```ts
|
|
1463
|
-
* import { generateCounterMelody, majorKey, parseChordSymbol } from '@libraz/libcantus';
|
|
1464
|
-
* const melody = [{ pitch: 72, startBeat: 0, durationBeat: 2 }];
|
|
1465
|
-
* const counter = generateCounterMelody({
|
|
1466
|
-
* melody,
|
|
1467
|
-
* chordAt: () => parseChordSymbol('C'),
|
|
1468
|
-
* key: majorKey(0),
|
|
1469
|
-
* }); // note events below the melody, in onset order
|
|
1470
|
-
* ```
|
|
1471
|
-
* @category Voicing & Counterpoint
|
|
1472
|
-
*/
|
|
1473
|
-
declare function generateCounterMelody(opts: CounterMelodyOptions): NoteEvent[];
|
|
1474
|
-
|
|
1475
|
-
/**
|
|
1476
|
-
* Whether an upper voice has crossed below a lower voice.
|
|
1477
|
-
*
|
|
1478
|
-
* @param upperPitch Pitch of the nominally higher voice.
|
|
1479
|
-
* @param lowerPitch Pitch of the nominally lower voice.
|
|
1480
|
-
* @returns True when the upper voice sits below the lower voice.
|
|
1481
|
-
* @category Voicing & Counterpoint
|
|
1482
|
-
*/
|
|
1483
|
-
declare function createsVoiceCrossing(upperPitch: number, lowerPitch: number): boolean;
|
|
1484
|
-
/**
|
|
1485
|
-
* Whether two simultaneous pitches form a dissonance.
|
|
1486
|
-
*
|
|
1487
|
-
* @param a First pitch.
|
|
1488
|
-
* @param b Second pitch.
|
|
1489
|
-
* @param twoVoice When true, the perfect fourth counts as dissonant.
|
|
1490
|
-
* @returns True when the vertical interval is dissonant.
|
|
1491
|
-
* @category Voicing & Counterpoint
|
|
1492
|
-
*/
|
|
1493
|
-
declare function createsVerticalDissonance(a: number, b: number, twoVoice: boolean): boolean;
|
|
1494
|
-
/**
|
|
1495
|
-
* Whether a melodic move is a forbidden leap: a tritone, either seventh (minor
|
|
1496
|
-
* or major), or any leap wider than an octave.
|
|
1497
|
-
*
|
|
1498
|
-
* Operates on the raw absolute distance, so compound leaps are not reduced to
|
|
1499
|
-
* their simple class before the octave check.
|
|
1500
|
-
*
|
|
1501
|
-
* @param prev Starting pitch.
|
|
1502
|
-
* @param cur Ending pitch.
|
|
1503
|
-
* @returns True when the leap is forbidden in strict counterpoint.
|
|
1504
|
-
* @category Voicing & Counterpoint
|
|
1505
|
-
*/
|
|
1506
|
-
declare function isForbiddenMelodicLeap(prev: number, cur: number): boolean;
|
|
1507
|
-
/**
|
|
1508
|
-
* Whether two voices move into consecutive perfect intervals of the same kind
|
|
1509
|
-
* (fifth-to-fifth, octave-to-octave, unison-to-unison).
|
|
1510
|
-
*
|
|
1511
|
-
* Both true parallels (similar motion) and anti-parallels — the same perfect
|
|
1512
|
-
* class reached by contrary motion, e.g. octave to octave with the voices moving
|
|
1513
|
-
* in opposite directions — are flagged, as both are forbidden in strict two-voice
|
|
1514
|
-
* counterpoint. The rule requires that both voices actually move: oblique motion
|
|
1515
|
-
* (either voice stationary) and the no-change case (identical pitches) are excluded.
|
|
1516
|
-
*
|
|
1517
|
-
* A fifth expanding to a twelfth counts (same perfect class); a fifth moving to
|
|
1518
|
-
* an octave does not (different perfect kinds — the direct/hidden case owned by
|
|
1519
|
-
* {@link createsHiddenParallelPerfect}).
|
|
1520
|
-
*
|
|
1521
|
-
* @category Voicing & Counterpoint
|
|
1522
|
-
*/
|
|
1523
|
-
declare function createsParallelPerfect(aPrev: number, aCur: number, bPrev: number, bCur: number): boolean;
|
|
1524
|
-
/**
|
|
1525
|
-
* Whether two voices move in consecutive parallel octaves (or unisons) by
|
|
1526
|
-
* similar motion.
|
|
1527
|
-
*
|
|
1528
|
-
* This is a strict subset of {@link createsParallelPerfect}: a similar-motion
|
|
1529
|
-
* octave-to-octave is the perfect-class-zero case that predicate already flags
|
|
1530
|
-
* (and it additionally catches the contrary-motion anti-parallel). Callers that
|
|
1531
|
-
* tally parallel violations should therefore use {@link createsParallelPerfect}
|
|
1532
|
-
* alone to avoid double counting; this predicate remains for callers wanting a
|
|
1533
|
-
* dedicated similar-motion octave test.
|
|
1534
|
-
*
|
|
1535
|
-
* @category Voicing & Counterpoint
|
|
1536
|
-
*/
|
|
1537
|
-
declare function createsParallelOctave(aPrev: number, aCur: number, bPrev: number, bCur: number): boolean;
|
|
1538
|
-
/**
|
|
1539
|
-
* Whether two voices move in consecutive parallel unisons — both landing on the
|
|
1540
|
-
* same pitch, having shared a pitch on the previous move.
|
|
1541
|
-
*
|
|
1542
|
-
* @category Voicing & Counterpoint
|
|
1543
|
-
*/
|
|
1544
|
-
declare function createsParallelUnison(aPrev: number, aCur: number, bPrev: number, bCur: number): boolean;
|
|
1545
|
-
/**
|
|
1546
|
-
* Whether two voices reach a perfect interval by similar motion from an
|
|
1547
|
-
* imperfect one (a hidden/direct fifth or octave).
|
|
1548
|
-
*
|
|
1549
|
-
* The traditional step exception is applied: the approach is allowed when the
|
|
1550
|
-
* upper of the two voices moves by step, so only leaps into the perfect
|
|
1551
|
-
* interval are flagged.
|
|
1552
|
-
*
|
|
1553
|
-
* @category Voicing & Counterpoint
|
|
1554
|
-
*/
|
|
1555
|
-
declare function createsHiddenParallelPerfect(aPrev: number, aCur: number, bPrev: number, bCur: number): boolean;
|
|
1556
|
-
/**
|
|
1557
|
-
* Whether two voices overlap: the upper voice descends below where the lower
|
|
1558
|
-
* voice just was, or the lower voice rises above where the upper voice just was.
|
|
1559
|
-
* Distinct from a simultaneous voice crossing.
|
|
1560
|
-
*
|
|
1561
|
-
* @param upperPrev Previous pitch of the upper voice.
|
|
1562
|
-
* @param upperCur Current pitch of the upper voice.
|
|
1563
|
-
* @param lowerPrev Previous pitch of the lower voice.
|
|
1564
|
-
* @param lowerCur Current pitch of the lower voice.
|
|
1565
|
-
* @category Voicing & Counterpoint
|
|
1566
|
-
*/
|
|
1567
|
-
declare function createsVoiceOverlap(upperPrev: number, upperCur: number, lowerPrev: number, lowerCur: number): boolean;
|
|
1568
|
-
/**
|
|
1569
|
-
* Whether two adjacent upper voices are spaced more than a maximum apart
|
|
1570
|
-
* (commonly an octave). Bass-to-tenor spacing is conventionally exempt, so this
|
|
1571
|
-
* is meant for the upper voice pairs.
|
|
1572
|
-
*
|
|
1573
|
-
* @param upperPitch Pitch of the higher voice.
|
|
1574
|
-
* @param lowerPitch Pitch of the lower voice.
|
|
1575
|
-
* @param maxSemitones Maximum allowed spacing in semitones (default an octave).
|
|
1576
|
-
* @category Voicing & Counterpoint
|
|
1577
|
-
*/
|
|
1578
|
-
declare function exceedsSpacing(upperPitch: number, lowerPitch: number, maxSemitones?: number): boolean;
|
|
1579
|
-
/**
|
|
1580
|
-
* Whether a leading tone resolves correctly upward to the tonic.
|
|
1581
|
-
*
|
|
1582
|
-
* @param prev The leading-tone pitch.
|
|
1583
|
-
* @param cur The following pitch.
|
|
1584
|
-
* @param key Key context supplying the tonic.
|
|
1585
|
-
* @returns True when `prev` is the leading tone and `cur` is the tonic a step above.
|
|
1586
|
-
* @category Voicing & Counterpoint
|
|
1587
|
-
*/
|
|
1588
|
-
declare function isLeadingToneResolution(prev: number, cur: number, key: KeyScale): boolean;
|
|
1589
|
-
|
|
1590
|
-
/**
|
|
1591
|
-
* Recognition: infer a chord name from a set of pitches, or a key from a set of
|
|
1592
|
-
* pitch classes. This is the inverse direction of the chord/scale builders,
|
|
1593
|
-
* which only go name -> notes.
|
|
1594
|
-
*/
|
|
1595
|
-
|
|
1596
|
-
/**
|
|
1597
|
-
* A candidate chord interpretation of a pitch set.
|
|
1598
|
-
*
|
|
1599
|
-
* @category Recognition
|
|
1600
|
-
*/
|
|
1601
|
-
type ChordMatch = {
|
|
1602
|
-
rootPc: number;
|
|
1603
|
-
quality: ChordQuality;
|
|
1604
|
-
/** Chord tones absent from the input (an incomplete voicing). */
|
|
1605
|
-
missingPcs: number[];
|
|
1606
|
-
/** Input pitch classes not belonging to the chord. */
|
|
1607
|
-
extraPcs: number[];
|
|
1608
|
-
/** True when the input pitch-class set equals the chord exactly. */
|
|
1609
|
-
exact: boolean;
|
|
1610
|
-
/** Inversion implied by the lowest note: 0 root position, 1 first, ... */
|
|
1611
|
-
inversion: number;
|
|
1612
|
-
/** Bass pitch class when inverted (the lowest note is not the root). */
|
|
1613
|
-
bassPc?: number;
|
|
1614
|
-
};
|
|
1615
|
-
/**
|
|
1616
|
-
* A candidate key interpretation of a pitch-class set.
|
|
1617
|
-
*
|
|
1618
|
-
* @category Recognition
|
|
1619
|
-
*/
|
|
1620
|
-
type KeyMatch = {
|
|
1621
|
-
key: KeyScale;
|
|
1622
|
-
mode: 'major' | 'minor';
|
|
1623
|
-
/** Fraction of input pitch classes that are in the scale, in [0, 1]. */
|
|
1624
|
-
fit: number;
|
|
1625
|
-
};
|
|
1626
|
-
/**
|
|
1627
|
-
* Identify chords matching a set of pitches.
|
|
1628
|
-
*
|
|
1629
|
-
* Every input pitch class is tried as a root against every known chord quality.
|
|
1630
|
-
* A match is reported when all of the chord's tones are present in the input, or
|
|
1631
|
-
* when the only absent tone is the perfect fifth (a common omission in shell
|
|
1632
|
-
* voicings); matches are ranked best-first by fewest extra notes, then fewest
|
|
1633
|
-
* missing notes, then most specific (largest) chord. An exact match (no extras,
|
|
1634
|
-
* no missing) is flagged and ranked first.
|
|
1635
|
-
*
|
|
1636
|
-
* @param pitches MIDI pitches or bare pitch classes (octave-agnostic).
|
|
1637
|
-
* @returns Ranked chord interpretations (may be empty).
|
|
1638
|
-
* @example
|
|
1639
|
-
* ```ts
|
|
1640
|
-
* import { detectChord } from '@libraz/libcantus';
|
|
1641
|
-
* const matches = detectChord([60, 64, 67]); // C E G
|
|
1642
|
-
* matches[0]; // { rootPc: 0, quality: 'maj', exact: true, ... }
|
|
1643
|
-
* ```
|
|
1644
|
-
* @category Recognition
|
|
1645
|
-
*/
|
|
1646
|
-
declare function detectChord(pitches: number[]): ChordMatch[];
|
|
1647
|
-
/**
|
|
1648
|
-
* The single best chord interpretation of a pitch set, or null if none.
|
|
1649
|
-
*
|
|
1650
|
-
* @param pitches MIDI pitches or bare pitch classes.
|
|
1651
|
-
* @returns The top-ranked chord, or null when nothing matches.
|
|
1652
|
-
* @example
|
|
1653
|
-
* ```ts
|
|
1654
|
-
* import { detectChordBest } from '@libraz/libcantus';
|
|
1655
|
-
* detectChordBest([60, 64, 67]); // C major triad: { rootPc: 0, quality: 'maj', ... }
|
|
1656
|
-
* ```
|
|
1657
|
-
* @category Recognition
|
|
1658
|
-
*/
|
|
1659
|
-
declare function detectChordBest(pitches: number[]): Chord$1 | null;
|
|
1660
|
-
/**
|
|
1661
|
-
* Rank major and minor keys by how well they contain a set of pitch classes.
|
|
1662
|
-
*
|
|
1663
|
-
* The tonic is weighted so that, among equally-fitting keys, the one whose root
|
|
1664
|
-
* appears in the input is preferred. Minor candidates are scored against the
|
|
1665
|
-
* natural, harmonic, and melodic minor variants and keep the best of the three,
|
|
1666
|
-
* so a minor cadence containing the leading tone still resolves to its own
|
|
1667
|
-
* tonic; the returned key is always the natural-minor scale. Returns all 24
|
|
1668
|
-
* keys ranked best-first, or an empty array for an empty input (mirroring
|
|
1669
|
-
* {@link detectChord}).
|
|
1670
|
-
*
|
|
1671
|
-
* @param pitches MIDI pitches or bare pitch classes.
|
|
1672
|
-
* @returns Ranked key interpretations (empty for an empty input).
|
|
1673
|
-
* @example
|
|
1674
|
-
* ```ts
|
|
1675
|
-
* import { detectKey } from '@libraz/libcantus';
|
|
1676
|
-
* const keys = detectKey([60, 62, 64, 65, 67, 69, 71]); // C major scale
|
|
1677
|
-
* keys[0].mode; // 'major', with keys[0].key.rootPc === 0
|
|
1678
|
-
* ```
|
|
1679
|
-
* @category Recognition
|
|
1680
|
-
*/
|
|
1681
|
-
declare function detectKey(pitches: number[]): KeyMatch[];
|
|
1682
|
-
|
|
1683
|
-
/** A single percussion onset. */
|
|
1684
|
-
type DrumHit = {
|
|
1685
|
-
pitch: number;
|
|
1686
|
-
startBeat: number;
|
|
1687
|
-
durationBeat: number;
|
|
1688
|
-
velocity: number;
|
|
1689
|
-
};
|
|
1690
|
-
|
|
1691
|
-
/** Groove feel controlling off-beat swing. */
|
|
1692
|
-
type Feel = 'straight' | 'swing' | 'shuffle';
|
|
1693
|
-
/** Public groove style identifiers. */
|
|
1694
|
-
type GrooveStyle = 'standard' | 'funk' | 'shuffle' | 'bossa' | 'trap' | 'halftime' | 'breakbeat' | 'house' | 'synthpop';
|
|
1695
|
-
/** Public role identifiers gating which voices are present. */
|
|
1696
|
-
type DrumRole = 'full' | 'ambient' | 'minimal' | 'fxOnly';
|
|
1697
|
-
/** Public section identifiers. */
|
|
1698
|
-
type PublicSection = 'intro' | 'verse' | 'prechorus' | 'chorus' | 'bridge' | 'outro';
|
|
1699
|
-
|
|
1700
|
-
/**
|
|
1701
|
-
* Groove feel (the swing/straight rhythmic character) for {@link generateDrums}.
|
|
1702
|
-
*
|
|
1703
|
-
* @category Composition
|
|
1704
|
-
*/
|
|
1705
|
-
type GrooveFeel = Feel;
|
|
1706
|
-
|
|
1707
|
-
/**
|
|
1708
|
-
* Public section identifiers for {@link generateDrums}.
|
|
1709
|
-
*
|
|
1710
|
-
* @category Composition
|
|
1711
|
-
*/
|
|
1712
|
-
type Section = PublicSection;
|
|
1713
|
-
/**
|
|
1714
|
-
* A Euclidean (Bjorklund) kick pattern for {@link generateDrums}.
|
|
1715
|
-
*
|
|
1716
|
-
* @category Composition
|
|
1717
|
-
*/
|
|
1718
|
-
type EuclideanKick = {
|
|
1719
|
-
/** Number of kick onsets, clamped to `[0, steps]`. */
|
|
1720
|
-
pulses: number;
|
|
1721
|
-
/**
|
|
1722
|
-
* Total steps in the bar (1..16).
|
|
1723
|
-
*
|
|
1724
|
-
* @defaultValue 16
|
|
1725
|
-
*/
|
|
1726
|
-
steps?: number;
|
|
1727
|
-
/**
|
|
1728
|
-
* Steps to rotate the onsets toward later positions.
|
|
1729
|
-
*
|
|
1730
|
-
* @defaultValue 0
|
|
1731
|
-
*/
|
|
1732
|
-
rotation?: number;
|
|
1733
|
-
};
|
|
1734
|
-
/**
|
|
1735
|
-
* Options controlling {@link generateDrums}.
|
|
1736
|
-
*
|
|
1737
|
-
* @category Composition
|
|
1738
|
-
*/
|
|
1739
|
-
type DrumGenOptions = {
|
|
1740
|
-
bars: number;
|
|
1741
|
-
bpm: number;
|
|
1742
|
-
style: GrooveStyle;
|
|
1743
|
-
section: Section;
|
|
1744
|
-
density: number;
|
|
1745
|
-
/**
|
|
1746
|
-
* Replace the final bar with a fill.
|
|
1747
|
-
*
|
|
1748
|
-
* @defaultValue false
|
|
1749
|
-
*/
|
|
1750
|
-
fills?: boolean;
|
|
1751
|
-
feel?: GrooveFeel;
|
|
1752
|
-
/**
|
|
1753
|
-
* Voicing role; `'fxOnly'` suppresses the main kick/snare/ghost/fill voices.
|
|
1754
|
-
*
|
|
1755
|
-
* @defaultValue `'full'`
|
|
1756
|
-
*/
|
|
1757
|
-
role?: DrumRole;
|
|
1758
|
-
/**
|
|
1759
|
-
* Seed for the deterministic PRNG.
|
|
1760
|
-
*
|
|
1761
|
-
* @defaultValue 0
|
|
1762
|
-
*/
|
|
1763
|
-
seed?: number;
|
|
1764
|
-
/**
|
|
1765
|
-
* Section the final-bar fill leads into. Shapes which fill archetype is
|
|
1766
|
-
* chosen (into-chorus and out-of-intro fills differ from generic ones).
|
|
1767
|
-
* Defaults to `section`, i.e. a within-section fill.
|
|
1768
|
-
*/
|
|
1769
|
-
nextSection?: Section;
|
|
1770
|
-
/**
|
|
1771
|
-
* When set, the kick follows this Euclidean rhythm instead of the
|
|
1772
|
-
* style/section pattern, giving direct access to evenly spread onsets.
|
|
1773
|
-
*/
|
|
1774
|
-
euclideanKick?: EuclideanKick;
|
|
1775
|
-
};
|
|
1776
|
-
/**
|
|
1777
|
-
* Generate a drum performance as a flat list of onsets.
|
|
1778
|
-
*
|
|
1779
|
-
* Every voice (kick, snare, ghost snares, closed/open/foot hi-hats, ride, toms,
|
|
1780
|
-
* crash, and auxiliary percussion) is emitted as a {@link DrumHit} distinguished
|
|
1781
|
-
* by its General MIDI pitch. Groove style selects an internal style and feel;
|
|
1782
|
-
* `density` sets the backing-density level; `section` shapes kick, hi-hat, ghost,
|
|
1783
|
-
* and percussion density. 16th-note hi-hats drop to 8ths at or above 150 BPM.
|
|
1784
|
-
* When `fills` is true the final bar is replaced with a fill whose archetype is
|
|
1785
|
-
* shaped by `nextSection`; a fill that would emit nothing on its beat falls back
|
|
1786
|
-
* to the normal groove so the phrase end is never silent. `euclideanKick`
|
|
1787
|
-
* overrides the kick with an evenly-spread Euclidean pattern. Output is fully
|
|
1788
|
-
* determined by the options plus `seed`.
|
|
1789
|
-
*
|
|
1790
|
-
* @param opts Generation options.
|
|
1791
|
-
* @returns Percussion onsets in bar order.
|
|
1792
|
-
*
|
|
1793
|
-
* @example
|
|
1794
|
-
* ```ts
|
|
1795
|
-
* import { generateDrums } from '@libraz/libcantus';
|
|
1796
|
-
* const hits = generateDrums({ bars: 4, bpm: 120, style: 'standard', section: 'chorus', density: 0.6, fills: true });
|
|
1797
|
-
* // Fully determined by the options plus seed (defaults to 0).
|
|
1798
|
-
* ```
|
|
1799
|
-
*
|
|
1800
|
-
* @category Composition
|
|
1801
|
-
*/
|
|
1802
|
-
declare function generateDrums(opts: DrumGenOptions): DrumHit[];
|
|
1803
|
-
|
|
1804
|
-
/**
|
|
1805
|
-
* Groove and humanization: nudging quantized note events toward a more human
|
|
1806
|
-
* feel, and capturing/replaying the timing-and-velocity "feel" of a
|
|
1807
|
-
* performance as a reusable groove template.
|
|
1808
|
-
*
|
|
1809
|
-
* Positions and durations are measured in quarter-note beats, matching the
|
|
1810
|
-
* library-wide convention. Randomness, where used, always goes through the
|
|
1811
|
-
* seeded PRNG from the `random` module so results are fully reproducible.
|
|
1812
|
-
*/
|
|
1813
|
-
|
|
1814
|
-
/**
|
|
1815
|
-
* Options controlling {@link humanize}.
|
|
1816
|
-
*
|
|
1817
|
-
* @category Rhythm & Meter
|
|
1818
|
-
*/
|
|
1819
|
-
type HumanizeOptions = {
|
|
1820
|
-
/**
|
|
1821
|
-
* Time signature used to derive metric accents.
|
|
1822
|
-
*
|
|
1823
|
-
* @defaultValue 4/4
|
|
1824
|
-
*/
|
|
1825
|
-
ts?: TimeSignature;
|
|
1826
|
-
/**
|
|
1827
|
-
* Maximum timing jitter in quarter-note beats, applied as ±this value.
|
|
1828
|
-
*
|
|
1829
|
-
* @defaultValue 0.02
|
|
1830
|
-
*/
|
|
1831
|
-
timing?: number;
|
|
1832
|
-
/**
|
|
1833
|
-
* Maximum velocity jitter (MIDI units), applied as ±this value.
|
|
1834
|
-
*
|
|
1835
|
-
* @defaultValue 8
|
|
1836
|
-
*/
|
|
1837
|
-
velocity?: number;
|
|
1838
|
-
/**
|
|
1839
|
-
* How much louder strong beats get relative to weak ones, in MIDI velocity units.
|
|
1840
|
-
*
|
|
1841
|
-
* @defaultValue 12
|
|
1842
|
-
*/
|
|
1843
|
-
accent?: number;
|
|
1844
|
-
/**
|
|
1845
|
-
* Velocity assumed for events with no `velocity` of their own.
|
|
1846
|
-
*
|
|
1847
|
-
* @defaultValue 80
|
|
1848
|
-
*/
|
|
1849
|
-
baseVelocity?: number;
|
|
1850
|
-
/**
|
|
1851
|
-
* Seed for the deterministic PRNG.
|
|
1852
|
-
*
|
|
1853
|
-
* @defaultValue 0
|
|
1854
|
-
*/
|
|
1855
|
-
seed?: number;
|
|
1856
|
-
};
|
|
1857
|
-
/**
|
|
1858
|
-
* Humanize a sequence of note events by nudging their timing and velocity
|
|
1859
|
-
* with small, deterministic (seeded) randomness plus a metric-accent shape:
|
|
1860
|
-
* events on strong beats (see {@link metricWeight}) come out louder on
|
|
1861
|
-
* average than events on weak ones.
|
|
1862
|
-
*
|
|
1863
|
-
* Each returned event is a copy; `startBeat` is jittered within
|
|
1864
|
-
* `[-timing, +timing]` beats and clamped to be non-negative, and `velocity`
|
|
1865
|
-
* is the event's own velocity (or `baseVelocity` if it has none) plus an
|
|
1866
|
-
* accent term scaled by the event's metric weight plus a jitter within
|
|
1867
|
-
* `[-velocity, +velocity]`, clamped to `[1, 127]` and rounded. The metric
|
|
1868
|
-
* weight is computed from each event's original (pre-jitter) `startBeat`.
|
|
1869
|
-
* `pitch` and `durationBeat` pass through unchanged, and the output keeps the
|
|
1870
|
-
* input order.
|
|
1871
|
-
*
|
|
1872
|
-
* @param events The events to humanize.
|
|
1873
|
-
* @param opts Humanization options.
|
|
1874
|
-
* @returns Humanized copies of `events`, in input order.
|
|
1875
|
-
* @example
|
|
1876
|
-
* ```ts
|
|
1877
|
-
* import { humanize } from '@libraz/libcantus';
|
|
1878
|
-
* const events = [{ pitch: 60, startBeat: 0, durationBeat: 1, velocity: 80 }];
|
|
1879
|
-
* humanize(events, { seed: 1, timing: 0.03 }); // copies with jittered timing and accented velocity
|
|
1880
|
-
* ```
|
|
1881
|
-
* @category Rhythm & Meter
|
|
1882
|
-
*/
|
|
1883
|
-
declare function humanize(events: NoteEvent[], opts?: HumanizeOptions): NoteEvent[];
|
|
1884
|
-
/**
|
|
1885
|
-
* The recorded feel at a single grid slot: an average timing deviation and velocity.
|
|
1886
|
-
*
|
|
1887
|
-
* @category Rhythm & Meter
|
|
1888
|
-
*/
|
|
1889
|
-
type GrooveSlot = {
|
|
1890
|
-
/** Average `actualStartBeat - quantizedBeat` (in quarter-note beats) for events landing on this slot. */
|
|
1891
|
-
timingOffset: number;
|
|
1892
|
-
/**
|
|
1893
|
-
* Average velocity of events landing on this slot, or `null` if no event
|
|
1894
|
-
* with a velocity did. `null` (not 0) is the "unrecorded" sentinel so that a
|
|
1895
|
-
* genuine velocity of 0 is preserved and applied like any other value.
|
|
1896
|
-
*/
|
|
1897
|
-
velocity: number | null;
|
|
1898
|
-
};
|
|
1899
|
-
/**
|
|
1900
|
-
* A per-bar grid of timing and velocity deviations captured from a performance.
|
|
1901
|
-
*
|
|
1902
|
-
* @category Rhythm & Meter
|
|
1903
|
-
*/
|
|
1904
|
-
type GrooveTemplate = {
|
|
1905
|
-
/** Grid resolution: equal grid steps per quarter-note beat. */
|
|
1906
|
-
subdivision: number;
|
|
1907
|
-
/** Number of grid slots per bar (`beatsPerBar(ts) * subdivision`). */
|
|
1908
|
-
slotsPerBar: number;
|
|
1909
|
-
/** One entry per grid slot, in slot-index order (slot 0 is the downbeat). */
|
|
1910
|
-
slots: GrooveSlot[];
|
|
1911
|
-
/**
|
|
1912
|
-
* The time signature the template was extracted under. {@link applyGrooveTemplate}
|
|
1913
|
-
* requires the apply-time meter to match this so the per-bar grid lines up
|
|
1914
|
-
* instead of silently drifting. Optional for backward compatibility with
|
|
1915
|
-
* templates constructed without it (in which case no check is performed).
|
|
1916
|
-
*/
|
|
1917
|
-
ts?: TimeSignature;
|
|
1918
|
-
};
|
|
1919
|
-
/**
|
|
1920
|
-
* Extract a groove template from a set of note events: for each grid slot,
|
|
1921
|
-
* the average timing deviation from the quantized grid and the average
|
|
1922
|
-
* velocity of events landing on it. Slots with no velocity-carrying event
|
|
1923
|
-
* record `velocity: null` (the "unrecorded" sentinel); empty slots default to
|
|
1924
|
-
* `{ timingOffset: 0, velocity: null }`. The time signature is stored on the
|
|
1925
|
-
* template so {@link applyGrooveTemplate} can verify the meter matches.
|
|
1926
|
-
*
|
|
1927
|
-
* @param events The (typically "groovy", human-played) events to analyze.
|
|
1928
|
-
* @param ts The time signature, used to compute the bar length.
|
|
1929
|
-
* @param subdivision Grid resolution: equal grid steps per quarter-note beat.
|
|
1930
|
-
* @returns The extracted groove template.
|
|
1931
|
-
* @category Rhythm & Meter
|
|
1932
|
-
*/
|
|
1933
|
-
declare function extractGrooveTemplate(events: NoteEvent[], ts: TimeSignature, subdivision: number): GrooveTemplate;
|
|
1934
|
-
/**
|
|
1935
|
-
* Apply a groove template to a set of (typically quantized) note events: each
|
|
1936
|
-
* event is snapped to its grid slot and then offset by that slot's recorded
|
|
1937
|
-
* timing deviation, pushing stiff timing toward the template's feel.
|
|
1938
|
-
* Velocity is set to the slot's recorded average when it recorded one (a
|
|
1939
|
-
* non-`null` velocity, including a genuine 0); otherwise the event's own
|
|
1940
|
-
* velocity is left untouched.
|
|
1941
|
-
*
|
|
1942
|
-
* If the template carries a time signature (see {@link GrooveTemplate.ts}) it
|
|
1943
|
-
* must match `ts`, since a differing bar length would misalign the per-bar
|
|
1944
|
-
* grid and drift the feel; a mismatch throws rather than corrupting timing
|
|
1945
|
-
* silently.
|
|
1946
|
-
*
|
|
1947
|
-
* @param events The events to reshape.
|
|
1948
|
-
* @param template The groove template, from {@link extractGrooveTemplate}.
|
|
1949
|
-
* @param ts The time signature, used to compute the bar length.
|
|
1950
|
-
* @returns Reshaped copies of `events`, in input order.
|
|
1951
|
-
* @throws If `template.ts` is set and does not match `ts`.
|
|
1952
|
-
* @example
|
|
1953
|
-
* ```ts
|
|
1954
|
-
* import { extractGrooveTemplate, applyGrooveTemplate, parseTimeSignature } from '@libraz/libcantus';
|
|
1955
|
-
* const ts = parseTimeSignature('4/4');
|
|
1956
|
-
* // Learn the feel from a loosely played performance...
|
|
1957
|
-
* const groovy = [
|
|
1958
|
-
* { pitch: 36, startBeat: 0.02, durationBeat: 1, velocity: 100 },
|
|
1959
|
-
* { pitch: 38, startBeat: 1.06, durationBeat: 1, velocity: 70 },
|
|
1960
|
-
* ];
|
|
1961
|
-
* const template = extractGrooveTemplate(groovy, ts, 4);
|
|
1962
|
-
* // ...then impose it on stiff, quantized events.
|
|
1963
|
-
* const quantized = [{ pitch: 36, startBeat: 0, durationBeat: 1, velocity: 80 }];
|
|
1964
|
-
* applyGrooveTemplate(quantized, template, ts); // events nudged toward the captured feel
|
|
1965
|
-
* ```
|
|
1966
|
-
* @category Rhythm & Meter
|
|
1967
|
-
*/
|
|
1968
|
-
declare function applyGrooveTemplate(events: NoteEvent[], template: GrooveTemplate, ts: TimeSignature): NoteEvent[];
|
|
1969
|
-
|
|
1970
|
-
/**
|
|
1971
|
-
* Harmonic role a pitch plays within a chord.
|
|
1972
|
-
*
|
|
1973
|
-
* @category Functional Harmony
|
|
1974
|
-
*/
|
|
1975
|
-
type HarmonyRole = 'root' | 'third' | 'fifth' | 'sixth' | 'seventh' | 'tension' | 'doubling';
|
|
1976
|
-
/**
|
|
1977
|
-
* How firmly a pitch is locked to the chord's identity.
|
|
1978
|
-
*
|
|
1979
|
-
* - `identity`: moving it produces a different chord (the root).
|
|
1980
|
-
* - `quality`: moving it flips the chord quality (the third).
|
|
1981
|
-
* - `voicing`: it can move freely without changing chord identity or quality.
|
|
1982
|
-
*
|
|
1983
|
-
* @category Functional Harmony
|
|
1984
|
-
*/
|
|
1985
|
-
type LockLevel = 'identity' | 'quality' | 'voicing';
|
|
1986
|
-
/**
|
|
1987
|
-
* A pitch's role, lock level, and owning chord.
|
|
1988
|
-
*
|
|
1989
|
-
* @category Functional Harmony
|
|
1990
|
-
*/
|
|
1991
|
-
type VoicedRole = {
|
|
1992
|
-
role: HarmonyRole;
|
|
1993
|
-
lock: LockLevel;
|
|
1994
|
-
belongsToChordId: number;
|
|
1995
|
-
};
|
|
1996
|
-
/**
|
|
1997
|
-
* Classify a pitch's harmonic role and lock level within a chord.
|
|
1998
|
-
*
|
|
1999
|
-
* The role comes from the pitch's interval class above the chord root: root (0),
|
|
2000
|
-
* third (3/4), fifth (6/7/8), seventh (10/11), and 9/11/13 tensions (2/5/9, and
|
|
2001
|
-
* the flat ninth 1). The root locks the chord identity, the third locks its
|
|
2002
|
-
* quality, and everything else is free voicing. In a suspended chord (a chord
|
|
2003
|
-
* whose intervals include a 4th (5) or 2nd (2) but no third), the suspended tone
|
|
2004
|
-
* takes the third's place as the quality-defining tone and is locked to
|
|
2005
|
-
* `quality`, since moving it changes the chord. Detecting an octave doubling
|
|
2006
|
-
* requires the surrounding voicing, which this single-pitch query does not carry,
|
|
2007
|
-
* so `doubling` is part of the type but not returned here.
|
|
2008
|
-
*
|
|
2009
|
-
* @param pitch MIDI pitch or bare pitch class.
|
|
2010
|
-
* @param chord The chord providing the root reference.
|
|
2011
|
-
* @param chordId Identifier stored on the result (defaults to 0).
|
|
2012
|
-
* @returns The pitch's role, lock level, and owning chord id.
|
|
2013
|
-
* @example
|
|
2014
|
-
* ```ts
|
|
2015
|
-
* import { roleOf, makeChord } from '@libraz/libcantus';
|
|
2016
|
-
* roleOf(64, makeChord(0, 'maj')); // E over C major
|
|
2017
|
-
* // { role: 'third', lock: 'quality', belongsToChordId: 0 }
|
|
2018
|
-
* ```
|
|
2019
|
-
* @category Functional Harmony
|
|
2020
|
-
*/
|
|
2021
|
-
declare function roleOf(pitch: number, chord: Chord$1, chordId?: number): VoicedRole;
|
|
2022
|
-
|
|
2023
|
-
/**
|
|
2024
|
-
* A melody note supplied to the harmonizer: a {@link NoteEvent}.
|
|
2025
|
-
*
|
|
2026
|
-
* @category Reharmonization
|
|
2027
|
-
*/
|
|
2028
|
-
type MelodyNote = NoteEvent;
|
|
2029
|
-
/**
|
|
2030
|
-
* Options controlling {@link harmonizeMelody}.
|
|
2031
|
-
*
|
|
2032
|
-
* @category Reharmonization
|
|
2033
|
-
*/
|
|
2034
|
-
type HarmonizeOptions = {
|
|
2035
|
-
melody: MelodyNote[];
|
|
2036
|
-
key: KeyScale | 'infer';
|
|
2037
|
-
harmonicRhythm: number;
|
|
2038
|
-
reharmonize: 'diatonic' | 'secondaryDominant' | 'borrowed';
|
|
2039
|
-
placement: {
|
|
2040
|
-
transposeSearch: boolean;
|
|
2041
|
-
octaveSearch: boolean;
|
|
2042
|
-
};
|
|
2043
|
-
/**
|
|
2044
|
-
* Seed for the deterministic tie-break perturbation.
|
|
2045
|
-
*
|
|
2046
|
-
* @defaultValue 0
|
|
2047
|
-
*/
|
|
2048
|
-
seed?: number;
|
|
2049
|
-
};
|
|
2050
|
-
/**
|
|
2051
|
-
* The chosen transpose, key, chord path, and per-note roles.
|
|
2052
|
-
*
|
|
2053
|
-
* @category Reharmonization
|
|
2054
|
-
*/
|
|
2055
|
-
type HarmonizeResult = {
|
|
2056
|
-
transposeSemitones: number;
|
|
2057
|
-
key: KeyScale;
|
|
2058
|
-
chords: GeneratedChord[];
|
|
2059
|
-
melodyRoles: {
|
|
2060
|
-
noteIndex: number;
|
|
2061
|
-
role: HarmonyRole;
|
|
2062
|
-
}[];
|
|
2063
|
-
};
|
|
2064
|
-
/**
|
|
2065
|
-
* Harmonize a melody with a min-cost chord progression.
|
|
2066
|
-
*
|
|
2067
|
-
* The melody is segmented by `harmonicRhythm`; each segment is scored against
|
|
2068
|
-
* diatonic (and, per `reharmonize`, secondary-dominant and borrowed) candidate
|
|
2069
|
-
* chords by melody fit, and a Viterbi search picks the lowest-cost path using a
|
|
2070
|
-
* functional-flow transition cost. When `placement.transposeSearch`/`octaveSearch`
|
|
2071
|
-
* is set, the whole melody is transposed across a range and the best
|
|
2072
|
-
* `(transpose, progression)` pair is returned; a small tessitura cost breaks
|
|
2073
|
-
* ties toward placements that keep the melody in a comfortable register.
|
|
2074
|
-
*
|
|
2075
|
-
* The `seed` drives a deterministic tie-break only: it perturbs candidates by a
|
|
2076
|
-
* magnitude far below any real cost difference (see {@link TIE_BREAK_JITTER}),
|
|
2077
|
-
* so it can decide between chords or paths of otherwise-equal cost but never
|
|
2078
|
-
* overrides melody fit or functional flow. For a well-determined melody the
|
|
2079
|
-
* result is identical across seeds; the same seed always yields the same result.
|
|
2080
|
-
*
|
|
2081
|
-
* @param opts Melody, key (or `'infer'`), harmonic rhythm, reharmonization
|
|
2082
|
-
* strength, height-search flags, and seed.
|
|
2083
|
-
* @returns The chosen transpose, key, chord path, and per-note roles.
|
|
2084
|
-
* @example
|
|
2085
|
-
* ```ts
|
|
2086
|
-
* import { harmonizeMelody, majorKey } from '@libraz/libcantus';
|
|
2087
|
-
* const result = harmonizeMelody({
|
|
2088
|
-
* melody: [
|
|
2089
|
-
* { pitch: 60, startBeat: 0, durationBeat: 1 },
|
|
2090
|
-
* { pitch: 64, startBeat: 1, durationBeat: 1 },
|
|
2091
|
-
* ],
|
|
2092
|
-
* key: majorKey(0),
|
|
2093
|
-
* harmonicRhythm: 1,
|
|
2094
|
-
* reharmonize: 'diatonic',
|
|
2095
|
-
* placement: { transposeSearch: false, octaveSearch: false },
|
|
2096
|
-
* });
|
|
2097
|
-
* result.chords; // one GeneratedChord per harmonic-rhythm segment
|
|
2098
|
-
* ```
|
|
2099
|
-
* @category Reharmonization
|
|
2100
|
-
*/
|
|
2101
|
-
declare function harmonizeMelody(opts: HarmonizeOptions): HarmonizeResult;
|
|
2102
|
-
|
|
2103
|
-
/**
|
|
2104
|
-
* Counterpoint classification of a harmonic interval.
|
|
2105
|
-
*
|
|
2106
|
-
* @category Pitch & Intervals
|
|
2107
|
-
*/
|
|
2108
|
-
declare enum IntervalQuality {
|
|
2109
|
-
PerfectConsonance = 0,
|
|
2110
|
-
ImperfectConsonance = 1,
|
|
2111
|
-
Dissonance = 2
|
|
2112
|
-
}
|
|
2113
|
-
/**
|
|
2114
|
-
* Classify an interval for counterpoint evaluation.
|
|
2115
|
-
*
|
|
2116
|
-
* The interval is reduced modulo 12, so compound intervals classify as their
|
|
2117
|
-
* simple equivalents. The perfect fourth (5) is context-dependent: with
|
|
2118
|
-
* `twoVoice` (the default) it classifies as a dissonance, matching
|
|
2119
|
-
* {@link isConsonantInterval}; otherwise it is an imperfect consonance.
|
|
2120
|
-
*
|
|
2121
|
-
* @param semitones Interval size in semitones (may be negative or compound).
|
|
2122
|
-
* @param twoVoice When true, the perfect fourth is treated as dissonant.
|
|
2123
|
-
* @returns The counterpoint quality of the interval.
|
|
2124
|
-
* @example
|
|
2125
|
-
* ```ts
|
|
2126
|
-
* import { classifyInterval, IntervalQuality } from '@libraz/libcantus';
|
|
2127
|
-
* classifyInterval(7); // IntervalQuality.PerfectConsonance
|
|
2128
|
-
* classifyInterval(5); // IntervalQuality.Dissonance (two-voice)
|
|
2129
|
-
* classifyInterval(5, false); // IntervalQuality.ImperfectConsonance
|
|
2130
|
-
* ```
|
|
2131
|
-
* @category Pitch & Intervals
|
|
2132
|
-
*/
|
|
2133
|
-
declare function classifyInterval(semitones: number, twoVoice?: boolean): IntervalQuality;
|
|
2134
|
-
/**
|
|
2135
|
-
* Test whether an interval is a perfect interval (unison/octave or fifth).
|
|
2136
|
-
*
|
|
2137
|
-
* @param semitones Interval size in semitones (may be negative or compound).
|
|
2138
|
-
* @returns True for the unison/octave (0) and the perfect fifth (7) mod 12.
|
|
2139
|
-
* @category Pitch & Intervals
|
|
2140
|
-
*/
|
|
2141
|
-
declare function isPerfectInterval(semitones: number): boolean;
|
|
2142
|
-
/**
|
|
2143
|
-
* Test whether an interval is consonant.
|
|
2144
|
-
*
|
|
2145
|
-
* The consonant set is {0, 3, 4, 5, 7, 8, 9} mod 12. In two-voice counterpoint
|
|
2146
|
-
* the perfect fourth (5) is treated as a dissonance, so `twoVoice` set to true
|
|
2147
|
-
* excludes it.
|
|
2148
|
-
*
|
|
2149
|
-
* @param semitones Interval size in semitones (may be negative or compound).
|
|
2150
|
-
* @param twoVoice When true, the perfect fourth is treated as dissonant.
|
|
2151
|
-
* @returns True if the interval is consonant in the given context.
|
|
2152
|
-
* @category Pitch & Intervals
|
|
2153
|
-
*/
|
|
2154
|
-
declare function isConsonantInterval(semitones: number, twoVoice?: boolean): boolean;
|
|
2155
|
-
|
|
2156
|
-
/**
|
|
2157
|
-
* Pitch spelling: letter-name notes, enharmonic-aware conversion, and spelled
|
|
2158
|
-
* intervals.
|
|
2159
|
-
*
|
|
2160
|
-
* The rest of the library works in pitch classes (0..11), which cannot tell a
|
|
2161
|
-
* G# from an Ab or an augmented fourth from a diminished fifth. This module adds
|
|
2162
|
-
* an explicit spelling layer — a note is a diatonic letter plus a chromatic
|
|
2163
|
-
* alteration — so interval quality (P/M/m/A/d) and enharmonic identity are
|
|
2164
|
-
* preserved.
|
|
2165
|
-
*/
|
|
2166
|
-
/**
|
|
2167
|
-
* A spelled note: a diatonic letter, a chromatic alteration, and an optional
|
|
2168
|
-
* octave.
|
|
2169
|
-
*
|
|
2170
|
-
* - `letter` is 0..6 for C..B.
|
|
2171
|
-
* - `alter` is the number of semitones of alteration: -2 double-flat, -1 flat,
|
|
2172
|
-
* 0 natural, +1 sharp, +2 double-sharp.
|
|
2173
|
-
* - `octave` follows scientific pitch notation (middle C = C4 = MIDI 60). When
|
|
2174
|
-
* absent, the note denotes a bare pitch class.
|
|
2175
|
-
*
|
|
2176
|
-
* @category Pitch & Intervals
|
|
2177
|
-
*/
|
|
2178
|
-
type Note$1 = {
|
|
2179
|
-
letter: number;
|
|
2180
|
-
alter: number;
|
|
2181
|
-
octave?: number;
|
|
2182
|
-
};
|
|
2183
|
-
/**
|
|
2184
|
-
* A spelled interval: a diatonic number, a quality label, and its semitone span.
|
|
2185
|
-
*
|
|
2186
|
-
* @category Pitch & Intervals
|
|
2187
|
-
*/
|
|
2188
|
-
type SpelledInterval = {
|
|
2189
|
-
/** Diatonic size: 1 = unison, 2 = second, ... 8 = octave, and beyond. */
|
|
2190
|
-
number: number;
|
|
2191
|
-
/** Quality label: 'P', 'M', 'm', or repeated 'A'/'d' for (multiply) aug/dim. */
|
|
2192
|
-
quality: string;
|
|
2193
|
-
/** Signed semitone distance from the first note to the second. */
|
|
2194
|
-
semitones: number;
|
|
2195
|
-
};
|
|
2196
|
-
/**
|
|
2197
|
-
* Parse scientific pitch notation into a {@link Note}.
|
|
2198
|
-
*
|
|
2199
|
-
* Accepts a letter (case-insensitive) followed by any number of same-direction
|
|
2200
|
-
* accidentals and an optional octave, e.g. `"C"`, `"C#4"`, `"Bb"`, `"F##3"`,
|
|
2201
|
-
* `"Ebb2"`. Both `#` and `x` (double-sharp) are accepted for sharps; `b` for
|
|
2202
|
-
* flats. Mixing sharps and flats (e.g. `"C#b"`) is rejected.
|
|
2203
|
-
*
|
|
2204
|
-
* @param text The note text.
|
|
2205
|
-
* @returns The parsed note.
|
|
2206
|
-
* @throws If the text is not a valid note.
|
|
2207
|
-
* @example
|
|
2208
|
-
* ```ts
|
|
2209
|
-
* import { parseNote, noteToMidi } from '@libraz/libcantus';
|
|
2210
|
-
* const n = parseNote('C#4');
|
|
2211
|
-
* noteToMidi(n); // 61
|
|
2212
|
-
* ```
|
|
2213
|
-
* @category Pitch & Intervals
|
|
2214
|
-
*/
|
|
2215
|
-
declare function parseNote(text: string): Note$1;
|
|
2216
|
-
/**
|
|
2217
|
-
* Render a {@link Note} as scientific pitch notation.
|
|
2218
|
-
*
|
|
2219
|
-
* @param note The note to format.
|
|
2220
|
-
* @returns The note text, including the octave when present.
|
|
2221
|
-
* @example
|
|
2222
|
-
* ```ts
|
|
2223
|
-
* import { formatNote, parseNote } from '@libraz/libcantus';
|
|
2224
|
-
* formatNote(parseNote('C#4')); // 'C#4'
|
|
2225
|
-
* ```
|
|
2226
|
-
* @category Pitch & Intervals
|
|
2227
|
-
*/
|
|
2228
|
-
declare function formatNote(note: Note$1): string;
|
|
2229
|
-
/**
|
|
2230
|
-
* Pitch class (0..11) of a note, ignoring octave.
|
|
2231
|
-
*
|
|
2232
|
-
* @param note The note.
|
|
2233
|
-
* @returns The pitch class.
|
|
2234
|
-
* @example
|
|
2235
|
-
* ```ts
|
|
2236
|
-
* import { noteToPitchClass, parseNote } from '@libraz/libcantus';
|
|
2237
|
-
* noteToPitchClass(parseNote('Db')); // 1
|
|
2238
|
-
* ```
|
|
2239
|
-
* @category Pitch & Intervals
|
|
2240
|
-
*/
|
|
2241
|
-
declare function noteToPitchClass(note: Note$1): number;
|
|
2242
|
-
/**
|
|
2243
|
-
* MIDI number of a note (middle C = C4 = 60).
|
|
2244
|
-
*
|
|
2245
|
-
* @param note The note; must carry an octave.
|
|
2246
|
-
* @returns The MIDI number.
|
|
2247
|
-
* @throws If the note has no octave.
|
|
2248
|
-
* @example
|
|
2249
|
-
* ```ts
|
|
2250
|
-
* import { noteToMidi, parseNote } from '@libraz/libcantus';
|
|
2251
|
-
* noteToMidi(parseNote('A4')); // 69
|
|
2252
|
-
* ```
|
|
2253
|
-
* @category Pitch & Intervals
|
|
2254
|
-
*/
|
|
2255
|
-
declare function noteToMidi(note: Note$1): number;
|
|
2256
|
-
/**
|
|
2257
|
-
* Name a MIDI number as a {@link Note}, choosing sharp or flat spelling.
|
|
2258
|
-
*
|
|
2259
|
-
* The input is rounded to the nearest integer but is not clamped to the MIDI
|
|
2260
|
-
* range 0..127: out-of-range values extrapolate linearly (e.g. `-1` -> `B-2`,
|
|
2261
|
-
* `128` -> `G#9`) and remain an exact inverse of {@link noteToMidi}.
|
|
2262
|
-
*
|
|
2263
|
-
* @param midi The MIDI number.
|
|
2264
|
-
* @param spelling Whether to prefer sharps or flats for black keys.
|
|
2265
|
-
* @returns The spelled note, with octave.
|
|
2266
|
-
* @example
|
|
2267
|
-
* ```ts
|
|
2268
|
-
* import { midiToNote, formatNote } from '@libraz/libcantus';
|
|
2269
|
-
* formatNote(midiToNote(61)); // 'C#4'
|
|
2270
|
-
* formatNote(midiToNote(61, 'flat')); // 'Db4'
|
|
2271
|
-
* ```
|
|
2272
|
-
* @category Pitch & Intervals
|
|
2273
|
-
*/
|
|
2274
|
-
declare function midiToNote(midi: number, spelling?: 'sharp' | 'flat'): Note$1;
|
|
2275
|
-
/**
|
|
2276
|
-
* The spelled interval from one note to another.
|
|
2277
|
-
*
|
|
2278
|
-
* When both notes carry octaves, the interval reflects their full signed
|
|
2279
|
-
* distance (so `C4 -> C5` is a perfect octave). When either lacks an octave the
|
|
2280
|
-
* interval is measured within a single ascending octave from `a` to `b`.
|
|
2281
|
-
*
|
|
2282
|
-
* @param a The lower/first note.
|
|
2283
|
-
* @param b The upper/second note.
|
|
2284
|
-
* @returns The diatonic number, quality, and semitone span.
|
|
2285
|
-
* @example
|
|
2286
|
-
* ```ts
|
|
2287
|
-
* import { spelledInterval, parseNote } from '@libraz/libcantus';
|
|
2288
|
-
* spelledInterval(parseNote('C4'), parseNote('G4'));
|
|
2289
|
-
* // { number: 5, quality: 'P', semitones: 7 }
|
|
2290
|
-
* ```
|
|
2291
|
-
* @category Pitch & Intervals
|
|
2292
|
-
*/
|
|
2293
|
-
declare function spelledInterval(a: Note$1, b: Note$1): SpelledInterval;
|
|
2294
|
-
|
|
2295
|
-
/**
|
|
2296
|
-
* An inclusive MIDI pitch range for a single voice.
|
|
2297
|
-
*
|
|
2298
|
-
* @category Voicing & Counterpoint
|
|
2299
|
-
*/
|
|
2300
|
-
type VoiceRange = {
|
|
2301
|
-
min: number;
|
|
2302
|
-
max: number;
|
|
2303
|
-
};
|
|
2304
|
-
/**
|
|
2305
|
-
* Default four-voice SATB ranges, ascending (index 0 = lowest):
|
|
2306
|
-
* bass E2–C4 (40–60), tenor C3–G4 (48–67), alto G3–D5 (55–74),
|
|
2307
|
-
* soprano C4–G5 (60–79).
|
|
2308
|
-
*
|
|
2309
|
-
* @category Voicing & Counterpoint
|
|
2310
|
-
*/
|
|
2311
|
-
declare const SATB_RANGES: readonly VoiceRange[];
|
|
2312
|
-
/**
|
|
2313
|
-
* Options controlling {@link voiceChord} and {@link voiceProgression}.
|
|
2314
|
-
*
|
|
2315
|
-
* @category Voicing & Counterpoint
|
|
2316
|
-
*/
|
|
2317
|
-
type VoicingOptions = {
|
|
2318
|
-
/**
|
|
2319
|
-
* Number of voices to realize. Ignored when `ranges` is given.
|
|
2320
|
-
*
|
|
2321
|
-
* @defaultValue 4
|
|
2322
|
-
*/
|
|
2323
|
-
voices?: number;
|
|
2324
|
-
/** Explicit per-voice ranges, ascending (index 0 = lowest). Takes precedence over `voices`. */
|
|
2325
|
-
ranges?: VoiceRange[];
|
|
2326
|
-
/**
|
|
2327
|
-
* Maximum spacing in semitones between adjacent upper voices.
|
|
2328
|
-
*
|
|
2329
|
-
* @defaultValue 12
|
|
2330
|
-
*/
|
|
2331
|
-
maxSpacing?: number;
|
|
2332
|
-
};
|
|
2333
|
-
/**
|
|
2334
|
-
* Total voice-leading cost between two voicings: the sum of absolute semitone
|
|
2335
|
-
* motion across voices, plus a moderate {@link HIDDEN_PERFECT_PENALTY} when the
|
|
2336
|
-
* outer-voice (bass–soprano) pair reaches a hidden/direct perfect fifth or
|
|
2337
|
-
* octave by similar motion. The arrays must be the same length; when they
|
|
2338
|
-
* differ the voicings are not comparable and the cost is `Infinity`.
|
|
2339
|
-
*
|
|
2340
|
-
* @param from The previous voicing, one MIDI pitch per voice.
|
|
2341
|
-
* @param to The next voicing, one MIDI pitch per voice.
|
|
2342
|
-
* @returns The summed absolute motion (plus any hidden-perfect penalty), or
|
|
2343
|
-
* `Infinity` when lengths differ.
|
|
2344
|
-
* @category Voicing & Counterpoint
|
|
2345
|
-
*/
|
|
2346
|
-
declare function voiceLeadingCost(from: number[], to: number[]): number;
|
|
2347
|
-
/**
|
|
2348
|
-
* Realize a single chord as one MIDI pitch per voice, ascending (index 0 =
|
|
2349
|
-
* lowest). The bass voice takes the chord's `bassPc` when set, otherwise the
|
|
2350
|
-
* root; upper voices take chord pitch classes, doubling the root or fifth as
|
|
2351
|
-
* needed to fill all voices. The result stays inside each voice's range, keeps
|
|
2352
|
-
* adjacent upper voices within `maxSpacing`, avoids voice crossing, and is
|
|
2353
|
-
* deterministic: a compact close-position voicing centered in the ranges.
|
|
2354
|
-
*
|
|
2355
|
-
* @param chord The chord to voice.
|
|
2356
|
-
* @param opts Voicing options; defaults to four voices in {@link SATB_RANGES}.
|
|
2357
|
-
* @returns MIDI pitches, ascending, one per voice.
|
|
2358
|
-
* @throws If no voicing fits the given ranges.
|
|
2359
|
-
* @example
|
|
2360
|
-
* ```ts
|
|
2361
|
-
* import { parseChordSymbol, voiceChord } from '@libraz/libcantus';
|
|
2362
|
-
* const chord = parseChordSymbol('Cmaj7');
|
|
2363
|
-
* voiceChord(chord); // four ascending MIDI pitches within the SATB ranges
|
|
2364
|
-
* ```
|
|
2365
|
-
* @category Voicing & Counterpoint
|
|
2366
|
-
*/
|
|
2367
|
-
declare function voiceChord(chord: Chord$1, opts?: VoicingOptions): number[];
|
|
2368
|
-
/**
|
|
2369
|
-
* Voice a chord progression with smooth voice leading. The first chord is
|
|
2370
|
-
* voiced with {@link voiceChord}; each subsequent chord picks, from a bounded
|
|
2371
|
-
* deterministic candidate set, the voicing minimizing the voice-leading cost
|
|
2372
|
-
* from the previous voicing plus a large penalty per counterpoint violation
|
|
2373
|
-
* (parallel perfects/octaves, voice crossing, voice overlap, and over-wide
|
|
2374
|
-
* upper-voice spacing).
|
|
2375
|
-
*
|
|
2376
|
-
* @param chords The chords to voice in order.
|
|
2377
|
-
* @param opts Voicing options; defaults to four voices in {@link SATB_RANGES}.
|
|
2378
|
-
* @returns One voicing per chord, each ascending with one MIDI pitch per voice.
|
|
2379
|
-
* @throws If any chord admits no voicing within the given ranges.
|
|
2380
|
-
* @example
|
|
2381
|
-
* ```ts
|
|
2382
|
-
* import { parseChordSymbol, voiceProgression } from '@libraz/libcantus';
|
|
2383
|
-
* const chords = ['C', 'Am', 'F', 'G'].map((s) => parseChordSymbol(s));
|
|
2384
|
-
* voiceProgression(chords); // one four-voice voicing per chord, smoothly led
|
|
2385
|
-
* ```
|
|
2386
|
-
* @category Voicing & Counterpoint
|
|
2387
|
-
*/
|
|
2388
|
-
declare function voiceProgression(chords: Chord$1[], opts?: VoicingOptions): number[][];
|
|
2389
|
-
/**
|
|
2390
|
-
* A tertian voicing style for {@link voiceChordStyled}.
|
|
2391
|
-
*
|
|
2392
|
-
* - `close`: the plain close-position tertian stack.
|
|
2393
|
-
* - `drop2`: the second voice from the top dropped an octave (drop-2 voicing).
|
|
2394
|
-
* - `drop3`: the third voice from the top dropped an octave (drop-3 voicing).
|
|
2395
|
-
* - `shell`: root plus guide tones (third and seventh) for seventh chords, or
|
|
2396
|
-
* root/third/fifth for triads; the fifth and tensions are omitted.
|
|
2397
|
-
* - `rootless`: the root omitted, keeping third/fifth/seventh and tensions
|
|
2398
|
-
* (a typical left-hand jazz voicing).
|
|
2399
|
-
*
|
|
2400
|
-
* @category Voicing & Counterpoint
|
|
2401
|
-
*/
|
|
2402
|
-
type VoicingStyle = 'close' | 'drop2' | 'drop3' | 'shell' | 'rootless';
|
|
2403
|
-
/**
|
|
2404
|
-
* Options controlling {@link voiceChordStyled}.
|
|
2405
|
-
*
|
|
2406
|
-
* @category Voicing & Counterpoint
|
|
2407
|
-
*/
|
|
2408
|
-
type StyledVoicingOptions = {
|
|
2409
|
-
/**
|
|
2410
|
-
* Voicing style to build.
|
|
2411
|
-
*
|
|
2412
|
-
* @defaultValue 'close'
|
|
2413
|
-
*/
|
|
2414
|
-
style?: VoicingStyle;
|
|
2415
|
-
/** Constrain the highest voice to this pitch class (0..11) when given. */
|
|
2416
|
-
topNote?: number;
|
|
2417
|
-
/**
|
|
2418
|
-
* Base octave for the close stack; the stack begins near `12 * octave`.
|
|
2419
|
-
*
|
|
2420
|
-
* @defaultValue 4
|
|
2421
|
-
*/
|
|
2422
|
-
octave?: number;
|
|
2423
|
-
/**
|
|
2424
|
-
* Omit the root regardless of style (relevant for jazz voicings).
|
|
2425
|
-
*
|
|
2426
|
-
* @defaultValue false
|
|
2427
|
-
*/
|
|
2428
|
-
rootless?: boolean;
|
|
2429
|
-
};
|
|
2430
|
-
/**
|
|
2431
|
-
* Realize a single chord as an explicit tertian voicing in a chosen style,
|
|
2432
|
-
* independent of the SATB range search used by {@link voiceChord}.
|
|
2433
|
-
*
|
|
2434
|
-
* The chord tones are stacked in close position from the bass (`bassPc`, else
|
|
2435
|
-
* `rootPc`) in the given scientific-pitch `octave` upward (octave 4 starts the
|
|
2436
|
-
* bass near C4 = MIDI 60, matching {@link midiToNote} and the bass module).
|
|
2437
|
-
* When `topNote` is given the stack is rotated so the highest voice's pitch
|
|
2438
|
-
* class equals that note (or the nearest chord tone). The chosen
|
|
2439
|
-
* {@link VoicingStyle} then transforms the stack, and the result is returned as
|
|
2440
|
-
* ascending MIDI pitches (index 0 = lowest).
|
|
2441
|
-
*
|
|
2442
|
-
* @param chord The chord to voice.
|
|
2443
|
-
* @param opts Styled voicing options; defaults to a close voicing at octave 4.
|
|
2444
|
-
* @returns MIDI pitches, ascending, one per retained voice.
|
|
2445
|
-
* @example
|
|
2446
|
-
* ```ts
|
|
2447
|
-
* import { parseChordSymbol, voiceChordStyled } from '@libraz/libcantus';
|
|
2448
|
-
* const chord = parseChordSymbol('Dm7');
|
|
2449
|
-
* voiceChordStyled(chord, { style: 'drop2' }); // ascending MIDI pitches, drop-2 voicing
|
|
2450
|
-
* ```
|
|
2451
|
-
* @category Voicing & Counterpoint
|
|
2452
|
-
*/
|
|
2453
|
-
declare function voiceChordStyled(chord: Chord$1, opts?: StyledVoicingOptions): number[];
|
|
2454
|
-
/**
|
|
2455
|
-
* Voice a single chord to follow smoothly from an arbitrary current voicing.
|
|
2456
|
-
*
|
|
2457
|
-
* Candidate voicings of `chord` are enumerated within ranges taken from `opts`,
|
|
2458
|
-
* or — when neither `voices` nor `ranges` is given — from a one-octave window
|
|
2459
|
-
* around each pitch of `current` (so the result matches `current`'s voice
|
|
2460
|
-
* count). Each candidate is scored by structural quality, voice-leading motion
|
|
2461
|
-
* from `current`, and a large penalty per counterpoint violation; the lowest
|
|
2462
|
-
* scoring candidate is returned, ascending.
|
|
2463
|
-
*
|
|
2464
|
-
* @param current The current voicing to lead from, ascending (index 0 = lowest).
|
|
2465
|
-
* @param chord The next chord to voice.
|
|
2466
|
-
* @param opts Voicing options; when omitted, ranges follow `current`'s span.
|
|
2467
|
-
* @returns The chosen voicing, ascending with one MIDI pitch per voice.
|
|
2468
|
-
* @throws If no voicing fits the derived ranges.
|
|
2469
|
-
* @category Voicing & Counterpoint
|
|
2470
|
-
*/
|
|
2471
|
-
declare function nextVoicing(current: number[], chord: Chord$1, opts?: VoicingOptions): number[];
|
|
2472
|
-
|
|
2473
|
-
/**
|
|
2474
|
-
* Fluent, immutable object model over the functional core.
|
|
2475
|
-
*
|
|
2476
|
-
* Each class wraps one of the library's plain data types (spelled notes,
|
|
2477
|
-
* chords, key/scales) and delegates every operation to the existing pure
|
|
2478
|
-
* functions. All instances are immutable: fields are read-only, transforming
|
|
2479
|
-
* methods return new instances, and getters hand out defensive copies of any
|
|
2480
|
-
* mutable data.
|
|
2481
|
-
*/
|
|
2482
|
-
|
|
2483
|
-
/**
|
|
2484
|
-
* An immutable spelled note: a diatonic letter plus a chromatic alteration and
|
|
2485
|
-
* an optional octave. Wraps the plain note object and delegates to the pitch
|
|
2486
|
-
* module; every transformation returns a new instance.
|
|
2487
|
-
*
|
|
2488
|
-
* @category Class API
|
|
2489
|
-
* @example
|
|
2490
|
-
* ```ts
|
|
2491
|
-
* import { Note } from '@libraz/libcantus';
|
|
2492
|
-
* Note.of('C4').transpose(7).name; // 'G4'
|
|
2493
|
-
* ```
|
|
2494
|
-
*/
|
|
2495
|
-
declare class Note {
|
|
2496
|
-
#private;
|
|
2497
|
-
/**
|
|
2498
|
-
* Wrap a plain note object.
|
|
2499
|
-
*
|
|
2500
|
-
* @param data The spelled note; it is copied, never retained or mutated.
|
|
2501
|
-
*/
|
|
2502
|
-
constructor(data: Note$1);
|
|
2503
|
-
/**
|
|
2504
|
-
* Parse scientific pitch notation (e.g. `'C#4'`, `'Bb'`, `'F##3'`).
|
|
2505
|
-
*
|
|
2506
|
-
* @param name The note text.
|
|
2507
|
-
* @returns The parsed note.
|
|
2508
|
-
* @throws If the text is not a valid note.
|
|
2509
|
-
*/
|
|
2510
|
-
static of(name: string): Note;
|
|
2511
|
-
/**
|
|
2512
|
-
* Name a MIDI number (middle C = C4 = 60) as a note.
|
|
2513
|
-
*
|
|
2514
|
-
* @param midi The MIDI number.
|
|
2515
|
-
* @param spelling Whether to prefer sharps or flats for black keys.
|
|
2516
|
-
* @returns The spelled note, with octave.
|
|
2517
|
-
*/
|
|
2518
|
-
static fromMidi(midi: number, spelling?: 'sharp' | 'flat'): Note;
|
|
2519
|
-
/**
|
|
2520
|
-
* Wrap an existing plain note object.
|
|
2521
|
-
*
|
|
2522
|
-
* @param data The plain note.
|
|
2523
|
-
* @returns The wrapped note.
|
|
2524
|
-
*/
|
|
2525
|
-
static fromData(data: Note$1): Note;
|
|
2526
|
-
/** The note rendered as scientific pitch notation, e.g. `'G4'` or `'Bb'`. */
|
|
2527
|
-
get name(): string;
|
|
2528
|
-
/** The pitch class (0..11), ignoring octave. */
|
|
2529
|
-
get pitchClass(): number;
|
|
2530
|
-
/**
|
|
2531
|
-
* The MIDI number (middle C = C4 = 60).
|
|
2532
|
-
*
|
|
2533
|
-
* @throws If the note has no octave and therefore no fixed pitch.
|
|
2534
|
-
*/
|
|
2535
|
-
get midi(): number;
|
|
2536
|
-
/** The diatonic letter number: 0..6 for C..B. */
|
|
2537
|
-
get letter(): number;
|
|
2538
|
-
/** The chromatic alteration in semitones: -1 flat, 0 natural, +1 sharp, ... */
|
|
2539
|
-
get alter(): number;
|
|
2540
|
-
/** The octave (scientific pitch notation), or undefined for a bare pitch class. */
|
|
2541
|
-
get octave(): number | undefined;
|
|
2542
|
-
/** A copy of the underlying plain note object. */
|
|
2543
|
-
get data(): Note$1;
|
|
2544
|
-
/**
|
|
2545
|
-
* Transpose by a signed number of semitones.
|
|
2546
|
-
*
|
|
2547
|
-
* When the note carries an octave the transposition happens in MIDI space and
|
|
2548
|
-
* the result is spelled with a sharp preference. An octave-less note stays
|
|
2549
|
-
* octave-less: only its pitch class is moved. Transposing by zero is the
|
|
2550
|
-
* identity: the original spelling is preserved (no enharmonic respelling).
|
|
2551
|
-
*
|
|
2552
|
-
* @param semitones The signed semitone offset.
|
|
2553
|
-
* @returns The transposed note.
|
|
2554
|
-
*/
|
|
2555
|
-
transpose(semitones: number): Note;
|
|
2556
|
-
/**
|
|
2557
|
-
* The spelled interval from this note to another.
|
|
2558
|
-
*
|
|
2559
|
-
* @param other The second note.
|
|
2560
|
-
* @returns The diatonic number, quality, and semitone span.
|
|
2561
|
-
*/
|
|
2562
|
-
intervalTo(other: Note): SpelledInterval;
|
|
2563
|
-
/**
|
|
2564
|
-
* Whether another note has the same letter, alteration, and octave.
|
|
2565
|
-
*
|
|
2566
|
-
* @param other The note to compare.
|
|
2567
|
-
* @returns True if the spellings are identical.
|
|
2568
|
-
*/
|
|
2569
|
-
equals(other: Note): boolean;
|
|
2570
|
-
/**
|
|
2571
|
-
* The plain note data, for JSON serialization.
|
|
2572
|
-
*
|
|
2573
|
-
* Private class fields do not serialize, so an explicit `toJSON` keeps
|
|
2574
|
-
* `JSON.stringify(note)` from collapsing to `{}`.
|
|
2575
|
-
*
|
|
2576
|
-
* @returns A copy of the underlying plain note object.
|
|
2577
|
-
*/
|
|
2578
|
-
toJSON(): Note$1;
|
|
2579
|
-
}
|
|
2580
|
-
/**
|
|
2581
|
-
* An immutable spelled interval value: a diatonic number, a quality label, and
|
|
2582
|
-
* a signed semitone span. A thin convenience wrapper over the pitch module's
|
|
2583
|
-
* plain interval result.
|
|
2584
|
-
*
|
|
2585
|
-
* @category Class API
|
|
2586
|
-
* @example
|
|
2587
|
-
* ```ts
|
|
2588
|
-
* import { Interval, Note } from '@libraz/libcantus';
|
|
2589
|
-
* Interval.between(Note.of('C4'), Note.of('G4')).name; // 'P5'
|
|
2590
|
-
* ```
|
|
2591
|
-
*/
|
|
2592
|
-
declare class Interval {
|
|
2593
|
-
#private;
|
|
2594
|
-
private constructor();
|
|
2595
|
-
/**
|
|
2596
|
-
* The spelled interval between two notes.
|
|
2597
|
-
*
|
|
2598
|
-
* @param a The first note.
|
|
2599
|
-
* @param b The second note.
|
|
2600
|
-
* @returns The interval from `a` to `b`.
|
|
2601
|
-
*/
|
|
2602
|
-
static between(a: Note, b: Note): Interval;
|
|
2603
|
-
/**
|
|
2604
|
-
* Build an interval from explicit components.
|
|
2605
|
-
*
|
|
2606
|
-
* @param numberValue Diatonic size: 1 = unison, 2 = second, ... 8 = octave.
|
|
2607
|
-
* @param quality Quality label: `'P'`, `'M'`, `'m'`, or repeated `'A'`/`'d'`.
|
|
2608
|
-
* @param semitones Signed semitone span.
|
|
2609
|
-
* @returns The interval.
|
|
2610
|
-
*/
|
|
2611
|
-
static of(numberValue: number, quality: string, semitones: number): Interval;
|
|
2612
|
-
/** Diatonic size: 1 = unison, 2 = second, ... 8 = octave, and beyond. */
|
|
2613
|
-
get number(): number;
|
|
2614
|
-
/** Quality label: `'P'`, `'M'`, `'m'`, or repeated `'A'`/`'d'`. */
|
|
2615
|
-
get quality(): string;
|
|
2616
|
-
/** Signed semitone span. */
|
|
2617
|
-
get semitones(): number;
|
|
2618
|
-
/** A readable label composed of quality and number, e.g. `'P5'` or `'M3'`. */
|
|
2619
|
-
get name(): string;
|
|
2620
|
-
/**
|
|
2621
|
-
* The plain interval data, for JSON serialization.
|
|
2622
|
-
*
|
|
2623
|
-
* Private class fields do not serialize, so an explicit `toJSON` keeps
|
|
2624
|
-
* `JSON.stringify(interval)` from collapsing to `{}`.
|
|
2625
|
-
*
|
|
2626
|
-
* @returns The diatonic number, quality, and semitone span.
|
|
2627
|
-
*/
|
|
2628
|
-
toJSON(): SpelledInterval;
|
|
2629
|
-
}
|
|
2630
|
-
/**
|
|
2631
|
-
* An immutable key/scale: a `KeyScale` (root pitch class plus mode mask) paired
|
|
2632
|
-
* with a spelled tonic that anchors letter-name spelling. Acts as the factory
|
|
2633
|
-
* for key-aware chords.
|
|
2634
|
-
*
|
|
2635
|
-
* @category Class API
|
|
2636
|
-
* @example
|
|
2637
|
-
* ```ts
|
|
2638
|
-
* import { Key } from '@libraz/libcantus';
|
|
2639
|
-
* Key.major('C').chord(4).symbol(); // 'G' (the diatonic triad on scale degree 4)
|
|
2640
|
-
* ```
|
|
2641
|
-
*/
|
|
2642
|
-
declare class Key {
|
|
2643
|
-
#private;
|
|
2644
|
-
/**
|
|
2645
|
-
* Wrap a key/scale and its spelled tonic.
|
|
2646
|
-
*
|
|
2647
|
-
* @param scale The key/scale; its root is normalized to a pitch class.
|
|
2648
|
-
* @param tonic The spelled tonic anchoring letter-name spelling.
|
|
2649
|
-
*/
|
|
2650
|
-
constructor(scale: KeyScale, tonic: Note);
|
|
2651
|
-
/**
|
|
2652
|
-
* A major key.
|
|
2653
|
-
*
|
|
2654
|
-
* @param root Tonic as a note name (e.g. `'Eb'`) or a pitch class; a numeric
|
|
2655
|
-
* root is spelled with whichever accidental side yields the fewest
|
|
2656
|
-
* accidentals across the scale.
|
|
2657
|
-
* @returns The major key.
|
|
2658
|
-
*/
|
|
2659
|
-
static major(root: string | number): Key;
|
|
2660
|
-
/**
|
|
2661
|
-
* A natural-minor key.
|
|
2662
|
-
*
|
|
2663
|
-
* @param root Tonic as a note name or a pitch class; a numeric root is
|
|
2664
|
-
* spelled with whichever accidental side yields the fewest accidentals
|
|
2665
|
-
* across the scale.
|
|
2666
|
-
* @returns The minor key.
|
|
2667
|
-
*/
|
|
2668
|
-
static minor(root: string | number): Key;
|
|
2669
|
-
/**
|
|
2670
|
-
* A key on a named scale (e.g. `'dorian'`, `'harmonicMinor'`).
|
|
2671
|
-
*
|
|
2672
|
-
* @param name The scale name, a key of the scale module's named-scale table.
|
|
2673
|
-
* @param root Tonic as a note name or a pitch class.
|
|
2674
|
-
* @returns The key.
|
|
2675
|
-
* @throws If the name is not a known scale.
|
|
2676
|
-
*/
|
|
2677
|
-
static named(name: string, root: string | number): Key;
|
|
2678
|
-
/**
|
|
2679
|
-
* Wrap an existing `KeyScale`, synthesizing a spelled tonic when none is
|
|
2680
|
-
* given (flat-preferred for minor-third scales, sharp-preferred otherwise).
|
|
2681
|
-
*
|
|
2682
|
-
* @param scale The key/scale to wrap.
|
|
2683
|
-
* @param tonic Optional spelled tonic.
|
|
2684
|
-
* @returns The key.
|
|
2685
|
-
*/
|
|
2686
|
-
static of(scale: KeyScale, tonic?: Note): Key;
|
|
2687
|
-
/** A copy of the underlying plain `KeyScale`. */
|
|
2688
|
-
get scale(): KeyScale;
|
|
2689
|
-
/** The spelled tonic. */
|
|
2690
|
-
get tonic(): Note;
|
|
2691
|
-
/** The tonic pitch class (0..11). */
|
|
2692
|
-
get rootPc(): number;
|
|
2693
|
-
/** Whether the scale has a minor third and no major third. */
|
|
2694
|
-
get isMinor(): boolean;
|
|
2695
|
-
/**
|
|
2696
|
-
* The scale's pitch classes in ascending scale-degree order (degree 0 first).
|
|
2697
|
-
*
|
|
2698
|
-
* @returns One pitch class per scale degree.
|
|
2699
|
-
*/
|
|
2700
|
-
pitchClasses(): number[];
|
|
2701
|
-
/**
|
|
2702
|
-
* The spelled scale, one note per degree (e.g. C D E F G A B for C major).
|
|
2703
|
-
*
|
|
2704
|
-
* @returns Spelled octave-less notes in scale-degree order.
|
|
2705
|
-
*/
|
|
2706
|
-
notes(): Note[];
|
|
2707
|
-
/**
|
|
2708
|
-
* Alias of {@link Key.notes}.
|
|
2709
|
-
*
|
|
2710
|
-
* @returns Spelled octave-less notes in scale-degree order.
|
|
2711
|
-
*/
|
|
2712
|
-
spell(): Note[];
|
|
2713
|
-
/**
|
|
2714
|
-
* The spelled scale as letter-name strings.
|
|
2715
|
-
*
|
|
2716
|
-
* @returns One name per scale degree.
|
|
2717
|
-
*/
|
|
2718
|
-
noteNames(): string[];
|
|
2719
|
-
/**
|
|
2720
|
-
* Build a chord on a scale degree, carrying this key as context.
|
|
2721
|
-
*
|
|
2722
|
-
* With an explicit quality the quality's interval template is attached to the
|
|
2723
|
-
* degree's diatonic root; without one the scale-correct diatonic triad is
|
|
2724
|
-
* stacked (e.g. a diminished triad on the leading tone of a major key).
|
|
2725
|
-
*
|
|
2726
|
-
* @param degree 0-based scale degree of the chord root.
|
|
2727
|
-
* @param quality Optional chord quality.
|
|
2728
|
-
* @returns The chord, with this key attached.
|
|
2729
|
-
*/
|
|
2730
|
-
chord(degree: number, quality?: ChordQuality): Chord;
|
|
2731
|
-
/**
|
|
2732
|
-
* The diatonic triad on a scale degree, carrying this key as context.
|
|
2733
|
-
*
|
|
2734
|
-
* @param degree 0-based scale degree of the chord root.
|
|
2735
|
-
* @returns The triad, with this key attached.
|
|
2736
|
-
*/
|
|
2737
|
-
diatonicTriad(degree: number): Chord;
|
|
2738
|
-
/**
|
|
2739
|
-
* The diatonic seventh chord on a scale degree, carrying this key as context.
|
|
2740
|
-
*
|
|
2741
|
-
* @param degree 0-based scale degree of the chord root.
|
|
2742
|
-
* @returns The seventh chord, with this key attached.
|
|
2743
|
-
*/
|
|
2744
|
-
diatonicSeventh(degree: number): Chord;
|
|
2745
|
-
/**
|
|
2746
|
-
* Build the chord denoted by a Roman numeral in this key (including applied
|
|
2747
|
-
* chords such as `'V7/V'`), carrying this key as context.
|
|
2748
|
-
*
|
|
2749
|
-
* @param text The Roman numeral.
|
|
2750
|
-
* @returns The chord, with this key attached.
|
|
2751
|
-
* @throws If the numeral is not valid.
|
|
2752
|
-
*/
|
|
2753
|
-
roman(text: string): Chord;
|
|
2754
|
-
/**
|
|
2755
|
-
* Whether a pitch belongs to the scale.
|
|
2756
|
-
*
|
|
2757
|
-
* @param x A MIDI pitch, bare pitch class, or note.
|
|
2758
|
-
* @returns True if the pitch class is a scale tone.
|
|
2759
|
-
*/
|
|
2760
|
-
contains(x: number | Note): boolean;
|
|
2761
|
-
/**
|
|
2762
|
-
* The plain key data, for JSON serialization.
|
|
2763
|
-
*
|
|
2764
|
-
* Private class fields do not serialize, so an explicit `toJSON` keeps
|
|
2765
|
-
* `JSON.stringify(key)` from collapsing to `{}`. The result pairs the
|
|
2766
|
-
* `KeyScale` with the spelled tonic, enough to reconstruct the key via
|
|
2767
|
-
* {@link Key.of}.
|
|
2768
|
-
*
|
|
2769
|
-
* @returns The key/scale and its spelled tonic.
|
|
2770
|
-
*/
|
|
2771
|
-
toJSON(): {
|
|
2772
|
-
scale: KeyScale;
|
|
2773
|
-
tonic: Note$1;
|
|
2774
|
-
};
|
|
2775
|
-
}
|
|
2776
|
-
/**
|
|
2777
|
-
* An immutable chord: a root pitch class, quality, interval template, and
|
|
2778
|
-
* optional slash bass, optionally carrying a {@link Key} context. Analysis
|
|
2779
|
-
* methods (`roman`, `function`, `analyze`, ...) use an explicitly passed key
|
|
2780
|
-
* first and fall back to the carried context.
|
|
2781
|
-
*
|
|
2782
|
-
* @category Class API
|
|
2783
|
-
* @example
|
|
2784
|
-
* ```ts
|
|
2785
|
-
* import { Chord } from '@libraz/libcantus';
|
|
2786
|
-
* Chord.parse('Cmaj7').invert(1).symbol(); // 'Cmaj7/E' (third in the bass)
|
|
2787
|
-
* ```
|
|
2788
|
-
*/
|
|
2789
|
-
declare class Chord {
|
|
2790
|
-
#private;
|
|
2791
|
-
/**
|
|
2792
|
-
* Wrap a plain chord object.
|
|
2793
|
-
*
|
|
2794
|
-
* @param data The chord; it is copied, never retained or mutated.
|
|
2795
|
-
* @param key Optional key context for analysis methods.
|
|
2796
|
-
*/
|
|
2797
|
-
constructor(data: Chord$1, key?: Key);
|
|
2798
|
-
/**
|
|
2799
|
-
* Build a chord from a root and quality.
|
|
2800
|
-
*
|
|
2801
|
-
* @param root Root as a note name (e.g. `'Eb'`) or a pitch class.
|
|
2802
|
-
* @param quality The chord quality.
|
|
2803
|
-
* @param bass Optional slash-chord bass pitch class.
|
|
2804
|
-
* @returns The chord (without key context).
|
|
2805
|
-
*/
|
|
2806
|
-
static of(root: string | number, quality: ChordQuality, bass?: number): Chord;
|
|
2807
|
-
/**
|
|
2808
|
-
* Wrap an existing plain chord object.
|
|
2809
|
-
*
|
|
2810
|
-
* @param data The plain chord.
|
|
2811
|
-
* @returns The wrapped chord (without key context).
|
|
2812
|
-
*/
|
|
2813
|
-
static from(data: Chord$1): Chord;
|
|
2814
|
-
/**
|
|
2815
|
-
* Parse a lead-sheet chord symbol (e.g. `'Cmaj7'`, `'F#m7b5'`, `'C/G'`).
|
|
2816
|
-
*
|
|
2817
|
-
* @param symbol The chord symbol.
|
|
2818
|
-
* @returns The chord (without key context).
|
|
2819
|
-
* @throws If the root or quality is not recognized.
|
|
2820
|
-
*/
|
|
2821
|
-
static parse(symbol: string): Chord;
|
|
2822
|
-
/**
|
|
2823
|
-
* Identify the chords matching a set of pitches, best interpretation first.
|
|
2824
|
-
*
|
|
2825
|
-
* @param pitches MIDI pitches or bare pitch classes.
|
|
2826
|
-
* @returns Ranked chord interpretations (may be empty).
|
|
2827
|
-
*/
|
|
2828
|
-
static detect(pitches: number[]): Chord[];
|
|
2829
|
-
/**
|
|
2830
|
-
* The single best chord interpretation of a pitch set.
|
|
2831
|
-
*
|
|
2832
|
-
* @param pitches MIDI pitches or bare pitch classes.
|
|
2833
|
-
* @returns The top-ranked chord, or null when nothing matches.
|
|
2834
|
-
*/
|
|
2835
|
-
static detectBest(pitches: number[]): Chord | null;
|
|
2836
|
-
/** The root pitch class (0..11). */
|
|
2837
|
-
get rootPc(): number;
|
|
2838
|
-
/** The chord quality. */
|
|
2839
|
-
get quality(): ChordQuality;
|
|
2840
|
-
/** A copy of the semitone offsets above the root. */
|
|
2841
|
-
get intervals(): number[];
|
|
2842
|
-
/** The slash-chord bass pitch class, or undefined in root position. */
|
|
2843
|
-
get bassPc(): number | undefined;
|
|
2844
|
-
/** A copy of the underlying plain chord object. */
|
|
2845
|
-
get data(): Chord$1;
|
|
2846
|
-
/** The carried key context, if any. */
|
|
2847
|
-
get key(): Key | undefined;
|
|
2848
|
-
/**
|
|
2849
|
-
* A copy of this chord carrying the given key context.
|
|
2850
|
-
*
|
|
2851
|
-
* @param key The key context to attach.
|
|
2852
|
-
* @returns The new chord.
|
|
2853
|
-
*/
|
|
2854
|
-
withKey(key: Key): Chord;
|
|
2855
|
-
/**
|
|
2856
|
-
* The chord's sorted, deduplicated pitch classes.
|
|
2857
|
-
*
|
|
2858
|
-
* @returns Pitch classes ascending in [0, 11].
|
|
2859
|
-
*/
|
|
2860
|
-
pitchClasses(): number[];
|
|
2861
|
-
/**
|
|
2862
|
-
* The chord's Roman numeral in a key.
|
|
2863
|
-
*
|
|
2864
|
-
* @param key Key to analyze in; falls back to the carried context.
|
|
2865
|
-
* @returns The Roman numeral string.
|
|
2866
|
-
* @throws If no key is given and none is carried.
|
|
2867
|
-
*/
|
|
2868
|
-
roman(key?: Key): string;
|
|
2869
|
-
/**
|
|
2870
|
-
* The chord's harmonic function (tonic / subdominant / dominant) in a key.
|
|
2871
|
-
*
|
|
2872
|
-
* @param key Key to analyze in; falls back to the carried context.
|
|
2873
|
-
* @returns The harmonic function.
|
|
2874
|
-
* @throws If no key is given and none is carried.
|
|
2875
|
-
*/
|
|
2876
|
-
function(key?: Key): HarmonicFunction;
|
|
2877
|
-
/**
|
|
2878
|
-
* Full functional analysis: function, borrowing, and Roman numeral.
|
|
2879
|
-
*
|
|
2880
|
-
* @param key Key to analyze in; falls back to the carried context.
|
|
2881
|
-
* @returns The chord analysis.
|
|
2882
|
-
* @throws If no key is given and none is carried.
|
|
2883
|
-
*/
|
|
2884
|
-
analyze(key?: Key): ChordAnalysis;
|
|
2885
|
-
/**
|
|
2886
|
-
* Whether the chord is borrowed from the parallel mode (modal interchange).
|
|
2887
|
-
*
|
|
2888
|
-
* @param key Key to analyze in; falls back to the carried context.
|
|
2889
|
-
* @returns True if the chord is borrowed.
|
|
2890
|
-
* @throws If no key is given and none is carried.
|
|
2891
|
-
*/
|
|
2892
|
-
isBorrowed(key?: Key): boolean;
|
|
2893
|
-
/**
|
|
2894
|
-
* The origin of a non-diatonic chord (parallel mode or Neapolitan), or null.
|
|
2895
|
-
*
|
|
2896
|
-
* @param key Key to analyze in; falls back to the carried context.
|
|
2897
|
-
* @returns The borrowing source, or null.
|
|
2898
|
-
* @throws If no key is given and none is carried.
|
|
2899
|
-
*/
|
|
2900
|
-
borrowedSource(key?: Key): BorrowedSource;
|
|
2901
|
-
/**
|
|
2902
|
-
* The chord rendered as a lead-sheet symbol (e.g. `'Cmaj7'`, `'F#m7'`, `'C/G'`).
|
|
2903
|
-
*
|
|
2904
|
-
* @param opts Set `flats: true` to spell the root/bass with flats.
|
|
2905
|
-
* @returns The chord symbol.
|
|
2906
|
-
*/
|
|
2907
|
-
symbol(opts?: {
|
|
2908
|
-
flats?: boolean;
|
|
2909
|
-
}): string;
|
|
2910
|
-
/**
|
|
2911
|
-
* Realize the chord as one MIDI pitch per voice, ascending.
|
|
2912
|
-
*
|
|
2913
|
-
* @param opts Voicing options; defaults to four SATB voices.
|
|
2914
|
-
* @returns MIDI pitches, ascending, one per voice.
|
|
2915
|
-
* @throws If no voicing fits the given ranges.
|
|
2916
|
-
*/
|
|
2917
|
-
voice(opts?: VoicingOptions): number[];
|
|
2918
|
-
/**
|
|
2919
|
-
* Realize the chord as a single styled voicing (`close`, `drop2`, `drop3`,
|
|
2920
|
-
* `shell`, or `rootless`), optionally constraining the top voice.
|
|
2921
|
-
*
|
|
2922
|
-
* @param opts Styled-voicing options; defaults to a close-position voicing.
|
|
2923
|
-
* @returns MIDI pitches, ascending.
|
|
2924
|
-
*/
|
|
2925
|
-
styledVoicing(opts?: StyledVoicingOptions): number[];
|
|
2926
|
-
/**
|
|
2927
|
-
* The negative-harmony mirror of the chord about the key's tonic–dominant
|
|
2928
|
-
* axis (major becomes minor and vice versa).
|
|
2929
|
-
*
|
|
2930
|
-
* @param key Key providing the reflection axis; falls back to the carried
|
|
2931
|
-
* context.
|
|
2932
|
-
* @returns The mirrored chord, keeping any key context.
|
|
2933
|
-
* @throws If no key is given and none is carried.
|
|
2934
|
-
*/
|
|
2935
|
-
negativeHarmony(key?: Key): Chord;
|
|
2936
|
-
/**
|
|
2937
|
-
* The n-th inversion: a copy whose bass is the chord tone `n` steps above the
|
|
2938
|
-
* root in the interval template (`invert(1)` puts the third in the bass).
|
|
2939
|
-
* `n` wraps around the template length; negative values count backwards.
|
|
2940
|
-
*
|
|
2941
|
-
* `invert(0)` (and any `n` that wraps to it) is root position, so it carries
|
|
2942
|
-
* no slash bass and equals the original chord.
|
|
2943
|
-
*
|
|
2944
|
-
* @param n The inversion number.
|
|
2945
|
-
* @returns The inverted chord, keeping any key context.
|
|
2946
|
-
* @throws If the chord has no intervals.
|
|
2947
|
-
*/
|
|
2948
|
-
invert(n: number): Chord;
|
|
2949
|
-
/**
|
|
2950
|
-
* The named scales that fit over this chord, best fit first, rooted on the
|
|
2951
|
-
* chord root.
|
|
2952
|
-
*
|
|
2953
|
-
* @returns The matching scales.
|
|
2954
|
-
*/
|
|
2955
|
-
scales(): ChordScaleMatch[];
|
|
2956
|
-
/**
|
|
2957
|
-
* The available tensions (usable non-chord, non-avoid scale tones) of a
|
|
2958
|
-
* scale over this chord.
|
|
2959
|
-
*
|
|
2960
|
-
* @param scaleName A named scale, rooted on the chord root.
|
|
2961
|
-
* @returns Tension pitch classes, ascending in [0, 11].
|
|
2962
|
-
*/
|
|
2963
|
-
tensions(scaleName: string): number[];
|
|
2964
|
-
/**
|
|
2965
|
-
* The avoid notes (scale tones a semitone above a chord tone) of a scale
|
|
2966
|
-
* over this chord.
|
|
2967
|
-
*
|
|
2968
|
-
* @param scaleName A named scale, rooted on the chord root.
|
|
2969
|
-
* @returns Avoid-note pitch classes, ascending in [0, 11].
|
|
2970
|
-
*/
|
|
2971
|
-
avoidNotes(scaleName: string): number[];
|
|
2972
|
-
/**
|
|
2973
|
-
* Spell the chord tones with letter names, root first, in the key's spelling.
|
|
2974
|
-
*
|
|
2975
|
-
* @param key Key providing the spelled tonic; falls back to the carried
|
|
2976
|
-
* context.
|
|
2977
|
-
* @returns Spelled octave-less notes in the chord's own (tertian) order.
|
|
2978
|
-
* @throws If no key is given and none is carried.
|
|
2979
|
-
*/
|
|
2980
|
-
spell(key?: Key): Note[];
|
|
2981
|
-
/**
|
|
2982
|
-
* Start a progression with this chord followed by others, carrying this
|
|
2983
|
-
* chord's key context (if any).
|
|
2984
|
-
*
|
|
2985
|
-
* @param others The chords following this one.
|
|
2986
|
-
* @returns The progression.
|
|
2987
|
-
*/
|
|
2988
|
-
progressionTo(...others: Chord[]): Progression;
|
|
2989
|
-
/**
|
|
2990
|
-
* Whether another chord has the same root, quality, intervals, and bass.
|
|
2991
|
-
* Key context is not compared.
|
|
2992
|
-
*
|
|
2993
|
-
* @param other The chord to compare.
|
|
2994
|
-
* @returns True if the chord data is identical.
|
|
2995
|
-
*/
|
|
2996
|
-
equals(other: Chord): boolean;
|
|
2997
|
-
/**
|
|
2998
|
-
* The plain chord data, for JSON serialization.
|
|
2999
|
-
*
|
|
3000
|
-
* @returns A copy of the underlying plain chord object.
|
|
3001
|
-
*/
|
|
3002
|
-
toJSON(): Chord$1;
|
|
3003
|
-
}
|
|
3004
|
-
/**
|
|
3005
|
-
* An immutable ordered sequence of chords, optionally carrying a {@link Key}
|
|
3006
|
-
* context shared by its analysis methods.
|
|
3007
|
-
*
|
|
3008
|
-
* @category Class API
|
|
3009
|
-
* @example
|
|
3010
|
-
* ```ts
|
|
3011
|
-
* import { Key } from '@libraz/libcantus';
|
|
3012
|
-
* const key = Key.major('C');
|
|
3013
|
-
* key.chord(1).progressionTo(key.chord(4), key.chord(0)).roman();
|
|
3014
|
-
* // ['ii', 'V', 'I']
|
|
3015
|
-
* ```
|
|
3016
|
-
*/
|
|
3017
|
-
declare class Progression {
|
|
3018
|
-
#private;
|
|
3019
|
-
/**
|
|
3020
|
-
* Wrap a chord sequence.
|
|
3021
|
-
*
|
|
3022
|
-
* @param chords The chords in order; the array is copied.
|
|
3023
|
-
* @param key Optional key context for analysis methods.
|
|
3024
|
-
*/
|
|
3025
|
-
constructor(chords: readonly Chord[], key?: Key);
|
|
3026
|
-
/** A copy of the chord sequence. */
|
|
3027
|
-
get chords(): readonly Chord[];
|
|
3028
|
-
/** The carried key context, if any. */
|
|
3029
|
-
get key(): Key | undefined;
|
|
3030
|
-
/** The number of chords. */
|
|
3031
|
-
get length(): number;
|
|
3032
|
-
/**
|
|
3033
|
-
* A copy of this progression with a chord appended.
|
|
3034
|
-
*
|
|
3035
|
-
* @param chord The chord to append.
|
|
3036
|
-
* @returns The new progression.
|
|
3037
|
-
*/
|
|
3038
|
-
add(chord: Chord): Progression;
|
|
3039
|
-
/**
|
|
3040
|
-
* A copy of this progression carrying the given key context.
|
|
3041
|
-
*
|
|
3042
|
-
* @param key The key context to attach.
|
|
3043
|
-
* @returns The new progression.
|
|
3044
|
-
*/
|
|
3045
|
-
withKey(key: Key): Progression;
|
|
3046
|
-
/**
|
|
3047
|
-
* Voice the progression with smooth voice leading.
|
|
3048
|
-
*
|
|
3049
|
-
* @param opts Voicing options; defaults to four SATB voices.
|
|
3050
|
-
* @returns One ascending voicing (MIDI pitches) per chord.
|
|
3051
|
-
* @throws If any chord admits no voicing within the given ranges.
|
|
3052
|
-
*/
|
|
3053
|
-
voice(opts?: VoicingOptions): number[][];
|
|
3054
|
-
/**
|
|
3055
|
-
* The Roman numeral of each chord in a key.
|
|
3056
|
-
*
|
|
3057
|
-
* @param key Key to analyze in; falls back to the carried context.
|
|
3058
|
-
* @returns One numeral per chord.
|
|
3059
|
-
* @throws If no key is given and none is carried.
|
|
3060
|
-
*/
|
|
3061
|
-
roman(key?: Key): string[];
|
|
3062
|
-
/**
|
|
3063
|
-
* The harmonic function of each chord in a key.
|
|
3064
|
-
*
|
|
3065
|
-
* @param key Key to analyze in; falls back to the carried context.
|
|
3066
|
-
* @returns One function per chord.
|
|
3067
|
-
* @throws If no key is given and none is carried.
|
|
3068
|
-
*/
|
|
3069
|
-
functions(key?: Key): HarmonicFunction[];
|
|
3070
|
-
/**
|
|
3071
|
-
* Analyze every chord and classify the closing cadence.
|
|
3072
|
-
*
|
|
3073
|
-
* The cadence is detected on the final chord pair and is null when the
|
|
3074
|
-
* progression has fewer than two chords.
|
|
3075
|
-
*
|
|
3076
|
-
* @param key Key to analyze in; falls back to the carried context.
|
|
3077
|
-
* @returns Per-chord analyses and the closing cadence.
|
|
3078
|
-
* @throws If no key is given and none is carried.
|
|
3079
|
-
*/
|
|
3080
|
-
analyze(key?: Key): {
|
|
3081
|
-
chords: ChordAnalysis[];
|
|
3082
|
-
cadence: Cadence;
|
|
3083
|
-
};
|
|
3084
|
-
/**
|
|
3085
|
-
* The plain progression data, for JSON serialization.
|
|
3086
|
-
*
|
|
3087
|
-
* Private class fields do not serialize, so an explicit `toJSON` keeps
|
|
3088
|
-
* `JSON.stringify(progression)` from collapsing to `{}`. The chords are
|
|
3089
|
-
* emitted as plain data and the carried key, when present, as its own data.
|
|
3090
|
-
*
|
|
3091
|
-
* @returns The chord data sequence and the carried key, if any.
|
|
3092
|
-
*/
|
|
3093
|
-
toJSON(): {
|
|
3094
|
-
chords: Chord$1[];
|
|
3095
|
-
key: {
|
|
3096
|
-
scale: KeyScale;
|
|
3097
|
-
tonic: Note$1;
|
|
3098
|
-
} | undefined;
|
|
3099
|
-
};
|
|
3100
|
-
}
|
|
3101
|
-
|
|
3102
|
-
/**
|
|
3103
|
-
* A transformation applicable to a motif cell.
|
|
3104
|
-
*
|
|
3105
|
-
* @category Composition
|
|
3106
|
-
*/
|
|
3107
|
-
type MotifTransform = 'transposeDiatonic' | 'transposeChromatic' | 'invert' | 'retrograde' | 'augment' | 'diminish' | 'sequence';
|
|
3108
|
-
/**
|
|
3109
|
-
* A single note within a motif cell.
|
|
3110
|
-
*
|
|
3111
|
-
* @category Composition
|
|
3112
|
-
*/
|
|
3113
|
-
type MotifNote = {
|
|
3114
|
-
pitch: number;
|
|
3115
|
-
startBeat: number;
|
|
3116
|
-
durationBeat: number;
|
|
3117
|
-
};
|
|
3118
|
-
/**
|
|
3119
|
-
* A short melodic cell.
|
|
3120
|
-
*
|
|
3121
|
-
* @category Composition
|
|
3122
|
-
*/
|
|
3123
|
-
type MotifCell = {
|
|
3124
|
-
notes: MotifNote[];
|
|
3125
|
-
};
|
|
3126
|
-
/**
|
|
3127
|
-
* Melodic contour shape for {@link generateMotif}.
|
|
3128
|
-
*
|
|
3129
|
-
* @category Composition
|
|
3130
|
-
*/
|
|
3131
|
-
type MotifContour = 'arch' | 'ascending' | 'descending' | 'wave';
|
|
3132
|
-
/**
|
|
3133
|
-
* Options controlling {@link generateMotif}.
|
|
3134
|
-
*
|
|
3135
|
-
* @category Composition
|
|
3136
|
-
*/
|
|
3137
|
-
type GenerateMotifOptions = {
|
|
3138
|
-
key: KeyScale;
|
|
3139
|
-
chord?: Chord$1 | null;
|
|
3140
|
-
bars: number;
|
|
3141
|
-
/**
|
|
3142
|
-
* Melodic contour shape the line follows.
|
|
3143
|
-
*
|
|
3144
|
-
* @defaultValue `'arch'`
|
|
3145
|
-
*/
|
|
3146
|
-
contour?: MotifContour;
|
|
3147
|
-
/**
|
|
3148
|
-
* Probability in [0, 1] that a note is nudged by a single diatonic step. The
|
|
3149
|
-
* nudge direction is balanced (up or down with equal odds), so it adds
|
|
3150
|
-
* variety without biasing the line off its contour. Default 0, which
|
|
3151
|
-
* reproduces the requested contour exactly (no drift, tails return to tonic).
|
|
3152
|
-
*
|
|
3153
|
-
* @defaultValue 0
|
|
3154
|
-
*/
|
|
3155
|
-
jitter?: number;
|
|
3156
|
-
/**
|
|
3157
|
-
* Seed for the deterministic PRNG.
|
|
3158
|
-
*
|
|
3159
|
-
* @defaultValue 0
|
|
3160
|
-
*/
|
|
3161
|
-
seed?: number;
|
|
3162
|
-
};
|
|
3163
|
-
/**
|
|
3164
|
-
* Generate a short seed motif over `bars`.
|
|
3165
|
-
*
|
|
3166
|
-
* The melody follows the requested contour in diatonic steps from the tonic,
|
|
3167
|
-
* snapped to the key. When a chord is supplied, notes landing on bar downbeats
|
|
3168
|
-
* are pulled to the nearest chord tone. An optional `jitter` adds balanced
|
|
3169
|
-
* per-note variation without biasing the contour; it is off by default, so the
|
|
3170
|
-
* contour is reproduced exactly. Output is deterministic for a given seed.
|
|
3171
|
-
*
|
|
3172
|
-
* @param opts Key, optional chord, length, contour, jitter, and seed.
|
|
3173
|
-
* @returns The generated motif cell.
|
|
3174
|
-
*
|
|
3175
|
-
* @example
|
|
3176
|
-
* ```ts
|
|
3177
|
-
* import { generateMotif, majorKey } from '@libraz/libcantus';
|
|
3178
|
-
* const cell = generateMotif({ key: majorKey(0), bars: 2, contour: 'arch' });
|
|
3179
|
-
* // cell.notes is a deterministic MotifCell (seed defaults to 0)
|
|
3180
|
-
* ```
|
|
3181
|
-
*
|
|
3182
|
-
* @category Composition
|
|
3183
|
-
*/
|
|
3184
|
-
declare function generateMotif(opts: GenerateMotifOptions): MotifCell;
|
|
3185
|
-
/**
|
|
3186
|
-
* Apply a transformation to a motif cell.
|
|
3187
|
-
*
|
|
3188
|
-
* `invert` reflects pitches about the first note (chromatic, self-inverse);
|
|
3189
|
-
* `retrograde` mirrors onsets about the cell span, preserving rests (self-inverse);
|
|
3190
|
-
* `augment`/`diminish` scale time by `amount ?? 2` and its reciprocal;
|
|
3191
|
-
* `transposeChromatic` adds `amount` semitones; `transposeDiatonic` shifts by
|
|
3192
|
-
* `amount` scale degrees when a `key` is given, or — with no `key` — falls back
|
|
3193
|
-
* to a chromatic shift of `amount` semitones; `sequence` appends a shifted copy
|
|
3194
|
-
* (by `amount` diatonic degrees with a `key`, or by `amount` semitones without
|
|
3195
|
-
* one, since it delegates to `transposeDiatonic`).
|
|
3196
|
-
*
|
|
3197
|
-
* @param cell The cell to transform.
|
|
3198
|
-
* @param t The transformation.
|
|
3199
|
-
* @param amount Optional parameter (semitones, degrees, or time factor).
|
|
3200
|
-
* @param key Key context for the diatonic transforms; without it,
|
|
3201
|
-
* `transposeDiatonic` and `sequence` shift chromatically by semitones.
|
|
3202
|
-
* @returns The transformed cell.
|
|
3203
|
-
*
|
|
3204
|
-
* @example
|
|
3205
|
-
* ```ts
|
|
3206
|
-
* import { generateMotif, transformMotif, majorKey } from '@libraz/libcantus';
|
|
3207
|
-
* const cell = generateMotif({ key: majorKey(0), bars: 1 });
|
|
3208
|
-
* const inverted = transformMotif(cell, 'invert');
|
|
3209
|
-
* ```
|
|
3210
|
-
*
|
|
3211
|
-
* @category Composition
|
|
3212
|
-
*/
|
|
3213
|
-
declare function transformMotif(cell: MotifCell, t: MotifTransform, amount?: number, key?: KeyScale): MotifCell;
|
|
3214
|
-
/**
|
|
3215
|
-
* Lay a motif across `bars` and snap it to a chord timeline.
|
|
3216
|
-
*
|
|
3217
|
-
* The cell is tiled back-to-back to fill the requested span; each note is then
|
|
3218
|
-
* pulled to the nearest chord tone of the segment sounding at its onset, so the
|
|
3219
|
-
* developed line spells the underlying harmony.
|
|
3220
|
-
*
|
|
3221
|
-
* @param cell The source motif.
|
|
3222
|
-
* @param timeline Chord segments to snap against.
|
|
3223
|
-
* @param key Key context (used to keep snapped pitches sensible).
|
|
3224
|
-
* @param bars Number of four-beat bars to fill.
|
|
3225
|
-
* @returns The developed, harmony-aware cell.
|
|
3226
|
-
*
|
|
3227
|
-
* @example
|
|
3228
|
-
* ```ts
|
|
3229
|
-
* import { chordTimelineFromChords, developMotif, generateMotif, majorKey } from '@libraz/libcantus';
|
|
3230
|
-
* const key = majorKey(0);
|
|
3231
|
-
* const timeline = chordTimelineFromChords([{ rootPc: 0, quality: 'maj', startBeat: 0 }], 8);
|
|
3232
|
-
* const developed = developMotif(generateMotif({ key, bars: 1 }), timeline, key, 2);
|
|
3233
|
-
* ```
|
|
3234
|
-
*
|
|
3235
|
-
* @category Composition
|
|
3236
|
-
*/
|
|
3237
|
-
declare function developMotif(cell: MotifCell, timeline: ChordTimeline, key: KeyScale, bars: number): MotifCell;
|
|
3238
|
-
|
|
3239
|
-
/**
|
|
3240
|
-
* Deterministic seeded pseudo-random number generation shared across the
|
|
3241
|
-
* generative modules (rhythm, drums, bass, groove, counter-melody). A single
|
|
3242
|
-
* mulberry32 core exposes the small set of samplers those modules need; given a
|
|
3243
|
-
* seed the stream is fully reproducible.
|
|
3244
|
-
*/
|
|
3245
|
-
/**
|
|
3246
|
-
* A deterministic PRNG with the sampling helpers the generators need.
|
|
3247
|
-
*
|
|
3248
|
-
* @category Utilities
|
|
3249
|
-
*/
|
|
3250
|
-
type Rng = {
|
|
3251
|
-
/** Next float in [0, 1). */
|
|
3252
|
-
next: () => number;
|
|
3253
|
-
/** True with probability `p`. */
|
|
3254
|
-
prob: (p: number) => boolean;
|
|
3255
|
-
/** Integer in the inclusive range [lo, hi]. */
|
|
3256
|
-
range: (lo: number, hi: number) => number;
|
|
3257
|
-
/** Float in [lo, hi). */
|
|
3258
|
-
float: (lo: number, hi: number) => number;
|
|
3259
|
-
};
|
|
3260
|
-
/**
|
|
3261
|
-
* Create a seeded PRNG (mulberry32) exposing the shared samplers.
|
|
3262
|
-
*
|
|
3263
|
-
* @param seed The 32-bit seed; the same seed always yields the same stream.
|
|
3264
|
-
* @returns The seeded generator.
|
|
3265
|
-
* @example
|
|
3266
|
-
* ```ts
|
|
3267
|
-
* import { createRng } from '@libraz/libcantus';
|
|
3268
|
-
* const rng = createRng(42);
|
|
3269
|
-
* rng.next(); // deterministic float in [0, 1)
|
|
3270
|
-
* rng.range(1, 6); // deterministic integer in [1, 6]
|
|
3271
|
-
* ```
|
|
3272
|
-
* @category Utilities
|
|
3273
|
-
*/
|
|
3274
|
-
declare function createRng(seed: number): Rng;
|
|
3275
|
-
|
|
3276
|
-
/**
|
|
3277
|
-
* Reharmonization: chord substitution, modal-interchange palettes, and negative
|
|
3278
|
-
* harmony. These transforms take an existing chord (or a key) and propose
|
|
3279
|
-
* alternative harmonies that preserve a chosen relationship — a shared function,
|
|
3280
|
-
* a common tone, a tonicizing dominant, or a reflection across the key axis.
|
|
3281
|
-
*
|
|
3282
|
-
* Roots are pitch classes (0..11); no spelled key signature is required.
|
|
3283
|
-
*/
|
|
3284
|
-
|
|
3285
|
-
/**
|
|
3286
|
-
* The kind of substitution relationship a candidate realizes.
|
|
3287
|
-
*
|
|
3288
|
-
* @category Reharmonization
|
|
3289
|
-
*/
|
|
3290
|
-
type SubstitutionType = 'tritone' | 'relative' | 'borrowed' | 'chromatic-mediant' | 'secondary-dominant';
|
|
3291
|
-
/**
|
|
3292
|
-
* A proposed chord substitution with its relationship, numeral, and function.
|
|
3293
|
-
*
|
|
3294
|
-
* @category Reharmonization
|
|
3295
|
-
*/
|
|
3296
|
-
type Substitution = {
|
|
3297
|
-
chord: Chord$1;
|
|
3298
|
-
type: SubstitutionType;
|
|
3299
|
-
roman: string;
|
|
3300
|
-
function: HarmonicFunction;
|
|
3301
|
-
};
|
|
3302
|
-
/**
|
|
3303
|
-
* Options controlling which substitutions {@link substituteChord} returns.
|
|
3304
|
-
*
|
|
3305
|
-
* @category Reharmonization
|
|
3306
|
-
*/
|
|
3307
|
-
type SubstituteOptions = {
|
|
3308
|
-
/**
|
|
3309
|
-
* Melody pitch classes that must remain chord tones. When given, only
|
|
3310
|
-
* substitutions whose pitch classes contain every listed pitch class are
|
|
3311
|
-
* kept, so the melody stays consonant against the new harmony.
|
|
3312
|
-
*/
|
|
3313
|
-
melodyPcs?: number[];
|
|
3314
|
-
};
|
|
3315
|
-
/**
|
|
3316
|
-
* Propose substitutions for a chord within a key.
|
|
3317
|
-
*
|
|
3318
|
-
* Candidates are generated by several relationships and deduplicated against the
|
|
3319
|
-
* original chord and each other:
|
|
3320
|
-
*
|
|
3321
|
-
* - `tritone`: for a dominant-type chord, the dominant seventh a tritone away.
|
|
3322
|
-
* - `secondary-dominant`: for a stable target, the dominant seventh a fifth
|
|
3323
|
-
* above its root (tonicizing it).
|
|
3324
|
-
* - `relative`: a diatonic triad a third away that shares two common tones.
|
|
3325
|
-
* - `borrowed`: a triad from the parallel mode with the same harmonic function.
|
|
3326
|
-
* - `chromatic-mediant`: a major/minor triad a third away sharing one common
|
|
3327
|
-
* tone.
|
|
3328
|
-
*
|
|
3329
|
-
* Each result carries its Roman numeral and harmonic function in `key`. When
|
|
3330
|
-
* `opts.melodyPcs` is given, only substitutions whose pitch classes contain all
|
|
3331
|
-
* of those pitch classes are returned.
|
|
3332
|
-
*
|
|
3333
|
-
* @param chord The chord to reharmonize.
|
|
3334
|
-
* @param key The prevailing key.
|
|
3335
|
-
* @param opts Optional melody-preservation constraint.
|
|
3336
|
-
* @returns The deduplicated substitution candidates.
|
|
3337
|
-
* @example
|
|
3338
|
-
* ```ts
|
|
3339
|
-
* import { substituteChord, makeChord, majorKey } from '@libraz/libcantus';
|
|
3340
|
-
* const subs = substituteChord(makeChord(7, 'dom7'), majorKey(0));
|
|
3341
|
-
* // includes the tritone sub Db7 (rootPc 1, quality 'dom7')
|
|
3342
|
-
* ```
|
|
3343
|
-
* @category Reharmonization
|
|
3344
|
-
*/
|
|
3345
|
-
declare function substituteChord(chord: Chord$1, key: KeyScale, opts?: SubstituteOptions): Substitution[];
|
|
3346
|
-
/**
|
|
3347
|
-
* A borrowed chord in the modal-interchange palette of a key.
|
|
3348
|
-
*
|
|
3349
|
-
* @category Reharmonization
|
|
3350
|
-
*/
|
|
3351
|
-
type BorrowedChord = {
|
|
3352
|
-
chord: Chord$1;
|
|
3353
|
-
roman: string;
|
|
3354
|
-
source: BorrowedSource;
|
|
3355
|
-
};
|
|
3356
|
-
/**
|
|
3357
|
-
* The modal-interchange palette of a key.
|
|
3358
|
-
*
|
|
3359
|
-
* Lists the diatonic triads of the {@link parallelKey} that are not diatonic to
|
|
3360
|
-
* `key` (the classic borrowed chords such as `iv`, `bVI`, and `bVII` in a major
|
|
3361
|
-
* key), plus the Neapolitan (a major triad on the flat second degree). Each
|
|
3362
|
-
* carries its Roman numeral and {@link borrowedSource} relative to `key`.
|
|
3363
|
-
*
|
|
3364
|
-
* @param key The prevailing key.
|
|
3365
|
-
* @returns The borrowed-chord palette.
|
|
3366
|
-
* @category Reharmonization
|
|
3367
|
-
*/
|
|
3368
|
-
declare function modalInterchangePalette(key: KeyScale): BorrowedChord[];
|
|
3369
|
-
/**
|
|
3370
|
-
* Reflect a chord across the tonic–dominant axis of a key (negative harmony).
|
|
3371
|
-
*
|
|
3372
|
-
* Every pitch class `p` maps to `(2*T + 7 - p) mod 12`, where `T` is the key
|
|
3373
|
-
* tonic — the reflection that swaps the tonic with the dominant. The mirrored
|
|
3374
|
-
* pitch classes (including the bass, if set) are reassembled into a chord by
|
|
3375
|
-
* {@link detectChordBest}; when no chord is recognized, the mirrored root and
|
|
3376
|
-
* the original quality are used as a fallback.
|
|
3377
|
-
*
|
|
3378
|
-
* @param chord The chord to reflect.
|
|
3379
|
-
* @param key The prevailing key.
|
|
3380
|
-
* @returns The negative-harmony counterpart of the chord.
|
|
3381
|
-
* @example
|
|
3382
|
-
* ```ts
|
|
3383
|
-
* import { negativeHarmonyMirror, makeChord, majorKey } from '@libraz/libcantus';
|
|
3384
|
-
* negativeHarmonyMirror(makeChord(7, 'maj'), majorKey(0));
|
|
3385
|
-
* // G major reflected across C's axis => F minor (rootPc 5, quality 'min')
|
|
3386
|
-
* ```
|
|
3387
|
-
* @category Reharmonization
|
|
3388
|
-
*/
|
|
3389
|
-
declare function negativeHarmonyMirror(chord: Chord$1, key: KeyScale): Chord$1;
|
|
3390
|
-
|
|
3391
|
-
/**
|
|
3392
|
-
* Deterministic rhythm generation over a metric grid.
|
|
3393
|
-
*
|
|
3394
|
-
* Builds a fixed-resolution grid across one or more bars of a time signature
|
|
3395
|
-
* and decides, per grid slot, whether it becomes a note onset. Onset
|
|
3396
|
-
* probability follows the metric-accent hierarchy from the `meter` module, so
|
|
3397
|
-
* strong positions (downbeats, secondary pulses) are favored over weak
|
|
3398
|
-
* off-pulse subdivisions. Given a seed the output is fully reproducible.
|
|
3399
|
-
*
|
|
3400
|
-
* Positions and durations are measured in quarter-note beats, matching the
|
|
3401
|
-
* library-wide convention.
|
|
3402
|
-
*/
|
|
3403
|
-
|
|
3404
|
-
/**
|
|
3405
|
-
* A single rhythmic note: an onset position and how long it sounds.
|
|
3406
|
-
*
|
|
3407
|
-
* @category Rhythm & Meter
|
|
3408
|
-
*/
|
|
3409
|
-
type RhythmEvent = {
|
|
3410
|
-
/** Onset position in quarter-note beats, absolute from the start of the span. */
|
|
3411
|
-
position: number;
|
|
3412
|
-
/** Duration in quarter-note beats, extending to the next onset. */
|
|
3413
|
-
duration: number;
|
|
3414
|
-
};
|
|
3415
|
-
/**
|
|
3416
|
-
* Options controlling {@link generateRhythm}.
|
|
3417
|
-
*
|
|
3418
|
-
* @category Rhythm & Meter
|
|
3419
|
-
*/
|
|
3420
|
-
type RhythmOptions = {
|
|
3421
|
-
/**
|
|
3422
|
-
* Seed for the deterministic PRNG.
|
|
3423
|
-
*
|
|
3424
|
-
* @defaultValue 0
|
|
3425
|
-
*/
|
|
3426
|
-
seed?: number;
|
|
3427
|
-
/**
|
|
3428
|
-
* Number of bars to generate.
|
|
3429
|
-
*
|
|
3430
|
-
* @defaultValue 1
|
|
3431
|
-
*/
|
|
3432
|
-
bars?: number;
|
|
3433
|
-
/**
|
|
3434
|
-
* Grid resolution as the number of equal grid steps per quarter-note beat.
|
|
3435
|
-
* The default of 2 yields an eighth-note grid; 4 yields a sixteenth-note
|
|
3436
|
-
* grid, 3 an eighth-note triplet grid, and so on.
|
|
3437
|
-
*
|
|
3438
|
-
* @defaultValue 2
|
|
3439
|
-
*/
|
|
3440
|
-
subdivision?: number;
|
|
3441
|
-
/**
|
|
3442
|
-
* Overall onset density in [0, 1]. Scales the per-slot onset probability, so
|
|
3443
|
-
* higher values fill more grid slots. Values outside [0, 1] are clamped into
|
|
3444
|
-
* range.
|
|
3445
|
-
*
|
|
3446
|
-
* @defaultValue 0.5
|
|
3447
|
-
*/
|
|
3448
|
-
density?: number;
|
|
3449
|
-
};
|
|
3450
|
-
/**
|
|
3451
|
-
* Map a metric weight (0–3 from {@link metricWeight}) to a base onset
|
|
3452
|
-
* probability before density scaling. Strong positions are much more likely to
|
|
3453
|
-
* carry an onset than weak ones; the curve is intentionally small and explicit
|
|
3454
|
-
* so its behavior is easy to inspect and test.
|
|
3455
|
-
*
|
|
3456
|
-
* @param weight The metric weight, 0 (off-pulse) to 3 (downbeat).
|
|
3457
|
-
* @returns A base onset probability in [0, 1].
|
|
3458
|
-
* @category Rhythm & Meter
|
|
3459
|
-
*/
|
|
3460
|
-
declare function onsetWeightCurve(weight: number): number;
|
|
3461
|
-
/**
|
|
3462
|
-
* Generate a deterministic rhythmic pattern over `bars` bars of a time
|
|
3463
|
-
* signature. A grid is built at the chosen subdivision; each slot becomes an
|
|
3464
|
-
* onset with a probability derived from its metric weight scaled by `density`
|
|
3465
|
-
* and sampled from the seeded PRNG. Every bar's downbeat is always an onset, so
|
|
3466
|
-
* a pattern of any length has a reliable pulse independent of the seed. Each
|
|
3467
|
-
* event's duration extends to the next onset, and the last event extends to the
|
|
3468
|
-
* end of the span. `density` is clamped to [0, 1].
|
|
3469
|
-
*
|
|
3470
|
-
* @param ts The time signature.
|
|
3471
|
-
* @param opts Generation options.
|
|
3472
|
-
* @returns Onset events sorted by position, non-overlapping, covering the span.
|
|
3473
|
-
* @example
|
|
3474
|
-
* ```ts
|
|
3475
|
-
* import { parseTimeSignature, generateRhythm } from '@libraz/libcantus';
|
|
3476
|
-
* const ts = parseTimeSignature('4/4');
|
|
3477
|
-
* generateRhythm(ts, { seed: 42, density: 0.6 }); // onset events over one bar
|
|
3478
|
-
* ```
|
|
3479
|
-
* @category Rhythm & Meter
|
|
3480
|
-
*/
|
|
3481
|
-
declare function generateRhythm(ts: TimeSignature, opts?: RhythmOptions): RhythmEvent[];
|
|
3482
|
-
/**
|
|
3483
|
-
* Onset density of a generated pattern: the mean number of onsets per bar.
|
|
3484
|
-
*
|
|
3485
|
-
* @param events Events from {@link generateRhythm}.
|
|
3486
|
-
* @param ts The time signature.
|
|
3487
|
-
* @returns The onset count divided by the number of bars the events span.
|
|
3488
|
-
* @category Rhythm & Meter
|
|
3489
|
-
*/
|
|
3490
|
-
declare function rhythmDensity(events: RhythmEvent[], ts: TimeSignature): number;
|
|
3491
|
-
|
|
3492
|
-
/**
|
|
3493
|
-
* Build a 12-bit mode mask from a list of semitone offsets above the root.
|
|
3494
|
-
*
|
|
3495
|
-
* Bit 0 (the root) is always set, enforcing the `KeyScale` invariant that the
|
|
3496
|
-
* root is a scale tone even when the offset list omits 0.
|
|
3497
|
-
*
|
|
3498
|
-
* @category Scales
|
|
3499
|
-
*/
|
|
3500
|
-
declare function maskFromOffsets(offsets: readonly number[]): number;
|
|
3501
|
-
/**
|
|
3502
|
-
* Mode mask for the major (Ionian) scale: offsets {0, 2, 4, 5, 7, 9, 11}.
|
|
3503
|
-
*
|
|
3504
|
-
* @category Scales
|
|
3505
|
-
*/
|
|
3506
|
-
declare const MAJOR_MASK = 2741;
|
|
3507
|
-
/**
|
|
3508
|
-
* Mode mask for the natural minor (Aeolian) scale: offsets {0, 2, 3, 5, 7, 8, 10}.
|
|
3509
|
-
*
|
|
3510
|
-
* @category Scales
|
|
3511
|
-
*/
|
|
3512
|
-
declare const NATURAL_MINOR_MASK = 1453;
|
|
3513
|
-
/**
|
|
3514
|
-
* Harmonic minor: natural minor with a raised seventh — offsets {0,2,3,5,7,8,11}.
|
|
3515
|
-
*
|
|
3516
|
-
* @category Scales
|
|
3517
|
-
*/
|
|
3518
|
-
declare const HARMONIC_MINOR_MASK: number;
|
|
3519
|
-
/**
|
|
3520
|
-
* Ascending melodic minor: offsets {0,2,3,5,7,9,11}.
|
|
3521
|
-
*
|
|
3522
|
-
* @category Scales
|
|
3523
|
-
*/
|
|
3524
|
-
declare const MELODIC_MINOR_MASK: number;
|
|
3525
|
-
/**
|
|
3526
|
-
* Dorian mode: offsets {0,2,3,5,7,9,10}.
|
|
3527
|
-
*
|
|
3528
|
-
* @category Scales
|
|
3529
|
-
*/
|
|
3530
|
-
declare const DORIAN_MASK: number;
|
|
3531
|
-
/**
|
|
3532
|
-
* Phrygian mode: offsets {0,1,3,5,7,8,10}.
|
|
3533
|
-
*
|
|
3534
|
-
* @category Scales
|
|
3535
|
-
*/
|
|
3536
|
-
declare const PHRYGIAN_MASK: number;
|
|
3537
|
-
/**
|
|
3538
|
-
* Lydian mode: offsets {0,2,4,6,7,9,11}.
|
|
3539
|
-
*
|
|
3540
|
-
* @category Scales
|
|
3541
|
-
*/
|
|
3542
|
-
declare const LYDIAN_MASK: number;
|
|
3543
|
-
/**
|
|
3544
|
-
* Mixolydian mode: offsets {0,2,4,5,7,9,10}.
|
|
3545
|
-
*
|
|
3546
|
-
* @category Scales
|
|
3547
|
-
*/
|
|
3548
|
-
declare const MIXOLYDIAN_MASK: number;
|
|
3549
|
-
/**
|
|
3550
|
-
* Locrian mode: offsets {0,1,3,5,6,8,10}.
|
|
3551
|
-
*
|
|
3552
|
-
* @category Scales
|
|
3553
|
-
*/
|
|
3554
|
-
declare const LOCRIAN_MASK: number;
|
|
3555
|
-
/**
|
|
3556
|
-
* Major pentatonic: offsets {0,2,4,7,9}.
|
|
3557
|
-
*
|
|
3558
|
-
* @category Scales
|
|
3559
|
-
*/
|
|
3560
|
-
declare const MAJOR_PENTATONIC_MASK: number;
|
|
3561
|
-
/**
|
|
3562
|
-
* Minor pentatonic: offsets {0,3,5,7,10}.
|
|
3563
|
-
*
|
|
3564
|
-
* @category Scales
|
|
3565
|
-
*/
|
|
3566
|
-
declare const MINOR_PENTATONIC_MASK: number;
|
|
3567
|
-
/**
|
|
3568
|
-
* Hexatonic blues scale: minor pentatonic plus the flat-fifth — {0,3,5,6,7,10}.
|
|
3569
|
-
*
|
|
3570
|
-
* @category Scales
|
|
3571
|
-
*/
|
|
3572
|
-
declare const BLUES_MASK: number;
|
|
3573
|
-
/**
|
|
3574
|
-
* Whole-tone scale: offsets {0,2,4,6,8,10}.
|
|
3575
|
-
*
|
|
3576
|
-
* @category Scales
|
|
3577
|
-
*/
|
|
3578
|
-
declare const WHOLE_TONE_MASK: number;
|
|
3579
|
-
/**
|
|
3580
|
-
* Octatonic (half-step first): offsets {0,1,3,4,6,7,9,10}.
|
|
3581
|
-
*
|
|
3582
|
-
* @category Scales
|
|
3583
|
-
*/
|
|
3584
|
-
declare const OCTATONIC_HALF_WHOLE_MASK: number;
|
|
3585
|
-
/**
|
|
3586
|
-
* Octatonic (whole-step first): offsets {0,2,3,5,6,8,9,11}.
|
|
3587
|
-
*
|
|
3588
|
-
* @category Scales
|
|
3589
|
-
*/
|
|
3590
|
-
declare const OCTATONIC_WHOLE_HALF_MASK: number;
|
|
3591
|
-
/**
|
|
3592
|
-
* Chromatic scale: all twelve pitch classes.
|
|
3593
|
-
*
|
|
3594
|
-
* @category Scales
|
|
3595
|
-
*/
|
|
3596
|
-
declare const CHROMATIC_MASK = 4095;
|
|
3597
|
-
/**
|
|
3598
|
-
* Named scale masks addressable by {@link scaleByName}.
|
|
3599
|
-
*
|
|
3600
|
-
* @category Scales
|
|
3601
|
-
*/
|
|
3602
|
-
declare const NAMED_SCALES: Record<string, number>;
|
|
3603
|
-
/**
|
|
3604
|
-
* Build a `KeyScale` for a major key on the given root pitch class.
|
|
3605
|
-
*
|
|
3606
|
-
* @example
|
|
3607
|
-
* ```ts
|
|
3608
|
-
* import { majorKey } from '@libraz/libcantus';
|
|
3609
|
-
* const cMajor = majorKey(0); // C major: { rootPc: 0, modeMask12: MAJOR_MASK }
|
|
3610
|
-
* ```
|
|
3611
|
-
*
|
|
3612
|
-
* @category Scales
|
|
3613
|
-
*/
|
|
3614
|
-
declare function majorKey(rootPc: number): KeyScale;
|
|
3615
|
-
/**
|
|
3616
|
-
* Build a `KeyScale` for a natural-minor key on the given root pitch class.
|
|
3617
|
-
*
|
|
3618
|
-
* @example
|
|
3619
|
-
* ```ts
|
|
3620
|
-
* import { minorKey } from '@libraz/libcantus';
|
|
3621
|
-
* const aMinor = minorKey(9); // A natural minor: { rootPc: 9, modeMask12: NATURAL_MINOR_MASK }
|
|
3622
|
-
* ```
|
|
3623
|
-
*
|
|
3624
|
-
* @category Scales
|
|
3625
|
-
*/
|
|
3626
|
-
declare function minorKey(rootPc: number): KeyScale;
|
|
3627
|
-
/**
|
|
3628
|
-
* Build a `KeyScale` from a named scale (see {@link NAMED_SCALES}).
|
|
3629
|
-
*
|
|
3630
|
-
* @param name The scale name, e.g. `'dorian'` or `'harmonicMinor'`.
|
|
3631
|
-
* @param rootPc The root pitch class.
|
|
3632
|
-
* @returns The key/scale.
|
|
3633
|
-
* @throws If the name is not a known scale.
|
|
3634
|
-
*
|
|
3635
|
-
* @example
|
|
3636
|
-
* ```ts
|
|
3637
|
-
* import { scaleByName } from '@libraz/libcantus';
|
|
3638
|
-
* const dDorian = scaleByName('dorian', 2); // D Dorian, rootPc 2
|
|
3639
|
-
* ```
|
|
3640
|
-
*
|
|
3641
|
-
* @category Scales
|
|
3642
|
-
*/
|
|
3643
|
-
declare function scaleByName(name: string, rootPc: number): KeyScale;
|
|
3644
|
-
/**
|
|
3645
|
-
* Test whether a pitch belongs to the scale.
|
|
3646
|
-
*
|
|
3647
|
-
* @param pitch MIDI pitch or bare pitch class.
|
|
3648
|
-
* @param key The key/scale to test against.
|
|
3649
|
-
* @returns True if the pitch class is a member of the scale.
|
|
3650
|
-
*
|
|
3651
|
-
* @example
|
|
3652
|
-
* ```ts
|
|
3653
|
-
* import { majorKey, isScaleTone } from '@libraz/libcantus';
|
|
3654
|
-
* const key = majorKey(0); // C major
|
|
3655
|
-
* isScaleTone(64, key); // true — E is in C major
|
|
3656
|
-
* isScaleTone(61, key); // false — C# is not
|
|
3657
|
-
* ```
|
|
3658
|
-
*
|
|
3659
|
-
* @category Scales
|
|
3660
|
-
*/
|
|
3661
|
-
declare function isScaleTone(pitch: number, key: KeyScale): boolean;
|
|
3662
|
-
/**
|
|
3663
|
-
* Find the nearest MIDI pitch whose pitch class is in the scale.
|
|
3664
|
-
*
|
|
3665
|
-
* The search expands symmetrically outward from `pitch`. On a tie (equal
|
|
3666
|
-
* distance above and below) the lower pitch is returned.
|
|
3667
|
-
*
|
|
3668
|
-
* @param pitch MIDI pitch to snap.
|
|
3669
|
-
* @param key The key/scale to snap to.
|
|
3670
|
-
* @returns The nearest in-scale MIDI pitch.
|
|
3671
|
-
*
|
|
3672
|
-
* @category Scales
|
|
3673
|
-
*/
|
|
3674
|
-
declare function nearestScaleTone(pitch: number, key: KeyScale): number;
|
|
3675
|
-
/**
|
|
3676
|
-
* Get the 0-based scale degree of a pitch.
|
|
3677
|
-
*
|
|
3678
|
-
* @param pitch MIDI pitch or bare pitch class.
|
|
3679
|
-
* @param key The key/scale to measure against.
|
|
3680
|
-
* @returns The 0-based degree, or -1 if the pitch is not in the scale.
|
|
3681
|
-
*
|
|
3682
|
-
* @category Scales
|
|
3683
|
-
*/
|
|
3684
|
-
declare function pitchToScaleDegree(pitch: number, key: KeyScale): number;
|
|
3685
|
-
/**
|
|
3686
|
-
* List the pitch classes of a key's scale.
|
|
3687
|
-
*
|
|
3688
|
-
* @param key The key/scale to enumerate.
|
|
3689
|
-
* @returns The member pitch classes, sorted ascending in [0, 11].
|
|
3690
|
-
*
|
|
3691
|
-
* @category Scales
|
|
3692
|
-
*/
|
|
3693
|
-
declare function diatonicPitchClasses(key: KeyScale): number[];
|
|
3694
|
-
/**
|
|
3695
|
-
* List the pitch classes of a key's scale in ascending scale-degree order.
|
|
3696
|
-
*
|
|
3697
|
-
* Degree 0 is the root; degrees follow the mask bits in offset order rather
|
|
3698
|
-
* than sorted pitch-class order.
|
|
3699
|
-
*
|
|
3700
|
-
* @param key The key/scale to enumerate.
|
|
3701
|
-
* @returns The member pitch classes ordered by scale degree.
|
|
3702
|
-
*
|
|
3703
|
-
* @category Scales
|
|
3704
|
-
*/
|
|
3705
|
-
declare function scaleTonesInDegreeOrder(key: KeyScale): number[];
|
|
3706
|
-
|
|
3707
|
-
/**
|
|
3708
|
-
* Spelling: derive letter-name notes for scales and chords from a spelled tonic.
|
|
3709
|
-
*
|
|
3710
|
-
* The theory core works in pitch classes, which cannot choose between (say) a
|
|
3711
|
-
* G# and an Ab. Given a spelled tonic, this module assigns diatonic letters to
|
|
3712
|
-
* scale degrees and chord tones so a C major scale spells as C D E F G A B and
|
|
3713
|
-
* A harmonic minor spells its seventh as G#.
|
|
3714
|
-
*/
|
|
3715
|
-
|
|
3716
|
-
/**
|
|
3717
|
-
* Spell a single pitch class relative to a spelled tonic and key.
|
|
3718
|
-
*
|
|
3719
|
-
* Diatonic pitch classes take the scale's letter for their degree; the common
|
|
3720
|
-
* chromatic tones (b2, b3, #4, b6, b7) and a minor key's raised degrees (#6, #7)
|
|
3721
|
-
* take their conventional, key-correct accidental spelling; anything else falls
|
|
3722
|
-
* back to a sharp spelling of the nearest natural.
|
|
3723
|
-
*
|
|
3724
|
-
* @param pc The pitch class to spell.
|
|
3725
|
-
* @param tonic The spelled tonic (its letter anchors the spelling).
|
|
3726
|
-
* @param key The key/scale.
|
|
3727
|
-
* @returns The spelled note (without octave).
|
|
3728
|
-
* @category Pitch & Intervals
|
|
3729
|
-
*/
|
|
3730
|
-
declare function spellPitchClass(pc: number, tonic: Note$1, key: KeyScale): Note$1;
|
|
3731
|
-
/**
|
|
3732
|
-
* Spell every pitch class of a scale, in ascending scale-degree order.
|
|
3733
|
-
*
|
|
3734
|
-
* Correct for heptatonic scales (each degree gets the next letter). Non-standard
|
|
3735
|
-
* scales are spelled tone-by-tone with a sharp preference.
|
|
3736
|
-
*
|
|
3737
|
-
* @param tonic The spelled tonic.
|
|
3738
|
-
* @param key The key/scale.
|
|
3739
|
-
* @returns Spelled notes, one per scale degree.
|
|
3740
|
-
* @example
|
|
3741
|
-
* ```ts
|
|
3742
|
-
* import { spellScale, noteNames, parseNote, majorKey } from '@libraz/libcantus';
|
|
3743
|
-
* noteNames(spellScale(parseNote('C'), majorKey(0)));
|
|
3744
|
-
* // ['C', 'D', 'E', 'F', 'G', 'A', 'B']
|
|
3745
|
-
* ```
|
|
3746
|
-
* @category Pitch & Intervals
|
|
3747
|
-
*/
|
|
3748
|
-
declare function spellScale(tonic: Note$1, key: KeyScale): Note$1[];
|
|
3749
|
-
/**
|
|
3750
|
-
* Spell an arbitrary list of pitch classes relative to a key.
|
|
3751
|
-
*
|
|
3752
|
-
* @param pcs The pitch classes.
|
|
3753
|
-
* @param tonic The spelled tonic.
|
|
3754
|
-
* @param key The key/scale.
|
|
3755
|
-
* @returns Spelled notes, in input order.
|
|
3756
|
-
* @category Pitch & Intervals
|
|
3757
|
-
*/
|
|
3758
|
-
declare function spellPitchClasses(pcs: number[], tonic: Note$1, key: KeyScale): Note$1[];
|
|
3759
|
-
/**
|
|
3760
|
-
* Spell a chord's tones, in the chord's own (tertian) order, relative to a key.
|
|
3761
|
-
*
|
|
3762
|
-
* Diatonic chords spell exactly (e.g. G7 in C major -> G B D F). Chromatic chord
|
|
3763
|
-
* tones take their conventional spelling; enharmonically ambiguous altered
|
|
3764
|
-
* tensions may be spelled by the general convention rather than by chord
|
|
3765
|
-
* function.
|
|
3766
|
-
*
|
|
3767
|
-
* @param chord The chord.
|
|
3768
|
-
* @param tonic The spelled tonic of the key.
|
|
3769
|
-
* @param key The key/scale.
|
|
3770
|
-
* @returns Spelled chord tones, root first.
|
|
3771
|
-
* @example
|
|
3772
|
-
* ```ts
|
|
3773
|
-
* import { spellChord, noteNames, parseNote, majorKey, makeChord } from '@libraz/libcantus';
|
|
3774
|
-
* // G7 in C major
|
|
3775
|
-
* noteNames(spellChord(makeChord(7, 'dom7'), parseNote('C'), majorKey(0)));
|
|
3776
|
-
* // ['G', 'B', 'D', 'F']
|
|
3777
|
-
* ```
|
|
3778
|
-
* @category Pitch & Intervals
|
|
3779
|
-
*/
|
|
3780
|
-
declare function spellChord(chord: Chord$1, tonic: Note$1, key: KeyScale): Note$1[];
|
|
3781
|
-
/**
|
|
3782
|
-
* Convenience: render spelled notes as letter-name strings.
|
|
3783
|
-
*
|
|
3784
|
-
* @param notes The notes.
|
|
3785
|
-
* @returns Their formatted names.
|
|
3786
|
-
* @category Pitch & Intervals
|
|
3787
|
-
*/
|
|
3788
|
-
declare function noteNames(notes: Note$1[]): string[];
|
|
3789
|
-
|
|
3790
|
-
/**
|
|
3791
|
-
* Lead-sheet chord symbol parsing and formatting.
|
|
3792
|
-
*
|
|
3793
|
-
* Bridges the informal `<root><quality>[/<bass>]` notation musicians write
|
|
3794
|
-
* (`Cmaj7`, `F#m7b5`, `Bb7`, `C/G`) and the library's structured {@link Chord}
|
|
3795
|
-
* type, so callers can accept/emit plain text at the edges of the API.
|
|
3796
|
-
*/
|
|
3797
|
-
|
|
3798
|
-
/**
|
|
3799
|
-
* Parse a lead-sheet chord symbol into a {@link Chord}.
|
|
3800
|
-
*
|
|
3801
|
-
* Accepts `<root><quality>[/<bass>]`, e.g. `Cmaj7`, `F#m7b5`, `Bb7`, `C/G`,
|
|
3802
|
-
* `C6/9`, `C6/9/E`. Root and bass letters are case-insensitive, matching
|
|
3803
|
-
* {@link parseNote}. A `/` is ambiguous between a slash bass and the `6/9`
|
|
3804
|
-
* quality; the text splits at the last `/` whose right-hand side is a valid
|
|
3805
|
-
* bare note preceded by a recognized quality, so `6/9` (with or without a
|
|
3806
|
-
* further slash bass) parses as a quality.
|
|
3807
|
-
*
|
|
3808
|
-
* The parsed chord carries the root/bass spellings as enharmonic hints
|
|
3809
|
-
* (`rootSpelling`/`bassSpelling`) so {@link formatChordSymbol} can reproduce
|
|
3810
|
-
* flat spellings such as `Bbmaj7` instead of respelling them with sharps.
|
|
3811
|
-
*
|
|
3812
|
-
* @param text The chord symbol text.
|
|
3813
|
-
* @returns The parsed chord.
|
|
3814
|
-
* @throws If the root or quality is not recognized.
|
|
3815
|
-
* @example
|
|
3816
|
-
* ```ts
|
|
3817
|
-
* import { parseChordSymbol, formatChordSymbol } from '@libraz/libcantus';
|
|
3818
|
-
* const c = parseChordSymbol('Bbmaj7');
|
|
3819
|
-
* formatChordSymbol(c); // 'Bbmaj7' — flat spelling is preserved on round-trip
|
|
3820
|
-
* ```
|
|
3821
|
-
* @category Chords
|
|
3822
|
-
*/
|
|
3823
|
-
declare function parseChordSymbol(text: string): Chord$1;
|
|
3824
|
-
/**
|
|
3825
|
-
* Format a {@link Chord} as a lead-sheet chord symbol.
|
|
3826
|
-
*
|
|
3827
|
-
* The inverse of {@link parseChordSymbol}: each quality maps to one canonical
|
|
3828
|
-
* suffix spelling, and a slash bass is appended only when it differs from the
|
|
3829
|
-
* root. When the chord carries `rootSpelling`/`bassSpelling` hints (as chords
|
|
3830
|
-
* from {@link parseChordSymbol} do) and no explicit `flats` preference is
|
|
3831
|
-
* given, the hints are reused so flat symbols round-trip unchanged.
|
|
3832
|
-
*
|
|
3833
|
-
* @param chord The chord to format.
|
|
3834
|
-
* @param opts Formatting options.
|
|
3835
|
-
* @param opts.flats Prefer flat spellings over sharps for altered roots/basses;
|
|
3836
|
-
* passing either `true` or `false` overrides any spelling hints.
|
|
3837
|
-
* @returns The chord symbol text.
|
|
3838
|
-
* @example
|
|
3839
|
-
* ```ts
|
|
3840
|
-
* import { makeChord, formatChordSymbol } from '@libraz/libcantus';
|
|
3841
|
-
* formatChordSymbol(makeChord(0, 'min7')); // 'Cm7'
|
|
3842
|
-
* ```
|
|
3843
|
-
* @category Chords
|
|
3844
|
-
*/
|
|
3845
|
-
declare function formatChordSymbol(chord: Chord$1, opts?: {
|
|
3846
|
-
flats?: boolean;
|
|
3847
|
-
}): string;
|
|
3848
|
-
/**
|
|
3849
|
-
* Transpose a chord symbol by a number of semitones.
|
|
3850
|
-
*
|
|
3851
|
-
* @param text The chord symbol text.
|
|
3852
|
-
* @param semitones Signed semitone offset to apply to the root and bass.
|
|
3853
|
-
* @param opts Formatting options for the result; see {@link formatChordSymbol}.
|
|
3854
|
-
* @returns The transposed chord symbol text.
|
|
3855
|
-
* @throws If `text` does not parse as a chord symbol.
|
|
3856
|
-
* @example
|
|
3857
|
-
* ```ts
|
|
3858
|
-
* import { transposeChordSymbol } from '@libraz/libcantus';
|
|
3859
|
-
* transposeChordSymbol('C/G', 2); // 'D/A'
|
|
3860
|
-
* ```
|
|
3861
|
-
* @category Chords
|
|
3862
|
-
*/
|
|
3863
|
-
declare function transposeChordSymbol(text: string, semitones: number, opts?: {
|
|
3864
|
-
flats?: boolean;
|
|
3865
|
-
}): string;
|
|
3866
|
-
|
|
3867
|
-
/**
|
|
3868
|
-
* Tuning and microtonality: frequency conversion, cents, arbitrary equal
|
|
3869
|
-
* temperaments (EDO), and just-intonation ratios.
|
|
3870
|
-
*
|
|
3871
|
-
* The rest of the library reasons in twelve-tone pitch classes, which is a
|
|
3872
|
-
* deliberate scope choice for tonal theory. This module is the escape hatch for
|
|
3873
|
-
* anyone who needs actual frequencies, cents, non-12 equal temperaments, or the
|
|
3874
|
-
* acoustic (just) tuning behind the tempered intervals.
|
|
3875
|
-
*/
|
|
3876
|
-
/**
|
|
3877
|
-
* An equal-tempered tuning: a reference pitch and a number of equal divisions of
|
|
3878
|
-
* the octave. With `divisions === 12` a step index is an ordinary MIDI number.
|
|
3879
|
-
*
|
|
3880
|
-
* @category Pitch & Intervals
|
|
3881
|
-
*/
|
|
3882
|
-
type Tuning = {
|
|
3883
|
-
/** Step index (MIDI number when `divisions` is 12) whose frequency is `refFreq`. */
|
|
3884
|
-
refStep: number;
|
|
3885
|
-
/** Frequency in Hz of `refStep`. */
|
|
3886
|
-
refFreq: number;
|
|
3887
|
-
/** Equal divisions of the octave (12 standard; e.g. 19 or 31 for microtonal). */
|
|
3888
|
-
divisions: number;
|
|
3889
|
-
};
|
|
3890
|
-
/**
|
|
3891
|
-
* Standard twelve-tone equal temperament, A4 (MIDI 69) = 440 Hz.
|
|
3892
|
-
*
|
|
3893
|
-
* @category Pitch & Intervals
|
|
3894
|
-
*/
|
|
3895
|
-
declare const TWELVE_TET: Tuning;
|
|
3896
|
-
/**
|
|
3897
|
-
* Build an equal temperament with `n` divisions of the octave.
|
|
3898
|
-
*
|
|
3899
|
-
* @param n Divisions of the octave (e.g. 19, 24, 31).
|
|
3900
|
-
* @param refFreq Reference frequency in Hz (default 440).
|
|
3901
|
-
* @param refStep Step index of the reference (default 69).
|
|
3902
|
-
* @returns The tuning.
|
|
3903
|
-
* @example
|
|
3904
|
-
* ```ts
|
|
3905
|
-
* import { edo, frequencyOf } from '@libraz/libcantus';
|
|
3906
|
-
* const et19 = edo(19); // { refStep: 69, refFreq: 440, divisions: 19 }
|
|
3907
|
-
* frequencyOf(70, et19); // one 19-EDO step above A4
|
|
3908
|
-
* ```
|
|
3909
|
-
* @category Pitch & Intervals
|
|
3910
|
-
*/
|
|
3911
|
-
declare function edo(n: number, refFreq?: number, refStep?: number): Tuning;
|
|
3912
|
-
/**
|
|
3913
|
-
* Frequency in Hz of a step index under a tuning.
|
|
3914
|
-
*
|
|
3915
|
-
* @param step Step index (a MIDI number under 12-EDO).
|
|
3916
|
-
* @param tuning The tuning (default 12-TET).
|
|
3917
|
-
* @returns The frequency in Hz.
|
|
3918
|
-
* @example
|
|
3919
|
-
* ```ts
|
|
3920
|
-
* import { frequencyOf } from '@libraz/libcantus';
|
|
3921
|
-
* frequencyOf(69); // 440 (A4 in 12-TET)
|
|
3922
|
-
* frequencyOf(60); // middle C in Hz
|
|
3923
|
-
* ```
|
|
3924
|
-
* @category Pitch & Intervals
|
|
3925
|
-
*/
|
|
3926
|
-
declare function frequencyOf(step: number, tuning?: Tuning): number;
|
|
3927
|
-
/**
|
|
3928
|
-
* Nearest step index to a frequency under a tuning (the inverse of
|
|
3929
|
-
* {@link frequencyOf}, rounded).
|
|
3930
|
-
*
|
|
3931
|
-
* @param freq Frequency in Hz.
|
|
3932
|
-
* @param tuning The tuning (default 12-TET).
|
|
3933
|
-
* @returns The nearest step index.
|
|
3934
|
-
* @category Pitch & Intervals
|
|
3935
|
-
*/
|
|
3936
|
-
declare function nearestStep(freq: number, tuning?: Tuning): number;
|
|
3937
|
-
/**
|
|
3938
|
-
* Interval in cents between two frequencies.
|
|
3939
|
-
*
|
|
3940
|
-
* @param a Lower/first frequency in Hz.
|
|
3941
|
-
* @param b Upper/second frequency in Hz.
|
|
3942
|
-
* @returns Cents from `a` to `b` (negative if `b` is lower).
|
|
3943
|
-
* @category Pitch & Intervals
|
|
3944
|
-
*/
|
|
3945
|
-
declare function centsBetweenFreq(a: number, b: number): number;
|
|
3946
|
-
/**
|
|
3947
|
-
* Cents spanned by a number of equal-temperament steps.
|
|
3948
|
-
*
|
|
3949
|
-
* @param steps Number of steps.
|
|
3950
|
-
* @param tuning The tuning (default 12-TET).
|
|
3951
|
-
* @returns The cents.
|
|
3952
|
-
* @category Pitch & Intervals
|
|
3953
|
-
*/
|
|
3954
|
-
declare function centsOfSteps(steps: number, tuning?: Tuning): number;
|
|
3955
|
-
/**
|
|
3956
|
-
* Cents of a frequency ratio, e.g. `ratioToCents(3, 2)` ≈ 701.955 for the just
|
|
3957
|
-
* perfect fifth.
|
|
3958
|
-
*
|
|
3959
|
-
* @param numerator Ratio numerator.
|
|
3960
|
-
* @param denominator Ratio denominator.
|
|
3961
|
-
* @returns The interval in cents.
|
|
3962
|
-
* @category Pitch & Intervals
|
|
3963
|
-
*/
|
|
3964
|
-
declare function ratioToCents(numerator: number, denominator: number): number;
|
|
3965
|
-
/**
|
|
3966
|
-
* Five-limit just-intonation ratios for the twelve interval classes above a
|
|
3967
|
-
* unison, indexed by semitone class (0..12).
|
|
3968
|
-
*
|
|
3969
|
-
* @category Pitch & Intervals
|
|
3970
|
-
*/
|
|
3971
|
-
declare const JUST_RATIOS: Record<number, [number, number]>;
|
|
3972
|
-
/**
|
|
3973
|
-
* Cents by which a five-limit just interval departs from its 12-TET tempering
|
|
3974
|
-
* (positive means the just interval is wider).
|
|
3975
|
-
*
|
|
3976
|
-
* @param semitoneClass Semitone class in [0, 12].
|
|
3977
|
-
* @returns The deviation in cents, or NaN if the class has no listed ratio.
|
|
3978
|
-
* @category Pitch & Intervals
|
|
3979
|
-
*/
|
|
3980
|
-
declare function justDeviationCents(semitoneClass: number): number;
|
|
3981
|
-
|
|
3982
|
-
export { type AnalyzedNote, type ArrangementAnalysis, type ArrangementOptions, type ArrangementTrack, BLUES_MASK, type BarPosition, type BassLineOptions, type BassSegment, type BassStyle, type BorrowedChord, type BorrowedSource, CHROMATIC_MASK, type Cadence, type CadenceHit, Chord, type ChordAnalysis, type Chord$1 as ChordData, type ChordMatch, type ChordQuality, type ChordScaleMatch, type ChordScaleReportEntry, type ChordSegment, type ChordTimeline, type ChordTimelineOptions, type ChordTimelineResult, type Conflict, type CounterMelodyOptions, DORIAN_MASK, type DrumGenOptions, type DrumHit, type DrumRole, type EuclideanKick, type GenerateMotifOptions, type GenerateProgressionOptions, type GeneratedChord, type GrooveFeel, type GrooveSlot, type GrooveStyle, type GrooveTemplate, HARMONIC_MINOR_MASK, type HarmonicFunction, type HarmonizeOptions, type HarmonizeResult, type HarmonyRole, type HumanizeOptions, Interval, IntervalQuality, JUST_RATIOS, Key, type KeyMatch, type KeyScale, LOCRIAN_MASK, LYDIAN_MASK, type LockLevel, MAJOR_MASK, MAJOR_PENTATONIC_MASK, MELODIC_MINOR_MASK, MINOR_PENTATONIC_MASK, MIXOLYDIAN_MASK, type MelodyNote, type MotifCell, type MotifContour, type MotifNote, type MotifTransform, NAMED_SCALES, NATURAL_MINOR_MASK, Note, type Note$1 as NoteData, type NoteEvent, NoteSafety, OCTATONIC_HALF_WHOLE_MASK, OCTATONIC_WHOLE_HALF_MASK, PHRYGIAN_MASK, type ProgFunction, type ProgStyle, Progression, type ProgressionPreset, ReasonFlag, type RhythmEvent, type RhythmOptions, type Rng, SATB_RANGES, type SafetyProfile, type SafetyQuery, type SafetyResult, type ScaleChoice, type Section, type SpelledInterval, type StyledVoicingOptions, type SubstituteOptions, type Substitution, type SubstitutionType, TWELVE_TET, type TensionPoint, type TheoryLabel, type TimeSignature, type TrackAnalysis, type TrackRole, type Tuning, type VoiceNote, type VoiceRange, type VoiceSnapshot, type VoicedRole, type VoicingOptions, type VoicingStyle, WHOLE_TONE_MASK, analyzeArrangement, analyzeChord, analyzeVoice, applyGrooveTemplate, availableTensions, avoidNotes, barPositionToBeat, beatToBarPosition, beatsPerBar, borrowedSource, centsBetweenFreq, centsOfSteps, chordFromDegree, chordPitchClasses, chordQualities, chordScaleReport, chordScales, chordTimelineFromChords, chordTimelineFromNotes, chordToRoman, chordToneRole, classifyInterval, createRng, createsHiddenParallelPerfect, createsParallelOctave, createsParallelPerfect, createsParallelUnison, createsVerticalDissonance, createsVoiceCrossing, createsVoiceOverlap, detectCadence, detectCadences, detectChord, detectChordBest, detectKey, developMotif, diatonicPitchClasses, diatonicSeventh, diatonicTriad, edo, enumerateSafePitches, evaluateSafety, exceedsSpacing, extractGrooveTemplate, formatChordSymbol, formatNote, formatTimeSignature, frequencyOf, functionOf, generateBassLine, generateCounterMelody, generateDrums, generateMotif, generateProgression, generateRhythm, harmonizeMelody, humanize, isBorrowedChord, isCompound, isConsonantInterval, isDiatonic, isForbiddenMelodicLeap, isLeadingToneResolution, isMinorKey, isPerfectInterval, isScaleTone, isStrongBeat, justDeviationCents, majorKey, makeChord, maskFromOffsets, metricWeight, midiToNote, minorKey, modalInterchangePalette, nearestScaleTone, nearestStep, negativeHarmonyMirror, nextVoicing, noteNames, noteToMidi, noteToPitchClass, onsetWeightCurve, parallelKey, parseChordSymbol, parseNote, parseTimeSignature, pitchToScaleDegree, progressions, progressionsByStyle, pulsesPerBar, ratioToCents, rhythmDensity, roleOf, romanToChord, scaleByName, scaleMatchesChord, scaleTonesInDegreeOrder, scalesForChanges, secondaryDominant, spellChord, spellPitchClass, spellPitchClasses, spellScale, spelledInterval, substituteChord, tensionCurve, transformMotif, transposeChordSymbol, tuplet, voiceChord, voiceChordStyled, voiceLeadingCost, voiceProgression };
|
|
1
|
+
export { AnalyzedNote, ArrangementAnalysis, ArrangementOptions, ArrangementTrack, ChordMatch, Conflict, KeyMatch, TensionPoint, TheoryLabel, TrackAnalysis, TrackRole, VoiceNote, analyzeArrangement, analyzeVoice, chordToRoman, detectChord, detectChordBest, detectKey, romanToChord, tensionCurve } from './analyze/index.js';
|
|
2
|
+
export { B as BorrowedSource, C as Cadence, a as ChordAnalysis, H as HarmonicFunction, b as analyzeChord, c as borrowedSource, d as detectCadence, f as functionOf, i as isBorrowedChord, e as isDiatonic, g as isMinorKey, p as parallelKey, s as secondaryDominant } from './function-2bJW1Zp_.js';
|
|
3
|
+
export { C as CadenceHit, a as ChordSegment, b as ChordTimeline, c as ChordTimelineOptions, d as ChordTimelineResult, e as chordTimelineFromChords, f as chordTimelineFromNotes, g as detectCadences } from './index-BMPxwjwV.js';
|
|
4
|
+
export { IntervalQuality, JUST_RATIOS, Rng, TWELVE_TET, Tuning, centsBetweenFreq, centsOfSteps, classifyInterval, createRng, edo, frequencyOf, isConsonantInterval, isPerfectInterval, justDeviationCents, nearestStep, ratioToCents } from './core/index.js';
|
|
5
|
+
export { B as BarPosition, T as TimeSignature, b as barPositionToBeat, a as beatToBarPosition, c as beatsPerBar, f as formatTimeSignature, i as isCompound, d as isStrongBeat, m as metricWeight, p as parseTimeSignature, e as pulsesPerBar, t as tuplet } from './index-Cl7mhOFM.js';
|
|
6
|
+
export { N as NoteData, S as SpelledInterval, f as formatNote, m as midiToNote, n as noteToMidi, a as noteToPitchClass, p as parseNote, s as spelledInterval } from './index-CGMZNCx6.js';
|
|
7
|
+
export { K as KeyScale, N as NoteEvent } from './types-MGP29r3t.js';
|
|
8
|
+
export { BassLineOptions, BassSegment, BassStyle, BorrowedChord, CounterMelodyOptions, DrumHit, DrumRole, DrumsOptions, EuclideanKick, GrooveFeel, GrooveSlot, GrooveStyle, GrooveTemplate, HarmonizeOptions, HarmonizeResult, HumanizeOptions, MelodyNote, MotifCell, MotifContour, MotifNote, MotifOptions, MotifTransform, ProgFunction, ProgStyle, ProgressionOptions, ProgressionPreset, RhythmEvent, RhythmOptions, Section, SubstituteOptions, Substitution, SubstitutionType, applyGrooveTemplate, developMotif, extractGrooveTemplate, generateBassLine, generateCounterMelody, generateDrums, generateMotif, generateProgression, generateRhythm, harmonizeMelody, humanize, modalInterchangePalette, negativeHarmonyMirror, onsetWeightCurve, progressions, progressionsByStyle, rhythmDensity, substituteChord, transformMotif } from './generate/index.js';
|
|
9
|
+
export { Chord, Interval, Key, Note, Progression } from './model/index.js';
|
|
10
|
+
export { C as ChordData, a as ChordQuality, b as ChordSpan, c as chordFromDegree, d as chordPitchClasses, e as chordQualities, f as chordToneRole, g as diatonicSeventh, h as diatonicTriad, m as makeChord } from './index-CM5W4rcm.js';
|
|
11
|
+
export { C as ChordScaleMatch, a as ChordScaleReportEntry, S as SATB_RANGES, b as ScaleChoice, c as StyledVoicingOptions, V as VoiceRange, d as VoicingOptions, e as VoicingStyle, f as availableTensions, g as avoidNotes, h as chordScaleReport, i as chordScales, s as scaleMatchesChord, j as scalesForChanges, v as voiceChord, k as voiceChordStyled, l as voiceProgression } from './styled-D7BAx3S3.js';
|
|
12
|
+
export { BLUES_MASK, CHROMATIC_MASK, DORIAN_MASK, HARMONIC_MINOR_MASK, LOCRIAN_MASK, LYDIAN_MASK, MAJOR_MASK, MAJOR_PENTATONIC_MASK, MELODIC_MINOR_MASK, MINOR_PENTATONIC_MASK, MIXOLYDIAN_MASK, NAMED_SCALES, NATURAL_MINOR_MASK, OCTATONIC_HALF_WHOLE_MASK, OCTATONIC_WHOLE_HALF_MASK, PHRYGIAN_MASK, WHOLE_TONE_MASK, createsHiddenParallelPerfect, createsParallelOctave, createsParallelPerfect, createsParallelUnison, createsVerticalDissonance, createsVoiceCrossing, createsVoiceOverlap, diatonicPitchClasses, exceedsSpacing, formatChordSymbol, isForbiddenMelodicLeap, isLeadingToneResolution, isScaleTone, majorKey, maskFromOffsets, minorKey, nearestScaleTone, nextVoicing, noteNames, parseChordSymbol, pitchToScaleDegree, scaleByName, scaleTonesInDegreeOrder, spellChord, spellPitchClass, spellPitchClasses, spellScale, transposeChordSymbol, voiceLeadingCost } from './theory/index.js';
|
|
13
|
+
export { H as HarmonyRole, L as LockLevel, V as VoicedRole, r as roleOf } from './index-CP3wAfEH.js';
|
|
14
|
+
export { N as NoteSafety, R as ReasonFlag, S as SafetyProfile, a as SafetyQuery, b as SafetyResult, V as VoiceSnapshot, e as enumerateSafePitches, c as evaluateSafety } from './index-BreoJRw0.js';
|