@waveform-playlist/core 12.6.2 → 13.0.0-next.1
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 +76 -2
- package/dist/index.d.mts +470 -43
- package/dist/index.d.ts +470 -43
- package/dist/index.js +610 -38
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +589 -37
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -76,8 +76,11 @@ type ColorMapValue = ColorMapName | ColorMapEntry[];
|
|
|
76
76
|
type SpectrogramComputeConfig = Pick<SpectrogramConfig, 'fftSize' | 'hopSize' | 'windowFunction' | 'alpha' | 'zeroPaddingFactor'>;
|
|
77
77
|
/** Subset of SpectrogramConfig fields that only affect display/rendering (not FFT computation) */
|
|
78
78
|
type SpectrogramDisplayConfig = Pick<SpectrogramConfig, 'frequencyScale' | 'minFrequency' | 'maxFrequency' | 'gainDb' | 'rangeDb' | 'labels' | 'labelsColor' | 'labelsBackground'>;
|
|
79
|
-
/**
|
|
80
|
-
|
|
79
|
+
/**
|
|
80
|
+
* How an audio track is drawn. A MIDI track (`kind: 'midi'`) has no render
|
|
81
|
+
* mode: it is always drawn as a piano roll.
|
|
82
|
+
*/
|
|
83
|
+
type RenderMode = 'waveform' | 'spectrogram' | 'both';
|
|
81
84
|
/** Per-track overrides for spectrogram rendering (render mode, config, color map) */
|
|
82
85
|
interface TrackSpectrogramOverrides {
|
|
83
86
|
renderMode: RenderMode;
|
|
@@ -134,31 +137,6 @@ interface WaveformDataObject {
|
|
|
134
137
|
endIndex: number;
|
|
135
138
|
}) => WaveformDataObject;
|
|
136
139
|
}
|
|
137
|
-
/**
|
|
138
|
-
* Generic effects function type for track-level audio processing.
|
|
139
|
-
*
|
|
140
|
-
* The actual implementation receives Tone.js audio nodes. Using generic types
|
|
141
|
-
* here to avoid circular dependencies with the playout package.
|
|
142
|
-
*
|
|
143
|
-
* @param graphEnd - The end of the track's audio graph (Tone.js Gain node)
|
|
144
|
-
* @param destination - Where to connect the effects output (Tone.js ToneAudioNode)
|
|
145
|
-
* @param isOffline - Whether rendering offline (for export)
|
|
146
|
-
* @returns Optional cleanup function called when track is disposed
|
|
147
|
-
*
|
|
148
|
-
* @example
|
|
149
|
-
* ```typescript
|
|
150
|
-
* const trackEffects: TrackEffectsFunction = (graphEnd, destination, isOffline) => {
|
|
151
|
-
* const reverb = new Tone.Reverb({ decay: 1.5 });
|
|
152
|
-
* graphEnd.connect(reverb);
|
|
153
|
-
* reverb.connect(destination);
|
|
154
|
-
*
|
|
155
|
-
* return () => {
|
|
156
|
-
* reverb.dispose();
|
|
157
|
-
* };
|
|
158
|
-
* };
|
|
159
|
-
* ```
|
|
160
|
-
*/
|
|
161
|
-
type TrackEffectsFunction = (graphEnd: unknown, destination: unknown, isOffline: boolean) => void | (() => void);
|
|
162
140
|
/**
|
|
163
141
|
* Represents a single audio clip on the timeline
|
|
164
142
|
*
|
|
@@ -229,13 +207,55 @@ interface AudioClip {
|
|
|
229
207
|
midiChannel?: number;
|
|
230
208
|
/** MIDI program number (0-127). GM instrument number for SoundFont playback. */
|
|
231
209
|
midiProgram?: number;
|
|
210
|
+
/** The source this clip's audio came from (a URL, Blob or File), when it is known. */
|
|
211
|
+
src?: ClipSource;
|
|
232
212
|
}
|
|
213
|
+
/** What a loading clip names. A string is a URL; a Blob or File is keyed by identity. */
|
|
214
|
+
type ClipSource = string | Blob;
|
|
233
215
|
/**
|
|
234
|
-
*
|
|
216
|
+
* A clip whose audio is not loaded yet. Times are in seconds; whatever loads
|
|
217
|
+
* `src` turns it into an `AudioClip` (integer samples).
|
|
218
|
+
*/
|
|
219
|
+
interface LoadingClip {
|
|
220
|
+
/** Unique identifier for this clip */
|
|
221
|
+
id: string;
|
|
222
|
+
/** The audio to load */
|
|
223
|
+
src: ClipSource;
|
|
224
|
+
/** Position on the timeline, in seconds. Default 0. */
|
|
225
|
+
start?: number;
|
|
226
|
+
/** Duration in seconds. Default: the whole source from `offset`. */
|
|
227
|
+
duration?: number;
|
|
228
|
+
/** Start within the source, in seconds. Default 0. */
|
|
229
|
+
offset?: number;
|
|
230
|
+
name?: string;
|
|
231
|
+
gain?: number;
|
|
232
|
+
fadeIn?: Fade;
|
|
233
|
+
fadeOut?: Fade;
|
|
234
|
+
color?: string;
|
|
235
|
+
/** Pre-computed peaks, drawn while the audio loads */
|
|
236
|
+
waveformData?: WaveformDataObject;
|
|
237
|
+
}
|
|
238
|
+
/** A track whose clips are loaded (`AudioClip`) or not loaded yet (`LoadingClip`). */
|
|
239
|
+
type ArrangementTrack = Omit<ClipTrack, 'clips'> & {
|
|
240
|
+
clips: (AudioClip | LoadingClip)[];
|
|
241
|
+
};
|
|
242
|
+
/** True for a clip whose audio is not loaded yet (it has no `sampleRate`). */
|
|
243
|
+
declare function isLoadingClip(clip: AudioClip | LoadingClip): clip is LoadingClip;
|
|
244
|
+
/** What a track holds: audio clips or MIDI clips. A track never holds both. */
|
|
245
|
+
type TrackKind = 'audio' | 'midi';
|
|
246
|
+
/**
|
|
247
|
+
* Represents a track containing multiple clips of one kind
|
|
235
248
|
*/
|
|
236
249
|
interface ClipTrack {
|
|
237
250
|
/** Unique identifier for this track */
|
|
238
251
|
id: string;
|
|
252
|
+
/**
|
|
253
|
+
* What the track holds. Every clip on an audio track is an audio clip and
|
|
254
|
+
* every clip on a MIDI track has `midiNotes`; the engine throws on a track
|
|
255
|
+
* that breaks this. An empty track has a kind too, which decides what may be
|
|
256
|
+
* recorded or added to it. A MIDI track is drawn as a piano roll.
|
|
257
|
+
*/
|
|
258
|
+
kind: TrackKind;
|
|
239
259
|
/** Display name for this track */
|
|
240
260
|
name: string;
|
|
241
261
|
/** Array of audio clips on this track */
|
|
@@ -252,8 +272,6 @@ interface ClipTrack {
|
|
|
252
272
|
color?: string;
|
|
253
273
|
/** Track height in pixels (for UI) */
|
|
254
274
|
height?: number;
|
|
255
|
-
/** Optional effects function for this track */
|
|
256
|
-
effects?: TrackEffectsFunction;
|
|
257
275
|
/** Visualization render mode. Default: 'waveform' */
|
|
258
276
|
renderMode?: RenderMode;
|
|
259
277
|
/** Per-track spectrogram configuration (FFT size, window, frequency scale, etc.) */
|
|
@@ -311,6 +329,8 @@ interface CreateClipOptions {
|
|
|
311
329
|
midiChannel?: number;
|
|
312
330
|
/** MIDI program number (0-127). GM instrument for SoundFont playback. */
|
|
313
331
|
midiProgram?: number;
|
|
332
|
+
/** The source this clip was loaded from — passed through to the created AudioClip */
|
|
333
|
+
src?: ClipSource;
|
|
314
334
|
}
|
|
315
335
|
/**
|
|
316
336
|
* Options for creating a new audio clip (using seconds for convenience)
|
|
@@ -342,6 +362,8 @@ interface CreateClipOptionsSeconds {
|
|
|
342
362
|
midiChannel?: number;
|
|
343
363
|
/** MIDI program number (0-127). GM instrument for SoundFont playback. */
|
|
344
364
|
midiProgram?: number;
|
|
365
|
+
/** The source this clip was loaded from — passed through to the created AudioClip */
|
|
366
|
+
src?: ClipSource;
|
|
345
367
|
}
|
|
346
368
|
/**
|
|
347
369
|
* Options for creating a new audio clip from tick position.
|
|
@@ -370,6 +392,8 @@ interface CreateClipOptionsTicks {
|
|
|
370
392
|
midiNotes?: MidiNoteData[];
|
|
371
393
|
midiChannel?: number;
|
|
372
394
|
midiProgram?: number;
|
|
395
|
+
/** The source this clip was loaded from — passed through to the created AudioClip */
|
|
396
|
+
src?: ClipSource;
|
|
373
397
|
}
|
|
374
398
|
declare function createClipFromTicks(options: CreateClipOptionsTicks): AudioClip;
|
|
375
399
|
/**
|
|
@@ -377,6 +401,8 @@ declare function createClipFromTicks(options: CreateClipOptionsTicks): AudioClip
|
|
|
377
401
|
*/
|
|
378
402
|
interface CreateTrackOptions {
|
|
379
403
|
name: string;
|
|
404
|
+
/** What the track holds. Default: 'audio'. */
|
|
405
|
+
kind?: TrackKind;
|
|
380
406
|
clips?: AudioClip[];
|
|
381
407
|
muted?: boolean;
|
|
382
408
|
soloed?: boolean;
|
|
@@ -863,7 +889,7 @@ declare function calculateDuration(sampleCount: number, sampleRate: number): num
|
|
|
863
889
|
* non-finite or non-positive inputs.
|
|
864
890
|
*
|
|
865
891
|
* Single source of truth for `useIntegratedRecording` (buffer trim) and
|
|
866
|
-
*
|
|
892
|
+
* the view's recording preview (live preview peak slice). Keep the two in lockstep
|
|
867
893
|
* so the live preview width matches the finalized clip.
|
|
868
894
|
*/
|
|
869
895
|
declare function audibleLatencySamples(outputLatency: number, lookAhead: number, sampleRate: number): number;
|
|
@@ -877,7 +903,7 @@ declare function audibleLatencySamples(outputLatency: number, lookAhead: number,
|
|
|
877
903
|
*
|
|
878
904
|
* Single source of truth for the override-vs-auto decision across dawcore
|
|
879
905
|
* (`RecordingController`) and React (`useIntegratedRecording` finalization +
|
|
880
|
-
*
|
|
906
|
+
* the view's live preview). The override branch is the same math as
|
|
881
907
|
* the auto branch with `lookAhead = 0`, so both inherit the finite/positive
|
|
882
908
|
* guards in `audibleLatencySamples`.
|
|
883
909
|
*/
|
|
@@ -941,6 +967,86 @@ declare const DEFAULT_SPECTROGRAM_COLOR_MAP: ColorMapValue;
|
|
|
941
967
|
*/
|
|
942
968
|
declare function carveClipRange(clips: readonly AudioClip[], rangeStart: number, rangeEnd: number): AudioClip[];
|
|
943
969
|
|
|
970
|
+
/**
|
|
971
|
+
* A value that changes too often to live in UI state (meter levels, recording
|
|
972
|
+
* progress): read it with `getSnapshot()`, or be told about each new value
|
|
973
|
+
* with `subscribe()`.
|
|
974
|
+
*
|
|
975
|
+
* The pair matches React's `useSyncExternalStore(source.subscribe,
|
|
976
|
+
* source.getSnapshot)`, but nothing here depends on React.
|
|
977
|
+
*/
|
|
978
|
+
interface ValueSource<T> {
|
|
979
|
+
/**
|
|
980
|
+
* Call `listener` with each new value. Returns the function that removes
|
|
981
|
+
* the subscription.
|
|
982
|
+
*/
|
|
983
|
+
subscribe(listener: (value: T) => void): () => void;
|
|
984
|
+
/** The latest value. The same object is returned until the next change. */
|
|
985
|
+
getSnapshot(): T;
|
|
986
|
+
}
|
|
987
|
+
/** Per-channel meter readings, each normalized to 0-1. */
|
|
988
|
+
interface MeterLevels {
|
|
989
|
+
/** Smoothed peak level per channel. */
|
|
990
|
+
levels: number[];
|
|
991
|
+
/** Highest level seen per channel since the last reset. */
|
|
992
|
+
peakLevels: number[];
|
|
993
|
+
/** RMS level per channel. */
|
|
994
|
+
rmsLevels: number[];
|
|
995
|
+
}
|
|
996
|
+
type MeterSource = ValueSource<MeterLevels>;
|
|
997
|
+
/** What a recording in progress has captured so far. */
|
|
998
|
+
interface RecordingProgress {
|
|
999
|
+
/** Elapsed recording time in seconds. */
|
|
1000
|
+
duration: number;
|
|
1001
|
+
/** Min/max peak pairs per channel, for the live waveform preview. */
|
|
1002
|
+
peaks: (Int8Array | Int16Array)[];
|
|
1003
|
+
}
|
|
1004
|
+
type RecordingProgressSource = ValueSource<RecordingProgress>;
|
|
1005
|
+
interface ValueSourceHandle<T> {
|
|
1006
|
+
/** The read side, safe to hand to consumers. */
|
|
1007
|
+
source: ValueSource<T>;
|
|
1008
|
+
/** Replace the value and notify listeners. A no-op for the current value. */
|
|
1009
|
+
publish(value: T): void;
|
|
1010
|
+
}
|
|
1011
|
+
/** Build a `MeterLevels` of zeros for `channelCount` channels. */
|
|
1012
|
+
declare function silentMeterLevels(channelCount: number): MeterLevels;
|
|
1013
|
+
/**
|
|
1014
|
+
* Create a `ValueSource` together with the function that publishes to it.
|
|
1015
|
+
* Published values must be new objects: listeners and `getSnapshot` callers
|
|
1016
|
+
* compare by identity.
|
|
1017
|
+
*/
|
|
1018
|
+
declare function createValueSource<T>(initial: T): ValueSourceHandle<T>;
|
|
1019
|
+
|
|
1020
|
+
/** Exponential decay per reading for the smoothed peak (~800 ms to 1/e at 60 Hz). */
|
|
1021
|
+
declare const METER_PEAK_DECAY = 0.98;
|
|
1022
|
+
interface MeterReading {
|
|
1023
|
+
/** Raw-gain smoothed peak per metered channel; pass back in with the next message. */
|
|
1024
|
+
smoothedPeaks: number[];
|
|
1025
|
+
/** The levels to show. */
|
|
1026
|
+
levels: MeterLevels;
|
|
1027
|
+
}
|
|
1028
|
+
interface ReadMeterMessageParams {
|
|
1029
|
+
/**
|
|
1030
|
+
* A meter worklet message: N peak gains followed by N RMS gains.
|
|
1031
|
+
*/
|
|
1032
|
+
data: ArrayLike<number>;
|
|
1033
|
+
/** `smoothedPeaks` from the previous reading (empty for the first). */
|
|
1034
|
+
previousSmoothedPeaks: readonly number[];
|
|
1035
|
+
/** `levels.peakLevels` from the previous reading (empty after a reset). */
|
|
1036
|
+
heldPeakLevels: readonly number[];
|
|
1037
|
+
/**
|
|
1038
|
+
* When the message has fewer channels than this, channel 0 is repeated to
|
|
1039
|
+
* fill it (a mono microphone shown on a stereo meter). Default: 0.
|
|
1040
|
+
*/
|
|
1041
|
+
minChannels?: number;
|
|
1042
|
+
}
|
|
1043
|
+
/**
|
|
1044
|
+
* Turn one meter worklet message into display levels: the peak jumps up at
|
|
1045
|
+
* once and decays slowly, RMS is passed through, and the held peak keeps the
|
|
1046
|
+
* highest level seen. Pure: nothing passed in is modified.
|
|
1047
|
+
*/
|
|
1048
|
+
declare function readMeterMessage({ data, previousSmoothedPeaks, heldPeakLevels, minChannels, }: ReadMeterMessageParams): MeterReading;
|
|
1049
|
+
|
|
944
1050
|
/** Clip start position in seconds */
|
|
945
1051
|
declare function clipStartTime(clip: AudioClip): number;
|
|
946
1052
|
/** Clip end position in seconds (start + duration) */
|
|
@@ -949,11 +1055,20 @@ declare function clipEndTime(clip: AudioClip): number;
|
|
|
949
1055
|
declare function clipOffsetTime(clip: AudioClip): number;
|
|
950
1056
|
/** Clip duration in seconds */
|
|
951
1057
|
declare function clipDurationTime(clip: AudioClip): number;
|
|
1058
|
+
/** The part of a track `trackChannelCount` reads — `ClipTrack` satisfies it. */
|
|
1059
|
+
interface TrackChannelSource {
|
|
1060
|
+
clips: ReadonlyArray<{
|
|
1061
|
+
audioBuffer?: {
|
|
1062
|
+
numberOfChannels: number;
|
|
1063
|
+
};
|
|
1064
|
+
}>;
|
|
1065
|
+
}
|
|
952
1066
|
/**
|
|
953
|
-
* Max audio channel count across a track's clips
|
|
954
|
-
*
|
|
1067
|
+
* Max audio channel count across a track's clips (1 for a track with no
|
|
1068
|
+
* decoded audio). Selects the track's pan law (`createPanStage`) and the
|
|
1069
|
+
* offline render's output channels.
|
|
955
1070
|
*/
|
|
956
|
-
declare function trackChannelCount(track:
|
|
1071
|
+
declare function trackChannelCount(track: TrackChannelSource): number;
|
|
957
1072
|
/**
|
|
958
1073
|
* Clip width in pixels at a given samplesPerPixel.
|
|
959
1074
|
* Shared by Clip.tsx (container sizing) and ChannelWithProgress.tsx (progress overlay)
|
|
@@ -962,6 +1077,33 @@ declare function trackChannelCount(track: ClipTrack): number;
|
|
|
962
1077
|
*/
|
|
963
1078
|
declare function clipPixelWidth(startSample: number, durationSamples: number, samplesPerPixel: number): number;
|
|
964
1079
|
|
|
1080
|
+
/**
|
|
1081
|
+
* What a clip is: MIDI when it carries `midiNotes` (an empty array included),
|
|
1082
|
+
* audio otherwise (decoded, or peaks-only before the decode finishes).
|
|
1083
|
+
*/
|
|
1084
|
+
declare function clipKind(clip: Pick<AudioClip, 'midiNotes'>): TrackKind;
|
|
1085
|
+
/**
|
|
1086
|
+
* A track's kind. `kind` is required by the type; a track built in plain
|
|
1087
|
+
* JavaScript without it is read as audio.
|
|
1088
|
+
*/
|
|
1089
|
+
declare function trackKind(track: Pick<ClipTrack, 'kind'>): TrackKind;
|
|
1090
|
+
/**
|
|
1091
|
+
* Throws unless every clip on the track is of the track's kind. A track holds
|
|
1092
|
+
* audio clips or MIDI clips, never both (#756): the engine calls this wherever
|
|
1093
|
+
* a track enters it, so a mixed track cannot reach a playout adapter.
|
|
1094
|
+
*/
|
|
1095
|
+
declare function assertTrackKind(track: ClipTrack): void;
|
|
1096
|
+
/**
|
|
1097
|
+
* Splits a track by the kind of its clips, for data from before tracks had a
|
|
1098
|
+
* kind. A track whose clips are all of one kind comes back as one track with
|
|
1099
|
+
* that kind (an empty track keeps the kind it has). A track holding both comes
|
|
1100
|
+
* back as two: the audio track keeps the id, the MIDI track gets `midiTrackId`
|
|
1101
|
+
* (default: the id + '-midi') and copies of the name, volume, pan, mute and solo.
|
|
1102
|
+
*/
|
|
1103
|
+
declare function splitTrackByKind(track: Omit<ClipTrack, 'kind'> & {
|
|
1104
|
+
kind?: TrackKind;
|
|
1105
|
+
}, midiTrackId?: string): ClipTrack[];
|
|
1106
|
+
|
|
965
1107
|
/**
|
|
966
1108
|
* Canonical spectrogram canvas-ID contract.
|
|
967
1109
|
*
|
|
@@ -978,6 +1120,36 @@ declare function clipPixelWidth(startSample: number, durationSamples: number, sa
|
|
|
978
1120
|
* which `@waveform-playlist/ui-components` does not depend on). The format is a
|
|
979
1121
|
* pure string contract with no FFT/compute dependency.
|
|
980
1122
|
*/
|
|
1123
|
+
/**
|
|
1124
|
+
* What a spectrogram canvas registers with: the canvas handed over to the
|
|
1125
|
+
* worker and where it sits. Declared here, once, because the component that
|
|
1126
|
+
* registers (`SpectrogramChannel` in ui-components), the context that carries
|
|
1127
|
+
* the call (browser) and the provider that receives it (spectrogram) are three
|
|
1128
|
+
* packages that all depend on core.
|
|
1129
|
+
*
|
|
1130
|
+
* The receiver looks the track up from `clipId` and derives the canvas's pixel
|
|
1131
|
+
* offset from `chunkIndex`.
|
|
1132
|
+
*
|
|
1133
|
+
* A canvas registers with the range of the audio it is drawn for: the view
|
|
1134
|
+
* may draw a clip with a geometry the tracks do not have yet (a trim being
|
|
1135
|
+
* dragged), so the receiver draws `offsetSamples` / `durationSamples` from
|
|
1136
|
+
* here and falls back to the clip's own when a registration has none. A canvas
|
|
1137
|
+
* is registered once, so a new range means new canvases (`SpectrogramChannel`
|
|
1138
|
+
* keys them on it).
|
|
1139
|
+
*/
|
|
1140
|
+
interface SpectrogramCanvasRegistration {
|
|
1141
|
+
canvasId: string;
|
|
1142
|
+
canvas: OffscreenCanvas;
|
|
1143
|
+
clipId: string;
|
|
1144
|
+
channelIndex: number;
|
|
1145
|
+
chunkIndex: number;
|
|
1146
|
+
widthPx: number;
|
|
1147
|
+
heightPx: number;
|
|
1148
|
+
/** Where in the audio the drawn clip starts, in samples. Omitted: the clip's own. */
|
|
1149
|
+
offsetSamples?: number;
|
|
1150
|
+
/** How much of the audio the drawn clip covers, in samples. Omitted: the clip's own. */
|
|
1151
|
+
durationSamples?: number;
|
|
1152
|
+
}
|
|
981
1153
|
interface SpectrogramCanvasIdParts {
|
|
982
1154
|
clipId: string;
|
|
983
1155
|
channelIndex: number;
|
|
@@ -1063,17 +1235,31 @@ type KeyBinding = Pick<KeyboardShortcut, 'key' | 'ctrlKey' | 'shiftKey' | 'metaK
|
|
|
1063
1235
|
*/
|
|
1064
1236
|
declare function matchesKeyBinding(event: KeyboardEvent, binding: KeyBinding): boolean;
|
|
1065
1237
|
/**
|
|
1066
|
-
*
|
|
1067
|
-
*
|
|
1238
|
+
* True when the key already means something to the control that has focus, so
|
|
1239
|
+
* a global shortcut must leave it alone:
|
|
1240
|
+
*
|
|
1241
|
+
* - `<input>` (every type), `<textarea>`, `<select>` and contenteditable keep
|
|
1242
|
+
* every key;
|
|
1243
|
+
* - Escape belongs to an open modal dialog, wherever focus is;
|
|
1244
|
+
* - Space and Enter belong to a focused `<button>` or `<summary>`, and Enter to
|
|
1245
|
+
* a focused link.
|
|
1246
|
+
*
|
|
1247
|
+
* It makes no difference how the control got focus. A button the user clicked
|
|
1248
|
+
* still has focus, so Space activates it again, exactly as it does on any
|
|
1249
|
+
* other page; a shortcut only gets the key once focus is somewhere else.
|
|
1250
|
+
*
|
|
1251
|
+
* `handleKeyboardEvent` applies this itself. It is exported for listeners that
|
|
1252
|
+
* match keys on their own.
|
|
1068
1253
|
*/
|
|
1069
|
-
declare function
|
|
1254
|
+
declare function keyBelongsToFocusedControl(event: KeyboardEvent): boolean;
|
|
1070
1255
|
/**
|
|
1071
|
-
*
|
|
1256
|
+
* Handle a keyboard event against a list of shortcuts.
|
|
1257
|
+
* Pure function, no framework dependency.
|
|
1072
1258
|
*
|
|
1073
|
-
*
|
|
1074
|
-
*
|
|
1259
|
+
* Shortcuts do not fire for a key the focused control uses itself; see
|
|
1260
|
+
* `keyBelongsToFocusedControl`.
|
|
1075
1261
|
*/
|
|
1076
|
-
declare
|
|
1262
|
+
declare function handleKeyboardEvent(event: KeyboardEvent, shortcuts: KeyboardShortcut[], enabled: boolean): void;
|
|
1077
1263
|
|
|
1078
1264
|
type RangeSupport = 'supported' | 'unsupported' | 'unknown';
|
|
1079
1265
|
type FetchLike = (url: string, init?: RequestInit) => Promise<Response>;
|
|
@@ -1204,4 +1390,245 @@ declare function resolveAnnotationShortcuts(remap: AnnotationShortcutMap | null)
|
|
|
1204
1390
|
binding: KeyBinding;
|
|
1205
1391
|
}>;
|
|
1206
1392
|
|
|
1207
|
-
|
|
1393
|
+
/** Gains of the pan matrix: `out = [[ll, rl], [lr, rr]] · in`, where e.g.
|
|
1394
|
+
* `rl` is how much of the input's RIGHT channel reaches the LEFT output. */
|
|
1395
|
+
interface PanMatrix {
|
|
1396
|
+
ll: number;
|
|
1397
|
+
lr: number;
|
|
1398
|
+
rl: number;
|
|
1399
|
+
rr: number;
|
|
1400
|
+
}
|
|
1401
|
+
/**
|
|
1402
|
+
* The pan law for a track, chosen by the channel count of its SOURCE
|
|
1403
|
+
* material — exactly the two algorithms of the Web Audio `StereoPannerNode`.
|
|
1404
|
+
*
|
|
1405
|
+
* - Mono source — equal-power pan, θ = (pan + 1)·π/4: L × cos θ, R × sin θ.
|
|
1406
|
+
* For a mono signal (taken as L = R) that is the mono law, L = m·cos θ and
|
|
1407
|
+
* R = m·sin θ: −3 dB per side at centre. A stereo signal from the track's
|
|
1408
|
+
* effects is balanced by the same gains, so it stays stereo at the same
|
|
1409
|
+
* centre level as the dry signal.
|
|
1410
|
+
* - Stereo source — the stereo law: centre passes both channels at unity;
|
|
1411
|
+
* panning left folds the right channel into the left
|
|
1412
|
+
* (L + R·cos x, R·sin x with x = (pan + 1)·π/2), and symmetrically right.
|
|
1413
|
+
*
|
|
1414
|
+
* `pan` is clamped to −1 … 1; a non-finite value is treated as centre.
|
|
1415
|
+
*/
|
|
1416
|
+
declare function panMatrix(pan: number, sourceChannelCount: number): PanMatrix;
|
|
1417
|
+
/**
|
|
1418
|
+
* The part of an audio context the pan stage needs. Any `AudioContext` or
|
|
1419
|
+
* `OfflineAudioContext` satisfies it, and so does the `rawContext` behind
|
|
1420
|
+
* Tone.js (native or standardized-audio-context).
|
|
1421
|
+
*/
|
|
1422
|
+
type PanStageContext = Pick<BaseAudioContext, 'createGain' | 'createChannelSplitter' | 'createChannelMerger'>;
|
|
1423
|
+
/** A track's pan stage: `input → … → output`, with `setPan(-1 … 1)`. */
|
|
1424
|
+
interface PanStage {
|
|
1425
|
+
readonly input: AudioNode;
|
|
1426
|
+
readonly output: AudioNode;
|
|
1427
|
+
setPan(pan: number): void;
|
|
1428
|
+
/** Switch the pan law (1 = mono law, 2+ = stereo law), keeping the pan. */
|
|
1429
|
+
setSourceChannelCount(sourceChannelCount: number): void;
|
|
1430
|
+
/** Disconnect every node of the stage. */
|
|
1431
|
+
dispose(): void;
|
|
1432
|
+
}
|
|
1433
|
+
/**
|
|
1434
|
+
* Build the pan stage for a track whose source material has
|
|
1435
|
+
* `sourceChannelCount` channels (1 for mono clips and synth voices).
|
|
1436
|
+
*
|
|
1437
|
+
* Why this is not a `StereoPannerNode`: a track's pan stage is fed by its
|
|
1438
|
+
* effects chain (pre-fader inserts), whose channel layout is not the
|
|
1439
|
+
* source's. A `StereoPannerNode` picks its law from the layout it RECEIVES,
|
|
1440
|
+
* so a stereo effect on a mono track would jump ~3 dB at centre. And under
|
|
1441
|
+
* standardized-audio-context (Tone.js's default context) a panner's channel
|
|
1442
|
+
* mode cannot be changed at all (its bug #105), which pins a mono track's
|
|
1443
|
+
* panner to one channel.
|
|
1444
|
+
*
|
|
1445
|
+
* This stage is a 2×2 gain matrix built from plain gain, splitter and merger
|
|
1446
|
+
* nodes — none of which is restricted — so it behaves identically on every
|
|
1447
|
+
* context, always passes stereo through, and takes its law from the caller.
|
|
1448
|
+
*/
|
|
1449
|
+
declare function createPanStage(context: PanStageContext, pan: number, sourceChannelCount: number): PanStage;
|
|
1450
|
+
|
|
1451
|
+
type SourceState<V> = {
|
|
1452
|
+
status: 'pending';
|
|
1453
|
+
} | {
|
|
1454
|
+
status: 'loaded';
|
|
1455
|
+
value: V;
|
|
1456
|
+
} | {
|
|
1457
|
+
status: 'failed';
|
|
1458
|
+
error: Error;
|
|
1459
|
+
};
|
|
1460
|
+
interface SourceLoader<K, V> {
|
|
1461
|
+
/** Declare the whole set of keys that are wanted now. */
|
|
1462
|
+
setWanted(keys: Iterable<K>): void;
|
|
1463
|
+
/** Abort every load in flight. Wanted keys and loaded values are kept. */
|
|
1464
|
+
suspend(): void;
|
|
1465
|
+
/** Record a value the caller already holds as loaded. */
|
|
1466
|
+
provide(key: K, value: V): void;
|
|
1467
|
+
/** Start a failed key again. A no-op for any other state. */
|
|
1468
|
+
retry(key: K): void;
|
|
1469
|
+
/** `ValueSource` shape: a new Map object on every change. */
|
|
1470
|
+
subscribe(listener: (states: ReadonlyMap<K, SourceState<V>>) => void): () => void;
|
|
1471
|
+
getSnapshot(): ReadonlyMap<K, SourceState<V>>;
|
|
1472
|
+
}
|
|
1473
|
+
/**
|
|
1474
|
+
* Loads sources by key. One owner declares the whole set of wanted keys with
|
|
1475
|
+
* `setWanted`; a key is loaded once, kept while it stays wanted, and dropped
|
|
1476
|
+
* (its load aborted) when it leaves the set. Framework-free: read it with
|
|
1477
|
+
* `useSyncExternalStore(loader.subscribe, loader.getSnapshot)`.
|
|
1478
|
+
*
|
|
1479
|
+
* A rejection is ignored only when the loader aborted that load; a load that
|
|
1480
|
+
* rejects with an AbortError of its own is recorded as `failed` (`retry` restarts it).
|
|
1481
|
+
*/
|
|
1482
|
+
declare function createSourceLoader<K, V>(options: {
|
|
1483
|
+
load: (key: K, signal: AbortSignal) => Promise<V>;
|
|
1484
|
+
}): SourceLoader<K, V>;
|
|
1485
|
+
|
|
1486
|
+
interface AudioTrackOptions {
|
|
1487
|
+
/** Track id. Default: generated. An empty string counts as none. */
|
|
1488
|
+
id?: string;
|
|
1489
|
+
/** Id of the clip. Default: generated. An empty string counts as none. */
|
|
1490
|
+
clipId?: string;
|
|
1491
|
+
/** Track name. Default: the file name of `src` without its extension, else 'Untitled'. */
|
|
1492
|
+
name?: string;
|
|
1493
|
+
/** The audio to load. A string is a URL; a Blob or File is keyed by identity. */
|
|
1494
|
+
src?: ClipSource;
|
|
1495
|
+
/** Audio already in memory. With `src` too, the clip is an `AudioClip` that records `src`. */
|
|
1496
|
+
audioBuffer?: AudioBuffer;
|
|
1497
|
+
/** Pre-computed peaks. Without `src` or `audioBuffer`, the clip is built from these alone. */
|
|
1498
|
+
waveformData?: WaveformDataObject;
|
|
1499
|
+
/** Position on the timeline, in seconds. Default 0. */
|
|
1500
|
+
start?: number;
|
|
1501
|
+
/** Duration in seconds. Default: the whole source from `offset`. */
|
|
1502
|
+
duration?: number;
|
|
1503
|
+
/** Start within the source, in seconds. Default 0. */
|
|
1504
|
+
offset?: number;
|
|
1505
|
+
fadeIn?: Fade;
|
|
1506
|
+
fadeOut?: Fade;
|
|
1507
|
+
/** Clip gain. Default 1. */
|
|
1508
|
+
gain?: number;
|
|
1509
|
+
color?: string;
|
|
1510
|
+
muted?: boolean;
|
|
1511
|
+
soloed?: boolean;
|
|
1512
|
+
volume?: number;
|
|
1513
|
+
pan?: number;
|
|
1514
|
+
renderMode?: RenderMode;
|
|
1515
|
+
spectrogramConfig?: SpectrogramConfig;
|
|
1516
|
+
spectrogramColorMap?: ColorMapValue;
|
|
1517
|
+
}
|
|
1518
|
+
/**
|
|
1519
|
+
* Builds a track whose one clip names its audio. With `src` and no
|
|
1520
|
+
* `audioBuffer` the clip is a `LoadingClip` (audio not loaded yet); with
|
|
1521
|
+
* `audioBuffer`, or `waveformData` and no `src`, it is an `AudioClip` built now.
|
|
1522
|
+
* A duration that runs past the end of the audio is cut to it, with a warning.
|
|
1523
|
+
*/
|
|
1524
|
+
declare function audioTrack(options: AudioTrackOptions): ArrangementTrack;
|
|
1525
|
+
|
|
1526
|
+
/**
|
|
1527
|
+
* The effect registry shared by `<daw-editor>` and the React effects hooks:
|
|
1528
|
+
* one `registerEffect()` call makes a custom effect (an AudioWorklet, or any
|
|
1529
|
+
* chain of native nodes) available to both. Nothing here creates an audio
|
|
1530
|
+
* node; definitions are handed the context they must build on.
|
|
1531
|
+
*/
|
|
1532
|
+
/** Range/display metadata for one effect parameter. */
|
|
1533
|
+
interface EffectParamDef {
|
|
1534
|
+
min: number;
|
|
1535
|
+
max: number;
|
|
1536
|
+
step?: number;
|
|
1537
|
+
/** 's', 'ms', 'Hz', 'dB', '%' … */
|
|
1538
|
+
unit?: string;
|
|
1539
|
+
/** Display name for a parameter panel. Defaults to the parameter's key. */
|
|
1540
|
+
label?: string;
|
|
1541
|
+
}
|
|
1542
|
+
/**
|
|
1543
|
+
* A live, wired effect. `input`/`output` are the chain attachment points
|
|
1544
|
+
* (the same node for single-node effects). `applyParams` updates AudioParams
|
|
1545
|
+
* in place — the chain never rebuilds for parameter changes.
|
|
1546
|
+
*
|
|
1547
|
+
* The host owns every connection OUT of `output`: when it rewires the chain
|
|
1548
|
+
* it disconnects all of them. Do not connect `output` to anything inside the
|
|
1549
|
+
* effect (a feedback path, say); take such a tap from a node before it.
|
|
1550
|
+
*/
|
|
1551
|
+
interface NativeEffectInstance {
|
|
1552
|
+
input: AudioNode;
|
|
1553
|
+
output: AudioNode;
|
|
1554
|
+
applyParams: (params: Record<string, number>) => void;
|
|
1555
|
+
dispose?: () => void;
|
|
1556
|
+
/** Serializable snapshot of plugin-internal state (WAM getState). */
|
|
1557
|
+
getState?: () => Promise<unknown>;
|
|
1558
|
+
/** Builds the plugin's own GUI element (WAM createGui). GUI lifecycle is
|
|
1559
|
+
* independent of audio — hiding/destroying a GUI never stops processing. */
|
|
1560
|
+
createGui?: () => Promise<HTMLElement>;
|
|
1561
|
+
/** Releases a GUI element previously built by `createGui` (WAM destroyGui). */
|
|
1562
|
+
destroyGui?: (gui: HTMLElement) => void;
|
|
1563
|
+
/** Parameter metadata for the generic fallback panel (WAM getParameterInfo). */
|
|
1564
|
+
getParameterInfo?: () => Promise<unknown>;
|
|
1565
|
+
}
|
|
1566
|
+
/** A registered effect type. `create` must work on any BaseAudioContext so
|
|
1567
|
+
* the same definitions serve offline rendering. */
|
|
1568
|
+
interface NativeEffectDefinition {
|
|
1569
|
+
label: string;
|
|
1570
|
+
category: string;
|
|
1571
|
+
defaults: Record<string, number>;
|
|
1572
|
+
params: Record<string, EffectParamDef>;
|
|
1573
|
+
/** Name of the wet/dry param, when the effect has one. Bypass zeroes it
|
|
1574
|
+
* (storing the original); effects without one are bypassed by
|
|
1575
|
+
* disconnection. */
|
|
1576
|
+
wetParam?: string;
|
|
1577
|
+
/**
|
|
1578
|
+
* Optional async setup that must finish before `create` can run on a given
|
|
1579
|
+
* context — typically `audioContext.audioWorklet.addModule(url)` for an
|
|
1580
|
+
* AudioWorklet-backed effect. Worklet modules are context-bound, so this
|
|
1581
|
+
* runs once per context, including the OfflineAudioContext of every export
|
|
1582
|
+
* (which the consumer never sees). Hosts await it wherever they can: the
|
|
1583
|
+
* React hooks' `addEffect`, both surfaces' exports, `<daw-editor>`'s
|
|
1584
|
+
* `setEffectsState()`. `<daw-editor>`'s `addEffect()` is synchronous and
|
|
1585
|
+
* cannot — call `editor.prepareEffect(type)` first.
|
|
1586
|
+
*
|
|
1587
|
+
* Must be safe to run more than once on the same context: it runs again
|
|
1588
|
+
* after a failed attempt and when the type is re-registered.
|
|
1589
|
+
*/
|
|
1590
|
+
prepare?: (audioContext: BaseAudioContext) => Promise<void>;
|
|
1591
|
+
create: (audioContext: BaseAudioContext, params: Record<string, number>) => NativeEffectInstance;
|
|
1592
|
+
/**
|
|
1593
|
+
* Set by a host library on the effects of its own catalogue (dawcore's
|
|
1594
|
+
* `native-*`), never by an app. The registry is shared between hosts, and a
|
|
1595
|
+
* host lists its own catalogue plus what the app registered, not another
|
|
1596
|
+
* host's catalogue: the React effect picker leaves these out. The effect
|
|
1597
|
+
* can still be added by id anywhere.
|
|
1598
|
+
*/
|
|
1599
|
+
builtIn?: boolean;
|
|
1600
|
+
}
|
|
1601
|
+
/** Result of creating an effect via the registry. */
|
|
1602
|
+
interface CreatedNativeEffect {
|
|
1603
|
+
instance: NativeEffectInstance;
|
|
1604
|
+
params: Record<string, number>;
|
|
1605
|
+
wetParam?: string;
|
|
1606
|
+
}
|
|
1607
|
+
declare function registerEffect(type: string, definition: NativeEffectDefinition): void;
|
|
1608
|
+
/** Remove a registered type. Returns whether it was registered. Effects
|
|
1609
|
+
* already created from it keep working. */
|
|
1610
|
+
declare function unregisterEffect(type: string): boolean;
|
|
1611
|
+
/** A copy — mutating the returned map does not affect the registry. */
|
|
1612
|
+
declare function getEffectDefinitions(): Map<string, NativeEffectDefinition>;
|
|
1613
|
+
/**
|
|
1614
|
+
* Run a registered effect's `prepare` hook for one context, once. Concurrent
|
|
1615
|
+
* and later calls share the same run; a failed run is forgotten so the next
|
|
1616
|
+
* call retries. Resolves immediately for definitions without a hook, and for
|
|
1617
|
+
* unknown types (creating the effect reports those).
|
|
1618
|
+
*/
|
|
1619
|
+
declare function prepareEffect(type: string, audioContext: BaseAudioContext): Promise<void>;
|
|
1620
|
+
/**
|
|
1621
|
+
* Whether `type` has a prepare hook that has not completed on this context
|
|
1622
|
+
* for its CURRENT definition. Synchronous, so async callers can skip the
|
|
1623
|
+
* await (and stay synchronous) for the common case of effects without one.
|
|
1624
|
+
*/
|
|
1625
|
+
declare function needsPrepare(type: string, audioContext: BaseAudioContext): boolean;
|
|
1626
|
+
/**
|
|
1627
|
+
* Await a type's preparation until it holds for the definition registered
|
|
1628
|
+
* NOW. A type re-registered while its old definition was preparing would
|
|
1629
|
+
* otherwise reach `create` unprepared. Rejects with the hook's own error.
|
|
1630
|
+
*/
|
|
1631
|
+
declare function ensureEffectPrepared(type: string, audioContext: BaseAudioContext): Promise<void>;
|
|
1632
|
+
declare function createEffectInstance(type: string, audioContext: BaseAudioContext, params?: Record<string, number>): CreatedNativeEffect;
|
|
1633
|
+
|
|
1634
|
+
export { ANNOTATION_LINK_THRESHOLD_TICKS, type AnnotationAction, type AnnotationActionOptions, type AnnotationBoundaryOptions, type AnnotationBoundaryUpdate, type AnnotationData, type AnnotationEventMap, type AnnotationFormat, type AnnotationListOptions, type AnnotationShortcutAction, type AnnotationShortcutMap, type ArrangementTrack, type AudioBuffer$1 as AudioBuffer, type AudioClip, type AudioTrackOptions, type Bits, type ClipSource, type ClipTrack, type ColorMapEntry, type ColorMapName, type ColorMapValue, type CreateClipOptions, type CreateClipOptionsSeconds, type CreateClipOptionsTicks, type CreateTrackOptions, type CreatedNativeEffect, DEFAULT_ANNOTATION_SHORTCUTS, DEFAULT_SPECTROGRAM_COLOR_MAP, type EffectParamDef, type FFTSize, type Fade, type FadeConfig, type FadeType, type Gap, InteractionState, type KeyBinding, type KeyboardShortcut, LINK_THRESHOLD, type LoadingClip, MAX_CANVAS_WIDTH, METER_PEAK_DECAY, MIN_ANNOTATION_DURATION, MIN_PIXELS_PER_UNIT, type MeterEntry, type MeterLevels, type MeterReading, type MeterSource, type MicrophoneDeviceInfo, type MicrophoneEnumeration, type MidiNoteData, type MusicalTick, type MusicalTickData, type MusicalTickParams, type NativeEffectDefinition, type NativeEffectInstance, PPQN, type PanMatrix, type PanStage, type PanStageContext, type PeakData, type Peaks, type PlaylistConfig, type PlayoutState, type RangeSupport, type ReadMeterMessageParams, type RecordingProgress, type RecordingProgressSource, type RenderAnnotationItemProps, type RenderMode, SPECTROGRAM_DEFAULTS, type SnapTo, type SourceLoader, type SourceState, type SpectrogramCanvasIdParts, type SpectrogramCanvasRegistration, type SpectrogramComputeConfig, type SpectrogramConfig, type SpectrogramData, type SpectrogramDisplayConfig, type TickType, type TimeSelection, type Timeline, type Track, type TrackChannelSource, type TrackKind, type TrackSpectrogramOverrides, type ValueSource, type ValueSourceHandle, type WaveformConfig, type WaveformDataObject, type ZoomLevel, annotationMinDurationTicks, appendPeaks, appendToAudioBuffer, applyFadeIn, applyFadeOut, assertTrackKind, audibleLatencySamples, audioTrack, buildSpectrogramCanvasId, calculateDuration, carveClipRange, clipDurationTime, clipEndTime, clipKind, clipOffsetTime, clipPixelWidth, clipStartTime, clipsOverlap, computeMusicalTicks, concatenateAudioData, createAudioBuffer, createClip, createClipFromSeconds, createClipFromTicks, createEffectInstance, createPanStage, createSourceLoader, createTimeline, createTrack, createValueSource, dBToNormalized, detectMeterChanges, ensureEffectPrepared, enumerateMicrophones, exponentialCurve, findGaps, gainToDb, gainToNormalized, generateCurve, generatePeaks, getClipsAtSample, getClipsInRange, getEffectDefinitions, handleKeyboardEvent, isLoadingClip, keyBelongsToFocusedControl, linearCurve, logarithmicCurve, matchesKeyBinding, needsPrepare, normalizedToDb, panMatrix, parseSpectrogramCanvasId, pixelsToSamples, pixelsToSeconds, prepareEffect, probeRangeSupport, readMeterMessage, registerEffect, resolveAnnotationShortcuts, resolveRecordingOffsetSamples, sCurveCurve, samplesToPixels, samplesToSeconds, samplesToTicks, secondsToPixels, secondsToSamples, silentMeterLevels, snapTickToGrid, snapToGrid, snapToTicks, sortClipsByTime, splitTrackByKind, ticksPerBar, ticksPerBeat, ticksToBarBeat, ticksToSamples, trackChannelCount, trackKind, unregisterEffect, updateAnnotationBoundaries, watchMicrophoneDevices };
|