@libraz/libcantus-wasm 0.0.0-stage → 1.4.0

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.
@@ -0,0 +1,293 @@
1
+ /// <reference lib="esnext.disposable" />
2
+ export { D as DurationData, I as IndexedNoteEvent, J as JUST_RATIOS, N as NOTE_VALUES, a as NoteEventIndex, b as NoteEventIndexOptions, c as NotePlacement, d as NoteValue, O as OnsetTieBreak, P as PlayabilityIssue, e as PlayabilityIssueType, f as PlayabilityLayer, g as PlayabilityReport, S as SpelledDuration, T as TWELVE_TET, h as TempoEvent, i as TempoMap, j as TuningTable, k as Tuplet, l as beatsToDuration, m as beatsToSeconds, n as beatsToTicks, o as beatsToTiedDurations, p as centsBetweenFreq, q as centsFromNearestStep, r as centsOfSteps, s as centsToRatio, t as createNoteEventIndex, u as durationToBeats, v as durationToSeconds, w as edo, x as frequencyOf, y as justDeviationCents, z as nearestStep, A as playability, B as ratioToCents, C as secondsToBeats, E as stepOf, F as stepsOfCents, G as tempoAt, H as ticksToBeats } from '../index-Dg-SAfhz.js';
3
+ import { h as NoteEvent } from '../index-C9MYbuKS.js';
4
+ export { A as ARTICULATIONS, a as Articulation, B as BudgetExceededError, I as IntervalData, b as IntervalLike, c as IntervalQualityLabel, d as InvalidInputError, K as KeyName, e as KeyScale, L as LibcantusError, f as LibcantusErrorCode, N as NoSolutionError, g as NoteData, i as NoteLike, j as NoteNameOptions, k as NoteNameSystem, P as ParseResult, S as SpelledInterval, l as detectNoteNameSystem, m as diatonicLetterOf, n as formatKeyName, o as formatNote, p as intervalSemitones, q as isLibcantusError, r as midiToNote, s as naturalPitchClassOf, t as noteToMidi, u as noteToPitchClass, v as parseInterval, w as parseKeyName, x as parseNote, y as pitchClassOf, z as spelledInterval, C as toNoteData, D as toSpelledInterval, E as transposeByInterval, F as transposeNote, G as tryParseInterval, H as tryParseKeyName, J as tryParseNote } from '../index-C9MYbuKS.js';
5
+ import { f as StringedProfile } from '../positional-DLnfUgqG.js';
6
+ export { I as InstrumentProfile, a as InstrumentProfileCommon, b as InstrumentProfileLike, L as LIMBS, c as Limb, P as PercussionProfile, d as PositionalRng, S as SeedPath, e as StringFingering, V as ValidatedPercussionProfile, g as ValidatedProfile, h as ValidatedStringedProfile, i as canSound, j as createPositionalRng, k as deriveSeed, l as fingeringsFor, m as foldIntoRange, n as includeAt, o as instrumentRange, t as toInstrumentProfile, p as toStringedProfile } from '../positional-DLnfUgqG.js';
7
+ export { C as ConsonanceClass, c as classifyInterval, i as isConsonantInterval, a as isPerfectInterval } from '../index-DInQqT8Q.js';
8
+ import { c as MeterMap, T as TimeSignature } from '../index-Bf0Sv8a9.js';
9
+ export { B as BarPosition, M as MeterChange, a as MeterData, b as MeterLike, d as barIndexAt, e as barPositionToBeat, f as barPositionToPulse, g as barStartBeat, h as beatToBarPosition, i as beatsPerBar, j as beatsPerBarAt, k as formatBarPosition, l as formatTimeSignature, m as isCompound, n as isStrongBeat, o as meterAt, p as metricWeight, q as parseTimeSignature, r as pulseBeats, s as pulsesPerBar, t as resolveMeters, u as toMeterData, v as tryParseTimeSignature, w as tuplet } from '../index-Bf0Sv8a9.js';
10
+
11
+ /**
12
+ * Electric bass in standard tuning: E1 A1 D2 G2 over a 24-fret neck.
13
+ *
14
+ * @category Core
15
+ */
16
+ declare const BASS_4_STRING: StringedProfile;
17
+ /**
18
+ * Five-string bass with the low B: B0 E1 A1 D2 G2.
19
+ *
20
+ * @category Core
21
+ */
22
+ declare const BASS_5_STRING: StringedProfile;
23
+ /**
24
+ * Six-string guitar in standard tuning: E2 A2 D3 G3 B3 E4.
25
+ *
26
+ * @category Core
27
+ */
28
+ declare const GUITAR_STANDARD: StringedProfile;
29
+ /**
30
+ * Six-string guitar in drop D: the lowest string down a tone to D2, the rest
31
+ * standard. Only the tuning differs, which is the whole point of deriving the
32
+ * range from it.
33
+ *
34
+ * @category Core
35
+ */
36
+ declare const GUITAR_DROP_D: StringedProfile;
37
+
38
+ /**
39
+ * Default upper bound for synchronous event/window/candidate generation.
40
+ *
41
+ * @category Core
42
+ */
43
+ declare const DEFAULT_GENERATION_BUDGET = 1000000;
44
+ /**
45
+ * Require a finite JavaScript number and return it unchanged.
46
+ *
47
+ * @category Core
48
+ */
49
+ declare function assertFiniteNumber(value: number, name: string): number;
50
+ /**
51
+ * Require an integer in the inclusive range `[min, max]`.
52
+ *
53
+ * @category Core
54
+ */
55
+ declare function assertInteger(value: number, name: string, min?: number, max?: number): number;
56
+ /** Require an integer MIDI pitch in the inclusive range 0..127. */
57
+ declare function assertMidiPitch(value: number, name?: string): number;
58
+ /** Clamp an integer MIDI pitch to the inclusive range 0..127. */
59
+ declare function clampToMidi(value: number, name?: string): number;
60
+ /**
61
+ * Require a bounded scale/chord degree, counted from 1 the way musicians count
62
+ * degrees: 1 is the tonic, 5 the dominant. Zero and negative degrees name no
63
+ * degree at all and are rejected.
64
+ */
65
+ declare function assertDegree(value: number, name?: string): number;
66
+ /** Require a finite semitone offset before pitch-class reduction. */
67
+ declare function assertFiniteSemitones(value: number, name?: string): number;
68
+ /**
69
+ * Drop the notes that never sound.
70
+ *
71
+ * A MIDI or DAW import routinely carries zero-length artefacts. Every entry
72
+ * point in this library ignores them, but a caller holding such an array still
73
+ * has to decide what to do with it before comparing note counts or indices;
74
+ * this is the one filter to apply.
75
+ *
76
+ * @param events The note events to filter.
77
+ * @returns A new array containing only the notes with a positive duration.
78
+ * @example
79
+ * ```ts
80
+ * import { dropSilentNotes } from '@libraz/libcantus';
81
+ * dropSilentNotes([{ pitch: 60, startBeat: 0, durationBeat: 0 }]); // []
82
+ * ```
83
+ * @category Core
84
+ */
85
+ declare function dropSilentNotes(events: readonly NoteEvent[]): NoteEvent[];
86
+ /** Alias that makes the shared positive-duration policy explicit at API entrances. */
87
+ declare const soundingNotesOnly: typeof dropSilentNotes;
88
+ /**
89
+ * Require a value to be one of a fixed set of names.
90
+ *
91
+ * TypeScript checks string-union options at compile time only, so a value that
92
+ * arrives from JSON, a config file, or a JavaScript caller reaches the engine
93
+ * unchecked and is then read against a table that has no entry for it —
94
+ * producing a silent `undefined`, a NaN velocity, or a crash far from the call.
95
+ *
96
+ * @param value The value to check.
97
+ * @param allowed Every accepted name.
98
+ * @param name What the value is, for the error message.
99
+ * @returns The value, narrowed to the allowed union.
100
+ * @throws If the value is not one of `allowed`. The message names the value by
101
+ * its type unless it is a string, and echoes at most the head of that string,
102
+ * so building it cannot itself fail on a circular object and cannot grow with
103
+ * the size of what was pasted into the field.
104
+ *
105
+ * @category Core
106
+ */
107
+ declare function assertOneOf<const T extends string>(value: unknown, allowed: readonly T[], name: string): T;
108
+ /**
109
+ * Require a positive safe integer, optionally capped by `max`.
110
+ *
111
+ * @category Core
112
+ */
113
+ declare function assertPositiveInt(value: number, name: string, max?: number): number;
114
+ /**
115
+ * Require a finite number in the inclusive range `[min, max]`.
116
+ *
117
+ * @category Core
118
+ */
119
+ declare function assertRange(value: number, min: number, max: number, name: string): number;
120
+ /**
121
+ * Reject work estimates that would exceed a synchronous generation budget.
122
+ *
123
+ * @category Core
124
+ */
125
+ declare function assertGenerationBudget(estimated: number, name: string, limit?: number | undefined): number;
126
+ /**
127
+ * Validate a time signature, including additive grouping, before any early return.
128
+ *
129
+ * @category Core
130
+ */
131
+ declare function assertTimeSignature(ts: TimeSignature, name?: string): TimeSignature;
132
+ /**
133
+ * Validate a meter map: a non-empty run of time signatures, each with the beat
134
+ * it takes effect at, in strictly increasing beat order.
135
+ *
136
+ * The first entry also governs everything before it, so a map need not start at
137
+ * beat 0 — that is what lets a pickup at a negative beat be read in the
138
+ * signature the piece opens in. Where the first entry is written does not move
139
+ * the bar lines: the opening signature counts its bars from beat 0 either way,
140
+ * so beat 0 is the downbeat of bar 0 and the pickup before it is bar -1.
141
+ *
142
+ * The map is also bounded, the way an event array is: a map is consulted once
143
+ * per analysed slot, so its length is a per-slot cost and not only a one-time
144
+ * one.
145
+ *
146
+ * @category Core
147
+ */
148
+ declare function assertMeterMap(meters: MeterMap, name?: string): MeterMap;
149
+ /**
150
+ * How strictly {@link assertNoteEvent} and {@link assertNoteEvents} read an
151
+ * event array.
152
+ *
153
+ * @category Core
154
+ */
155
+ type NoteEventAssertOptions = {
156
+ /**
157
+ * Accept notes that never sound. The analysis side does, so an array from a
158
+ * MIDI import can be validated before the zero-length artefacts are dropped.
159
+ */
160
+ allowNonPositiveDuration?: boolean;
161
+ /** Upper bound on the event count; defaults to the generation budget. */
162
+ budget?: number;
163
+ /**
164
+ * Earliest accepted onset. Onsets are unbounded below by default, because a
165
+ * pickup sounds before the downbeat and the downbeat is beat 0; pass
166
+ * `-pickupBeats` to reject a note starting earlier than the pickup a caller
167
+ * has declared.
168
+ *
169
+ * @defaultValue `-Number.MAX_SAFE_INTEGER`
170
+ */
171
+ minStartBeat?: number;
172
+ };
173
+ /**
174
+ * Validate the finite fields of one timeline note event.
175
+ *
176
+ * @category Core
177
+ */
178
+ declare function assertNoteEvent(event: NoteEvent, name?: string, options?: NoteEventAssertOptions): NoteEvent;
179
+ /**
180
+ * Validate an event array and its allocation budget without copying it.
181
+ *
182
+ * @category Core
183
+ */
184
+ declare function assertNoteEvents(events: readonly NoteEvent[], name?: string, options?: NoteEventAssertOptions): NoteEvent[];
185
+
186
+ /**
187
+ * How generated output is pinned across builds.
188
+ *
189
+ * A saved project is a seed plus parameters, and it reopens as the same piece
190
+ * only while the library turns them into the same notes. The algorithm version
191
+ * is the number that says which reading of those parameters a project was
192
+ * written against. It is drawn into every seed, so two versions never draw the
193
+ * same stream, and a caller records it beside the seed.
194
+ */
195
+ /**
196
+ * The generator algorithm version this build produces by default.
197
+ *
198
+ * What it carries: for a fixed algorithm version, the same inputs — seed,
199
+ * version and every documented parameter — produce the same generated output
200
+ * from a given build. It covers what the generators return, and nothing else:
201
+ * analysis results, error messages and output taken under a different version
202
+ * are outside it.
203
+ *
204
+ * What it does not carry is a reading frozen against correction. The
205
+ * generators hold one implementation rather than one per version, so pinning
206
+ * an older number selects a different draw of the current implementation and
207
+ * does not restore what that number produced before: a fix to output that was
208
+ * musically wrong moves the notes of a version already in use, ships as a
209
+ * patch, and is stated in the changelog. Reproducing a piece exactly therefore
210
+ * means recording the package version alongside the seed and this number.
211
+ *
212
+ * Raising this constant marks a deliberate change of approach rather than a
213
+ * correction. A project pinned to a version this build does not know is
214
+ * rejected rather than reinterpreted.
215
+ *
216
+ * @category Utilities
217
+ */
218
+ declare const ALGORITHM_VERSION = 1;
219
+ /**
220
+ * The oldest algorithm version this build still accepts.
221
+ *
222
+ * @category Utilities
223
+ */
224
+ declare const MIN_ALGORITHM_VERSION = 1;
225
+ /**
226
+ * Resolve the algorithm version a request runs under.
227
+ *
228
+ * An unpinned request runs at {@link ALGORITHM_VERSION}, which is what a
229
+ * caller who wants the current behaviour means; a caller who wants the piece
230
+ * back records the resolved number and passes it next time. A version this
231
+ * build does not produce is rejected — a project saved by a newer build cannot
232
+ * be reproduced by an older one, and quietly rendering it at another version
233
+ * would return a different piece under the same name.
234
+ *
235
+ * @param requested The pinned version, or undefined for the current one.
236
+ * @returns The version to generate under.
237
+ * @throws If the version is not an integer this build produces.
238
+ * @example
239
+ * ```ts
240
+ * import { ALGORITHM_VERSION, resolveAlgorithmVersion } from '@libraz/libcantus';
241
+ * resolveAlgorithmVersion(undefined); // ALGORITHM_VERSION
242
+ * resolveAlgorithmVersion(ALGORITHM_VERSION); // the pinned value, unchanged
243
+ * ```
244
+ * @category Utilities
245
+ */
246
+ declare function resolveAlgorithmVersion(requested?: number): number;
247
+
248
+ /**
249
+ * Deterministic seeded pseudo-random number generation shared across the
250
+ * generative modules (rhythm, drums, bass, groove, counter-melody). A single
251
+ * mulberry32 core exposes the small set of samplers those modules need; given a
252
+ * seed the stream is fully reproducible.
253
+ *
254
+ * Around that core sit the pieces that make a whole project reproducible: seeds
255
+ * derived hierarchically from one project number, draws addressed by position
256
+ * rather than by call order, and the algorithm version the output is pinned to.
257
+ */
258
+
259
+ /**
260
+ * A deterministic PRNG with the sampling helpers the generators need.
261
+ *
262
+ * @category Utilities
263
+ */
264
+ type Rng = {
265
+ /** Release the handle now; later calls on it fail with `RELEASED_HANDLE`. */
266
+ [Symbol.dispose](): void;
267
+ /** Next float in [0, 1). */
268
+ next: () => number;
269
+ /** True with probability `p`. */
270
+ prob: (p: number) => boolean;
271
+ /** Integer in the inclusive range [lo, hi]. */
272
+ range: (lo: number, hi: number) => number;
273
+ /** Float in [lo, hi). */
274
+ float: (lo: number, hi: number) => number;
275
+ };
276
+ /**
277
+ * Create a seeded PRNG (mulberry32) exposing the shared samplers.
278
+ *
279
+ * @param seed The 32-bit seed; the same seed always yields the same stream.
280
+ * @returns The seeded generator.
281
+ * @example
282
+ * ```ts
283
+ * import { createRng } from '@libraz/libcantus';
284
+ * const rng = createRng(42);
285
+ * rng.next(); // deterministic float in [0, 1)
286
+ * rng.range(1, 6); // deterministic integer in [1, 6]
287
+ * ```
288
+ * @category Utilities
289
+ */
290
+ declare function createRng(seed: number): Rng;
291
+
292
+ export { ALGORITHM_VERSION, BASS_4_STRING, BASS_5_STRING, DEFAULT_GENERATION_BUDGET, GUITAR_DROP_D, GUITAR_STANDARD, MIN_ALGORITHM_VERSION, MeterMap, NoteEvent, StringedProfile, TimeSignature, assertDegree, assertFiniteNumber, assertFiniteSemitones, assertGenerationBudget, assertInteger, assertMeterMap, assertMidiPitch, assertNoteEvent, assertNoteEvents, assertOneOf, assertPositiveInt, assertRange, assertTimeSignature, clampToMidi, createRng, dropSilentNotes, resolveAlgorithmVersion, soundingNotesOnly };
293
+ export type { NoteEventAssertOptions, Rng };
@@ -0,0 +1,224 @@
1
+ import {
2
+ ALGORITHM_VERSION,
3
+ ARTICULATIONS,
4
+ BASS_4_STRING,
5
+ BASS_5_STRING,
6
+ BudgetExceededError,
7
+ ConsonanceClass,
8
+ DEFAULT_GENERATION_BUDGET,
9
+ GUITAR_DROP_D,
10
+ GUITAR_STANDARD,
11
+ InvalidInputError,
12
+ JUST_RATIOS,
13
+ LIMBS,
14
+ MIN_ALGORITHM_VERSION,
15
+ NOTE_VALUES,
16
+ NoSolutionError,
17
+ TWELVE_TET,
18
+ assertDegree,
19
+ assertFiniteNumber,
20
+ assertFiniteSemitones,
21
+ assertGenerationBudget,
22
+ assertInteger,
23
+ assertMeterMap,
24
+ assertMidiPitch,
25
+ assertNoteEvent,
26
+ assertNoteEvents,
27
+ assertOneOf,
28
+ assertPositiveInt,
29
+ assertRange,
30
+ assertTimeSignature,
31
+ barIndexAt,
32
+ barPositionToBeat,
33
+ barPositionToPulse,
34
+ barStartBeat,
35
+ beatToBarPosition,
36
+ beatsPerBar,
37
+ beatsPerBarAt,
38
+ beatsToDuration,
39
+ beatsToSeconds,
40
+ beatsToTicks,
41
+ beatsToTiedDurations,
42
+ canSound,
43
+ centsBetweenFreq,
44
+ centsFromNearestStep,
45
+ centsOfSteps,
46
+ centsToRatio,
47
+ clampToMidi,
48
+ classifyInterval,
49
+ createNoteEventIndex,
50
+ createPositionalRng,
51
+ createRng,
52
+ deriveSeed,
53
+ detectNoteNameSystem,
54
+ diatonicLetterOf,
55
+ dropSilentNotes,
56
+ durationToBeats,
57
+ durationToSeconds,
58
+ edo,
59
+ fingeringsFor,
60
+ foldIntoRange,
61
+ formatBarPosition,
62
+ formatKeyName,
63
+ formatNote,
64
+ formatTimeSignature,
65
+ frequencyOf,
66
+ includeAt,
67
+ instrumentRange,
68
+ intervalSemitones,
69
+ isCompound,
70
+ isConsonantInterval,
71
+ isLibcantusError,
72
+ isPerfectInterval,
73
+ isStrongBeat,
74
+ justDeviationCents,
75
+ meterAt,
76
+ metricWeight,
77
+ midiToNote,
78
+ naturalPitchClassOf,
79
+ nearestStep,
80
+ noteToMidi,
81
+ noteToPitchClass,
82
+ parseInterval,
83
+ parseKeyName,
84
+ parseNote,
85
+ parseTimeSignature,
86
+ pitchClassOf,
87
+ playability,
88
+ pulseBeats,
89
+ pulsesPerBar,
90
+ ratioToCents,
91
+ resolveAlgorithmVersion,
92
+ resolveMeters,
93
+ secondsToBeats,
94
+ soundingNotesOnly,
95
+ spelledInterval,
96
+ stepOf,
97
+ stepsOfCents,
98
+ tempoAt,
99
+ ticksToBeats,
100
+ toInstrumentProfile,
101
+ toMeterData,
102
+ toNoteData,
103
+ toSpelledInterval,
104
+ toStringedProfile,
105
+ transposeByInterval,
106
+ transposeNote,
107
+ tryParseInterval,
108
+ tryParseKeyName,
109
+ tryParseNote,
110
+ tryParseTimeSignature,
111
+ tuplet
112
+ } from "../chunk-4LABHUBW.js";
113
+ export {
114
+ ALGORITHM_VERSION,
115
+ ARTICULATIONS,
116
+ BASS_4_STRING,
117
+ BASS_5_STRING,
118
+ BudgetExceededError,
119
+ ConsonanceClass,
120
+ DEFAULT_GENERATION_BUDGET,
121
+ GUITAR_DROP_D,
122
+ GUITAR_STANDARD,
123
+ InvalidInputError,
124
+ JUST_RATIOS,
125
+ LIMBS,
126
+ MIN_ALGORITHM_VERSION,
127
+ NOTE_VALUES,
128
+ NoSolutionError,
129
+ TWELVE_TET,
130
+ assertDegree,
131
+ assertFiniteNumber,
132
+ assertFiniteSemitones,
133
+ assertGenerationBudget,
134
+ assertInteger,
135
+ assertMeterMap,
136
+ assertMidiPitch,
137
+ assertNoteEvent,
138
+ assertNoteEvents,
139
+ assertOneOf,
140
+ assertPositiveInt,
141
+ assertRange,
142
+ assertTimeSignature,
143
+ barIndexAt,
144
+ barPositionToBeat,
145
+ barPositionToPulse,
146
+ barStartBeat,
147
+ beatToBarPosition,
148
+ beatsPerBar,
149
+ beatsPerBarAt,
150
+ beatsToDuration,
151
+ beatsToSeconds,
152
+ beatsToTicks,
153
+ beatsToTiedDurations,
154
+ canSound,
155
+ centsBetweenFreq,
156
+ centsFromNearestStep,
157
+ centsOfSteps,
158
+ centsToRatio,
159
+ clampToMidi,
160
+ classifyInterval,
161
+ createNoteEventIndex,
162
+ createPositionalRng,
163
+ createRng,
164
+ deriveSeed,
165
+ detectNoteNameSystem,
166
+ diatonicLetterOf,
167
+ dropSilentNotes,
168
+ durationToBeats,
169
+ durationToSeconds,
170
+ edo,
171
+ fingeringsFor,
172
+ foldIntoRange,
173
+ formatBarPosition,
174
+ formatKeyName,
175
+ formatNote,
176
+ formatTimeSignature,
177
+ frequencyOf,
178
+ includeAt,
179
+ instrumentRange,
180
+ intervalSemitones,
181
+ isCompound,
182
+ isConsonantInterval,
183
+ isLibcantusError,
184
+ isPerfectInterval,
185
+ isStrongBeat,
186
+ justDeviationCents,
187
+ meterAt,
188
+ metricWeight,
189
+ midiToNote,
190
+ naturalPitchClassOf,
191
+ nearestStep,
192
+ noteToMidi,
193
+ noteToPitchClass,
194
+ parseInterval,
195
+ parseKeyName,
196
+ parseNote,
197
+ parseTimeSignature,
198
+ pitchClassOf,
199
+ playability,
200
+ pulseBeats,
201
+ pulsesPerBar,
202
+ ratioToCents,
203
+ resolveAlgorithmVersion,
204
+ resolveMeters,
205
+ secondsToBeats,
206
+ soundingNotesOnly,
207
+ spelledInterval,
208
+ stepOf,
209
+ stepsOfCents,
210
+ tempoAt,
211
+ ticksToBeats,
212
+ toInstrumentProfile,
213
+ toMeterData,
214
+ toNoteData,
215
+ toSpelledInterval,
216
+ toStringedProfile,
217
+ transposeByInterval,
218
+ transposeNote,
219
+ tryParseInterval,
220
+ tryParseKeyName,
221
+ tryParseNote,
222
+ tryParseTimeSignature,
223
+ tuplet
224
+ };