@waveform-playlist/engine 14.0.0-next.1 → 14.0.0-next.3
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 +57 -17
- package/dist/index.d.mts +88 -27
- package/dist/index.d.ts +88 -27
- package/dist/index.js +463 -148
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +463 -148
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ Used by `@waveform-playlist/browser` (the React provider) and `@dawcore/componen
|
|
|
10
10
|
- **Sample + tick timeline math** — integer samples for precision, ticks for tempo-independent positioning
|
|
11
11
|
- **The arrangement** — one object owns the tracks, the mix (volume, mute, solo and pan by track id) and the undo history; it needs no engine and outlives the engine that plays it
|
|
12
12
|
- **Loading audio** — a clip may name its audio (`src`: a URL, `Blob` or `File`) instead of carrying it; the arrangement fetches and decodes each source once, reports where each one is (`arrangement.sources`) and replaces the clip with a loaded one when the audio arrives
|
|
13
|
-
- **Undo/redo** — history for the
|
|
13
|
+
- **Undo/redo** — one history for the tracks, the clips and the mix: a fader move is an undo step, a whole drag is one step (`createMixerGesture()` from `@waveform-playlist/core`), and transactions group a clip drag
|
|
14
14
|
- **Selection, loop, and zoom state** — engine owns selection range, loop region, zoom level, and master volume
|
|
15
15
|
- **`statechange` events** — subscribe once and mirror a single `EngineState` snapshot into any UI framework
|
|
16
16
|
- **Adapter-pluggable playback** — bring your own `PlayoutAdapter` (Tone.js, native Web Audio, or a custom backend); the engine runs headless without one
|
|
@@ -111,9 +111,36 @@ A `setTempo` places every clip that has a tick on the tick grid of the engine it
|
|
|
111
111
|
|
|
112
112
|
A different tempo is not converted. A tick is the musical position, so an engine built at another tempo than the one the ticks were made under has clips whose `startSample` and `startTick` disagree until the next `setTempo`, which moves `startSample` to follow the tick. Clips added under the new engine get their ticks at its tempo and keep their place at that `setTempo`, while the older ones move.
|
|
113
113
|
|
|
114
|
-
An arrangement plays through one engine at a time: building a second engine on it while the first has not been disposed logs a warning. Two engines alive on one arrangement is unsupported, in particular with different `ppqn`: the second engine's time base replaces the first's, so ticks the first engine gives later are computed with the second engine's. The engine's own `undoLimit` option is ignored, with a warning, when an arrangement is passed; set it on `createArrangement({ undoLimit })`. The `arrangement` option accepts only an arrangement made by `createArrangement()`. The engine recognises one by a versioned `Symbol.for` key and not by `instanceof`, so an arrangement made by another installed copy of this package (an app and a library that pin different versions) is accepted as long as both copies use the same key version.
|
|
114
|
+
An arrangement plays through one engine at a time: building a second engine on it while the first has not been disposed logs a warning. Two engines alive on one arrangement is unsupported, in particular with different `ppqn`: the second engine's time base replaces the first's, so ticks the first engine gives later are computed with the second engine's. The engine's own `undoLimit` option is ignored, with a warning, when an arrangement is passed; set it on `createArrangement({ undoLimit })`. The `arrangement` option accepts only an arrangement made by `createArrangement()`. The engine recognises one by a versioned `Symbol.for` key and not by `instanceof`, so an arrangement made by another installed copy of this package (an app and a library that pin different versions) is accepted as long as both copies use the same key version. The key version changed with the mixer undo steps (`/v2`) and again with `addTrack`'s `index` (`/v3`): an engine and an arrangement from copies on either side of such a change refuse each other.
|
|
115
115
|
|
|
116
|
-
The engine's track, clip, mixer and history methods call the arrangement's, so a change made through either reaches the adapter and emits `statechange`. The arrangement's `removeTrack` also takes `{ undoable: false }` (no undo step, and the track is taken out of every undo and redo state, so no undo brings it back: for a dropped file that could not be decoded), and its `updateTrack` takes a function of the current track: `arrangement.updateTrack(id, (track) => ({ ...track, name: 'Bass' }))`.
|
|
116
|
+
The engine's track, clip, mixer, recording and history methods call the arrangement's, so a change made through either reaches the adapter and emits `statechange`. The arrangement's `removeTrack` also takes `{ undoable: false }` (no undo step, and the track is taken out of every undo and redo state, so no undo brings it back: for a dropped file that could not be decoded), and its `updateTrack` takes a function of the current track: `arrangement.updateTrack(id, (track) => ({ ...track, name: 'Bass' }))`.
|
|
117
|
+
|
|
118
|
+
### Mixer moves are undo steps
|
|
119
|
+
|
|
120
|
+
`setTrackVolume`, `setTrackMute`, `setTrackSolo` and `setTrackPan` (on the arrangement and on the engine) are undo steps: an undo puts the fader back. Their last argument, `options?: MixerChangeOptions`, says how a change goes into the history:
|
|
121
|
+
|
|
122
|
+
- nothing: each call is a step of its own;
|
|
123
|
+
- `{ gesture: id }`: calls with the same id, one after another, are one step (a fader drag from press to release);
|
|
124
|
+
- `{ undoable: false }`: no step. The value is written into every saved state as well, so no undo or redo brings back an older one (automation, a value that is not the user's edit). It wins over `gesture`.
|
|
125
|
+
|
|
126
|
+
A call that changes nothing (the value the track already has, or a track that is not in the current tracks) makes no step and no `statechange`. Inside an open transaction an undoable mixer change is part of it, and an abort takes it back; an `{ undoable: false }` change is written into the transaction's base too, so an abort keeps it. Undo, redo and an abort bring back the mix of the state they return to.
|
|
127
|
+
|
|
128
|
+
`createMixerGesture()` from `@waveform-playlist/core` makes the ids for one control. Use one per slider:
|
|
129
|
+
|
|
130
|
+
```typescript
|
|
131
|
+
import { createMixerGesture } from '@waveform-playlist/core';
|
|
132
|
+
|
|
133
|
+
const gesture = createMixerGesture();
|
|
134
|
+
const detach = gesture.attach(slider); // ends the gesture on the slider's own events
|
|
135
|
+
slider.addEventListener('input', () => {
|
|
136
|
+
engine.setTrackVolume('track-1', slider.valueAsNumber, { gesture: gesture.id });
|
|
137
|
+
});
|
|
138
|
+
// gesture.end() ends it by hand; detach() removes the listeners
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
`attach` ends the gesture on the input's `change` (the end of a pointer drag), except while an arrow, Page Up/Down, Home or End key is held: then on that key's `keyup`, so a held key is one step. A `blur` ends it too. Mute and solo buttons need no helper: each click is a step.
|
|
142
|
+
|
|
143
|
+
**The take's mute.** `setTrackRecording(trackId, recording)` (arrangement and engine) marks the track a take is recording onto, and `arrangement.recordingTrackIds` is the set of those ids (`engine.recordingTrackIds` reads the same set, for example to disable that track's mute control). Such a track plays muted for the length of the take: `engine.getState().tracks` and the adapter have it muted, while its mute in `getMixer()` stays as it is and comes back when the take ends. It is not an undo step, and undo, redo, an abort, `setTracks` and `clearHistory` do not change which tracks are recording. It is not a record-arm: it lasts only while a take is recorded.
|
|
117
144
|
|
|
118
145
|
### Loading audio
|
|
119
146
|
|
|
@@ -211,8 +238,8 @@ Rules that hold for the engine and the arrangement alike:
|
|
|
211
238
|
|
|
212
239
|
- **Nothing handed out is a copy.** `arrangement.getTracks()`, `engine.getState().tracks` and the tracks an adapter receives are shared with the undo history. Never write to the array, a track or a clip: copy first (`{ ...track, clips: [...] }`) and pass the copy to `updateTrack`. `arrangement.updateTrack`, given a track object or a function, keeps each clip object the track already holds and copies every other clip, so the clips you did not replace are the same objects afterwards. Outside production builds (`process.env.NODE_ENV` is not `'production'`; a page that loads the module with no bundler, and so has no `process`, counts as production) the tracks array, each track, its `clips` array and each clip are frozen, so a write throws in strict code (every module is strict). What a clip refers to (its `AudioBuffer`, peaks, fades, notes) is not frozen. Tracks are copied on their way in, so the objects you pass stay yours.
|
|
213
240
|
- **A change replaces only what changed.** The tracks array and the changed track and clip objects are new; every other track is the same object as before, so a comparison by identity finds what changed. The exception is `setTracks`, which copies every track it is given: after it no track is the object it was.
|
|
214
|
-
- **The mix is separate from the tracks.** A track's own `volume`, `muted`, `soloed` and `pan` fields are the values it enters with. They seed its mixer entry when its id has none. `setTracks` keeps the mix of an id that is in the tracks it replaces, `updateTrack` keeps the track's mix (also when it gives the track a new id
|
|
215
|
-
- **Undo, redo and an aborted transaction restore tracks
|
|
241
|
+
- **The mix is separate from the tracks.** A track's own `volume`, `muted`, `soloed` and `pan` fields are the values it enters with. They seed its mixer entry when its id has none. `setTracks` keeps the mix of an id that is in the tracks it replaces, and `updateTrack` keeps the track's mix (also when it gives the track a new id); in those cases the fields are not read. `addTrack` seeds the entry from the new track's fields, also for the id of a track removed earlier. `getMixer()` holds the entries of the current tracks; each undo and redo state keeps its own. Change the mix with `setTrackVolume`, `setTrackMute`, `setTrackSolo` and `setTrackPan`, which act on a track that is in the current tracks. `engine.getState().tracks` and the tracks an adapter receives carry the current mix in those fields; `arrangement.getTracks()` does not (read `getMixer()`).
|
|
242
|
+
- **Undo, redo and an aborted transaction restore the tracks, the clips and the mix** of the state they return to. Undoing a `removeTrack` brings the track back with the mix it had, and undoing an `updateTrack` that gave a track a new id brings back the old id with the mix it had then.
|
|
216
243
|
- **Ids are unique.** `setTracks`, `addTrack` and `updateTrack` throw an `Error` for a duplicate track id, for two clips with one id on the same track, and for a track whose clips do not match its `kind` (a loading clip is an audio clip), before anything changes.
|
|
217
244
|
- **Without an engine** clips are given no `startTick`, and a clip that came with one loses it when it is moved, trimmed on the left or split. Every clip without a tick, in the current tracks and in every undo and redo state, gets one from its `startSample` when an engine attaches. The shortest a clip may be is 0.1 s at the clip's own sample rate.
|
|
218
245
|
|
|
@@ -228,7 +255,7 @@ class PlaylistEngine {
|
|
|
228
255
|
|
|
229
256
|
// Tracks
|
|
230
257
|
setTracks(tracks: readonly ClipTrack[]): void; // replaces every track, clears the undo history
|
|
231
|
-
addTrack(track: ClipTrack): void;
|
|
258
|
+
addTrack(track: ClipTrack, options?: AddTrackOptions): void; // { index }: where it enters (default: the end)
|
|
232
259
|
removeTrack(trackId: string): void;
|
|
233
260
|
updateTrack(trackId: string, track?: ClipTrack): void; // with a track: replace it; without: send the current one to the adapter again
|
|
234
261
|
reorderTrack(trackId: string, toIndex: number): void;
|
|
@@ -255,16 +282,18 @@ class PlaylistEngine {
|
|
|
255
282
|
setLoopRegion(start: number, end: number): void;
|
|
256
283
|
setLoopEnabled(enabled: boolean): void;
|
|
257
284
|
setMasterVolume(volume: number): void;
|
|
258
|
-
setTrackVolume(trackId: string, volume: number): void;
|
|
259
|
-
setTrackMute(trackId: string, muted: boolean): void;
|
|
260
|
-
setTrackSolo(trackId: string, soloed: boolean): void;
|
|
261
|
-
setTrackPan(trackId: string, pan: number): void;
|
|
285
|
+
setTrackVolume(trackId: string, volume: number, options?: MixerChangeOptions): void; // an undo step
|
|
286
|
+
setTrackMute(trackId: string, muted: boolean, options?: MixerChangeOptions): void;
|
|
287
|
+
setTrackSolo(trackId: string, soloed: boolean, options?: MixerChangeOptions): void;
|
|
288
|
+
setTrackPan(trackId: string, pan: number, options?: MixerChangeOptions): void;
|
|
289
|
+
setTrackRecording(trackId: string, recording: boolean): void; // plays muted during the take; not an undo step
|
|
290
|
+
readonly recordingTrackIds: ReadonlySet<string>; // the arrangement's set (the same object), read-only
|
|
262
291
|
zoomIn(): void;
|
|
263
292
|
zoomOut(): void;
|
|
264
293
|
setZoomLevel(samplesPerPixel: number): void;
|
|
265
294
|
setTempo(bpm: number, atTick?: number): void;
|
|
266
295
|
|
|
267
|
-
// Undo/redo (tracks
|
|
296
|
+
// Undo/redo (tracks, clips and the mix)
|
|
268
297
|
undo(): void; // with a transaction open: aborts it first
|
|
269
298
|
redo(): void; // with a transaction open: aborts it first
|
|
270
299
|
clearHistory(): void;
|
|
@@ -304,7 +333,7 @@ interface Arrangement {
|
|
|
304
333
|
|
|
305
334
|
// tracks
|
|
306
335
|
setTracks(tracks: readonly ArrangementTrack[]): void;
|
|
307
|
-
addTrack(track: ArrangementTrack): void;
|
|
336
|
+
addTrack(track: ArrangementTrack, options?: AddTrackOptions): void; // { index }: where it enters (default: the end)
|
|
308
337
|
removeTrack(trackId: string, options?: RemoveTrackOptions): void;
|
|
309
338
|
updateTrack(
|
|
310
339
|
trackId: string,
|
|
@@ -319,11 +348,15 @@ interface Arrangement {
|
|
|
319
348
|
getClipBounds(trackId: string, clipId: string): ClipBounds | null;
|
|
320
349
|
constrainTrimDelta(trackId: string, clipId: string, boundary: 'left' | 'right', deltaSamples: number): number;
|
|
321
350
|
|
|
322
|
-
// mixer
|
|
323
|
-
setTrackVolume(trackId: string, volume: number): void;
|
|
324
|
-
setTrackMute(trackId: string, muted: boolean): void;
|
|
325
|
-
setTrackSolo(trackId: string, soloed: boolean): void;
|
|
326
|
-
setTrackPan(trackId: string, pan: number): void;
|
|
351
|
+
// mixer (each call is an undo step; see MixerChangeOptions)
|
|
352
|
+
setTrackVolume(trackId: string, volume: number, options?: MixerChangeOptions): void;
|
|
353
|
+
setTrackMute(trackId: string, muted: boolean, options?: MixerChangeOptions): void;
|
|
354
|
+
setTrackSolo(trackId: string, soloed: boolean, options?: MixerChangeOptions): void;
|
|
355
|
+
setTrackPan(trackId: string, pan: number, options?: MixerChangeOptions): void;
|
|
356
|
+
|
|
357
|
+
// the take's mute: the tracks a take is recording onto (outside the history)
|
|
358
|
+
readonly recordingTrackIds: ReadonlySet<string>;
|
|
359
|
+
setTrackRecording(trackId: string, recording: boolean): void;
|
|
327
360
|
|
|
328
361
|
// history
|
|
329
362
|
readonly canUndo: boolean;
|
|
@@ -340,6 +373,13 @@ interface Arrangement {
|
|
|
340
373
|
retry(src: ClipSource): void; // start a source whose load failed again
|
|
341
374
|
}
|
|
342
375
|
|
|
376
|
+
interface MixerChangeOptions {
|
|
377
|
+
/** Changes with the same id, one after another, are one undo step. */
|
|
378
|
+
gesture?: string;
|
|
379
|
+
/** Not an undo step: the value is written into every saved state as well. */
|
|
380
|
+
undoable?: false;
|
|
381
|
+
}
|
|
382
|
+
|
|
343
383
|
interface ArrangementSourceState {
|
|
344
384
|
status: 'pending' | 'loaded' | 'failed';
|
|
345
385
|
error?: Error; // when failed
|
package/dist/index.d.mts
CHANGED
|
@@ -212,10 +212,11 @@ interface ArrangementSourcesValue {
|
|
|
212
212
|
* as pure functions over an immutable Map.
|
|
213
213
|
*
|
|
214
214
|
* The values live here and not on the track objects, so a fader move
|
|
215
|
-
* replaces no track
|
|
216
|
-
*
|
|
217
|
-
*
|
|
218
|
-
* not read while it
|
|
215
|
+
* replaces no track. The current Map holds an entry for each current track;
|
|
216
|
+
* each saved state of the history holds its own Map (#843). A track's own
|
|
217
|
+
* `volume` / `muted` / `soloed` / `pan` fields are the values it ENTERED
|
|
218
|
+
* with; they seed its entry when its id has none, and are not read while it
|
|
219
|
+
* has one.
|
|
219
220
|
*/
|
|
220
221
|
|
|
221
222
|
interface TrackMixerValues {
|
|
@@ -244,6 +245,21 @@ interface RemoveTrackOptions {
|
|
|
244
245
|
*/
|
|
245
246
|
undoable?: boolean;
|
|
246
247
|
}
|
|
248
|
+
/** Options of `addTrack`. */
|
|
249
|
+
interface AddTrackOptions {
|
|
250
|
+
/**
|
|
251
|
+
* Where the track enters: its index in the new order (cut to a whole
|
|
252
|
+
* number, then held between 0 and the number of tracks). Left out: at the end.
|
|
253
|
+
*/
|
|
254
|
+
index?: number;
|
|
255
|
+
}
|
|
256
|
+
/** How a mixer setter's change goes into the undo history. */
|
|
257
|
+
interface MixerChangeOptions {
|
|
258
|
+
/** Changes with the same id, one after another, are one undo step. */
|
|
259
|
+
gesture?: string;
|
|
260
|
+
/** Not an undo step: the value is written into every saved state as well. */
|
|
261
|
+
undoable?: false;
|
|
262
|
+
}
|
|
247
263
|
/**
|
|
248
264
|
* The owner of the tracks, of the mix and of the undo history. Everything
|
|
249
265
|
* else reads it (`getTracks`, `getMixer`, `subscribe`) and changes it by
|
|
@@ -260,11 +276,15 @@ interface Arrangement {
|
|
|
260
276
|
*/
|
|
261
277
|
getTracks(): readonly ArrangementTrack[];
|
|
262
278
|
/**
|
|
263
|
-
* The current volume, mute, solo and pan by track id
|
|
264
|
-
*
|
|
265
|
-
*
|
|
266
|
-
*
|
|
267
|
-
*
|
|
279
|
+
* The current volume, mute, solo and pan by track id (the stored mute: the
|
|
280
|
+
* mute of the track a take is recording onto is not forced here). The same
|
|
281
|
+
* Map until a value changes, a track with a new id enters, entries of
|
|
282
|
+
* tracks that are gone are dropped, or an undo, a redo or an abort brings
|
|
283
|
+
* back another state's Map. `mixerVersion` counts the value changes of
|
|
284
|
+
* current tracks, and also the start or end of a take's mute on a current
|
|
285
|
+
* track, which leaves this Map as it is; an entry seeded, carried or
|
|
286
|
+
* dropped with its track is not counted. A track's own mixer fields in
|
|
287
|
+
* `getTracks()` are the values it entered with; the current ones are here.
|
|
268
288
|
*/
|
|
269
289
|
getMixer(): ReadonlyMap<string, TrackMixerValues>;
|
|
270
290
|
/**
|
|
@@ -283,7 +303,8 @@ interface Arrangement {
|
|
|
283
303
|
* transaction. An id that is in the tracks being replaced keeps its mix.
|
|
284
304
|
*/
|
|
285
305
|
setTracks(tracks: readonly ArrangementTrack[]): void;
|
|
286
|
-
|
|
306
|
+
/** Add a track: an undo step. Throws for an `index` that is not a finite number. */
|
|
307
|
+
addTrack(track: ArrangementTrack, options?: AddTrackOptions): void;
|
|
287
308
|
removeTrack(trackId: string, options?: RemoveTrackOptions): void;
|
|
288
309
|
/**
|
|
289
310
|
* Replace a track, with a track or with a function of the current one.
|
|
@@ -301,10 +322,26 @@ interface Arrangement {
|
|
|
301
322
|
splitClip(trackId: string, clipId: string, atSample: number): void;
|
|
302
323
|
getClipBounds(trackId: string, clipId: string): ClipBounds | null;
|
|
303
324
|
constrainTrimDelta(trackId: string, clipId: string, boundary: 'left' | 'right', deltaSamples: number): number;
|
|
304
|
-
setTrackVolume(trackId: string, volume: number): void;
|
|
305
|
-
setTrackMute(trackId: string, muted: boolean): void;
|
|
306
|
-
setTrackSolo(trackId: string, soloed: boolean): void;
|
|
307
|
-
setTrackPan(trackId: string, pan: number): void;
|
|
325
|
+
setTrackVolume(trackId: string, volume: number, options?: MixerChangeOptions): void;
|
|
326
|
+
setTrackMute(trackId: string, muted: boolean, options?: MixerChangeOptions): void;
|
|
327
|
+
setTrackSolo(trackId: string, soloed: boolean, options?: MixerChangeOptions): void;
|
|
328
|
+
setTrackPan(trackId: string, pan: number, options?: MixerChangeOptions): void;
|
|
329
|
+
/**
|
|
330
|
+
* The ids of the tracks a take is recording onto. The same Set until one
|
|
331
|
+
* is added or removed; never write to it.
|
|
332
|
+
*/
|
|
333
|
+
readonly recordingTrackIds: ReadonlySet<string>;
|
|
334
|
+
/**
|
|
335
|
+
* Mark a track as the one a take is recording onto, or clear it when the
|
|
336
|
+
* take ends. Such a track plays muted: the engine's `getState().tracks`
|
|
337
|
+
* and its adapter have it muted, while its mute in `getMixer()` stays as
|
|
338
|
+
* it is and comes back when the take ends. This is not an undo step, and
|
|
339
|
+
* undo, redo, an abort, `setTracks` and `clearHistory` do not change which
|
|
340
|
+
* tracks are recording. An id that is not in the current tracks is
|
|
341
|
+
* recorded too, and mutes nothing until a track of that id enters. The
|
|
342
|
+
* same value changes nothing.
|
|
343
|
+
*/
|
|
344
|
+
setTrackRecording(trackId: string, recording: boolean): void;
|
|
308
345
|
readonly canUndo: boolean;
|
|
309
346
|
readonly canRedo: boolean;
|
|
310
347
|
/** With a transaction open: aborts it first. */
|
|
@@ -315,7 +352,7 @@ interface Arrangement {
|
|
|
315
352
|
/** Changes made until `commitTransaction` are one undo step. */
|
|
316
353
|
beginTransaction(): void;
|
|
317
354
|
commitTransaction(): void;
|
|
318
|
-
/** Put the tracks back as they were when the transaction began. */
|
|
355
|
+
/** Put the tracks and the mix back as they were when the transaction began. */
|
|
319
356
|
abortTransaction(): void;
|
|
320
357
|
/**
|
|
321
358
|
* Where each source the clips name is: pending, loaded or failed (also a
|
|
@@ -359,12 +396,20 @@ interface CreateArrangementOptions {
|
|
|
359
396
|
*
|
|
360
397
|
* The keys carry a version. An engine that finds the time-base key treats
|
|
361
398
|
* the object as an arrangement of this version and uses it BY NAME: the
|
|
362
|
-
* whole public `Arrangement` interface (every track, clip, mixer
|
|
363
|
-
* method it delegates to, `getTracks`, `getMixer`,
|
|
364
|
-
*
|
|
365
|
-
*
|
|
366
|
-
* and `
|
|
367
|
-
*
|
|
399
|
+
* whole public `Arrangement` interface (every track, clip, mixer, recording
|
|
400
|
+
* and history method it delegates to, `getTracks`, `getMixer`,
|
|
401
|
+
* `recordingTrackIds`,
|
|
402
|
+
* the two version counters) and the internal `onChange(listener)` (with the
|
|
403
|
+
* `ArrangementChange` and `ArrangementVersions` shapes of this version),
|
|
404
|
+
* `recomputeStartSamples()` and `undoLimit`. A change to any of that needs a
|
|
405
|
+
* new key, so that copies which do not agree refuse each other instead of
|
|
406
|
+
* misreading each other.
|
|
407
|
+
*
|
|
408
|
+
* v2 (#843): the mixer setters take options and are undo steps, the history
|
|
409
|
+
* holds the mix (`'restoreMix'`), and the arrangement has the take's mute
|
|
410
|
+
* (`setTrackRecording`, `recordingTrackIds`, `'recording'`).
|
|
411
|
+
*
|
|
412
|
+
* v3 (#848): `addTrack(track, { index })` puts the track at a place in the order.
|
|
368
413
|
*/
|
|
369
414
|
|
|
370
415
|
type GetDecodeContext = () => Promise<BaseAudioContext>;
|
|
@@ -601,7 +646,7 @@ declare class PlaylistEngine {
|
|
|
601
646
|
abortTransaction(): void;
|
|
602
647
|
getState(): EngineState;
|
|
603
648
|
setTracks(tracks: readonly ClipTrack[]): void;
|
|
604
|
-
addTrack(track: ClipTrack): void;
|
|
649
|
+
addTrack(track: ClipTrack, options?: AddTrackOptions): void;
|
|
605
650
|
removeTrack(trackId: string): void;
|
|
606
651
|
/**
|
|
607
652
|
* Move a track to a new position in the track order. Purely organizational —
|
|
@@ -664,10 +709,26 @@ declare class PlaylistEngine {
|
|
|
664
709
|
setSelection(start: number, end: number): void;
|
|
665
710
|
setLoopRegion(start: number, end: number): void;
|
|
666
711
|
setLoopEnabled(enabled: boolean): void;
|
|
667
|
-
setTrackVolume(trackId: string, volume: number): void;
|
|
668
|
-
setTrackMute(trackId: string, muted: boolean): void;
|
|
669
|
-
setTrackSolo(trackId: string, soloed: boolean): void;
|
|
670
|
-
setTrackPan(trackId: string, pan: number): void;
|
|
712
|
+
setTrackVolume(trackId: string, volume: number, options?: MixerChangeOptions): void;
|
|
713
|
+
setTrackMute(trackId: string, muted: boolean, options?: MixerChangeOptions): void;
|
|
714
|
+
setTrackSolo(trackId: string, soloed: boolean, options?: MixerChangeOptions): void;
|
|
715
|
+
setTrackPan(trackId: string, pan: number, options?: MixerChangeOptions): void;
|
|
716
|
+
/**
|
|
717
|
+
* Mark a track as the one a take is recording onto, or clear it when the
|
|
718
|
+
* take ends: the arrangement's `setTrackRecording`. That track plays muted
|
|
719
|
+
* (here and in the adapter) while its mute in the mix stays as it is; the
|
|
720
|
+
* take's mute is not an undo step. The arrangement's `'recording'`
|
|
721
|
+
* announcement brings the adapter in step, so there is no adapter call of
|
|
722
|
+
* its own here; a disposed engine changes the arrangement only.
|
|
723
|
+
*/
|
|
724
|
+
setTrackRecording(trackId: string, recording: boolean): void;
|
|
725
|
+
/**
|
|
726
|
+
* The tracks a take is recording onto, read from the arrangement (the
|
|
727
|
+
* owner; no copy). The same set object until it changes; never write to
|
|
728
|
+
* it, use `setTrackRecording`. Such a track plays muted, so a UI can
|
|
729
|
+
* disable its mute control while the id is in the set.
|
|
730
|
+
*/
|
|
731
|
+
get recordingTrackIds(): ReadonlySet<string>;
|
|
671
732
|
zoomIn(): void;
|
|
672
733
|
zoomOut(): void;
|
|
673
734
|
setZoomLevel(samplesPerPixel: number): void;
|
|
@@ -707,4 +768,4 @@ declare class PlaylistEngine {
|
|
|
707
768
|
private _emitStateChange;
|
|
708
769
|
}
|
|
709
770
|
|
|
710
|
-
export { type Arrangement, type ArrangementSourceState, type ArrangementSourcesValue, type ClipBounds, type CreateArrangementOptions, type EngineEvents, type EngineState, type LoadSource, PlaylistEngine, type PlaylistEngineOptions, type PlayoutAdapter, type RemoveTrackOptions, type TrackMixerValues, attachDecodeContext, calculateDuration, calculateSplitPoint, calculateViewportBounds, calculateZoomScrollPosition, canSplitAt, clampSeekPosition, constrainBoundaryTrim, constrainClipDrag, createArrangement, defaultLoadSource, findClosestZoomIndex, getVisibleChunkIndices, shouldUpdateViewport, splitClip };
|
|
771
|
+
export { type AddTrackOptions, type Arrangement, type ArrangementSourceState, type ArrangementSourcesValue, type ClipBounds, type CreateArrangementOptions, type EngineEvents, type EngineState, type LoadSource, type MixerChangeOptions, PlaylistEngine, type PlaylistEngineOptions, type PlayoutAdapter, type RemoveTrackOptions, type TrackMixerValues, attachDecodeContext, calculateDuration, calculateSplitPoint, calculateViewportBounds, calculateZoomScrollPosition, canSplitAt, clampSeekPosition, constrainBoundaryTrim, constrainClipDrag, createArrangement, defaultLoadSource, findClosestZoomIndex, getVisibleChunkIndices, shouldUpdateViewport, splitClip };
|
package/dist/index.d.ts
CHANGED
|
@@ -212,10 +212,11 @@ interface ArrangementSourcesValue {
|
|
|
212
212
|
* as pure functions over an immutable Map.
|
|
213
213
|
*
|
|
214
214
|
* The values live here and not on the track objects, so a fader move
|
|
215
|
-
* replaces no track
|
|
216
|
-
*
|
|
217
|
-
*
|
|
218
|
-
* not read while it
|
|
215
|
+
* replaces no track. The current Map holds an entry for each current track;
|
|
216
|
+
* each saved state of the history holds its own Map (#843). A track's own
|
|
217
|
+
* `volume` / `muted` / `soloed` / `pan` fields are the values it ENTERED
|
|
218
|
+
* with; they seed its entry when its id has none, and are not read while it
|
|
219
|
+
* has one.
|
|
219
220
|
*/
|
|
220
221
|
|
|
221
222
|
interface TrackMixerValues {
|
|
@@ -244,6 +245,21 @@ interface RemoveTrackOptions {
|
|
|
244
245
|
*/
|
|
245
246
|
undoable?: boolean;
|
|
246
247
|
}
|
|
248
|
+
/** Options of `addTrack`. */
|
|
249
|
+
interface AddTrackOptions {
|
|
250
|
+
/**
|
|
251
|
+
* Where the track enters: its index in the new order (cut to a whole
|
|
252
|
+
* number, then held between 0 and the number of tracks). Left out: at the end.
|
|
253
|
+
*/
|
|
254
|
+
index?: number;
|
|
255
|
+
}
|
|
256
|
+
/** How a mixer setter's change goes into the undo history. */
|
|
257
|
+
interface MixerChangeOptions {
|
|
258
|
+
/** Changes with the same id, one after another, are one undo step. */
|
|
259
|
+
gesture?: string;
|
|
260
|
+
/** Not an undo step: the value is written into every saved state as well. */
|
|
261
|
+
undoable?: false;
|
|
262
|
+
}
|
|
247
263
|
/**
|
|
248
264
|
* The owner of the tracks, of the mix and of the undo history. Everything
|
|
249
265
|
* else reads it (`getTracks`, `getMixer`, `subscribe`) and changes it by
|
|
@@ -260,11 +276,15 @@ interface Arrangement {
|
|
|
260
276
|
*/
|
|
261
277
|
getTracks(): readonly ArrangementTrack[];
|
|
262
278
|
/**
|
|
263
|
-
* The current volume, mute, solo and pan by track id
|
|
264
|
-
*
|
|
265
|
-
*
|
|
266
|
-
*
|
|
267
|
-
*
|
|
279
|
+
* The current volume, mute, solo and pan by track id (the stored mute: the
|
|
280
|
+
* mute of the track a take is recording onto is not forced here). The same
|
|
281
|
+
* Map until a value changes, a track with a new id enters, entries of
|
|
282
|
+
* tracks that are gone are dropped, or an undo, a redo or an abort brings
|
|
283
|
+
* back another state's Map. `mixerVersion` counts the value changes of
|
|
284
|
+
* current tracks, and also the start or end of a take's mute on a current
|
|
285
|
+
* track, which leaves this Map as it is; an entry seeded, carried or
|
|
286
|
+
* dropped with its track is not counted. A track's own mixer fields in
|
|
287
|
+
* `getTracks()` are the values it entered with; the current ones are here.
|
|
268
288
|
*/
|
|
269
289
|
getMixer(): ReadonlyMap<string, TrackMixerValues>;
|
|
270
290
|
/**
|
|
@@ -283,7 +303,8 @@ interface Arrangement {
|
|
|
283
303
|
* transaction. An id that is in the tracks being replaced keeps its mix.
|
|
284
304
|
*/
|
|
285
305
|
setTracks(tracks: readonly ArrangementTrack[]): void;
|
|
286
|
-
|
|
306
|
+
/** Add a track: an undo step. Throws for an `index` that is not a finite number. */
|
|
307
|
+
addTrack(track: ArrangementTrack, options?: AddTrackOptions): void;
|
|
287
308
|
removeTrack(trackId: string, options?: RemoveTrackOptions): void;
|
|
288
309
|
/**
|
|
289
310
|
* Replace a track, with a track or with a function of the current one.
|
|
@@ -301,10 +322,26 @@ interface Arrangement {
|
|
|
301
322
|
splitClip(trackId: string, clipId: string, atSample: number): void;
|
|
302
323
|
getClipBounds(trackId: string, clipId: string): ClipBounds | null;
|
|
303
324
|
constrainTrimDelta(trackId: string, clipId: string, boundary: 'left' | 'right', deltaSamples: number): number;
|
|
304
|
-
setTrackVolume(trackId: string, volume: number): void;
|
|
305
|
-
setTrackMute(trackId: string, muted: boolean): void;
|
|
306
|
-
setTrackSolo(trackId: string, soloed: boolean): void;
|
|
307
|
-
setTrackPan(trackId: string, pan: number): void;
|
|
325
|
+
setTrackVolume(trackId: string, volume: number, options?: MixerChangeOptions): void;
|
|
326
|
+
setTrackMute(trackId: string, muted: boolean, options?: MixerChangeOptions): void;
|
|
327
|
+
setTrackSolo(trackId: string, soloed: boolean, options?: MixerChangeOptions): void;
|
|
328
|
+
setTrackPan(trackId: string, pan: number, options?: MixerChangeOptions): void;
|
|
329
|
+
/**
|
|
330
|
+
* The ids of the tracks a take is recording onto. The same Set until one
|
|
331
|
+
* is added or removed; never write to it.
|
|
332
|
+
*/
|
|
333
|
+
readonly recordingTrackIds: ReadonlySet<string>;
|
|
334
|
+
/**
|
|
335
|
+
* Mark a track as the one a take is recording onto, or clear it when the
|
|
336
|
+
* take ends. Such a track plays muted: the engine's `getState().tracks`
|
|
337
|
+
* and its adapter have it muted, while its mute in `getMixer()` stays as
|
|
338
|
+
* it is and comes back when the take ends. This is not an undo step, and
|
|
339
|
+
* undo, redo, an abort, `setTracks` and `clearHistory` do not change which
|
|
340
|
+
* tracks are recording. An id that is not in the current tracks is
|
|
341
|
+
* recorded too, and mutes nothing until a track of that id enters. The
|
|
342
|
+
* same value changes nothing.
|
|
343
|
+
*/
|
|
344
|
+
setTrackRecording(trackId: string, recording: boolean): void;
|
|
308
345
|
readonly canUndo: boolean;
|
|
309
346
|
readonly canRedo: boolean;
|
|
310
347
|
/** With a transaction open: aborts it first. */
|
|
@@ -315,7 +352,7 @@ interface Arrangement {
|
|
|
315
352
|
/** Changes made until `commitTransaction` are one undo step. */
|
|
316
353
|
beginTransaction(): void;
|
|
317
354
|
commitTransaction(): void;
|
|
318
|
-
/** Put the tracks back as they were when the transaction began. */
|
|
355
|
+
/** Put the tracks and the mix back as they were when the transaction began. */
|
|
319
356
|
abortTransaction(): void;
|
|
320
357
|
/**
|
|
321
358
|
* Where each source the clips name is: pending, loaded or failed (also a
|
|
@@ -359,12 +396,20 @@ interface CreateArrangementOptions {
|
|
|
359
396
|
*
|
|
360
397
|
* The keys carry a version. An engine that finds the time-base key treats
|
|
361
398
|
* the object as an arrangement of this version and uses it BY NAME: the
|
|
362
|
-
* whole public `Arrangement` interface (every track, clip, mixer
|
|
363
|
-
* method it delegates to, `getTracks`, `getMixer`,
|
|
364
|
-
*
|
|
365
|
-
*
|
|
366
|
-
* and `
|
|
367
|
-
*
|
|
399
|
+
* whole public `Arrangement` interface (every track, clip, mixer, recording
|
|
400
|
+
* and history method it delegates to, `getTracks`, `getMixer`,
|
|
401
|
+
* `recordingTrackIds`,
|
|
402
|
+
* the two version counters) and the internal `onChange(listener)` (with the
|
|
403
|
+
* `ArrangementChange` and `ArrangementVersions` shapes of this version),
|
|
404
|
+
* `recomputeStartSamples()` and `undoLimit`. A change to any of that needs a
|
|
405
|
+
* new key, so that copies which do not agree refuse each other instead of
|
|
406
|
+
* misreading each other.
|
|
407
|
+
*
|
|
408
|
+
* v2 (#843): the mixer setters take options and are undo steps, the history
|
|
409
|
+
* holds the mix (`'restoreMix'`), and the arrangement has the take's mute
|
|
410
|
+
* (`setTrackRecording`, `recordingTrackIds`, `'recording'`).
|
|
411
|
+
*
|
|
412
|
+
* v3 (#848): `addTrack(track, { index })` puts the track at a place in the order.
|
|
368
413
|
*/
|
|
369
414
|
|
|
370
415
|
type GetDecodeContext = () => Promise<BaseAudioContext>;
|
|
@@ -601,7 +646,7 @@ declare class PlaylistEngine {
|
|
|
601
646
|
abortTransaction(): void;
|
|
602
647
|
getState(): EngineState;
|
|
603
648
|
setTracks(tracks: readonly ClipTrack[]): void;
|
|
604
|
-
addTrack(track: ClipTrack): void;
|
|
649
|
+
addTrack(track: ClipTrack, options?: AddTrackOptions): void;
|
|
605
650
|
removeTrack(trackId: string): void;
|
|
606
651
|
/**
|
|
607
652
|
* Move a track to a new position in the track order. Purely organizational —
|
|
@@ -664,10 +709,26 @@ declare class PlaylistEngine {
|
|
|
664
709
|
setSelection(start: number, end: number): void;
|
|
665
710
|
setLoopRegion(start: number, end: number): void;
|
|
666
711
|
setLoopEnabled(enabled: boolean): void;
|
|
667
|
-
setTrackVolume(trackId: string, volume: number): void;
|
|
668
|
-
setTrackMute(trackId: string, muted: boolean): void;
|
|
669
|
-
setTrackSolo(trackId: string, soloed: boolean): void;
|
|
670
|
-
setTrackPan(trackId: string, pan: number): void;
|
|
712
|
+
setTrackVolume(trackId: string, volume: number, options?: MixerChangeOptions): void;
|
|
713
|
+
setTrackMute(trackId: string, muted: boolean, options?: MixerChangeOptions): void;
|
|
714
|
+
setTrackSolo(trackId: string, soloed: boolean, options?: MixerChangeOptions): void;
|
|
715
|
+
setTrackPan(trackId: string, pan: number, options?: MixerChangeOptions): void;
|
|
716
|
+
/**
|
|
717
|
+
* Mark a track as the one a take is recording onto, or clear it when the
|
|
718
|
+
* take ends: the arrangement's `setTrackRecording`. That track plays muted
|
|
719
|
+
* (here and in the adapter) while its mute in the mix stays as it is; the
|
|
720
|
+
* take's mute is not an undo step. The arrangement's `'recording'`
|
|
721
|
+
* announcement brings the adapter in step, so there is no adapter call of
|
|
722
|
+
* its own here; a disposed engine changes the arrangement only.
|
|
723
|
+
*/
|
|
724
|
+
setTrackRecording(trackId: string, recording: boolean): void;
|
|
725
|
+
/**
|
|
726
|
+
* The tracks a take is recording onto, read from the arrangement (the
|
|
727
|
+
* owner; no copy). The same set object until it changes; never write to
|
|
728
|
+
* it, use `setTrackRecording`. Such a track plays muted, so a UI can
|
|
729
|
+
* disable its mute control while the id is in the set.
|
|
730
|
+
*/
|
|
731
|
+
get recordingTrackIds(): ReadonlySet<string>;
|
|
671
732
|
zoomIn(): void;
|
|
672
733
|
zoomOut(): void;
|
|
673
734
|
setZoomLevel(samplesPerPixel: number): void;
|
|
@@ -707,4 +768,4 @@ declare class PlaylistEngine {
|
|
|
707
768
|
private _emitStateChange;
|
|
708
769
|
}
|
|
709
770
|
|
|
710
|
-
export { type Arrangement, type ArrangementSourceState, type ArrangementSourcesValue, type ClipBounds, type CreateArrangementOptions, type EngineEvents, type EngineState, type LoadSource, PlaylistEngine, type PlaylistEngineOptions, type PlayoutAdapter, type RemoveTrackOptions, type TrackMixerValues, attachDecodeContext, calculateDuration, calculateSplitPoint, calculateViewportBounds, calculateZoomScrollPosition, canSplitAt, clampSeekPosition, constrainBoundaryTrim, constrainClipDrag, createArrangement, defaultLoadSource, findClosestZoomIndex, getVisibleChunkIndices, shouldUpdateViewport, splitClip };
|
|
771
|
+
export { type AddTrackOptions, type Arrangement, type ArrangementSourceState, type ArrangementSourcesValue, type ClipBounds, type CreateArrangementOptions, type EngineEvents, type EngineState, type LoadSource, type MixerChangeOptions, PlaylistEngine, type PlaylistEngineOptions, type PlayoutAdapter, type RemoveTrackOptions, type TrackMixerValues, attachDecodeContext, calculateDuration, calculateSplitPoint, calculateViewportBounds, calculateZoomScrollPosition, canSplitAt, clampSeekPosition, constrainBoundaryTrim, constrainClipDrag, createArrangement, defaultLoadSource, findClosestZoomIndex, getVisibleChunkIndices, shouldUpdateViewport, splitClip };
|