@waveform-playlist/engine 14.0.0-next.3 → 14.0.0-next.5
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 +12 -8
- package/dist/index.d.mts +38 -7
- package/dist/index.d.ts +38 -7
- package/dist/index.js +130 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +130 -22
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -113,7 +113,7 @@ A different tempo is not converted. A tick is the musical position, so an engine
|
|
|
113
113
|
|
|
114
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, 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' }))`.
|
|
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), `removeClip(trackId, clipId, options?)` removes a clip (an undo step; `{ undoable: false }` takes it out of every state in the same way), and its `updateTrack` takes a function of the current track: `arrangement.updateTrack(id, (track) => ({ ...track, name: 'Bass' }))`.
|
|
117
117
|
|
|
118
118
|
### Mixer moves are undo steps
|
|
119
119
|
|
|
@@ -188,7 +188,7 @@ What happens to a loading clip:
|
|
|
188
188
|
- **It is held like any clip.** It is copied on its way in, is the same object through every operation on its track, keeps its place among the track's clips and is part of the undo steps. It has no `startTick`.
|
|
189
189
|
- **It cannot be edited.** `moveClip`, `trimClip` and `splitClip` on it log a warning (`… is still loading and cannot be edited until its audio has loaded`) and change nothing; `getClipBounds` returns `null` and `constrainTrimDelta` returns 0. Loaded clips do not collide with it.
|
|
190
190
|
- **It is audio.** A loading clip on a `kind: 'midi'` track is refused: `createArrangement({ tracks })`, `setTracks`, `addTrack` and `updateTrack` throw the error for a track whose clips do not match its kind, and nothing changes.
|
|
191
|
-
- **An engine does not play or report it.** The tracks an adapter is sent and `engine.getState().tracks` are each track without its loading clips, and `getState().duration` counts loaded clips only. A change that leaves a track's loaded clips (the same objects in the same order) and its own fields as they were makes no adapter call for that track; the `statechange` is still emitted. `engine.updateTrack(id)` always sends.
|
|
191
|
+
- **An engine does not play or report it.** The tracks an adapter is sent and `engine.getState().tracks` are each track without its loading clips, and `getState().duration` counts loaded clips only. A change that leaves a track's loaded clips (the same objects in the same order) and its own fields other than the view fields (`TRACK_VIEW_FIELDS`) as they were makes no adapter call for that track; the `statechange` is still emitted. `engine.updateTrack(id)` always sends.
|
|
192
192
|
|
|
193
193
|
Which sources are loaded: every source a loading clip names in the current tracks, in an undo or redo state or in the base of an open transaction. So an undo never fetches a source again, and a source is dropped (its load aborted, its audio let go) when no state names it any more; named again later, it is fetched again. A loaded clip that carries both `src` and `audioBuffer` counts too: its buffer is used for that source and nothing is fetched. A loaded clip with `src` and no `audioBuffer` is not fetched and is not in `sources`: it never gets audio from the arrangement.
|
|
194
194
|
|
|
@@ -236,7 +236,7 @@ One context at a time: attaching a second while one is attached logs a warning a
|
|
|
236
236
|
|
|
237
237
|
Rules that hold for the engine and the arrangement alike:
|
|
238
238
|
|
|
239
|
-
- **Nothing handed out is a copy.** `arrangement.getTracks()
|
|
239
|
+
- **Nothing handed out is a copy.** `arrangement.getTracks()` and `engine.getState().tracks` are shared with the undo history. The tracks an adapter receives are copies without the view fields (core's `TRACK_VIEW_FIELDS`, typed `PlayoutTrack`) that share these clips, frozen the same way. 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.
|
|
240
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.
|
|
241
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
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.
|
|
@@ -308,7 +308,7 @@ class PlaylistEngine {
|
|
|
308
308
|
on<K extends keyof EngineEvents>(event: K, listener: EngineEvents[K]): void;
|
|
309
309
|
off<K extends keyof EngineEvents>(event: K, listener: EngineEvents[K]): void; // 'statechange' | 'play' | 'pause' | 'stop'
|
|
310
310
|
|
|
311
|
-
dispose(): void;
|
|
311
|
+
dispose(options?: { keepAdapter?: boolean }): void; // keepAdapter: stop, leave the adapter undisposed
|
|
312
312
|
}
|
|
313
313
|
```
|
|
314
314
|
|
|
@@ -335,6 +335,7 @@ interface Arrangement {
|
|
|
335
335
|
setTracks(tracks: readonly ArrangementTrack[]): void;
|
|
336
336
|
addTrack(track: ArrangementTrack, options?: AddTrackOptions): void; // { index }: where it enters (default: the end)
|
|
337
337
|
removeTrack(trackId: string, options?: RemoveTrackOptions): void;
|
|
338
|
+
removeClip(trackId: string, clipId: string, options?: RemoveClipOptions): void; // an undo step; undoable: false takes it out of every state
|
|
338
339
|
updateTrack(
|
|
339
340
|
trackId: string,
|
|
340
341
|
next: ArrangementTrack | ((track: ArrangementTrack) => ArrangementTrack)
|
|
@@ -344,7 +345,7 @@ interface Arrangement {
|
|
|
344
345
|
// clips (a clip that is still loading cannot be edited)
|
|
345
346
|
moveClip(trackId: string, clipId: string, deltaSamples: number): number;
|
|
346
347
|
trimClip(trackId: string, clipId: string, boundary: 'left' | 'right', deltaSamples: number): void;
|
|
347
|
-
splitClip(trackId: string, clipId: string, atSample: number): void;
|
|
348
|
+
splitClip(trackId: string, clipId: string, atSample: number): void; // the left half keeps clipId
|
|
348
349
|
getClipBounds(trackId: string, clipId: string): ClipBounds | null;
|
|
349
350
|
constrainTrimDelta(trackId: string, clipId: string, boundary: 'left' | 'right', deltaSamples: number): number;
|
|
350
351
|
|
|
@@ -418,10 +419,13 @@ interface PlayoutAdapter {
|
|
|
418
419
|
setPpqn?(ppqn: number): void;
|
|
419
420
|
|
|
420
421
|
init(): Promise<void>;
|
|
421
|
-
|
|
422
|
-
|
|
422
|
+
// PlayoutTrack (core): a ClipTrack without the view fields of TRACK_VIEW_FIELDS (name,
|
|
423
|
+
// color, height, renderMode, spectrogramConfig, spectrogramColorMap); a change of those
|
|
424
|
+
// alone makes no adapter call. Read the tracks, never write to them. Loaded clips only
|
|
425
|
+
setTracks(tracks: readonly PlayoutTrack[]): void;
|
|
426
|
+
addTrack?(track: PlayoutTrack): void;
|
|
423
427
|
removeTrack?(trackId: string): void;
|
|
424
|
-
updateTrack?(trackId: string, track:
|
|
428
|
+
updateTrack?(trackId: string, track: PlayoutTrack): void;
|
|
425
429
|
|
|
426
430
|
play(startTime: number, endTime?: number): void;
|
|
427
431
|
pause(): void;
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AudioClip, ClipTrack, ClipSource, ArrangementTrack, ValueSource } from '@waveform-playlist/core';
|
|
1
|
+
import { AudioClip, ClipTrack, ClipSource, ArrangementTrack, ValueSource, PlayoutTrack } from '@waveform-playlist/core';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Clip Operations
|
|
@@ -49,6 +49,7 @@ declare function calculateSplitPoint(splitSample: number, samplesPerPixel: numbe
|
|
|
49
49
|
*
|
|
50
50
|
* The left clip retains the original fadeIn; the right clip retains the original fadeOut.
|
|
51
51
|
* Both clips share the same waveformData reference and the same `src`.
|
|
52
|
+
* The left clip keeps the original's `id`; the right clip gets a new one.
|
|
52
53
|
* If the clip has a name, suffixes " (1)" and " (2)" are appended.
|
|
53
54
|
*
|
|
54
55
|
* @param clip - The clip to split
|
|
@@ -245,6 +246,15 @@ interface RemoveTrackOptions {
|
|
|
245
246
|
*/
|
|
246
247
|
undoable?: boolean;
|
|
247
248
|
}
|
|
249
|
+
/** Options of `removeClip`. */
|
|
250
|
+
interface RemoveClipOptions {
|
|
251
|
+
/**
|
|
252
|
+
* `false`: the removal is not an undo step, and the clip is also taken out
|
|
253
|
+
* of every undo and redo state, so no undo or redo brings it back (a
|
|
254
|
+
* `<daw-clip>` the page removed while its track was detached, #848).
|
|
255
|
+
*/
|
|
256
|
+
undoable?: boolean;
|
|
257
|
+
}
|
|
248
258
|
/** Options of `addTrack`. */
|
|
249
259
|
interface AddTrackOptions {
|
|
250
260
|
/**
|
|
@@ -306,6 +316,11 @@ interface Arrangement {
|
|
|
306
316
|
/** Add a track: an undo step. Throws for an `index` that is not a finite number. */
|
|
307
317
|
addTrack(track: ArrangementTrack, options?: AddTrackOptions): void;
|
|
308
318
|
removeTrack(trackId: string, options?: RemoveTrackOptions): void;
|
|
319
|
+
/**
|
|
320
|
+
* Remove a clip from a track: an undo step. With `undoable: false` there is
|
|
321
|
+
* no step, and the clip is also taken out of every undo and redo state.
|
|
322
|
+
*/
|
|
323
|
+
removeClip(trackId: string, clipId: string, options?: RemoveClipOptions): void;
|
|
309
324
|
/**
|
|
310
325
|
* Replace a track, with a track or with a function of the current one.
|
|
311
326
|
* Changes nothing for an id no track has (a track object is still checked
|
|
@@ -413,6 +428,8 @@ interface CreateArrangementOptions {
|
|
|
413
428
|
*/
|
|
414
429
|
|
|
415
430
|
type GetDecodeContext = () => Promise<BaseAudioContext>;
|
|
431
|
+
/** True for an arrangement made by `createArrangement()`, of this copy of the package or another. */
|
|
432
|
+
declare function isArrangement(value: unknown): boolean;
|
|
416
433
|
/**
|
|
417
434
|
* Give an arrangement the audio context its sources are decoded with.
|
|
418
435
|
* Nothing is fetched before; the sources its clips name are pending
|
|
@@ -446,14 +463,18 @@ interface PlayoutAdapter {
|
|
|
446
463
|
/** Set the adapter's tick resolution. Optional — adapters with fixed PPQN ignore this. */
|
|
447
464
|
setPpqn?(ppqn: number): void;
|
|
448
465
|
init(): Promise<void>;
|
|
449
|
-
/**
|
|
450
|
-
|
|
466
|
+
/**
|
|
467
|
+
* Copies of the engine's tracks without their view fields (core's
|
|
468
|
+
* `TRACK_VIEW_FIELDS`), sharing its clips: read them, never write to them.
|
|
469
|
+
* A change of view fields alone causes no adapter call.
|
|
470
|
+
*/
|
|
471
|
+
setTracks(tracks: readonly PlayoutTrack[]): void;
|
|
451
472
|
/** Incrementally add a single track without rebuilding the entire playout. */
|
|
452
|
-
addTrack?(track:
|
|
473
|
+
addTrack?(track: PlayoutTrack): void;
|
|
453
474
|
/** Incrementally remove a single track without rebuilding the entire playout. */
|
|
454
475
|
removeTrack?(trackId: string): void;
|
|
455
476
|
/** Update a single track's clips (removes old, adds new). */
|
|
456
|
-
updateTrack?(trackId: string, track:
|
|
477
|
+
updateTrack?(trackId: string, track: PlayoutTrack): void;
|
|
457
478
|
play(startTime: number, endTime?: number): void;
|
|
458
479
|
pause(): void;
|
|
459
480
|
stop(): void;
|
|
@@ -556,6 +577,16 @@ interface EngineState {
|
|
|
556
577
|
/** Whether redo is available. */
|
|
557
578
|
canRedo: boolean;
|
|
558
579
|
}
|
|
580
|
+
/** Options of `PlaylistEngine.dispose()`. */
|
|
581
|
+
interface EngineDisposeOptions {
|
|
582
|
+
/**
|
|
583
|
+
* Leave the adapter undisposed (#848), for a host that plays another
|
|
584
|
+
* arrangement on the same adapter next: playback is stopped, the engine
|
|
585
|
+
* lets go of its arrangement and of the adapter's `onPlaybackEnded`, and a
|
|
586
|
+
* new engine can be built with the adapter.
|
|
587
|
+
*/
|
|
588
|
+
keepAdapter?: boolean;
|
|
589
|
+
}
|
|
559
590
|
/**
|
|
560
591
|
* Configuration options for PlaylistEngine constructor.
|
|
561
592
|
*/
|
|
@@ -734,7 +765,7 @@ declare class PlaylistEngine {
|
|
|
734
765
|
setZoomLevel(samplesPerPixel: number): void;
|
|
735
766
|
on<K extends EventName>(event: K, listener: EngineEvents[K]): void;
|
|
736
767
|
off<K extends EventName>(event: K, listener: EngineEvents[K]): void;
|
|
737
|
-
dispose(): void;
|
|
768
|
+
dispose(options?: EngineDisposeOptions): void;
|
|
738
769
|
/** Runs a mixer setter on the arrangement. True when a value changed. */
|
|
739
770
|
private _mixerChanged;
|
|
740
771
|
/**
|
|
@@ -768,4 +799,4 @@ declare class PlaylistEngine {
|
|
|
768
799
|
private _emitStateChange;
|
|
769
800
|
}
|
|
770
801
|
|
|
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 };
|
|
802
|
+
export { type AddTrackOptions, type Arrangement, type ArrangementSourceState, type ArrangementSourcesValue, type ClipBounds, type CreateArrangementOptions, type EngineDisposeOptions, type EngineEvents, type EngineState, type LoadSource, type MixerChangeOptions, PlaylistEngine, type PlaylistEngineOptions, type PlayoutAdapter, type RemoveClipOptions, type RemoveTrackOptions, type TrackMixerValues, attachDecodeContext, calculateDuration, calculateSplitPoint, calculateViewportBounds, calculateZoomScrollPosition, canSplitAt, clampSeekPosition, constrainBoundaryTrim, constrainClipDrag, createArrangement, defaultLoadSource, findClosestZoomIndex, getVisibleChunkIndices, isArrangement, shouldUpdateViewport, splitClip };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AudioClip, ClipTrack, ClipSource, ArrangementTrack, ValueSource } from '@waveform-playlist/core';
|
|
1
|
+
import { AudioClip, ClipTrack, ClipSource, ArrangementTrack, ValueSource, PlayoutTrack } from '@waveform-playlist/core';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Clip Operations
|
|
@@ -49,6 +49,7 @@ declare function calculateSplitPoint(splitSample: number, samplesPerPixel: numbe
|
|
|
49
49
|
*
|
|
50
50
|
* The left clip retains the original fadeIn; the right clip retains the original fadeOut.
|
|
51
51
|
* Both clips share the same waveformData reference and the same `src`.
|
|
52
|
+
* The left clip keeps the original's `id`; the right clip gets a new one.
|
|
52
53
|
* If the clip has a name, suffixes " (1)" and " (2)" are appended.
|
|
53
54
|
*
|
|
54
55
|
* @param clip - The clip to split
|
|
@@ -245,6 +246,15 @@ interface RemoveTrackOptions {
|
|
|
245
246
|
*/
|
|
246
247
|
undoable?: boolean;
|
|
247
248
|
}
|
|
249
|
+
/** Options of `removeClip`. */
|
|
250
|
+
interface RemoveClipOptions {
|
|
251
|
+
/**
|
|
252
|
+
* `false`: the removal is not an undo step, and the clip is also taken out
|
|
253
|
+
* of every undo and redo state, so no undo or redo brings it back (a
|
|
254
|
+
* `<daw-clip>` the page removed while its track was detached, #848).
|
|
255
|
+
*/
|
|
256
|
+
undoable?: boolean;
|
|
257
|
+
}
|
|
248
258
|
/** Options of `addTrack`. */
|
|
249
259
|
interface AddTrackOptions {
|
|
250
260
|
/**
|
|
@@ -306,6 +316,11 @@ interface Arrangement {
|
|
|
306
316
|
/** Add a track: an undo step. Throws for an `index` that is not a finite number. */
|
|
307
317
|
addTrack(track: ArrangementTrack, options?: AddTrackOptions): void;
|
|
308
318
|
removeTrack(trackId: string, options?: RemoveTrackOptions): void;
|
|
319
|
+
/**
|
|
320
|
+
* Remove a clip from a track: an undo step. With `undoable: false` there is
|
|
321
|
+
* no step, and the clip is also taken out of every undo and redo state.
|
|
322
|
+
*/
|
|
323
|
+
removeClip(trackId: string, clipId: string, options?: RemoveClipOptions): void;
|
|
309
324
|
/**
|
|
310
325
|
* Replace a track, with a track or with a function of the current one.
|
|
311
326
|
* Changes nothing for an id no track has (a track object is still checked
|
|
@@ -413,6 +428,8 @@ interface CreateArrangementOptions {
|
|
|
413
428
|
*/
|
|
414
429
|
|
|
415
430
|
type GetDecodeContext = () => Promise<BaseAudioContext>;
|
|
431
|
+
/** True for an arrangement made by `createArrangement()`, of this copy of the package or another. */
|
|
432
|
+
declare function isArrangement(value: unknown): boolean;
|
|
416
433
|
/**
|
|
417
434
|
* Give an arrangement the audio context its sources are decoded with.
|
|
418
435
|
* Nothing is fetched before; the sources its clips name are pending
|
|
@@ -446,14 +463,18 @@ interface PlayoutAdapter {
|
|
|
446
463
|
/** Set the adapter's tick resolution. Optional — adapters with fixed PPQN ignore this. */
|
|
447
464
|
setPpqn?(ppqn: number): void;
|
|
448
465
|
init(): Promise<void>;
|
|
449
|
-
/**
|
|
450
|
-
|
|
466
|
+
/**
|
|
467
|
+
* Copies of the engine's tracks without their view fields (core's
|
|
468
|
+
* `TRACK_VIEW_FIELDS`), sharing its clips: read them, never write to them.
|
|
469
|
+
* A change of view fields alone causes no adapter call.
|
|
470
|
+
*/
|
|
471
|
+
setTracks(tracks: readonly PlayoutTrack[]): void;
|
|
451
472
|
/** Incrementally add a single track without rebuilding the entire playout. */
|
|
452
|
-
addTrack?(track:
|
|
473
|
+
addTrack?(track: PlayoutTrack): void;
|
|
453
474
|
/** Incrementally remove a single track without rebuilding the entire playout. */
|
|
454
475
|
removeTrack?(trackId: string): void;
|
|
455
476
|
/** Update a single track's clips (removes old, adds new). */
|
|
456
|
-
updateTrack?(trackId: string, track:
|
|
477
|
+
updateTrack?(trackId: string, track: PlayoutTrack): void;
|
|
457
478
|
play(startTime: number, endTime?: number): void;
|
|
458
479
|
pause(): void;
|
|
459
480
|
stop(): void;
|
|
@@ -556,6 +577,16 @@ interface EngineState {
|
|
|
556
577
|
/** Whether redo is available. */
|
|
557
578
|
canRedo: boolean;
|
|
558
579
|
}
|
|
580
|
+
/** Options of `PlaylistEngine.dispose()`. */
|
|
581
|
+
interface EngineDisposeOptions {
|
|
582
|
+
/**
|
|
583
|
+
* Leave the adapter undisposed (#848), for a host that plays another
|
|
584
|
+
* arrangement on the same adapter next: playback is stopped, the engine
|
|
585
|
+
* lets go of its arrangement and of the adapter's `onPlaybackEnded`, and a
|
|
586
|
+
* new engine can be built with the adapter.
|
|
587
|
+
*/
|
|
588
|
+
keepAdapter?: boolean;
|
|
589
|
+
}
|
|
559
590
|
/**
|
|
560
591
|
* Configuration options for PlaylistEngine constructor.
|
|
561
592
|
*/
|
|
@@ -734,7 +765,7 @@ declare class PlaylistEngine {
|
|
|
734
765
|
setZoomLevel(samplesPerPixel: number): void;
|
|
735
766
|
on<K extends EventName>(event: K, listener: EngineEvents[K]): void;
|
|
736
767
|
off<K extends EventName>(event: K, listener: EngineEvents[K]): void;
|
|
737
|
-
dispose(): void;
|
|
768
|
+
dispose(options?: EngineDisposeOptions): void;
|
|
738
769
|
/** Runs a mixer setter on the arrangement. True when a value changed. */
|
|
739
770
|
private _mixerChanged;
|
|
740
771
|
/**
|
|
@@ -768,4 +799,4 @@ declare class PlaylistEngine {
|
|
|
768
799
|
private _emitStateChange;
|
|
769
800
|
}
|
|
770
801
|
|
|
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 };
|
|
802
|
+
export { type AddTrackOptions, type Arrangement, type ArrangementSourceState, type ArrangementSourcesValue, type ClipBounds, type CreateArrangementOptions, type EngineDisposeOptions, type EngineEvents, type EngineState, type LoadSource, type MixerChangeOptions, PlaylistEngine, type PlaylistEngineOptions, type PlayoutAdapter, type RemoveClipOptions, type RemoveTrackOptions, type TrackMixerValues, attachDecodeContext, calculateDuration, calculateSplitPoint, calculateViewportBounds, calculateZoomScrollPosition, canSplitAt, clampSeekPosition, constrainBoundaryTrim, constrainClipDrag, createArrangement, defaultLoadSource, findClosestZoomIndex, getVisibleChunkIndices, isArrangement, shouldUpdateViewport, splitClip };
|
package/dist/index.js
CHANGED
|
@@ -34,6 +34,7 @@ __export(index_exports, {
|
|
|
34
34
|
defaultLoadSource: () => defaultLoadSource,
|
|
35
35
|
findClosestZoomIndex: () => findClosestZoomIndex,
|
|
36
36
|
getVisibleChunkIndices: () => getVisibleChunkIndices,
|
|
37
|
+
isArrangement: () => isArrangement,
|
|
37
38
|
shouldUpdateViewport: () => shouldUpdateViewport,
|
|
38
39
|
splitClip: () => splitClip
|
|
39
40
|
});
|
|
@@ -87,20 +88,23 @@ function splitClip(clip, splitSample) {
|
|
|
87
88
|
const rightDuration = clip.durationSamples - leftDuration;
|
|
88
89
|
const leftName = clip.name ? `${clip.name} (1)` : void 0;
|
|
89
90
|
const rightName = clip.name ? `${clip.name} (2)` : void 0;
|
|
90
|
-
const left =
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
91
|
+
const left = {
|
|
92
|
+
...(0, import_core.createClip)({
|
|
93
|
+
startSample: clip.startSample,
|
|
94
|
+
durationSamples: leftDuration,
|
|
95
|
+
offsetSamples: clip.offsetSamples,
|
|
96
|
+
sampleRate: clip.sampleRate,
|
|
97
|
+
sourceDurationSamples: clip.sourceDurationSamples,
|
|
98
|
+
gain: clip.gain,
|
|
99
|
+
name: leftName,
|
|
100
|
+
color: clip.color,
|
|
101
|
+
fadeIn: clip.fadeIn,
|
|
102
|
+
audioBuffer: clip.audioBuffer,
|
|
103
|
+
waveformData: clip.waveformData,
|
|
104
|
+
src: clip.src
|
|
105
|
+
}),
|
|
106
|
+
id: clip.id
|
|
107
|
+
};
|
|
104
108
|
const right = (0, import_core.createClip)({
|
|
105
109
|
startSample: splitSample,
|
|
106
110
|
durationSamples: rightDuration,
|
|
@@ -904,7 +908,56 @@ function mapHistoryStates(history, map) {
|
|
|
904
908
|
return { undo: history.undo.map(map), redo: history.redo.map(map) };
|
|
905
909
|
}
|
|
906
910
|
function purgeTrack(history, current, trackId, base = null) {
|
|
907
|
-
|
|
911
|
+
return purgeStates(history, current, stateWithoutTrack(trackId), base);
|
|
912
|
+
}
|
|
913
|
+
function purgeClip(history, current, trackId, clipId, base = null) {
|
|
914
|
+
return purgeStates(
|
|
915
|
+
history,
|
|
916
|
+
current,
|
|
917
|
+
stateWithoutClip(history, current, trackId, clipId, base),
|
|
918
|
+
base
|
|
919
|
+
);
|
|
920
|
+
}
|
|
921
|
+
function stateWithoutClip(history, current, trackId, clipId, base = null) {
|
|
922
|
+
const inOrder = [
|
|
923
|
+
...history.undo,
|
|
924
|
+
...base ? [base] : [],
|
|
925
|
+
current,
|
|
926
|
+
...[...history.redo].reverse()
|
|
927
|
+
];
|
|
928
|
+
const mapped = /* @__PURE__ */ new Map();
|
|
929
|
+
let before;
|
|
930
|
+
let stripped = false;
|
|
931
|
+
for (const state of inOrder) {
|
|
932
|
+
const known = mapped.get(state);
|
|
933
|
+
if (known) {
|
|
934
|
+
before = known.tracks.find((t) => t.id === trackId);
|
|
935
|
+
continue;
|
|
936
|
+
}
|
|
937
|
+
const track = state.tracks.find((t) => t.id === trackId);
|
|
938
|
+
let next = track;
|
|
939
|
+
if (track?.clips.some((c) => c.id === clipId)) {
|
|
940
|
+
next = { ...track, clips: track.clips.filter((c) => c.id !== clipId) };
|
|
941
|
+
stripped = true;
|
|
942
|
+
}
|
|
943
|
+
if (stripped && next && before && next !== before && sameTrackFields(before, next))
|
|
944
|
+
next = before;
|
|
945
|
+
mapped.set(
|
|
946
|
+
state,
|
|
947
|
+
next === track ? state : { tracks: state.tracks.map((t) => t === track ? next : t), mixer: state.mixer }
|
|
948
|
+
);
|
|
949
|
+
before = next;
|
|
950
|
+
}
|
|
951
|
+
return (state) => mapped.get(state) ?? state;
|
|
952
|
+
}
|
|
953
|
+
function sameTrackFields(a, b) {
|
|
954
|
+
const keys = /* @__PURE__ */ new Set([...Object.keys(a), ...Object.keys(b)]);
|
|
955
|
+
for (const key of keys) {
|
|
956
|
+
if (key !== "clips" && a[key] !== b[key]) return false;
|
|
957
|
+
}
|
|
958
|
+
return a.clips.length === b.clips.length && a.clips.every((c, i) => c === b.clips[i]);
|
|
959
|
+
}
|
|
960
|
+
function purgeStates(history, current, strip, base) {
|
|
908
961
|
const nextCurrent = strip(current);
|
|
909
962
|
const nextBase = base && strip(base);
|
|
910
963
|
const stripped = dropRepeats(mapHistoryStates(history, strip), nextBase ?? nextCurrent);
|
|
@@ -1287,6 +1340,21 @@ var ArrangementImpl = class {
|
|
|
1287
1340
|
this._tracksVersion++;
|
|
1288
1341
|
this._emit({ type: "remove", trackId });
|
|
1289
1342
|
}
|
|
1343
|
+
/**
|
|
1344
|
+
* Remove a clip from a track: an undo step. With `undoable: false` there is
|
|
1345
|
+
* no step, and the clip is also taken out of every undo and redo state, so
|
|
1346
|
+
* that no undo or redo brings it back (#848: a `<daw-clip>` the page removed
|
|
1347
|
+
* while its track was detached).
|
|
1348
|
+
*/
|
|
1349
|
+
removeClip(trackId, clipId, options) {
|
|
1350
|
+
if (options?.undoable === false) {
|
|
1351
|
+
this._removeClipEverywhere(trackId, clipId);
|
|
1352
|
+
return;
|
|
1353
|
+
}
|
|
1354
|
+
const current = this._tracks.find((t) => t.id === trackId);
|
|
1355
|
+
if (!current?.clips.some((c) => c.id === clipId)) return;
|
|
1356
|
+
this.updateTrack(trackId, (t) => ({ ...t, clips: t.clips.filter((c) => c.id !== clipId) }));
|
|
1357
|
+
}
|
|
1290
1358
|
/**
|
|
1291
1359
|
* Move a track to a new position in the track order. Purely organizational —
|
|
1292
1360
|
* track order is not audible.
|
|
@@ -1568,6 +1636,29 @@ var ArrangementImpl = class {
|
|
|
1568
1636
|
this._resyncSourcesQuietly();
|
|
1569
1637
|
}
|
|
1570
1638
|
}
|
|
1639
|
+
/** `removeClip` with `undoable: false`: out of the current tracks and out of every stored state. */
|
|
1640
|
+
_removeClipEverywhere(trackId, clipId) {
|
|
1641
|
+
const previous = this._tracks.find((t) => t.id === trackId);
|
|
1642
|
+
const base = this._transaction?.state ?? null;
|
|
1643
|
+
const purged = purgeClip(this._history, this._currentState(), trackId, clipId, base);
|
|
1644
|
+
const historyChanged = purged.history !== this._history;
|
|
1645
|
+
const baseChanged = purged.base !== base;
|
|
1646
|
+
this._history = purged.history;
|
|
1647
|
+
if (this._transaction && purged.base) {
|
|
1648
|
+
this._transaction = { ...this._transaction, state: purged.base };
|
|
1649
|
+
}
|
|
1650
|
+
if (purged.current.tracks !== this._tracks && previous) {
|
|
1651
|
+
this._gesture = null;
|
|
1652
|
+
this._tracks = purged.current.tracks;
|
|
1653
|
+
this._tracksVersion++;
|
|
1654
|
+
this._emit({ type: "update", trackId, previous });
|
|
1655
|
+
} else if (historyChanged) {
|
|
1656
|
+
this._gesture = null;
|
|
1657
|
+
this._emit({ type: "history" });
|
|
1658
|
+
} else if (baseChanged) {
|
|
1659
|
+
this._resyncSourcesQuietly();
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1571
1662
|
/** The state before a change: an undo step, or the mark that an open transaction changed. */
|
|
1572
1663
|
_pushUndoSnapshot() {
|
|
1573
1664
|
if (this._transaction) {
|
|
@@ -1774,6 +1865,14 @@ var AdapterSync = class {
|
|
|
1774
1865
|
this._projection = { tracksVersion, mixerVersion, tracks };
|
|
1775
1866
|
return tracks;
|
|
1776
1867
|
}
|
|
1868
|
+
/**
|
|
1869
|
+
* `tracks()` as the adapter is given them: without the view fields. Made
|
|
1870
|
+
* for each send; nothing depends on the adapter's tracks keeping their
|
|
1871
|
+
* identity between sends.
|
|
1872
|
+
*/
|
|
1873
|
+
_playoutTracks() {
|
|
1874
|
+
return freezeTracksInDevelopment(this.tracks().map((track) => this._playout(track)));
|
|
1875
|
+
}
|
|
1777
1876
|
/** When an engine attaches: send the tracks that are there. With none, the adapter is in step as it is. */
|
|
1778
1877
|
sendInitialTracks() {
|
|
1779
1878
|
if (this._arrangement.getTracks().length > 0) {
|
|
@@ -1785,7 +1884,7 @@ var AdapterSync = class {
|
|
|
1785
1884
|
/** Send the adapter every track, and remember up to which change that covers. */
|
|
1786
1885
|
sendAllTracks() {
|
|
1787
1886
|
const version = this._arrangement.tracksVersion;
|
|
1788
|
-
this._adapter?.setTracks(this.
|
|
1887
|
+
this._adapter?.setTracks(this._playoutTracks());
|
|
1789
1888
|
this._syncedTracksVersion = version;
|
|
1790
1889
|
}
|
|
1791
1890
|
/** Send the arrangement's current track to the adapter. False when there is no such track. */
|
|
@@ -1793,7 +1892,7 @@ var AdapterSync = class {
|
|
|
1793
1892
|
const track = this._arrangement.getTracks().find((t) => t.id === trackId);
|
|
1794
1893
|
if (!track) return false;
|
|
1795
1894
|
if (this._adapter?.updateTrack) {
|
|
1796
|
-
this._adapter.updateTrack(trackId, this._project(track));
|
|
1895
|
+
this._adapter.updateTrack(trackId, this._playout(this._project(track)));
|
|
1797
1896
|
} else {
|
|
1798
1897
|
this.sendAllTracks();
|
|
1799
1898
|
}
|
|
@@ -1894,7 +1993,7 @@ var AdapterSync = class {
|
|
|
1894
1993
|
_addTrack(trackId) {
|
|
1895
1994
|
const track = this._arrangement.getTracks().find((t) => t.id === trackId);
|
|
1896
1995
|
if (track && this._adapter?.addTrack) {
|
|
1897
|
-
this._adapter.addTrack(this._project(track));
|
|
1996
|
+
this._adapter.addTrack(this._playout(this._project(track)));
|
|
1898
1997
|
} else {
|
|
1899
1998
|
this.sendAllTracks();
|
|
1900
1999
|
}
|
|
@@ -1934,9 +2033,10 @@ var AdapterSync = class {
|
|
|
1934
2033
|
if (before.clips.some((clip, i) => clip !== now.clips[i])) return false;
|
|
1935
2034
|
const keys = /* @__PURE__ */ new Set([...Object.keys(before), ...Object.keys(now)]);
|
|
1936
2035
|
keys.delete("clips");
|
|
2036
|
+
for (const field of import_core8.TRACK_VIEW_FIELDS) keys.delete(field);
|
|
1937
2037
|
return [...keys].every((key) => Object.is(before[key], now[key]));
|
|
1938
2038
|
}
|
|
1939
|
-
/** What
|
|
2039
|
+
/** What `getState()` is given for one of the arrangement's tracks (an adapter: `_playout` of it). */
|
|
1940
2040
|
_project(track) {
|
|
1941
2041
|
return this._withMix(this._loaded(track));
|
|
1942
2042
|
}
|
|
@@ -1961,6 +2061,12 @@ var AdapterSync = class {
|
|
|
1961
2061
|
_recordingNow(trackId) {
|
|
1962
2062
|
return this._arrangement.recordingTrackIds.has(trackId) && this._arrangement.getMixer().has(trackId);
|
|
1963
2063
|
}
|
|
2064
|
+
/** A projected track without its view fields: a copy that shares its clips. */
|
|
2065
|
+
_playout(track) {
|
|
2066
|
+
const copy = { ...track };
|
|
2067
|
+
for (const field of import_core8.TRACK_VIEW_FIELDS) delete copy[field];
|
|
2068
|
+
return freezeTrackInDevelopment(copy);
|
|
2069
|
+
}
|
|
1964
2070
|
/**
|
|
1965
2071
|
* One track with its current mixer values in its fields, muted while a
|
|
1966
2072
|
* take records onto it (memoized per track object).
|
|
@@ -2439,8 +2545,9 @@ var PlaylistEngine = class {
|
|
|
2439
2545
|
// ---------------------------------------------------------------------------
|
|
2440
2546
|
// Lifecycle
|
|
2441
2547
|
// ---------------------------------------------------------------------------
|
|
2442
|
-
dispose() {
|
|
2548
|
+
dispose(options = {}) {
|
|
2443
2549
|
if (this._disposed) return;
|
|
2550
|
+
if (options.keepAdapter && this._isPlaying) this.stop();
|
|
2444
2551
|
this._disposed = true;
|
|
2445
2552
|
this._stopFollowingArrangement();
|
|
2446
2553
|
this._detachFromArrangement();
|
|
@@ -2449,7 +2556,8 @@ var PlaylistEngine = class {
|
|
|
2449
2556
|
this._isPlaying = false;
|
|
2450
2557
|
this._adapter?.onPlaybackEnded?.(null);
|
|
2451
2558
|
try {
|
|
2452
|
-
this._adapter?.
|
|
2559
|
+
if (options.keepAdapter) this._adapter?.setTracks([]);
|
|
2560
|
+
else this._adapter?.dispose();
|
|
2453
2561
|
} catch (err) {
|
|
2454
2562
|
console.warn("[waveform-playlist/engine] Error disposing adapter:", err);
|
|
2455
2563
|
}
|
|
@@ -2586,6 +2694,7 @@ function asArrangementImpl(arrangement) {
|
|
|
2586
2694
|
defaultLoadSource,
|
|
2587
2695
|
findClosestZoomIndex,
|
|
2588
2696
|
getVisibleChunkIndices,
|
|
2697
|
+
isArrangement,
|
|
2589
2698
|
shouldUpdateViewport,
|
|
2590
2699
|
splitClip
|
|
2591
2700
|
});
|