@webmusic/kernel 0.1.0 → 0.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.
- package/LICENSE +202 -21
- package/NOTICE +2 -0
- package/README.md +138 -101
- package/dist/audio-context.cjs.map +1 -1
- package/dist/build-receipt.json +3 -3
- package/dist/chunk-27LH6QLZ.cjs +277 -0
- package/dist/chunk-27LH6QLZ.cjs.map +1 -0
- package/dist/chunk-3INDOVUC.cjs.map +1 -1
- package/dist/chunk-3RR2VIKA.js +393 -0
- package/dist/chunk-3RR2VIKA.js.map +1 -0
- package/dist/chunk-3YTKIKKX.cjs +378 -0
- package/dist/chunk-3YTKIKKX.cjs.map +1 -0
- package/dist/chunk-4RG4WQKC.js +360 -0
- package/dist/chunk-4RG4WQKC.js.map +1 -0
- package/dist/chunk-5AHVQXTF.cjs +620 -0
- package/dist/chunk-5AHVQXTF.cjs.map +1 -0
- package/dist/chunk-624KWJWZ.js +170 -0
- package/dist/chunk-624KWJWZ.js.map +1 -0
- package/dist/chunk-6HGFEKD3.cjs +851 -0
- package/dist/chunk-6HGFEKD3.cjs.map +1 -0
- package/dist/chunk-7ZTZZ5PN.cjs.map +1 -1
- package/dist/chunk-ALWV4P7D.js +726 -0
- package/dist/chunk-ALWV4P7D.js.map +1 -0
- package/dist/chunk-BADJJ6DV.cjs +143 -0
- package/dist/chunk-BADJJ6DV.cjs.map +1 -0
- package/dist/chunk-C3LMS36L.cjs +393 -0
- package/dist/chunk-C3LMS36L.cjs.map +1 -0
- package/dist/chunk-C3YWUZW3.cjs.map +1 -1
- package/dist/chunk-CR6OUWBJ.cjs +726 -0
- package/dist/chunk-CR6OUWBJ.cjs.map +1 -0
- package/dist/chunk-CYWDZLWC.js +2141 -0
- package/dist/chunk-CYWDZLWC.js.map +1 -0
- package/dist/chunk-DDOGX2D5.js +378 -0
- package/dist/chunk-DDOGX2D5.js.map +1 -0
- package/dist/chunk-DVN6E5U3.js +620 -0
- package/dist/chunk-DVN6E5U3.js.map +1 -0
- package/dist/chunk-EURMRU2S.js +208 -0
- package/dist/chunk-EURMRU2S.js.map +1 -0
- package/dist/chunk-EXDCK2VL.cjs +20 -0
- package/dist/chunk-EXDCK2VL.cjs.map +1 -0
- package/dist/chunk-G5EIUP52.js +114 -0
- package/dist/chunk-G5EIUP52.js.map +1 -0
- package/dist/chunk-GB4DGKLZ.js +143 -0
- package/dist/chunk-GB4DGKLZ.js.map +1 -0
- package/dist/chunk-GPOEAYOW.js +2147 -0
- package/dist/chunk-GPOEAYOW.js.map +1 -0
- package/dist/chunk-I4YMA5VM.cjs +120 -0
- package/dist/chunk-I4YMA5VM.cjs.map +1 -0
- package/dist/chunk-IVWHMDCB.cjs +4383 -0
- package/dist/chunk-IVWHMDCB.cjs.map +1 -0
- package/dist/chunk-JFCBJMA7.cjs +2147 -0
- package/dist/chunk-JFCBJMA7.cjs.map +1 -0
- package/dist/chunk-JLVSAZ3K.cjs +813 -0
- package/dist/chunk-JLVSAZ3K.cjs.map +1 -0
- package/dist/chunk-K7FYH6UG.cjs +208 -0
- package/dist/chunk-K7FYH6UG.cjs.map +1 -0
- package/dist/chunk-L4MYCETM.cjs +970 -0
- package/dist/chunk-L4MYCETM.cjs.map +1 -0
- package/dist/chunk-MNCMYNYL.js +970 -0
- package/dist/chunk-MNCMYNYL.js.map +1 -0
- package/dist/chunk-NT2BZ3QM.js +120 -0
- package/dist/chunk-NT2BZ3QM.js.map +1 -0
- package/dist/chunk-O7SA5GLC.js +277 -0
- package/dist/chunk-O7SA5GLC.js.map +1 -0
- package/dist/chunk-OCKAHITL.cjs +548 -0
- package/dist/chunk-OCKAHITL.cjs.map +1 -0
- package/dist/{chunk-HOKRTYPV.js → chunk-OPBHDUZK.js} +39 -1
- package/dist/chunk-OPBHDUZK.js.map +1 -0
- package/dist/chunk-OTXYWCLA.js +206 -0
- package/dist/chunk-OTXYWCLA.js.map +1 -0
- package/dist/chunk-P6ZA63J7.js +548 -0
- package/dist/chunk-P6ZA63J7.js.map +1 -0
- package/dist/chunk-QLF3BOST.js +20 -0
- package/dist/chunk-QLF3BOST.js.map +1 -0
- package/dist/chunk-RCWFRZDR.js +4383 -0
- package/dist/chunk-RCWFRZDR.js.map +1 -0
- package/dist/chunk-RZBLPM3L.cjs +206 -0
- package/dist/chunk-RZBLPM3L.cjs.map +1 -0
- package/dist/chunk-TA3TNJZU.cjs +360 -0
- package/dist/chunk-TA3TNJZU.cjs.map +1 -0
- package/dist/chunk-TZSRPTQL.cjs +2141 -0
- package/dist/chunk-TZSRPTQL.cjs.map +1 -0
- package/dist/chunk-UMTPJ76S.cjs.map +1 -1
- package/dist/chunk-UY77FXDW.js +813 -0
- package/dist/chunk-UY77FXDW.js.map +1 -0
- package/dist/chunk-VFU3S7OC.js +851 -0
- package/dist/chunk-VFU3S7OC.js.map +1 -0
- package/dist/chunk-VY6WWZSW.cjs.map +1 -1
- package/dist/chunk-WN5DZOVT.cjs +170 -0
- package/dist/chunk-WN5DZOVT.cjs.map +1 -0
- package/dist/{chunk-HZQX4J2J.cjs → chunk-WOPW6WLR.cjs} +40 -2
- package/dist/chunk-WOPW6WLR.cjs.map +1 -0
- package/dist/chunk-XBSIYUHM.cjs +114 -0
- package/dist/chunk-XBSIYUHM.cjs.map +1 -0
- package/dist/chunk-ZMU72HJS.cjs.map +1 -1
- package/dist/context-DSa0ymyN.d.cts +664 -0
- package/dist/context-DaxfAg3b.d.ts +664 -0
- package/dist/effect-chain-Cu03O5Y0.d.ts +91 -0
- package/dist/effect-chain-Do75T7uK.d.cts +91 -0
- package/dist/effect.cjs +16 -1
- package/dist/effect.cjs.map +1 -1
- package/dist/effect.d.cts +56 -14
- package/dist/effect.d.ts +56 -14
- package/dist/effect.js +16 -1
- package/dist/elements.cjs +37 -2
- package/dist/elements.cjs.map +1 -1
- package/dist/elements.d.cts +197 -8
- package/dist/elements.d.ts +197 -8
- package/dist/elements.js +36 -1
- package/dist/events.cjs.map +1 -1
- package/dist/index.cjs +556 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +17 -5
- package/dist/index.d.ts +17 -5
- package/dist/index.js +567 -20
- package/dist/message.cjs +104 -0
- package/dist/message.cjs.map +1 -0
- package/dist/message.d.cts +738 -0
- package/dist/message.d.ts +738 -0
- package/dist/message.js +104 -0
- package/dist/meter.cjs +2 -2
- package/dist/meter.cjs.map +1 -1
- package/dist/meter.d.cts +9 -1
- package/dist/meter.d.ts +9 -1
- package/dist/meter.js +1 -1
- package/dist/module-control-C25BMtH7.d.ts +61 -0
- package/dist/module-control-yH6nTJM9.d.cts +61 -0
- package/dist/module-plugin-BnPmq1VP.d.ts +198 -0
- package/dist/module-plugin-CHb-5W0Y.d.cts +198 -0
- package/dist/module.cjs +263 -0
- package/dist/module.cjs.map +1 -0
- package/dist/module.d.cts +1112 -0
- package/dist/module.d.ts +1112 -0
- package/dist/module.js +263 -0
- package/dist/parameter-DwQzFmBR.d.cts +172 -0
- package/dist/parameter-DwQzFmBR.d.ts +172 -0
- package/dist/player.cjs.map +1 -1
- package/dist/processor-worklet.cjs +18 -0
- package/dist/processor-worklet.cjs.map +1 -0
- package/dist/processor-worklet.d.cts +166 -0
- package/dist/processor-worklet.d.ts +166 -0
- package/dist/processor-worklet.js +18 -0
- package/dist/processor-worklet.js.map +1 -0
- package/dist/processor.cjs +51 -0
- package/dist/processor.cjs.map +1 -0
- package/dist/processor.d.cts +397 -0
- package/dist/processor.d.ts +397 -0
- package/dist/processor.js +51 -0
- package/dist/processor.js.map +1 -0
- package/dist/project-types-BU4awMnL.d.ts +323 -0
- package/dist/project-types-DufCV8Ma.d.cts +323 -0
- package/dist/ring-C-i9N90a.d.cts +139 -0
- package/dist/ring-DkcMt2Eg.d.ts +139 -0
- package/dist/sequence.cjs +68 -0
- package/dist/sequence.cjs.map +1 -0
- package/dist/sequence.d.cts +303 -0
- package/dist/sequence.d.ts +303 -0
- package/dist/sequence.js +68 -0
- package/dist/sequence.js.map +1 -0
- package/dist/session.cjs +16 -0
- package/dist/session.cjs.map +1 -0
- package/dist/session.d.cts +407 -0
- package/dist/session.d.ts +407 -0
- package/dist/session.js +16 -0
- package/dist/session.js.map +1 -0
- package/dist/tick.cjs.map +1 -1
- package/dist/transport.cjs +50 -2
- package/dist/transport.cjs.map +1 -1
- package/dist/transport.d.cts +145 -1
- package/dist/transport.d.ts +145 -1
- package/dist/transport.js +51 -3
- package/dist/worker.cjs.map +1 -1
- package/package.json +62 -11
- package/dist/chunk-53YD73OY.js +0 -162
- package/dist/chunk-53YD73OY.js.map +0 -1
- package/dist/chunk-BR63OD53.cjs +0 -1
- package/dist/chunk-BR63OD53.cjs.map +0 -1
- package/dist/chunk-HOKRTYPV.js.map +0 -1
- package/dist/chunk-HZQX4J2J.cjs.map +0 -1
- package/dist/chunk-JNXB74G3.cjs +0 -987
- package/dist/chunk-JNXB74G3.cjs.map +0 -1
- package/dist/chunk-SM5YPDDI.cjs +0 -162
- package/dist/chunk-SM5YPDDI.cjs.map +0 -1
- package/dist/chunk-TEM2I2NN.js +0 -1
- package/dist/chunk-VVZX7DQ6.cjs +0 -254
- package/dist/chunk-VVZX7DQ6.cjs.map +0 -1
- package/dist/chunk-WNFGDB7B.js +0 -254
- package/dist/chunk-WNFGDB7B.js.map +0 -1
- package/dist/chunk-XBJBY4J5.js +0 -987
- package/dist/chunk-XBJBY4J5.js.map +0 -1
- package/dist/sync.cjs +0 -12
- package/dist/sync.cjs.map +0 -1
- package/dist/sync.d.cts +0 -304
- package/dist/sync.d.ts +0 -304
- package/dist/sync.js +0 -12
- /package/dist/{chunk-TEM2I2NN.js.map → message.js.map} +0 -0
- /package/dist/{sync.js.map → module.js.map} +0 -0
package/dist/transport.d.ts
CHANGED
|
@@ -110,5 +110,149 @@ interface TimelineMapping {
|
|
|
110
110
|
positionToSeconds(position: number): number;
|
|
111
111
|
secondsToPosition(seconds: number): number;
|
|
112
112
|
}
|
|
113
|
+
/** Upper bound on a grid tempo; beyond it beat lines are denser than any musical use. */
|
|
114
|
+
declare const MAX_TEMPO_GRID_BPM = 1000;
|
|
115
|
+
/** Upper bound on beats per bar. */
|
|
116
|
+
declare const MAX_TEMPO_GRID_BEATS_PER_BAR = 64;
|
|
117
|
+
/**
|
|
118
|
+
* A constant-tempo beat grid on a transport position axis (typically
|
|
119
|
+
* seconds). `anchor` is the position of one downbeat; every other beat lies a
|
|
120
|
+
* whole number of beat lengths away, extending in both directions without
|
|
121
|
+
* end. Immutable once created through {@link createTempoGrid}.
|
|
122
|
+
*/
|
|
123
|
+
interface TempoGrid {
|
|
124
|
+
/** Beats per minute of the position axis; finite, > 0 and ≤ {@link MAX_TEMPO_GRID_BPM}. */
|
|
125
|
+
readonly bpm: number;
|
|
126
|
+
/** Position of a downbeat (bar start), on the transport axis. */
|
|
127
|
+
readonly anchor: number;
|
|
128
|
+
/** Beats in one bar; an integer from 1 to {@link MAX_TEMPO_GRID_BEATS_PER_BAR}. */
|
|
129
|
+
readonly beatsPerBar: number;
|
|
130
|
+
}
|
|
131
|
+
interface TempoGridInit {
|
|
132
|
+
readonly bpm: number;
|
|
133
|
+
readonly anchor?: number;
|
|
134
|
+
readonly beatsPerBar?: number;
|
|
135
|
+
}
|
|
136
|
+
/** Where a position falls on a {@link TempoGrid}. */
|
|
137
|
+
interface TempoGridPosition {
|
|
138
|
+
/** Continuous beat index from the anchor; negative before it. */
|
|
139
|
+
readonly beat: number;
|
|
140
|
+
/** Bar index from the anchor's bar (0); negative before it. */
|
|
141
|
+
readonly bar: number;
|
|
142
|
+
/** Beat inside the bar, 0 … beatsPerBar − 1. */
|
|
143
|
+
readonly beatInBar: number;
|
|
144
|
+
/** Fraction of the current beat already elapsed, in [0, 1). */
|
|
145
|
+
readonly phase: number;
|
|
146
|
+
}
|
|
147
|
+
/** Validate and freeze a grid. Throws RangeError for an invalid tempo, anchor or meter. */
|
|
148
|
+
declare function createTempoGrid(init: TempoGridInit): TempoGrid;
|
|
149
|
+
/** Length of one beat on the grid's position axis (60 / bpm for a seconds axis). */
|
|
150
|
+
declare function tempoGridBeatLength(grid: TempoGrid): number;
|
|
151
|
+
/** Beat, bar and phase at a position. */
|
|
152
|
+
declare function tempoGridPosition(grid: TempoGrid, position: number): TempoGridPosition;
|
|
153
|
+
/** Position of a (possibly fractional) beat index. */
|
|
154
|
+
declare function tempoGridBeatPosition(grid: TempoGrid, beat: number): number;
|
|
155
|
+
interface TempoGridSnapOptions {
|
|
156
|
+
/** Grid lines per beat: 1 beats, 2 eighths in 4/4, 0.25 one line per 4 beats. Default 1. */
|
|
157
|
+
readonly division?: number;
|
|
158
|
+
/** `nearest` (default), `forward` (at or after) or `backward` (at or before). */
|
|
159
|
+
readonly direction?: 'nearest' | 'forward' | 'backward';
|
|
160
|
+
}
|
|
161
|
+
/** The grid line nearest a position, or the next/previous one. */
|
|
162
|
+
declare function snapToTempoGrid(grid: TempoGrid, position: number, options?: TempoGridSnapOptions): number;
|
|
163
|
+
/**
|
|
164
|
+
* Quantized jump: the position near `to` that keeps the beat phase of
|
|
165
|
+
* `from`, so a running transport lands on the beat as it would have played
|
|
166
|
+
* there (the DJ "quantize" behavior). `to` is rounded to its nearest beat
|
|
167
|
+
* first; the phase of `from` is then added.
|
|
168
|
+
*/
|
|
169
|
+
declare function tempoGridJump(grid: TempoGrid, from: number, to: number): number;
|
|
170
|
+
/** Positions of the grid lines inside [start, end], with their beat index. */
|
|
171
|
+
declare function tempoGridLines(grid: TempoGrid, start: number, end: number, division?: number): readonly {
|
|
172
|
+
readonly position: number;
|
|
173
|
+
readonly beat: number;
|
|
174
|
+
readonly downbeat: boolean;
|
|
175
|
+
}[];
|
|
176
|
+
/** The grid as a {@link TimelineMapping} between beats and its position axis. */
|
|
177
|
+
declare function tempoGridMapping(grid: TempoGrid): TimelineMapping;
|
|
178
|
+
/**
|
|
179
|
+
* Tempo from tap times (any monotonic seconds, such as `performance.now() / 1000`):
|
|
180
|
+
* the median interval of the most recent run of taps, where a gap longer than
|
|
181
|
+
* `resetSeconds` starts a new run. Undefined until a run has two taps.
|
|
182
|
+
*/
|
|
183
|
+
declare function tapTempo(times: readonly number[], resetSeconds?: number): number | undefined;
|
|
184
|
+
/**
|
|
185
|
+
* Beats read from a transport clock: a {@link TransportClockReader} paired
|
|
186
|
+
* with a {@link TempoGrid} on the same position axis. Read-only — it never
|
|
187
|
+
* re-anchors the clock — and immutable; pair the clock with a new grid
|
|
188
|
+
* through {@link withGrid}. All reference times are the clock's.
|
|
189
|
+
*/
|
|
190
|
+
declare class TempoClock {
|
|
191
|
+
readonly clock: TransportClockReader;
|
|
192
|
+
readonly grid: TempoGrid;
|
|
193
|
+
constructor(clock: TransportClockReader, grid: TempoGrid);
|
|
194
|
+
/** Same clock, another grid. */
|
|
195
|
+
withGrid(grid: TempoGrid): TempoClock;
|
|
196
|
+
/** Beat, bar and phase at reference time `t`. */
|
|
197
|
+
positionAt(t: number): TempoGridPosition;
|
|
198
|
+
/** Continuous beat index at reference time `t`. */
|
|
199
|
+
beatAt(t: number): number;
|
|
200
|
+
/** Tempo heard at the current rate: grid bpm × clock rate. */
|
|
201
|
+
get effectiveBpm(): number;
|
|
202
|
+
/**
|
|
203
|
+
* Reference time of the next grid line strictly after `t` (`division`
|
|
204
|
+
* lines per beat) — the instant to schedule a quantized action. Throws
|
|
205
|
+
* RangeError while the clock is paused, like {@link TransportClock.timeAt}.
|
|
206
|
+
*/
|
|
207
|
+
nextGridTime(t: number, division?: number): number;
|
|
208
|
+
/** Reference time at which a beat index plays. Throws RangeError while paused. */
|
|
209
|
+
timeAtBeat(beat: number): number;
|
|
210
|
+
}
|
|
211
|
+
/** Ticks in one quarter note, as in Max. */
|
|
212
|
+
declare const TICKS_PER_QUARTER = 480;
|
|
213
|
+
interface MusicalTempo {
|
|
214
|
+
/** Quarter notes per minute; finite and > 0. */
|
|
215
|
+
readonly bpm: number;
|
|
216
|
+
/** Beats in a bar (time-signature numerator). */
|
|
217
|
+
readonly beatsPerBar: number;
|
|
218
|
+
/** The note value of one beat (time-signature denominator): 2, 4, 8 or 16. */
|
|
219
|
+
readonly beatUnit: number;
|
|
220
|
+
}
|
|
221
|
+
/** A position as bars, beats and ticks, all counted from 1 except ticks (from 0). */
|
|
222
|
+
interface BarsBeatsTicks {
|
|
223
|
+
readonly bar: number;
|
|
224
|
+
readonly beat: number;
|
|
225
|
+
readonly tick: number;
|
|
226
|
+
}
|
|
227
|
+
declare const DEFAULT_MUSICAL_TEMPO: MusicalTempo;
|
|
228
|
+
/** Validate and freeze a tempo. */
|
|
229
|
+
declare function createMusicalTempo(init?: Partial<MusicalTempo>): MusicalTempo;
|
|
230
|
+
/** Seconds per tick at a tempo. */
|
|
231
|
+
declare const tickSeconds: (tempo: MusicalTempo) => number;
|
|
232
|
+
/** Ticks in one beat of the meter. */
|
|
233
|
+
declare const ticksPerBeat: (tempo: MusicalTempo) => number;
|
|
234
|
+
/** Ticks in one bar. */
|
|
235
|
+
declare const ticksPerBar: (tempo: MusicalTempo) => number;
|
|
236
|
+
/**
|
|
237
|
+
* The length in ticks of a time value: a note value (`1n`, `4n`, `8nd`
|
|
238
|
+
* dotted, `16nt` triplet), `bars.beats.ticks` as a length (`1.0.0` is one
|
|
239
|
+
* bar), or `480 ticks`. Undefined for a value that is not musical (`250ms`,
|
|
240
|
+
* `2hz`, a plain number of milliseconds).
|
|
241
|
+
*/
|
|
242
|
+
declare function timeValueTicks(text: string, tempo?: MusicalTempo): number | undefined;
|
|
243
|
+
/**
|
|
244
|
+
* The length in seconds of a time value at `tempo`: any musical value of
|
|
245
|
+
* {@link timeValueTicks}, or `250ms`, `0.5s`, `2hz` (one period) or a plain
|
|
246
|
+
* number of milliseconds.
|
|
247
|
+
*/
|
|
248
|
+
declare function timeValueSeconds(text: string, tempo?: MusicalTempo): number;
|
|
249
|
+
/** Bars, beats and ticks at `seconds` from `anchor` (where bar 1 beat 1 begins). */
|
|
250
|
+
declare function barsBeatsTicksAt(seconds: number, tempo: MusicalTempo, anchor?: number): BarsBeatsTicks;
|
|
251
|
+
/** Seconds at a bars:beats:ticks position. */
|
|
252
|
+
declare function secondsAtBarsBeatsTicks(position: BarsBeatsTicks, tempo: MusicalTempo, anchor?: number): number;
|
|
253
|
+
/** `bar.beat.tick`, as Max shows a transport position. */
|
|
254
|
+
declare function formatBarsBeatsTicks(position: BarsBeatsTicks): string;
|
|
255
|
+
/** The next multiple of `interval` seconds at or after `position`, measured from `anchor`. */
|
|
256
|
+
declare function nextGridTime(position: number, interval: number, anchor?: number): number;
|
|
113
257
|
|
|
114
|
-
export { type TimelineMapping, TransportClock, type TransportClockReader, type TransportClockState };
|
|
258
|
+
export { type BarsBeatsTicks, DEFAULT_MUSICAL_TEMPO, MAX_TEMPO_GRID_BEATS_PER_BAR, MAX_TEMPO_GRID_BPM, type MusicalTempo, TICKS_PER_QUARTER, TempoClock, type TempoGrid, type TempoGridInit, type TempoGridPosition, type TempoGridSnapOptions, type TimelineMapping, TransportClock, type TransportClockReader, type TransportClockState, barsBeatsTicksAt, createMusicalTempo, createTempoGrid, formatBarsBeatsTicks, nextGridTime, secondsAtBarsBeatsTicks, snapToTempoGrid, tapTempo, tempoGridBeatLength, tempoGridBeatPosition, tempoGridJump, tempoGridLines, tempoGridMapping, tempoGridPosition, tickSeconds, ticksPerBar, ticksPerBeat, timeValueSeconds, timeValueTicks };
|
package/dist/transport.js
CHANGED
|
@@ -1,8 +1,56 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
DEFAULT_MUSICAL_TEMPO,
|
|
3
|
+
MAX_TEMPO_GRID_BEATS_PER_BAR,
|
|
4
|
+
MAX_TEMPO_GRID_BPM,
|
|
5
|
+
TICKS_PER_QUARTER,
|
|
6
|
+
TempoClock,
|
|
7
|
+
TransportClock,
|
|
8
|
+
barsBeatsTicksAt,
|
|
9
|
+
createMusicalTempo,
|
|
10
|
+
createTempoGrid,
|
|
11
|
+
formatBarsBeatsTicks,
|
|
12
|
+
nextGridTime,
|
|
13
|
+
secondsAtBarsBeatsTicks,
|
|
14
|
+
snapToTempoGrid,
|
|
15
|
+
tapTempo,
|
|
16
|
+
tempoGridBeatLength,
|
|
17
|
+
tempoGridBeatPosition,
|
|
18
|
+
tempoGridJump,
|
|
19
|
+
tempoGridLines,
|
|
20
|
+
tempoGridMapping,
|
|
21
|
+
tempoGridPosition,
|
|
22
|
+
tickSeconds,
|
|
23
|
+
ticksPerBar,
|
|
24
|
+
ticksPerBeat,
|
|
25
|
+
timeValueSeconds,
|
|
26
|
+
timeValueTicks
|
|
27
|
+
} from "./chunk-4RG4WQKC.js";
|
|
4
28
|
import "./chunk-PXG64RU4.js";
|
|
5
29
|
export {
|
|
6
|
-
|
|
30
|
+
DEFAULT_MUSICAL_TEMPO,
|
|
31
|
+
MAX_TEMPO_GRID_BEATS_PER_BAR,
|
|
32
|
+
MAX_TEMPO_GRID_BPM,
|
|
33
|
+
TICKS_PER_QUARTER,
|
|
34
|
+
TempoClock,
|
|
35
|
+
TransportClock,
|
|
36
|
+
barsBeatsTicksAt,
|
|
37
|
+
createMusicalTempo,
|
|
38
|
+
createTempoGrid,
|
|
39
|
+
formatBarsBeatsTicks,
|
|
40
|
+
nextGridTime,
|
|
41
|
+
secondsAtBarsBeatsTicks,
|
|
42
|
+
snapToTempoGrid,
|
|
43
|
+
tapTempo,
|
|
44
|
+
tempoGridBeatLength,
|
|
45
|
+
tempoGridBeatPosition,
|
|
46
|
+
tempoGridJump,
|
|
47
|
+
tempoGridLines,
|
|
48
|
+
tempoGridMapping,
|
|
49
|
+
tempoGridPosition,
|
|
50
|
+
tickSeconds,
|
|
51
|
+
ticksPerBar,
|
|
52
|
+
ticksPerBeat,
|
|
53
|
+
timeValueSeconds,
|
|
54
|
+
timeValueTicks
|
|
7
55
|
};
|
|
8
56
|
//# sourceMappingURL=transport.js.map
|
package/dist/worker.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users
|
|
1
|
+
{"version":3,"sources":["/private/tmp/claude-501/-Users-mamingchen-GitHub-public-WebMusic/77eac0d8-82c0-45c6-aba8-0cd73cfd2b1b/scratchpad/release-0.4.0/platform/kernel/dist/worker.cjs"],"names":[],"mappings":"AAAA;AACE;AACA;AACF,wDAA6B;AAC7B,gCAA6B;AAC7B;AACE;AACA;AACF,6IAAC","file":"/private/tmp/claude-501/-Users-mamingchen-GitHub-public-WebMusic/77eac0d8-82c0-45c6-aba8-0cd73cfd2b1b/scratchpad/release-0.4.0/platform/kernel/dist/worker.cjs"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webmusic/kernel",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Domain-neutral WebMusic contracts and utilities for events, elements, workers, metering and synchronized playback.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -78,6 +78,16 @@
|
|
|
78
78
|
"default": "./dist/effect.cjs"
|
|
79
79
|
}
|
|
80
80
|
},
|
|
81
|
+
"./module": {
|
|
82
|
+
"import": {
|
|
83
|
+
"types": "./dist/module.d.ts",
|
|
84
|
+
"default": "./dist/module.js"
|
|
85
|
+
},
|
|
86
|
+
"require": {
|
|
87
|
+
"types": "./dist/module.d.cts",
|
|
88
|
+
"default": "./dist/module.cjs"
|
|
89
|
+
}
|
|
90
|
+
},
|
|
81
91
|
"./meter": {
|
|
82
92
|
"import": {
|
|
83
93
|
"types": "./dist/meter.d.ts",
|
|
@@ -108,20 +118,60 @@
|
|
|
108
118
|
"default": "./dist/tick.cjs"
|
|
109
119
|
}
|
|
110
120
|
},
|
|
111
|
-
"./
|
|
121
|
+
"./session": {
|
|
122
|
+
"import": {
|
|
123
|
+
"types": "./dist/session.d.ts",
|
|
124
|
+
"default": "./dist/session.js"
|
|
125
|
+
},
|
|
126
|
+
"require": {
|
|
127
|
+
"types": "./dist/session.d.cts",
|
|
128
|
+
"default": "./dist/session.cjs"
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
"./processor": {
|
|
132
|
+
"import": {
|
|
133
|
+
"types": "./dist/processor.d.ts",
|
|
134
|
+
"default": "./dist/processor.js"
|
|
135
|
+
},
|
|
136
|
+
"require": {
|
|
137
|
+
"types": "./dist/processor.d.cts",
|
|
138
|
+
"default": "./dist/processor.cjs"
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
"./processor-worklet": {
|
|
142
|
+
"import": {
|
|
143
|
+
"types": "./dist/processor-worklet.d.ts",
|
|
144
|
+
"default": "./dist/processor-worklet.js"
|
|
145
|
+
},
|
|
146
|
+
"require": {
|
|
147
|
+
"types": "./dist/processor-worklet.d.cts",
|
|
148
|
+
"default": "./dist/processor-worklet.cjs"
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
"./sequence": {
|
|
152
|
+
"import": {
|
|
153
|
+
"types": "./dist/sequence.d.ts",
|
|
154
|
+
"default": "./dist/sequence.js"
|
|
155
|
+
},
|
|
156
|
+
"require": {
|
|
157
|
+
"types": "./dist/sequence.d.cts",
|
|
158
|
+
"default": "./dist/sequence.cjs"
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
"./message": {
|
|
112
162
|
"import": {
|
|
113
|
-
"types": "./dist/
|
|
114
|
-
"default": "./dist/
|
|
163
|
+
"types": "./dist/message.d.ts",
|
|
164
|
+
"default": "./dist/message.js"
|
|
115
165
|
},
|
|
116
166
|
"require": {
|
|
117
|
-
"types": "./dist/
|
|
118
|
-
"default": "./dist/
|
|
167
|
+
"types": "./dist/message.d.cts",
|
|
168
|
+
"default": "./dist/message.cjs"
|
|
119
169
|
}
|
|
120
170
|
},
|
|
121
171
|
"./package.json": "./package.json"
|
|
122
172
|
},
|
|
123
173
|
"scripts": {
|
|
124
|
-
"build": "tsup src/index.ts src/events.ts src/elements.ts src/worker.ts src/audio-context.ts src/player.ts src/effect.ts src/meter.ts src/transport.ts src/tick.ts src/
|
|
174
|
+
"build": "node ../../scripts/clean-dist.mjs --begin dist && tsup src/index.ts src/events.ts src/elements.ts src/worker.ts src/audio-context.ts src/player.ts src/effect.ts src/module.ts src/meter.ts src/transport.ts src/tick.ts src/session.ts src/processor.ts src/processor-worklet.ts src/sequence.ts src/message.ts --tsconfig tsconfig.build.json --format esm,cjs --splitting --dts --sourcemap && node ../../scripts/clean-dist.mjs --prune dist && node ../../scripts/package-artifacts.mjs --write",
|
|
125
175
|
"test": "vitest run",
|
|
126
176
|
"typecheck": "tsc --noEmit",
|
|
127
177
|
"prepack": "node ../../scripts/package-artifacts.mjs"
|
|
@@ -129,20 +179,21 @@
|
|
|
129
179
|
"devDependencies": {
|
|
130
180
|
"tsup": "^8.5.0",
|
|
131
181
|
"typescript": "^5.4.0",
|
|
132
|
-
"vitest": "^
|
|
182
|
+
"vitest": "^5.1.0"
|
|
133
183
|
},
|
|
134
|
-
"license": "
|
|
184
|
+
"license": "Apache-2.0",
|
|
135
185
|
"publishConfig": {
|
|
136
186
|
"access": "public"
|
|
137
187
|
},
|
|
138
|
-
"author": "
|
|
188
|
+
"author": "Koperative",
|
|
139
189
|
"engines": {
|
|
140
190
|
"node": ">=22"
|
|
141
191
|
},
|
|
142
192
|
"files": [
|
|
143
193
|
"dist",
|
|
144
194
|
"README.md",
|
|
145
|
-
"LICENSE"
|
|
195
|
+
"LICENSE",
|
|
196
|
+
"NOTICE"
|
|
146
197
|
],
|
|
147
198
|
"repository": {
|
|
148
199
|
"type": "git",
|
package/dist/chunk-53YD73OY.js
DELETED
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
__privateAdd,
|
|
3
|
-
__privateGet,
|
|
4
|
-
__privateSet
|
|
5
|
-
} from "./chunk-PXG64RU4.js";
|
|
6
|
-
|
|
7
|
-
// src/transport.ts
|
|
8
|
-
var _originTime, _originPosition, _rate, _paused, _holdUntilOrigin, _now;
|
|
9
|
-
var TransportClock = class {
|
|
10
|
-
/** @param now Optional reference clock enabling the zero-arg `position` getter. */
|
|
11
|
-
constructor(now) {
|
|
12
|
-
__privateAdd(this, _originTime, 0);
|
|
13
|
-
__privateAdd(this, _originPosition, 0);
|
|
14
|
-
__privateAdd(this, _rate, 1);
|
|
15
|
-
__privateAdd(this, _paused, true);
|
|
16
|
-
__privateAdd(this, _holdUntilOrigin, false);
|
|
17
|
-
__privateAdd(this, _now);
|
|
18
|
-
__privateSet(this, _now, now);
|
|
19
|
-
}
|
|
20
|
-
get state() {
|
|
21
|
-
return {
|
|
22
|
-
originTime: __privateGet(this, _originTime),
|
|
23
|
-
originPosition: __privateGet(this, _originPosition),
|
|
24
|
-
rate: __privateGet(this, _rate),
|
|
25
|
-
paused: __privateGet(this, _paused)
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
get rate() {
|
|
29
|
-
return __privateGet(this, _rate);
|
|
30
|
-
}
|
|
31
|
-
get paused() {
|
|
32
|
-
return __privateGet(this, _paused);
|
|
33
|
-
}
|
|
34
|
-
/** Current position via the injected `now()` clock. Throws when none was injected. */
|
|
35
|
-
get position() {
|
|
36
|
-
if (!__privateGet(this, _now)) throw new Error("TransportClock has no injected now() clock; use positionAt(t).");
|
|
37
|
-
return this.positionAt(__privateGet(this, _now).call(this));
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* True when a {@link startAt} start is armed. The flag is cleared by the
|
|
41
|
-
* next {@link start} or {@link pause} — NOT by the origin time passing —
|
|
42
|
-
* so callers combining it with {@link TransportClockState.originTime}
|
|
43
|
-
* should treat "holding and origin still in the future" as the pre-roll
|
|
44
|
-
* condition (positionAt handles this internally either way).
|
|
45
|
-
*/
|
|
46
|
-
get holding() {
|
|
47
|
-
return __privateGet(this, _holdUntilOrigin);
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Position at reference time `t`. While paused this is constant. `t` before
|
|
51
|
-
* the anchor yields positions before it (possibly negative) — callers clamp
|
|
52
|
-
* to their own domain — EXCEPT after {@link startAt}, where the position
|
|
53
|
-
* holds at the armed origin position through the pre-roll (mirroring how a
|
|
54
|
-
* scheduled `source.start(when)` sounds nothing before `when`).
|
|
55
|
-
*/
|
|
56
|
-
positionAt(t) {
|
|
57
|
-
if (__privateGet(this, _paused)) return __privateGet(this, _originPosition);
|
|
58
|
-
if (__privateGet(this, _holdUntilOrigin) && t < __privateGet(this, _originTime)) return __privateGet(this, _originPosition);
|
|
59
|
-
return __privateGet(this, _originPosition) + (t - __privateGet(this, _originTime)) * __privateGet(this, _rate);
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Inverse of {@link positionAt}. Throws RangeError while paused: no
|
|
63
|
-
* reference time maps to a position when the transport is frozen — guard
|
|
64
|
-
* with {@link paused} before calling. While a {@link startAt} start is
|
|
65
|
-
* armed, positions before the armed origin position also throw: the
|
|
66
|
-
* position holds through the pre-roll and never passes below the origin,
|
|
67
|
-
* so no reference time maps to them (extrapolating backwards would return
|
|
68
|
-
* a time whose {@link positionAt} is NOT the requested position).
|
|
69
|
-
*/
|
|
70
|
-
timeAt(position) {
|
|
71
|
-
if (__privateGet(this, _paused)) throw new RangeError("TransportClock is paused; no reference time maps to a position.");
|
|
72
|
-
if (__privateGet(this, _holdUntilOrigin) && position < __privateGet(this, _originPosition)) {
|
|
73
|
-
throw new RangeError(
|
|
74
|
-
"TransportClock is holding a scheduled start; no reference time maps to a position before the armed origin position."
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
return __privateGet(this, _originTime) + (position - __privateGet(this, _originPosition)) / __privateGet(this, _rate);
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Anchor at `(t, position ?? current position)` and unpause. Re-anchoring
|
|
81
|
-
* while already playing is idempotent for the position at `t`.
|
|
82
|
-
*/
|
|
83
|
-
start(t, position) {
|
|
84
|
-
assertFiniteAnchor("start time", t);
|
|
85
|
-
if (position !== void 0) assertFiniteAnchor("start position", position);
|
|
86
|
-
__privateSet(this, _originPosition, position ?? this.positionAt(t));
|
|
87
|
-
__privateSet(this, _originTime, t);
|
|
88
|
-
__privateSet(this, _paused, false);
|
|
89
|
-
__privateSet(this, _holdUntilOrigin, false);
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Arm a SCHEDULED start: anchor at a (typically future) reference time and
|
|
93
|
-
* unpause, with the position holding at `position` until `t` arrives —
|
|
94
|
-
* the clock-side mirror of a sample-accurate `play(when)`. Transitions
|
|
95
|
-
* during the pre-roll keep the armed origin: {@link setRate} changes the
|
|
96
|
-
* slope after `t` without collapsing the hold, {@link seekTo} re-arms the
|
|
97
|
-
* held position, and {@link pause} cancels the pending start.
|
|
98
|
-
*/
|
|
99
|
-
startAt(t, position) {
|
|
100
|
-
assertFiniteAnchor("startAt time", t);
|
|
101
|
-
assertFiniteAnchor("startAt position", position);
|
|
102
|
-
__privateSet(this, _originPosition, position);
|
|
103
|
-
__privateSet(this, _originTime, t);
|
|
104
|
-
__privateSet(this, _paused, false);
|
|
105
|
-
__privateSet(this, _holdUntilOrigin, true);
|
|
106
|
-
}
|
|
107
|
-
/** Fold elapsed time into the anchor; `positionAt()` is constant afterwards. */
|
|
108
|
-
pause(t) {
|
|
109
|
-
assertFiniteAnchor("pause time", t);
|
|
110
|
-
__privateSet(this, _originPosition, this.positionAt(t));
|
|
111
|
-
__privateSet(this, _originTime, t);
|
|
112
|
-
__privateSet(this, _paused, true);
|
|
113
|
-
__privateSet(this, _holdUntilOrigin, false);
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Re-anchor at a new position; preserves the paused/playing state. During
|
|
117
|
-
* an armed pre-roll the scheduled origin time is kept (the pending start
|
|
118
|
-
* stays pending at the new position).
|
|
119
|
-
*/
|
|
120
|
-
seekTo(position, t) {
|
|
121
|
-
assertFiniteAnchor("seek position", position);
|
|
122
|
-
assertFiniteAnchor("seek time", t);
|
|
123
|
-
__privateSet(this, _originPosition, position);
|
|
124
|
-
if (!(__privateGet(this, _holdUntilOrigin) && t < __privateGet(this, _originTime))) {
|
|
125
|
-
__privateSet(this, _originTime, t);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Re-anchor so the position is continuous across the rate change:
|
|
130
|
-
* `originPosition = positionAt(t); originTime = t; rate = r`.
|
|
131
|
-
* Throws RangeError unless `r` is finite and > 0.
|
|
132
|
-
*/
|
|
133
|
-
setRate(r, t) {
|
|
134
|
-
if (!Number.isFinite(r) || r <= 0) {
|
|
135
|
-
throw new RangeError(`TransportClock rate must be finite and > 0, got ${r}.`);
|
|
136
|
-
}
|
|
137
|
-
assertFiniteAnchor("setRate time", t);
|
|
138
|
-
if (__privateGet(this, _holdUntilOrigin) && t < __privateGet(this, _originTime)) {
|
|
139
|
-
__privateSet(this, _rate, r);
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
__privateSet(this, _originPosition, this.positionAt(t));
|
|
143
|
-
__privateSet(this, _originTime, t);
|
|
144
|
-
__privateSet(this, _rate, r);
|
|
145
|
-
}
|
|
146
|
-
};
|
|
147
|
-
_originTime = new WeakMap();
|
|
148
|
-
_originPosition = new WeakMap();
|
|
149
|
-
_rate = new WeakMap();
|
|
150
|
-
_paused = new WeakMap();
|
|
151
|
-
_holdUntilOrigin = new WeakMap();
|
|
152
|
-
_now = new WeakMap();
|
|
153
|
-
function assertFiniteAnchor(name, value) {
|
|
154
|
-
if (!Number.isFinite(value)) {
|
|
155
|
-
throw new RangeError(`TransportClock ${name} must be a finite number, got ${value}.`);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
export {
|
|
160
|
-
TransportClock
|
|
161
|
-
};
|
|
162
|
-
//# sourceMappingURL=chunk-53YD73OY.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/transport.ts"],"sourcesContent":["// ============================================================================\n// Pure transport math shared by both families' playback engines, and the\n// timeline-mapping contract that lets musical time axes (score quarters,\n// audio beats) interoperate through seconds. No Web Audio, no domain types —\n// numbers in, numbers out. For the imperative playback control surface a\n// player exposes, see ./player.\n//\n// Terminology: TransportClock's \"position\" is a TIMELINE position (typically\n// media seconds); TimelineMapping's \"position\" is a MUSICAL position\n// (quarters, beats — the consumer defines the unit). The mapping converts\n// between the two axes.\n// ============================================================================\n\n/** Immutable snapshot of a transport anchor. All numbers, unit-agnostic. */\nexport interface TransportClockState {\n /** Reference-clock timestamp of the anchor. */\n readonly originTime: number;\n /** Timeline position at `originTime`. */\n readonly originPosition: number;\n /** Finite and > 0; position advances `rate`× reference time. */\n readonly rate: number;\n readonly paused: boolean;\n}\n\n/**\n * Affine mapping between an external monotonic reference clock (any number\n * domain — `AudioContext.currentTime`, `performance.now()/1000`, a test\n * counter) and a timeline position. Pure: never reads a real clock unless\n * `now` is injected; every mutator takes the current reference time\n * explicitly.\n *\n * position(t) = paused ? originPosition\n * : originPosition + (t - originTime) * rate\n *\n * The semantics mirror the two engines this abstracts: re-anchor math is the\n * score scheduler's retune (capture position, reset both anchors) and\n * BufferEngine's setRate; pause folds elapsed time into `originPosition`.\n * Loop/wrap is deliberately OUT of scope — consumers implement it as\n * `seekTo(loopStart, t)`, which is exactly what the engines do today.\n * Negative times and positions pass through unclamped; clamping to a\n * duration is domain policy. Every anchor mutator rejects non-finite\n * numbers: a NaN reference time or position would silently poison the\n * anchor and every later `positionAt` read, with no error at the source.\n */\nexport class TransportClock {\n #originTime = 0;\n #originPosition = 0;\n #rate = 1;\n #paused = true;\n #holdUntilOrigin = false;\n readonly #now?: () => number;\n\n /** @param now Optional reference clock enabling the zero-arg `position` getter. */\n constructor(now?: () => number) {\n this.#now = now;\n }\n\n get state(): TransportClockState {\n return {\n originTime: this.#originTime,\n originPosition: this.#originPosition,\n rate: this.#rate,\n paused: this.#paused,\n };\n }\n\n get rate(): number {\n return this.#rate;\n }\n\n get paused(): boolean {\n return this.#paused;\n }\n\n /** Current position via the injected `now()` clock. Throws when none was injected. */\n get position(): number {\n if (!this.#now) throw new Error('TransportClock has no injected now() clock; use positionAt(t).');\n return this.positionAt(this.#now());\n }\n\n /**\n * True when a {@link startAt} start is armed. The flag is cleared by the\n * next {@link start} or {@link pause} — NOT by the origin time passing —\n * so callers combining it with {@link TransportClockState.originTime}\n * should treat \"holding and origin still in the future\" as the pre-roll\n * condition (positionAt handles this internally either way).\n */\n get holding(): boolean {\n return this.#holdUntilOrigin;\n }\n\n /**\n * Position at reference time `t`. While paused this is constant. `t` before\n * the anchor yields positions before it (possibly negative) — callers clamp\n * to their own domain — EXCEPT after {@link startAt}, where the position\n * holds at the armed origin position through the pre-roll (mirroring how a\n * scheduled `source.start(when)` sounds nothing before `when`).\n */\n positionAt(t: number): number {\n if (this.#paused) return this.#originPosition;\n if (this.#holdUntilOrigin && t < this.#originTime) return this.#originPosition;\n return this.#originPosition + (t - this.#originTime) * this.#rate;\n }\n\n /**\n * Inverse of {@link positionAt}. Throws RangeError while paused: no\n * reference time maps to a position when the transport is frozen — guard\n * with {@link paused} before calling. While a {@link startAt} start is\n * armed, positions before the armed origin position also throw: the\n * position holds through the pre-roll and never passes below the origin,\n * so no reference time maps to them (extrapolating backwards would return\n * a time whose {@link positionAt} is NOT the requested position).\n */\n timeAt(position: number): number {\n if (this.#paused) throw new RangeError('TransportClock is paused; no reference time maps to a position.');\n if (this.#holdUntilOrigin && position < this.#originPosition) {\n throw new RangeError(\n 'TransportClock is holding a scheduled start; no reference time maps to a position before the armed origin position.',\n );\n }\n return this.#originTime + (position - this.#originPosition) / this.#rate;\n }\n\n /**\n * Anchor at `(t, position ?? current position)` and unpause. Re-anchoring\n * while already playing is idempotent for the position at `t`.\n */\n start(t: number, position?: number): void {\n assertFiniteAnchor('start time', t);\n if (position !== undefined) assertFiniteAnchor('start position', position);\n this.#originPosition = position ?? this.positionAt(t);\n this.#originTime = t;\n this.#paused = false;\n this.#holdUntilOrigin = false;\n }\n\n /**\n * Arm a SCHEDULED start: anchor at a (typically future) reference time and\n * unpause, with the position holding at `position` until `t` arrives —\n * the clock-side mirror of a sample-accurate `play(when)`. Transitions\n * during the pre-roll keep the armed origin: {@link setRate} changes the\n * slope after `t` without collapsing the hold, {@link seekTo} re-arms the\n * held position, and {@link pause} cancels the pending start.\n */\n startAt(t: number, position: number): void {\n assertFiniteAnchor('startAt time', t);\n assertFiniteAnchor('startAt position', position);\n this.#originPosition = position;\n this.#originTime = t;\n this.#paused = false;\n this.#holdUntilOrigin = true;\n }\n\n /** Fold elapsed time into the anchor; `positionAt()` is constant afterwards. */\n pause(t: number): void {\n assertFiniteAnchor('pause time', t);\n this.#originPosition = this.positionAt(t);\n this.#originTime = t;\n this.#paused = true;\n this.#holdUntilOrigin = false;\n }\n\n /**\n * Re-anchor at a new position; preserves the paused/playing state. During\n * an armed pre-roll the scheduled origin time is kept (the pending start\n * stays pending at the new position).\n */\n seekTo(position: number, t: number): void {\n assertFiniteAnchor('seek position', position);\n assertFiniteAnchor('seek time', t);\n this.#originPosition = position;\n if (!(this.#holdUntilOrigin && t < this.#originTime)) {\n this.#originTime = t;\n }\n }\n\n /**\n * Re-anchor so the position is continuous across the rate change:\n * `originPosition = positionAt(t); originTime = t; rate = r`.\n * Throws RangeError unless `r` is finite and > 0.\n */\n setRate(r: number, t: number): void {\n if (!Number.isFinite(r) || r <= 0) {\n throw new RangeError(`TransportClock rate must be finite and > 0, got ${r}.`);\n }\n assertFiniteAnchor('setRate time', t);\n if (this.#holdUntilOrigin && t < this.#originTime) {\n // Pre-roll: the position has not started moving; only the slope after\n // the armed origin changes. (Naively re-anchoring at `t` here is the\n // BufferEngine pre-roll setRate bug this mode exists to prevent.)\n this.#rate = r;\n return;\n }\n this.#originPosition = this.positionAt(t);\n this.#originTime = t;\n this.#rate = r;\n }\n}\n\nfunction assertFiniteAnchor(name: string, value: number): void {\n if (!Number.isFinite(value)) {\n throw new RangeError(`TransportClock ${name} must be a finite number, got ${value}.`);\n }\n}\n\n/**\n * Read-only view of a {@link TransportClock} — what a transport OWNER exposes\n * to consumers (the sync bridge, views) so they can anchor against the clock\n * without being able to re-anchor it.\n */\nexport type TransportClockReader = Pick<\n TransportClock,\n 'state' | 'rate' | 'paused' | 'holding' | 'positionAt' | 'timeAt'\n>;\n\n/**\n * Monotonic non-decreasing map between a musical position axis (quarters,\n * beats — the consumer defines the unit) and media seconds. Implementations\n * should be total over all reals (extrapolate past the ends); they MAY clamp\n * negative inputs, and MAY quantize (the score family's TimeMap quantizes the\n * inverse to 1/480 quarter), so round-trips are only approximate and only on\n * `[0, duration]`.\n */\nexport interface TimelineMapping {\n positionToSeconds(position: number): number;\n secondsToPosition(seconds: number): number;\n}\n"],"mappings":";;;;;;;AAAA;AA4CO,IAAM,iBAAN,MAAqB;AAAA;AAAA,EAS1B,YAAY,KAAoB;AARhC,oCAAc;AACd,wCAAkB;AAClB,8BAAQ;AACR,gCAAU;AACV,yCAAmB;AACnB,uBAAS;AAIP,uBAAK,MAAO;AAAA,EACd;AAAA,EAEA,IAAI,QAA6B;AAC/B,WAAO;AAAA,MACL,YAAY,mBAAK;AAAA,MACjB,gBAAgB,mBAAK;AAAA,MACrB,MAAM,mBAAK;AAAA,MACX,QAAQ,mBAAK;AAAA,IACf;AAAA,EACF;AAAA,EAEA,IAAI,OAAe;AACjB,WAAO,mBAAK;AAAA,EACd;AAAA,EAEA,IAAI,SAAkB;AACpB,WAAO,mBAAK;AAAA,EACd;AAAA;AAAA,EAGA,IAAI,WAAmB;AACrB,QAAI,CAAC,mBAAK,MAAM,OAAM,IAAI,MAAM,gEAAgE;AAChG,WAAO,KAAK,WAAW,mBAAK,MAAL,UAAW;AAAA,EACpC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,IAAI,UAAmB;AACrB,WAAO,mBAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,WAAW,GAAmB;AAC5B,QAAI,mBAAK,SAAS,QAAO,mBAAK;AAC9B,QAAI,mBAAK,qBAAoB,IAAI,mBAAK,aAAa,QAAO,mBAAK;AAC/D,WAAO,mBAAK,oBAAmB,IAAI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AAA;AAAA;AAAA;AAAA;AAAA,EAOA,QAAQ,GAAW,GAAiB;AAClC,QAAI,CAAC,OAAO,SAAS,CAAC,KAAK,KAAK,GAAG;AACjC,YAAM,IAAI,WAAW,mDAAmD,CAAC,GAAG;AAAA,IAC9E;AACA,uBAAmB,gBAAgB,CAAC;AACpC,QAAI,mBAAK,qBAAoB,IAAI,mBAAK,cAAa;AAIjD,yBAAK,OAAQ;AACb;AAAA,IACF;AACA,uBAAK,iBAAkB,KAAK,WAAW,CAAC;AACxC,uBAAK,aAAc;AACnB,uBAAK,OAAQ;AAAA,EACf;AACF;AAxJE;AACA;AACA;AACA;AACA;AACS;AAqJX,SAAS,mBAAmB,MAAc,OAAqB;AAC7D,MAAI,CAAC,OAAO,SAAS,KAAK,GAAG;AAC3B,UAAM,IAAI,WAAW,kBAAkB,IAAI,iCAAiC,KAAK,GAAG;AAAA,EACtF;AACF;","names":[]}
|
package/dist/chunk-BR63OD53.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";//# sourceMappingURL=chunk-BR63OD53.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/mamingchen/GitHub/public/WebMusic/platform/kernel/dist/chunk-BR63OD53.cjs"],"names":[],"mappings":"AAAA","file":"/Users/mamingchen/GitHub/public/WebMusic/platform/kernel/dist/chunk-BR63OD53.cjs"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/meter.ts"],"sourcesContent":["// ============================================================================\n// Analyser metering shared by both families' level meters: a transparent\n// `input -> analyser -> output` tap plus the byte-domain level and spectrum\n// maths that read it. Numbers and Web Audio nodes only — no score, no clip,\n// no presenter, and nothing here decides WHEN to read a frame (a framework,\n// canvas renderer or presenter drives that).\n//\n// Extracted because both families had grown their own copy of the same tap\n// and the same RMS / peak-hold / bar-aggregation arithmetic, and the copies\n// had begun to drift. Per-family differences that are genuinely editorial —\n// the minimum bar count, the frame shape each family publishes, whether a\n// failing disconnect is swallowed — stay with the families; only the\n// mechanism lives here.\n// ============================================================================\n\n/** One time-domain reading, before a family decides what to publish. */\nexport interface AnalyserMeterFrame {\n /** Raw root-mean-square of the frame, unscaled and unclamped. */\n rms: number;\n /** `rms` scaled by `levelScale` and clamped to [0, 1] — the display value. */\n level: number;\n /** Instantaneous sample peak, scaled and clamped the same way. */\n peak: number;\n /** Decaying peak hold: `max(level, previousHold - peakDecay)`. */\n peakHold: number;\n}\n\nexport interface SpectrumBarOptions {\n /** Requested bar count, floored to a positive integer. Non-finite values use the default 28. */\n bars?: number;\n /** Floor applied to the requested count. Floored to an integer >= 1; non-finite values use 1. */\n minimumBars?: number;\n /** Treat the input as byte FFT data (0..255) and scale to [0, 1]. Default true. */\n normalizeBytes?: boolean;\n}\n\nexport interface AnalyserMeterOptions {\n /** Build and own a transparent `input -> analyser -> output` tap. */\n context?: BaseAudioContext;\n /** Borrow an existing analyser. It is never connected or disconnected. */\n analyser?: AnalyserNode;\n /** FFT size assigned to an owned analyser. Default 1024. */\n fftSize?: number;\n /** Smoothing assigned to an owned analyser. Default 0.8. */\n smoothingTimeConstant?: number;\n /** Gain applied to RMS and peak for the display values. Default 1.8. */\n levelScale?: number;\n /** Absolute peak-hold decay applied on every read. Default 0.012. */\n peakDecay?: number;\n /** Floor applied to {@link AnalyserMeter.readSpectrum}'s bar count; non-finite values use 1. */\n minimumBars?: number;\n}\n\n/**\n * Aggregate an FFT vector into a fixed number of normalized bars. Each bar is\n * the mean of its contiguous slice. When there are at least as many bins as\n * bars, the slices tile the input exactly. When there are fewer bins than\n * bars, bins are repeated to fill the requested display width.\n */\nexport function aggregateSpectrumBars(\n spectrum: ArrayLike<number>,\n options: SpectrumBarOptions = {},\n): Float32Array {\n const minimum = positiveBarCount(options.minimumBars, 1);\n const barCount = Math.max(minimum, positiveBarCount(options.bars, 28));\n const result = new Float32Array(barCount);\n if (spectrum.length === 0) return result;\n const byteScale = options.normalizeBytes ?? true;\n for (let bar = 0; bar < barCount; bar += 1) {\n const start = Math.floor((bar * spectrum.length) / barCount);\n const end = Math.max(start + 1, Math.floor(((bar + 1) * spectrum.length) / barCount));\n let sum = 0;\n let count = 0;\n for (let index = start; index < end && index < spectrum.length; index += 1) {\n const raw = spectrum[index];\n sum += (Number.isFinite(raw) ? raw : 0) / (byteScale ? 255 : 1);\n count += 1;\n }\n result[bar] = clamp(count > 0 ? sum / count : 0, 0, 1);\n }\n return result;\n}\n\n/**\n * Live analyser meter.\n *\n * Supplying `context` creates an owned pass-through tap; supplying `analyser`\n * borrows that node. The two modes are mutually exclusive so resource\n * ownership is never ambiguous.\n */\nexport class AnalyserMeter {\n readonly #levelScale: number;\n readonly #peakDecay: number;\n readonly #minimumBars: number;\n #analyser?: AnalyserNode;\n #input?: GainNode;\n #output?: GainNode;\n #ownsGraph = false;\n #disposed = false;\n #timeBuffer?: Uint8Array<ArrayBuffer>;\n #frequencyBuffer?: Uint8Array<ArrayBuffer>;\n #peakHold = 0;\n\n constructor(options: AnalyserMeterOptions = {}) {\n if (options.context && options.analyser) {\n throw new TypeError('AnalyserMeter accepts either context or analyser, not both');\n }\n this.#levelScale = finiteNonNegative(options.levelScale, 1.8);\n this.#peakDecay = finiteNonNegative(options.peakDecay, 0.012);\n this.#minimumBars = positiveBarCount(options.minimumBars, 1);\n\n if (options.analyser) this.#analyser = options.analyser;\n else if (options.context) this.#buildOwnedGraph(options.context, options);\n }\n\n /** The owned or borrowed analyser currently read. */\n get analyser(): AnalyserNode | undefined {\n return this.#analyser;\n }\n\n /** Input of an owned tap; absent when borrowing an analyser. */\n get input(): AudioNode | undefined {\n return this.#input;\n }\n\n /** Output of an owned tap; absent when borrowing an analyser. */\n get output(): AudioNode | undefined {\n return this.#output;\n }\n\n /** Whether this meter created and owns its tap graph. */\n get ownsGraph(): boolean {\n return this.#ownsGraph;\n }\n\n /** Read one time-domain frame and derive its level, peak and peak hold. */\n readLevel(): AnalyserMeterFrame {\n const analyser = this.#assertReadable();\n const length = Math.max(1, analyser.fftSize);\n if (!this.#timeBuffer || this.#timeBuffer.length !== length) {\n this.#timeBuffer = new Uint8Array(new ArrayBuffer(length));\n }\n analyser.getByteTimeDomainData(this.#timeBuffer);\n\n let sumSquares = 0;\n let samplePeak = 0;\n for (let index = 0; index < length; index += 1) {\n const sample = ((this.#timeBuffer[index] ?? 128) - 128) / 128;\n sumSquares += sample * sample;\n samplePeak = Math.max(samplePeak, Math.abs(sample));\n }\n const rms = Math.sqrt(sumSquares / length);\n const level = clamp(rms * this.#levelScale, 0, 1);\n const peak = clamp(samplePeak * this.#levelScale, 0, 1);\n this.#peakHold = Math.max(level, this.#peakHold - this.#peakDecay);\n return {rms, level, peak, peakHold: this.#peakHold};\n }\n\n /** Read one frequency-domain frame, aggregated into normalized bars. */\n readSpectrum(bars = 28): Float32Array {\n const analyser = this.#assertReadable();\n const length = Math.max(1, analyser.frequencyBinCount);\n if (!this.#frequencyBuffer || this.#frequencyBuffer.length !== length) {\n this.#frequencyBuffer = new Uint8Array(new ArrayBuffer(length));\n }\n analyser.getByteFrequencyData(this.#frequencyBuffer);\n return aggregateSpectrumBars(this.#frequencyBuffer, {\n bars,\n minimumBars: this.#minimumBars,\n normalizeBytes: true,\n });\n }\n\n /**\n * Release an owned graph; a borrowed analyser is never disconnected. Every\n * owned node is attempted even when an earlier disconnect throws, and the\n * meter has reached its disposed state before the first error is rethrown.\n * Repeated calls are safe.\n */\n dispose(): void {\n if (this.#disposed) return;\n this.#disposed = true;\n const analyser = this.#analyser;\n const input = this.#input;\n const output = this.#output;\n const ownsGraph = this.#ownsGraph;\n\n this.#analyser = undefined;\n this.#input = undefined;\n this.#output = undefined;\n this.#ownsGraph = false;\n this.#timeBuffer = undefined;\n this.#frequencyBuffer = undefined;\n this.#peakHold = 0;\n\n if (!ownsGraph) return;\n let failed = false;\n let firstError: unknown;\n for (const node of [input, analyser, output]) {\n try {\n node?.disconnect();\n } catch (error) {\n if (!failed) firstError = error;\n failed = true;\n }\n }\n if (failed) throw firstError;\n }\n\n #buildOwnedGraph(context: BaseAudioContext, options: AnalyserMeterOptions): void {\n let input: GainNode | undefined;\n let output: GainNode | undefined;\n let analyser: AnalyserNode | undefined;\n try {\n input = context.createGain();\n output = context.createGain();\n analyser = context.createAnalyser();\n analyser.fftSize = options.fftSize ?? 1024;\n analyser.smoothingTimeConstant = options.smoothingTimeConstant ?? 0.8;\n input.connect(analyser);\n analyser.connect(output);\n } catch (error) {\n for (const node of [input, analyser, output]) {\n try {\n node?.disconnect();\n } catch {\n // Preserve the construction failure after a best-effort rollback.\n }\n }\n throw error;\n }\n this.#input = input;\n this.#output = output;\n this.#analyser = analyser;\n this.#ownsGraph = true;\n }\n\n #assertReadable(): AnalyserNode {\n if (this.#disposed) throw new Error('AnalyserMeter has been disposed');\n if (!this.#analyser) throw new Error('AnalyserMeter has no analyser');\n return this.#analyser;\n }\n}\n\n/** Build an {@link AnalyserMeter} (the `createX` convention). */\nexport function createAnalyserMeter(options?: AnalyserMeterOptions): AnalyserMeter {\n return new AnalyserMeter(options);\n}\n\nfunction finiteNonNegative(value: number | undefined, fallback: number): number {\n return value === undefined || !Number.isFinite(value) ? fallback : Math.max(0, value);\n}\n\nfunction positiveBarCount(value: number | undefined, fallback: number): number {\n return Math.max(1, Math.floor(finiteNonNegative(value, fallback)));\n}\n\nfunction clamp(value: number, min: number, max: number): number {\n return Math.max(min, Math.min(max, value));\n}\n"],"mappings":";;;;;;;;AA2DO,SAAS,sBACd,UACA,UAA8B,CAAC,GACjB;AACd,QAAM,UAAU,iBAAiB,QAAQ,aAAa,CAAC;AACvD,QAAM,WAAW,KAAK,IAAI,SAAS,iBAAiB,QAAQ,MAAM,EAAE,CAAC;AACrE,QAAM,SAAS,IAAI,aAAa,QAAQ;AACxC,MAAI,SAAS,WAAW,EAAG,QAAO;AAClC,QAAM,YAAY,QAAQ,kBAAkB;AAC5C,WAAS,MAAM,GAAG,MAAM,UAAU,OAAO,GAAG;AAC1C,UAAM,QAAQ,KAAK,MA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AClC;AAEA,SAAS,iBAAA,CAAkB,KAAA,EAA2B,QAAA,EAA0B;AAC9E,EAAA,OAAO,MAAA,IAAU,KAAA,EAAA,GAAa,CAAC,MAAA,CAAO,QAAA,CAAS,KAAK,EAAA,EAAI,SAAA,EAAW,IAAA,CAAK,GAAA,CAAI,CAAA,EAAG,KAAK,CAAA;AACtF;AAEA,SAAS,gBAAA,CAAiB,KAAA,EAA2B,QAAA,EAA0B;AAC7E,EAAA,OAAO,IAAA,CAAK,GAAA,CAAI,CAAA,EAAG,IAAA,CAAK,KAAA,CAAM,iBAAA,CAAkB,KAAA,EAAO,QAAQ,CAAC,CAAC,CAAA;AACnE;AAEA,SAAS,KAAA,CAAM,KAAA,EAAe,GAAA,EAAa,GAAA,EAAqB;AAC9D,EAAA,OAAO,IAAA,CAAK,GAAA,CAAI,GAAA,EAAK,IAAA,CAAK,GAAA,CAAI,GAAA,EAAK,KAAK,CAAC,CAAA;AAC3C;ADnEA;AACA;AACE;AACA;AACA;AACF,gJAAC","file":"/Users/mamingchen/GitHub/public/WebMusic/platform/kernel/dist/chunk-HZQX4J2J.cjs","sourcesContent":[null,"// ============================================================================\n// Analyser metering shared by both families' level meters: a transparent\n// `input -> analyser -> output` tap plus the byte-domain level and spectrum\n// maths that read it. Numbers and Web Audio nodes only — no score, no clip,\n// no presenter, and nothing here decides WHEN to read a frame (a framework,\n// canvas renderer or presenter drives that).\n//\n// Extracted because both families had grown their own copy of the same tap\n// and the same RMS / peak-hold / bar-aggregation arithmetic, and the copies\n// had begun to drift. Per-family differences that are genuinely editorial —\n// the minimum bar count, the frame shape each family publishes, whether a\n// failing disconnect is swallowed — stay with the families; only the\n// mechanism lives here.\n// ============================================================================\n\n/** One time-domain reading, before a family decides what to publish. */\nexport interface AnalyserMeterFrame {\n /** Raw root-mean-square of the frame, unscaled and unclamped. */\n rms: number;\n /** `rms` scaled by `levelScale` and clamped to [0, 1] — the display value. */\n level: number;\n /** Instantaneous sample peak, scaled and clamped the same way. */\n peak: number;\n /** Decaying peak hold: `max(level, previousHold - peakDecay)`. */\n peakHold: number;\n}\n\nexport interface SpectrumBarOptions {\n /** Requested bar count, floored to a positive integer. Non-finite values use the default 28. */\n bars?: number;\n /** Floor applied to the requested count. Floored to an integer >= 1; non-finite values use 1. */\n minimumBars?: number;\n /** Treat the input as byte FFT data (0..255) and scale to [0, 1]. Default true. */\n normalizeBytes?: boolean;\n}\n\nexport interface AnalyserMeterOptions {\n /** Build and own a transparent `input -> analyser -> output` tap. */\n context?: BaseAudioContext;\n /** Borrow an existing analyser. It is never connected or disconnected. */\n analyser?: AnalyserNode;\n /** FFT size assigned to an owned analyser. Default 1024. */\n fftSize?: number;\n /** Smoothing assigned to an owned analyser. Default 0.8. */\n smoothingTimeConstant?: number;\n /** Gain applied to RMS and peak for the display values. Default 1.8. */\n levelScale?: number;\n /** Absolute peak-hold decay applied on every read. Default 0.012. */\n peakDecay?: number;\n /** Floor applied to {@link AnalyserMeter.readSpectrum}'s bar count; non-finite values use 1. */\n minimumBars?: number;\n}\n\n/**\n * Aggregate an FFT vector into a fixed number of normalized bars. Each bar is\n * the mean of its contiguous slice. When there are at least as many bins as\n * bars, the slices tile the input exactly. When there are fewer bins than\n * bars, bins are repeated to fill the requested display width.\n */\nexport function aggregateSpectrumBars(\n spectrum: ArrayLike<number>,\n options: SpectrumBarOptions = {},\n): Float32Array {\n const minimum = positiveBarCount(options.minimumBars, 1);\n const barCount = Math.max(minimum, positiveBarCount(options.bars, 28));\n const result = new Float32Array(barCount);\n if (spectrum.length === 0) return result;\n const byteScale = options.normalizeBytes ?? true;\n for (let bar = 0; bar < barCount; bar += 1) {\n const start = Math.floor((bar * spectrum.length) / barCount);\n const end = Math.max(start + 1, Math.floor(((bar + 1) * spectrum.length) / barCount));\n let sum = 0;\n let count = 0;\n for (let index = start; index < end && index < spectrum.length; index += 1) {\n const raw = spectrum[index];\n sum += (Number.isFinite(raw) ? raw : 0) / (byteScale ? 255 : 1);\n count += 1;\n }\n result[bar] = clamp(count > 0 ? sum / count : 0, 0, 1);\n }\n return result;\n}\n\n/**\n * Live analyser meter.\n *\n * Supplying `context` creates an owned pass-through tap; supplying `analyser`\n * borrows that node. The two modes are mutually exclusive so resource\n * ownership is never ambiguous.\n */\nexport class AnalyserMeter {\n readonly #levelScale: number;\n readonly #peakDecay: number;\n readonly #minimumBars: number;\n #analyser?: AnalyserNode;\n #input?: GainNode;\n #output?: GainNode;\n #ownsGraph = false;\n #disposed = false;\n #timeBuffer?: Uint8Array<ArrayBuffer>;\n #frequencyBuffer?: Uint8Array<ArrayBuffer>;\n #peakHold = 0;\n\n constructor(options: AnalyserMeterOptions = {}) {\n if (options.context && options.analyser) {\n throw new TypeError('AnalyserMeter accepts either context or analyser, not both');\n }\n this.#levelScale = finiteNonNegative(options.levelScale, 1.8);\n this.#peakDecay = finiteNonNegative(options.peakDecay, 0.012);\n this.#minimumBars = positiveBarCount(options.minimumBars, 1);\n\n if (options.analyser) this.#analyser = options.analyser;\n else if (options.context) this.#buildOwnedGraph(options.context, options);\n }\n\n /** The owned or borrowed analyser currently read. */\n get analyser(): AnalyserNode | undefined {\n return this.#analyser;\n }\n\n /** Input of an owned tap; absent when borrowing an analyser. */\n get input(): AudioNode | undefined {\n return this.#input;\n }\n\n /** Output of an owned tap; absent when borrowing an analyser. */\n get output(): AudioNode | undefined {\n return this.#output;\n }\n\n /** Whether this meter created and owns its tap graph. */\n get ownsGraph(): boolean {\n return this.#ownsGraph;\n }\n\n /** Read one time-domain frame and derive its level, peak and peak hold. */\n readLevel(): AnalyserMeterFrame {\n const analyser = this.#assertReadable();\n const length = Math.max(1, analyser.fftSize);\n if (!this.#timeBuffer || this.#timeBuffer.length !== length) {\n this.#timeBuffer = new Uint8Array(new ArrayBuffer(length));\n }\n analyser.getByteTimeDomainData(this.#timeBuffer);\n\n let sumSquares = 0;\n let samplePeak = 0;\n for (let index = 0; index < length; index += 1) {\n const sample = ((this.#timeBuffer[index] ?? 128) - 128) / 128;\n sumSquares += sample * sample;\n samplePeak = Math.max(samplePeak, Math.abs(sample));\n }\n const rms = Math.sqrt(sumSquares / length);\n const level = clamp(rms * this.#levelScale, 0, 1);\n const peak = clamp(samplePeak * this.#levelScale, 0, 1);\n this.#peakHold = Math.max(level, this.#peakHold - this.#peakDecay);\n return {rms, level, peak, peakHold: this.#peakHold};\n }\n\n /** Read one frequency-domain frame, aggregated into normalized bars. */\n readSpectrum(bars = 28): Float32Array {\n const analyser = this.#assertReadable();\n const length = Math.max(1, analyser.frequencyBinCount);\n if (!this.#frequencyBuffer || this.#frequencyBuffer.length !== length) {\n this.#frequencyBuffer = new Uint8Array(new ArrayBuffer(length));\n }\n analyser.getByteFrequencyData(this.#frequencyBuffer);\n return aggregateSpectrumBars(this.#frequencyBuffer, {\n bars,\n minimumBars: this.#minimumBars,\n normalizeBytes: true,\n });\n }\n\n /**\n * Release an owned graph; a borrowed analyser is never disconnected. Every\n * owned node is attempted even when an earlier disconnect throws, and the\n * meter has reached its disposed state before the first error is rethrown.\n * Repeated calls are safe.\n */\n dispose(): void {\n if (this.#disposed) return;\n this.#disposed = true;\n const analyser = this.#analyser;\n const input = this.#input;\n const output = this.#output;\n const ownsGraph = this.#ownsGraph;\n\n this.#analyser = undefined;\n this.#input = undefined;\n this.#output = undefined;\n this.#ownsGraph = false;\n this.#timeBuffer = undefined;\n this.#frequencyBuffer = undefined;\n this.#peakHold = 0;\n\n if (!ownsGraph) return;\n let failed = false;\n let firstError: unknown;\n for (const node of [input, analyser, output]) {\n try {\n node?.disconnect();\n } catch (error) {\n if (!failed) firstError = error;\n failed = true;\n }\n }\n if (failed) throw firstError;\n }\n\n #buildOwnedGraph(context: BaseAudioContext, options: AnalyserMeterOptions): void {\n let input: GainNode | undefined;\n let output: GainNode | undefined;\n let analyser: AnalyserNode | undefined;\n try {\n input = context.createGain();\n output = context.createGain();\n analyser = context.createAnalyser();\n analyser.fftSize = options.fftSize ?? 1024;\n analyser.smoothingTimeConstant = options.smoothingTimeConstant ?? 0.8;\n input.connect(analyser);\n analyser.connect(output);\n } catch (error) {\n for (const node of [input, analyser, output]) {\n try {\n node?.disconnect();\n } catch {\n // Preserve the construction failure after a best-effort rollback.\n }\n }\n throw error;\n }\n this.#input = input;\n this.#output = output;\n this.#analyser = analyser;\n this.#ownsGraph = true;\n }\n\n #assertReadable(): AnalyserNode {\n if (this.#disposed) throw new Error('AnalyserMeter has been disposed');\n if (!this.#analyser) throw new Error('AnalyserMeter has no analyser');\n return this.#analyser;\n }\n}\n\n/** Build an {@link AnalyserMeter} (the `createX` convention). */\nexport function createAnalyserMeter(options?: AnalyserMeterOptions): AnalyserMeter {\n return new AnalyserMeter(options);\n}\n\nfunction finiteNonNegative(value: number | undefined, fallback: number): number {\n return value === undefined || !Number.isFinite(value) ? fallback : Math.max(0, value);\n}\n\nfunction positiveBarCount(value: number | undefined, fallback: number): number {\n return Math.max(1, Math.floor(finiteNonNegative(value, fallback)));\n}\n\nfunction clamp(value: number, min: number, max: number): number {\n return Math.max(min, Math.min(max, value));\n}\n"]}
|