@waveform-playlist/engine 14.0.0-next.1 → 14.0.0-next.2

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 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 structural changes (tracks and clips), with transaction grouping for drag gestures; an undo never changes the mix
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`): an engine and an arrangement from copies on either side of that 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, and then also over an entry the new id still has from a removed track), and `addTrack` of a track whose removal can still be undone finds the mix it had; in those cases the fields are not read. An entry is dropped as soon as no state holds its track any more: not the current tracks, not an undo or redo step, not the base of an open transaction (with `undoLimit: 0` a removed track's entry goes at once). 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()`).
215
- - **Undo, redo and an aborted transaction restore tracks and clips, never the mix.** Undoing a `removeTrack` brings the track back with the mix it had. One exception: undoing or redoing an `updateTrack` that gave a track a new id switches between the old id's mix and the new id's, so a fader moved after the rename is not what the old id has after the undo. A second one: when a track is given the id of a removed track whose removal can still be undone, the renamed track's mix replaces the removed track's, so undoing back past the removal brings that track back with the renamed track's mix.
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
 
@@ -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 and clips; never the mix)
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;
@@ -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, and an undo (which restores tracks) never changes the
216
- * mix. A track's own `volume` / `muted` / `soloed` / `pan` fields are the
217
- * values it ENTERED with; they seed its entry when its id has none, and are
218
- * not read while it has one.
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,13 @@ interface RemoveTrackOptions {
244
245
  */
245
246
  undoable?: boolean;
246
247
  }
248
+ /** How a mixer setter's change goes into the undo history. */
249
+ interface MixerChangeOptions {
250
+ /** Changes with the same id, one after another, are one undo step. */
251
+ gesture?: string;
252
+ /** Not an undo step: the value is written into every saved state as well. */
253
+ undoable?: false;
254
+ }
247
255
  /**
248
256
  * The owner of the tracks, of the mix and of the undo history. Everything
249
257
  * else reads it (`getTracks`, `getMixer`, `subscribe`) and changes it by
@@ -260,11 +268,15 @@ interface Arrangement {
260
268
  */
261
269
  getTracks(): readonly ArrangementTrack[];
262
270
  /**
263
- * The current volume, mute, solo and pan by track id. The same Map until a
264
- * value changes, a track with a new id enters, or entries of tracks that
265
- * are gone are dropped (`mixerVersion` counts value changes only). A
266
- * track's own mixer fields in `getTracks()` are the values it entered
267
- * with; the current ones are here.
271
+ * The current volume, mute, solo and pan by track id (the stored mute: the
272
+ * mute of the track a take is recording onto is not forced here). The same
273
+ * Map until a value changes, a track with a new id enters, entries of
274
+ * tracks that are gone are dropped, or an undo, a redo or an abort brings
275
+ * back another state's Map. `mixerVersion` counts the value changes of
276
+ * current tracks, and also the start or end of a take's mute on a current
277
+ * track, which leaves this Map as it is; an entry seeded, carried or
278
+ * dropped with its track is not counted. A track's own mixer fields in
279
+ * `getTracks()` are the values it entered with; the current ones are here.
268
280
  */
269
281
  getMixer(): ReadonlyMap<string, TrackMixerValues>;
270
282
  /**
@@ -301,10 +313,26 @@ interface Arrangement {
301
313
  splitClip(trackId: string, clipId: string, atSample: number): void;
302
314
  getClipBounds(trackId: string, clipId: string): ClipBounds | null;
303
315
  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;
316
+ setTrackVolume(trackId: string, volume: number, options?: MixerChangeOptions): void;
317
+ setTrackMute(trackId: string, muted: boolean, options?: MixerChangeOptions): void;
318
+ setTrackSolo(trackId: string, soloed: boolean, options?: MixerChangeOptions): void;
319
+ setTrackPan(trackId: string, pan: number, options?: MixerChangeOptions): void;
320
+ /**
321
+ * The ids of the tracks a take is recording onto. The same Set until one
322
+ * is added or removed; never write to it.
323
+ */
324
+ readonly recordingTrackIds: ReadonlySet<string>;
325
+ /**
326
+ * Mark a track as the one a take is recording onto, or clear it when the
327
+ * take ends. Such a track plays muted: the engine's `getState().tracks`
328
+ * and its adapter have it muted, while its mute in `getMixer()` stays as
329
+ * it is and comes back when the take ends. This is not an undo step, and
330
+ * undo, redo, an abort, `setTracks` and `clearHistory` do not change which
331
+ * tracks are recording. An id that is not in the current tracks is
332
+ * recorded too, and mutes nothing until a track of that id enters. The
333
+ * same value changes nothing.
334
+ */
335
+ setTrackRecording(trackId: string, recording: boolean): void;
308
336
  readonly canUndo: boolean;
309
337
  readonly canRedo: boolean;
310
338
  /** With a transaction open: aborts it first. */
@@ -315,7 +343,7 @@ interface Arrangement {
315
343
  /** Changes made until `commitTransaction` are one undo step. */
316
344
  beginTransaction(): void;
317
345
  commitTransaction(): void;
318
- /** Put the tracks back as they were when the transaction began. */
346
+ /** Put the tracks and the mix back as they were when the transaction began. */
319
347
  abortTransaction(): void;
320
348
  /**
321
349
  * Where each source the clips name is: pending, loaded or failed (also a
@@ -359,12 +387,18 @@ interface CreateArrangementOptions {
359
387
  *
360
388
  * The keys carry a version. An engine that finds the time-base key treats
361
389
  * the object as an arrangement of this version and uses it BY NAME: the
362
- * whole public `Arrangement` interface (every track, clip, mixer and history
363
- * method it delegates to, `getTracks`, `getMixer`, the two version counters)
364
- * and the internal `onChange(listener)` (with the `ArrangementChange` and
365
- * `ArrangementVersions` shapes of this version), `recomputeStartSamples()`
366
- * and `undoLimit`. A change to any of that needs a new key, so that copies
367
- * which do not agree refuse each other instead of misreading each other.
390
+ * whole public `Arrangement` interface (every track, clip, mixer, recording
391
+ * and history method it delegates to, `getTracks`, `getMixer`,
392
+ * `recordingTrackIds`,
393
+ * the two version counters) and the internal `onChange(listener)` (with the
394
+ * `ArrangementChange` and `ArrangementVersions` shapes of this version),
395
+ * `recomputeStartSamples()` and `undoLimit`. A change to any of that needs a
396
+ * new key, so that copies which do not agree refuse each other instead of
397
+ * misreading each other.
398
+ *
399
+ * v2 (#843): the mixer setters take options and are undo steps, the history
400
+ * holds the mix (`'restoreMix'`), and the arrangement has the take's mute
401
+ * (`setTrackRecording`, `recordingTrackIds`, `'recording'`).
368
402
  */
369
403
 
370
404
  type GetDecodeContext = () => Promise<BaseAudioContext>;
@@ -664,10 +698,26 @@ declare class PlaylistEngine {
664
698
  setSelection(start: number, end: number): void;
665
699
  setLoopRegion(start: number, end: number): void;
666
700
  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;
701
+ setTrackVolume(trackId: string, volume: number, options?: MixerChangeOptions): void;
702
+ setTrackMute(trackId: string, muted: boolean, options?: MixerChangeOptions): void;
703
+ setTrackSolo(trackId: string, soloed: boolean, options?: MixerChangeOptions): void;
704
+ setTrackPan(trackId: string, pan: number, options?: MixerChangeOptions): void;
705
+ /**
706
+ * Mark a track as the one a take is recording onto, or clear it when the
707
+ * take ends: the arrangement's `setTrackRecording`. That track plays muted
708
+ * (here and in the adapter) while its mute in the mix stays as it is; the
709
+ * take's mute is not an undo step. The arrangement's `'recording'`
710
+ * announcement brings the adapter in step, so there is no adapter call of
711
+ * its own here; a disposed engine changes the arrangement only.
712
+ */
713
+ setTrackRecording(trackId: string, recording: boolean): void;
714
+ /**
715
+ * The tracks a take is recording onto, read from the arrangement (the
716
+ * owner; no copy). The same set object until it changes; never write to
717
+ * it, use `setTrackRecording`. Such a track plays muted, so a UI can
718
+ * disable its mute control while the id is in the set.
719
+ */
720
+ get recordingTrackIds(): ReadonlySet<string>;
671
721
  zoomIn(): void;
672
722
  zoomOut(): void;
673
723
  setZoomLevel(samplesPerPixel: number): void;
@@ -707,4 +757,4 @@ declare class PlaylistEngine {
707
757
  private _emitStateChange;
708
758
  }
709
759
 
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 };
760
+ export { 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, and an undo (which restores tracks) never changes the
216
- * mix. A track's own `volume` / `muted` / `soloed` / `pan` fields are the
217
- * values it ENTERED with; they seed its entry when its id has none, and are
218
- * not read while it has one.
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,13 @@ interface RemoveTrackOptions {
244
245
  */
245
246
  undoable?: boolean;
246
247
  }
248
+ /** How a mixer setter's change goes into the undo history. */
249
+ interface MixerChangeOptions {
250
+ /** Changes with the same id, one after another, are one undo step. */
251
+ gesture?: string;
252
+ /** Not an undo step: the value is written into every saved state as well. */
253
+ undoable?: false;
254
+ }
247
255
  /**
248
256
  * The owner of the tracks, of the mix and of the undo history. Everything
249
257
  * else reads it (`getTracks`, `getMixer`, `subscribe`) and changes it by
@@ -260,11 +268,15 @@ interface Arrangement {
260
268
  */
261
269
  getTracks(): readonly ArrangementTrack[];
262
270
  /**
263
- * The current volume, mute, solo and pan by track id. The same Map until a
264
- * value changes, a track with a new id enters, or entries of tracks that
265
- * are gone are dropped (`mixerVersion` counts value changes only). A
266
- * track's own mixer fields in `getTracks()` are the values it entered
267
- * with; the current ones are here.
271
+ * The current volume, mute, solo and pan by track id (the stored mute: the
272
+ * mute of the track a take is recording onto is not forced here). The same
273
+ * Map until a value changes, a track with a new id enters, entries of
274
+ * tracks that are gone are dropped, or an undo, a redo or an abort brings
275
+ * back another state's Map. `mixerVersion` counts the value changes of
276
+ * current tracks, and also the start or end of a take's mute on a current
277
+ * track, which leaves this Map as it is; an entry seeded, carried or
278
+ * dropped with its track is not counted. A track's own mixer fields in
279
+ * `getTracks()` are the values it entered with; the current ones are here.
268
280
  */
269
281
  getMixer(): ReadonlyMap<string, TrackMixerValues>;
270
282
  /**
@@ -301,10 +313,26 @@ interface Arrangement {
301
313
  splitClip(trackId: string, clipId: string, atSample: number): void;
302
314
  getClipBounds(trackId: string, clipId: string): ClipBounds | null;
303
315
  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;
316
+ setTrackVolume(trackId: string, volume: number, options?: MixerChangeOptions): void;
317
+ setTrackMute(trackId: string, muted: boolean, options?: MixerChangeOptions): void;
318
+ setTrackSolo(trackId: string, soloed: boolean, options?: MixerChangeOptions): void;
319
+ setTrackPan(trackId: string, pan: number, options?: MixerChangeOptions): void;
320
+ /**
321
+ * The ids of the tracks a take is recording onto. The same Set until one
322
+ * is added or removed; never write to it.
323
+ */
324
+ readonly recordingTrackIds: ReadonlySet<string>;
325
+ /**
326
+ * Mark a track as the one a take is recording onto, or clear it when the
327
+ * take ends. Such a track plays muted: the engine's `getState().tracks`
328
+ * and its adapter have it muted, while its mute in `getMixer()` stays as
329
+ * it is and comes back when the take ends. This is not an undo step, and
330
+ * undo, redo, an abort, `setTracks` and `clearHistory` do not change which
331
+ * tracks are recording. An id that is not in the current tracks is
332
+ * recorded too, and mutes nothing until a track of that id enters. The
333
+ * same value changes nothing.
334
+ */
335
+ setTrackRecording(trackId: string, recording: boolean): void;
308
336
  readonly canUndo: boolean;
309
337
  readonly canRedo: boolean;
310
338
  /** With a transaction open: aborts it first. */
@@ -315,7 +343,7 @@ interface Arrangement {
315
343
  /** Changes made until `commitTransaction` are one undo step. */
316
344
  beginTransaction(): void;
317
345
  commitTransaction(): void;
318
- /** Put the tracks back as they were when the transaction began. */
346
+ /** Put the tracks and the mix back as they were when the transaction began. */
319
347
  abortTransaction(): void;
320
348
  /**
321
349
  * Where each source the clips name is: pending, loaded or failed (also a
@@ -359,12 +387,18 @@ interface CreateArrangementOptions {
359
387
  *
360
388
  * The keys carry a version. An engine that finds the time-base key treats
361
389
  * the object as an arrangement of this version and uses it BY NAME: the
362
- * whole public `Arrangement` interface (every track, clip, mixer and history
363
- * method it delegates to, `getTracks`, `getMixer`, the two version counters)
364
- * and the internal `onChange(listener)` (with the `ArrangementChange` and
365
- * `ArrangementVersions` shapes of this version), `recomputeStartSamples()`
366
- * and `undoLimit`. A change to any of that needs a new key, so that copies
367
- * which do not agree refuse each other instead of misreading each other.
390
+ * whole public `Arrangement` interface (every track, clip, mixer, recording
391
+ * and history method it delegates to, `getTracks`, `getMixer`,
392
+ * `recordingTrackIds`,
393
+ * the two version counters) and the internal `onChange(listener)` (with the
394
+ * `ArrangementChange` and `ArrangementVersions` shapes of this version),
395
+ * `recomputeStartSamples()` and `undoLimit`. A change to any of that needs a
396
+ * new key, so that copies which do not agree refuse each other instead of
397
+ * misreading each other.
398
+ *
399
+ * v2 (#843): the mixer setters take options and are undo steps, the history
400
+ * holds the mix (`'restoreMix'`), and the arrangement has the take's mute
401
+ * (`setTrackRecording`, `recordingTrackIds`, `'recording'`).
368
402
  */
369
403
 
370
404
  type GetDecodeContext = () => Promise<BaseAudioContext>;
@@ -664,10 +698,26 @@ declare class PlaylistEngine {
664
698
  setSelection(start: number, end: number): void;
665
699
  setLoopRegion(start: number, end: number): void;
666
700
  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;
701
+ setTrackVolume(trackId: string, volume: number, options?: MixerChangeOptions): void;
702
+ setTrackMute(trackId: string, muted: boolean, options?: MixerChangeOptions): void;
703
+ setTrackSolo(trackId: string, soloed: boolean, options?: MixerChangeOptions): void;
704
+ setTrackPan(trackId: string, pan: number, options?: MixerChangeOptions): void;
705
+ /**
706
+ * Mark a track as the one a take is recording onto, or clear it when the
707
+ * take ends: the arrangement's `setTrackRecording`. That track plays muted
708
+ * (here and in the adapter) while its mute in the mix stays as it is; the
709
+ * take's mute is not an undo step. The arrangement's `'recording'`
710
+ * announcement brings the adapter in step, so there is no adapter call of
711
+ * its own here; a disposed engine changes the arrangement only.
712
+ */
713
+ setTrackRecording(trackId: string, recording: boolean): void;
714
+ /**
715
+ * The tracks a take is recording onto, read from the arrangement (the
716
+ * owner; no copy). The same set object until it changes; never write to
717
+ * it, use `setTrackRecording`. Such a track plays muted, so a UI can
718
+ * disable its mute control while the id is in the set.
719
+ */
720
+ get recordingTrackIds(): ReadonlySet<string>;
671
721
  zoomIn(): void;
672
722
  zoomOut(): void;
673
723
  setZoomLevel(samplesPerPixel: number): void;
@@ -707,4 +757,4 @@ declare class PlaylistEngine {
707
757
  private _emitStateChange;
708
758
  }
709
759
 
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 };
760
+ export { 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 };