@dawcore/components 0.0.39-next.6 → 0.0.39-next.8

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/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import * as lit from 'lit';
2
2
  import { LitElement, PropertyValues, ReactiveController, ReactiveControllerHost } from 'lit';
3
- import { AnnotationData, AnnotationShortcutMap, MidiNoteData, TrackKind, RenderMode, SpectrogramConfig, Peaks, Bits, FadeType, PeakData, MeterEntry, SnapTo, ColorMapValue, ClipTrack, KeyboardShortcut } from '@waveform-playlist/core';
3
+ import { AnnotationData, AnnotationShortcutMap, MidiNoteData, TrackKind, RenderMode, SpectrogramConfig, Peaks, Bits, FadeType, PeakData, MeterEntry, AudioClip, SnapTo, ColorMapValue, ClipTrack, KeyboardShortcut } from '@waveform-playlist/core';
4
4
  import WaveformData from 'waveform-data';
5
- import { Arrangement, PlayoutAdapter, PlaylistEngine, TrackMixerValues } from '@waveform-playlist/engine';
5
+ import { Arrangement, TrackMixerValues, PlayoutAdapter, PlaylistEngine } from '@waveform-playlist/engine';
6
6
  import { MidiLoadOptions, MidiLoadResult } from '@dawcore/midi';
7
7
  import { ClipRegistration, CanvasRegistration, ViewportState } from '@dawcore/spectrogram';
8
8
 
@@ -97,6 +97,8 @@ declare class DawAnnotationTrackElement extends LitElement {
97
97
  private _runShortcutAction;
98
98
  private _childObserver;
99
99
  createRenderRoot(): this;
100
+ /** The listeners of this connection, aborted in disconnectedCallback. */
101
+ private _listeners;
100
102
  connectedCallback(): void;
101
103
  disconnectedCallback(): void;
102
104
  }
@@ -139,6 +141,8 @@ declare class DawAnnotationListElement extends LitElement {
139
141
  static styles: lit.CSSResult;
140
142
  get track(): DawAnnotationTrackElement | null;
141
143
  protected willUpdate(changed: Map<string, unknown>): void;
144
+ /** The listeners of this connection, aborted in disconnectedCallback. */
145
+ private _listeners;
142
146
  connectedCallback(): void;
143
147
  disconnectedCallback(): void;
144
148
  protected shouldUpdate(): boolean;
@@ -185,34 +189,55 @@ declare global {
185
189
  declare class DawClipElement extends LitElement {
186
190
  src: string;
187
191
  peaksSrc: string;
188
- /**
189
- * Timeline position in seconds. JS property only — NOT reflected to the
190
- * `start` attribute (Lit's `reflect` defaults to false). Tests that need
191
- * to assert clip position must read this property directly; reading
192
- * `el.getAttribute('start')` returns `null` regardless of correctness.
193
- */
194
- start: number;
195
- duration: number;
196
- offset: number;
197
- gain: number;
198
- name: string;
192
+ /** Timeline position in seconds. */
193
+ get start(): number;
194
+ set start(value: number);
195
+ get duration(): number;
196
+ set duration(value: number);
197
+ get offset(): number;
198
+ set offset(value: number);
199
+ get gain(): number;
200
+ set gain(value: number);
201
+ get name(): string;
202
+ set name(value: string);
199
203
  color: string;
200
204
  fadeIn: number;
201
205
  fadeOut: number;
202
206
  fadeType: string;
203
207
  /** MIDI notes — JS property only, not reflected (note arrays are too large for attributes). */
204
- midiNotes: MidiNoteData[] | null;
208
+ get midiNotes(): MidiNoteData[] | null;
209
+ set midiNotes(value: MidiNoteData[] | null);
205
210
  /** MIDI channel (0-indexed). Channel 9 = GM percussion. */
206
211
  get midiChannel(): number | null;
207
212
  set midiChannel(value: number | null);
208
- private _midiChannel;
209
213
  /** MIDI program (GM instrument 0-127). Used by SoundFontToneTrack. */
210
214
  get midiProgram(): number | null;
211
215
  set midiProgram(value: number | null);
212
- private _midiProgram;
216
+ /** What the page declared: the attributes, and a property set before the clip entered. */
217
+ private _declared;
218
+ private _fromAttribute;
219
+ private _internals;
220
+ attributeChangedCallback(name: string, old: string | null, value: string | null): void;
221
+ private get _trackId();
222
+ private _linked;
223
+ private _request;
224
+ /** @internal Shown as `:state(detached)` (#848). */
225
+ _setDetached(detached: boolean): void;
213
226
  readonly clipId: `${string}-${string}-${string}-${string}-${string}`;
214
227
  createRenderRoot(): this;
228
+ /**
229
+ * A move with `Node.moveBefore()` (#848; modern-web-guidance
230
+ * `custom-elements`): the browser calls this instead of
231
+ * `disconnectedCallback` → `connectedCallback`, so the element stays
232
+ * connected, and Lit's disconnect and connect do not run. It announces
233
+ * itself again, as a connect does, so the editor sees its new place: a
234
+ * clip in another track, a track back in an editor (#848; a real-Chromium
235
+ * check found both missed with an empty hook).
236
+ */
237
+ connectedMoveCallback(): void;
215
238
  connectedCallback(): void;
239
+ /** Tell the editor this element is here (a connect or a moveBefore() move). */
240
+ private _announceConnected;
216
241
  private _hasRendered;
217
242
  updated(changed: PropertyValues): void;
218
243
  }
@@ -266,15 +291,35 @@ type SerializedEffectEntry = {
266
291
 
267
292
  declare class DawTrackElement extends LitElement {
268
293
  src: string;
269
- name: string;
270
- volume: number;
271
- pan: number;
272
- muted: boolean;
273
- soloed: boolean;
294
+ /** The track's name: the arrangement's, or as declared. Setting it renames the track (an undo step). */
295
+ get name(): string;
296
+ set name(value: string);
297
+ get volume(): number;
298
+ set volume(value: number);
299
+ get pan(): number;
300
+ set pan(value: number);
301
+ /** The stored mute (a take's mute is not shown here). */
302
+ get muted(): boolean;
303
+ set muted(value: boolean);
304
+ get soloed(): boolean;
305
+ set soloed(value: boolean);
306
+ /** The track's position in the arrangement the editor plays; -1 when it is not there. */
307
+ get index(): number;
308
+ /** What the page declared: the attributes, and a property set before the track entered. */
309
+ private _declared;
310
+ private _fromAttribute;
311
+ private _internals;
312
+ attributeChangedCallback(name: string, old: string | null, value: string | null): void;
313
+ private _linked;
314
+ private _request;
315
+ /** @internal Shown as `:state(detached)` (#848). */
316
+ _setDetached(detached: boolean): void;
274
317
  /**
275
318
  * What the track holds: `'audio'` (default) or `'midi'`. Every `<daw-clip>`
276
- * child must be of this kind (#756). Set it before the track connects:
277
- * the editor reads it when it loads the track.
319
+ * child must be of this kind (#756). Set it before the track enters: the
320
+ * editor reads it then. Live (#848): once the track has entered, it reads
321
+ * the track's kind, which cannot change; a later change keeps the attribute
322
+ * (the page's declaration) and warns.
278
323
  */
279
324
  get kind(): TrackKind;
280
325
  set kind(value: TrackKind);
@@ -314,7 +359,19 @@ declare class DawTrackElement extends LitElement {
314
359
  moveEffect(effectId: string, newIndex: number): void;
315
360
  get effects(): EffectState[];
316
361
  private _effectsEditor;
362
+ /**
363
+ * A move with `Node.moveBefore()` (#848; modern-web-guidance
364
+ * `custom-elements`): the browser calls this instead of
365
+ * `disconnectedCallback` → `connectedCallback`, so the element stays
366
+ * connected, and Lit's disconnect and connect do not run. It announces
367
+ * itself again, as a connect does, so the editor sees its new place: a
368
+ * clip in another track, a track back in an editor (#848; a real-Chromium
369
+ * check found both missed with an empty hook).
370
+ */
371
+ connectedMoveCallback(): void;
317
372
  connectedCallback(): void;
373
+ /** Tell the editor this element is here (a connect or a moveBefore() move). */
374
+ private _announceConnected;
318
375
  private _hasRendered;
319
376
  updated(changed: PropertyValues): void;
320
377
  }
@@ -480,6 +537,8 @@ declare class DawTransportButton extends LitElement {
480
537
  * warns if it's still unusable.
481
538
  */
482
539
  protected get targetSupported(): boolean;
540
+ /** The host's capability listeners, one controller per connection. */
541
+ private _capabilityListeners;
483
542
  connectedCallback(): void;
484
543
  disconnectedCallback(): void;
485
544
  private _onCapabilityPointerEnter;
@@ -490,6 +549,8 @@ declare class DawTransportButton extends LitElement {
490
549
  declare class DawPlayButtonElement extends DawTransportButton {
491
550
  private _isRecording;
492
551
  private _targetRef;
552
+ /** The listeners on `_targetRef`, aborted when the target changes or the button disconnects. */
553
+ private _targetListeners;
493
554
  private _onRecStart;
494
555
  private _onRecEnd;
495
556
  connectedCallback(): void;
@@ -510,6 +571,8 @@ declare class DawPauseButtonElement extends DawTransportButton {
510
571
  private _isPaused;
511
572
  private _isRecording;
512
573
  private _targetRef;
574
+ /** The listeners on `_targetRef`, aborted when the target changes or the button disconnects. */
575
+ private _targetListeners;
513
576
  private _onRecStart;
514
577
  private _onRecEnd;
515
578
  private _onRecPause;
@@ -563,6 +626,21 @@ type TrackMixFields = 'volume' | 'pan' | 'muted' | 'soloed';
563
626
  * (#843); `editor.tracks` fills the four fields in from it.
564
627
  */
565
628
  type StoredTrackDescriptor = Omit<TrackDescriptor, TrackMixFields>;
629
+ /**
630
+ * What `<daw-editor>` keeps per track that the arrangement has no field for
631
+ * (internal, #848): how the track is drawn, the `<daw-track src>` shorthand
632
+ * as declared, and each clip's `peaks-src`. Names, times, gains and the mix
633
+ * are read from the arrangement; nothing here is written back to it.
634
+ */
635
+ interface TrackExtras {
636
+ kind: TrackKind;
637
+ renderMode: TrackRenderMode;
638
+ spectrogramConfig?: SpectrogramConfig | null;
639
+ /** The `<daw-track src>` shorthand as declared ('' when none). */
640
+ src: string;
641
+ /** A clip's `peaks-src`, by clip id. */
642
+ peaksSrc: ReadonlyMap<string, string>;
643
+ }
566
644
  /** A `TrackDescriptor` plus its `trackId` — the shape returned by `editor.tracks`
567
645
  * so consumers can map a track's name to the `trackId` the per-track APIs
568
646
  * (`addTrackEffect`, `removeTrack`, `updateTrack`, …) are keyed by. */
@@ -620,6 +698,16 @@ type ClipDescriptor = DomClipDescriptor | DropClipDescriptor;
620
698
  * inline `c.kind === 'dom'` repetition.
621
699
  */
622
700
  declare function isDomClip(desc: ClipDescriptor): desc is DomClipDescriptor;
701
+ /**
702
+ * Options of `addTrack`, `addClip` and `loadFiles` (#848). `signal` cancels
703
+ * the call: it rejects with the signal's `reason`, and what it added is
704
+ * taken out for good (see each method), with no undo step left. A Redo list
705
+ * its arrival cleared stays cleared, as after any edit. A signal already
706
+ * aborted rejects at once and adds nothing.
707
+ */
708
+ interface EditorCallOptions {
709
+ signal?: AbortSignal;
710
+ }
623
711
  /**
624
712
  * Public input shape for `editor.addTrack(config)`. All fields optional —
625
713
  * defaults match the declarative `<daw-track>` defaults.
@@ -907,9 +995,6 @@ interface RecordingSession {
907
995
  /** Display name for the take (preview header + finalized clip name). */
908
996
  readonly clipName?: string;
909
997
  readonly wasOverdub: boolean;
910
- /** Stored so it can be removed on stop/cleanup — not just when stream ends. */
911
- readonly _onTrackEnded: (() => void) | null;
912
- readonly _audioTrack: MediaStreamTrack | null;
913
998
  /** Set during stopRecording, cleared by the done message from the worklet. */
914
999
  stopAckResolve: (() => void) | null;
915
1000
  /** In-flight stop completion — re-entrant stopRecording calls await this
@@ -921,7 +1006,7 @@ interface RecordingSession {
921
1006
  stopping: boolean;
922
1007
  }
923
1008
  /** Readonly view of a recording session for external consumers. */
924
- type ReadonlyRecordingSession = Readonly<Omit<RecordingSession, 'chunks' | 'peaks' | '_onTrackEnded' | '_audioTrack' | 'latencySamples'>> & {
1009
+ type ReadonlyRecordingSession = Readonly<Omit<RecordingSession, 'chunks' | 'peaks' | 'latencySamples'>> & {
925
1010
  readonly latencySamples: number;
926
1011
  readonly chunks: ReadonlyArray<ReadonlyArray<Float32Array>>;
927
1012
  readonly peaks: ReadonlyArray<Int8Array | Int16Array>;
@@ -975,6 +1060,8 @@ interface RecordingHost extends ReactiveControllerHost {
975
1060
  declare class RecordingController implements ReactiveController {
976
1061
  private _host;
977
1062
  private _sessions;
1063
+ /** Each session's mic-unplug listener, aborted when the session ends. */
1064
+ private _trackEndedListeners;
978
1065
  /** Track IDs with a startRecording in flight (session not yet in _sessions).
979
1066
  * The session is only set after several awaits — without this, two rapid
980
1067
  * start calls both pass the _sessions guard and build two capture
@@ -1028,6 +1115,15 @@ declare class RecordingController implements ReactiveController {
1028
1115
  private _cleanupSession;
1029
1116
  }
1030
1117
 
1118
+ /** A clip drag past its threshold, with the clip's bounds when it started. */
1119
+ interface DraggedClip {
1120
+ trackId: string;
1121
+ clipId: string;
1122
+ startSample: number;
1123
+ durationSamples: number;
1124
+ offsetSamples: number;
1125
+ }
1126
+
1031
1127
  /** Snapshot of a clip's bounds for trim constraint computation. */
1032
1128
  interface ClipBounds {
1033
1129
  readonly offsetSamples: number;
@@ -1037,19 +1133,20 @@ interface ClipBounds {
1037
1133
  }
1038
1134
  /** Narrow engine contract for clip move/trim interactions. */
1039
1135
  interface ClipEngineContract {
1040
- moveClip(trackId: string, clipId: string, deltaSamples: number, skipAdapter?: boolean): number;
1041
- trimClip(trackId: string, clipId: string, boundary: 'left' | 'right', deltaSamples: number, skipAdapter?: boolean): void;
1042
- updateTrack(trackId: string): void;
1136
+ /** Move a clip; returns the delta actually applied. One undo step. */
1137
+ moveClip(trackId: string, clipId: string, deltaSamples: number): number;
1138
+ trimClip(trackId: string, clipId: string, boundary: 'left' | 'right', deltaSamples: number): void;
1139
+ /** The loaded clips of each track (a move collides with them, as `moveClip` does). */
1140
+ getState(): {
1141
+ tracks: readonly {
1142
+ id: string;
1143
+ clips: readonly AudioClip[];
1144
+ }[];
1145
+ };
1043
1146
  /** Get a clip's full bounds for trim constraint computation. */
1044
1147
  getClipBounds(trackId: string, clipId: string): ClipBounds | null;
1045
1148
  /** Constrain a trim delta using the engine's collision/bounds logic. */
1046
1149
  constrainTrimDelta(trackId: string, clipId: string, boundary: 'left' | 'right', deltaSamples: number): number;
1047
- /** Begin a transaction — groups mutations into one undo step. */
1048
- beginTransaction(): void;
1049
- /** Commit the transaction — pushes one undo step for all grouped mutations. */
1050
- commitTransaction(): void;
1051
- /** Abort the transaction — restores pre-transaction state without pushing to undo. */
1052
- abortTransaction(): void;
1053
1150
  }
1054
1151
  /** Peak data returned by reextractClipPeaks for imperative waveform updates. */
1055
1152
  interface ClipPeakSlice {
@@ -1086,11 +1183,14 @@ interface ClipPointerHost {
1086
1183
  * Handles pointer interactions for clip move and trim drag operations.
1087
1184
  * Converts pixel deltas to sample deltas and delegates to the engine.
1088
1185
  *
1089
- * Move: sends incremental deltas per-frame with skipAdapter=true (engine shifts
1090
- * startSample additively without touching audio adapter). Adapter synced once
1091
- * via updateTrack() at drag end.
1092
- * Trim: updates clip container CSS imperatively during drag for visual feedback,
1093
- * then applies cumulative delta to engine once at drag end.
1186
+ * Both show the drag in the view and change the arrangement once, on release
1187
+ * (#848): nothing is written while the pointer moves, so an arrangement change
1188
+ * during a drag always came from outside.
1189
+ *
1190
+ * Move: the clip container's `left` follows the pointer, constrained by the
1191
+ * track's other loaded clips as `moveClip` will be; one `moveClip` on release.
1192
+ * Trim: updates clip container CSS and peaks imperatively during drag, then
1193
+ * applies the cumulative delta to the engine once on release.
1094
1194
  */
1095
1195
  declare class ClipPointerHandler {
1096
1196
  private _host;
@@ -1107,6 +1207,8 @@ declare class ClipPointerHandler {
1107
1207
  private _originalOffsetSamples;
1108
1208
  private _originalDurationSamples;
1109
1209
  private _originalStartSample;
1210
+ private _moveClip;
1211
+ private _moveSorted;
1110
1212
  constructor(host: ClipPointerHost);
1111
1213
  /**
1112
1214
  * Convert a pixel delta to samples, snapping in tick space when in beats mode.
@@ -1117,11 +1219,21 @@ declare class ClipPointerHandler {
1117
1219
  * even if they started off-grid.
1118
1220
  */
1119
1221
  private _snapDeltaToSamples;
1222
+ /** A sample delta from `anchorSample` in pixels: in tick space in beats mode,
1223
+ * so the drawn position does not drift from the sample round-trip. */
1224
+ private _samplesToPx;
1120
1225
  /** Returns true if a drag interaction is currently in progress. */
1121
1226
  get isActive(): boolean;
1122
1227
  /** True once the pointer of the current press has moved past the drag
1123
1228
  * threshold: a press that has not moved is not a drag (#848). */
1124
1229
  get isDragging(): boolean;
1230
+ /**
1231
+ * The clip being dragged (past the threshold) with its bounds at the drag's
1232
+ * start, or null; null too while the release makes its one arrangement
1233
+ * call, so that call is not taken for an outside change (#848).
1234
+ */
1235
+ get draggedClip(): DraggedClip | null;
1236
+ private _committing;
1125
1237
  /**
1126
1238
  * Attempts to handle a pointerdown event on the given target element.
1127
1239
  * Returns true if the target is a recognized clip interaction element.
@@ -1130,11 +1242,10 @@ declare class ClipPointerHandler {
1130
1242
  private _beginDrag;
1131
1243
  /**
1132
1244
  * The press has become a drag (the pointer passed the threshold): take the
1133
- * clip's bounds and open the transaction now, not at the press. An undo
1134
- * made during the press (it is not a drag, so undo works) then has no
1135
- * transaction to abort, and the drag that follows starts from the clip as
1136
- * the undo left it, one undo step (#848, review of #915). Returns false
1137
- * when the clip is gone (the undo removed it): the press is dropped.
1245
+ * clip's bounds now, not at the press, so a drag after an undo made during
1246
+ * the press starts from the clip as the undo left it (#848, review of
1247
+ * #915). Returns false when the clip is gone (the undo removed it): the
1248
+ * press is dropped.
1138
1249
  */
1139
1250
  private _startDrag;
1140
1251
  /** Processes pointermove events during an active drag. */
@@ -1145,20 +1256,18 @@ declare class ClipPointerHandler {
1145
1256
  *
1146
1257
  * pointercancel fires INSTEAD of pointerup on touch interruption, pen
1147
1258
  * leaving hover range, or OS gestures. Without this handler the drag stays
1148
- * armed (hover keeps moving the clip), the engine transaction stays open
1149
- * (every later edit becomes un-undoable until some drag commits), and the
1150
- * per-frame skipAdapter moveClip mutations are never synced or rolled back
1151
- * (waveform and audio permanently disagree). */
1259
+ * armed (hover keeps moving the clip). The drag wrote nothing to the
1260
+ * arrangement, so reverting is putting the view back. */
1152
1261
  onPointerCancel(_e: PointerEvent): void;
1153
1262
  /** Re-extract peaks from cache and set on waveform elements during trim drag.
1154
1263
  * Returns true if peaks were successfully updated. */
1155
1264
  private _updateWaveformPeaks;
1156
1265
  /** Restore clip container CSS AND waveform peaks to original values after
1157
- * a trim visual preview. Peaks matter: the drag wrote re-extracted peak
1266
+ * a drag's visual preview. Peaks matter: a trim wrote re-extracted peak
1158
1267
  * arrays imperatively onto the <daw-waveform> elements (bypassing Lit), and
1159
- * a cancelled/zero-delta trim makes no engine mutation — so no statechange
1268
+ * a cancelled/zero-delta drag makes no engine mutation — so no statechange
1160
1269
  * re-render will ever repair them. */
1161
- private _restoreTrimVisual;
1270
+ private _restoreVisual;
1162
1271
  private _reset;
1163
1272
  }
1164
1273
 
@@ -1444,8 +1553,8 @@ interface LoadFilesResult {
1444
1553
 
1445
1554
  /**
1446
1555
  * MIDI loading logic extracted from daw-editor. Operates on the editor via a
1447
- * narrow host interface (`addTrack` + `querySelectorAll`) — `<daw-editor>`
1448
- * satisfies it without any new public surface.
1556
+ * narrow host interface (`addTrack`, `_discardTrack`, `_operationSignal`) —
1557
+ * `<daw-editor>` satisfies it.
1449
1558
  *
1450
1559
  * Numbered steps below match the Data Flow diagram in
1451
1560
  * `docs/specs/2026-05-23-dawcore-load-midi-design.md`.
@@ -1453,16 +1562,57 @@ interface LoadFilesResult {
1453
1562
 
1454
1563
  /**
1455
1564
  * Minimal host surface needed by `loadMidiImpl`. `<daw-editor>` satisfies this
1456
- * structurally. `querySelectorAll` is needed for cleanup-on-failure so the
1457
- * loader can identify `<daw-track>` elements appended during this call (both
1458
- * those whose `addTrack` resolved and those whose entry was refused — the
1459
- * latter aren't in the `addTrack` resolution value, so we need DOM
1460
- * observation to find them).
1565
+ * structurally. A track `addTrack` added is taken out for good on a failure
1566
+ * or an abort; a track whose entry was refused never entered, so there is
1567
+ * nothing to remove (#848: `addTrack` makes no element).
1461
1568
  */
1462
1569
  interface MidiLoaderHost {
1463
1570
  /** Resolves with the track id once the track has entered (#848). */
1464
- addTrack(config: TrackConfig): Promise<string>;
1465
- querySelectorAll(selector: string): NodeListOf<Element>;
1571
+ addTrack(config: TrackConfig, options?: EditorCallOptions): Promise<string>;
1572
+ /** Take a track out for good: no undo step, and no undo brings it back. */
1573
+ _discardTrack(trackId: string, from?: Arrangement): void;
1574
+ /** The arrangement played (the tracks enter it). */
1575
+ readonly arrangement: Arrangement;
1576
+ /** The caller's signal combined with the arrangement played (D6). */
1577
+ _operationSignal(signal?: AbortSignal): AbortSignal;
1578
+ }
1579
+
1580
+ /**
1581
+ * How `<daw-track>` and `<daw-clip>` are linked to the arrangement the editor
1582
+ * plays (#848 PR 3): by id. An element is
1583
+ *
1584
+ * - pending: not in an editor, or registered and not entered yet. Its
1585
+ * properties are its own declaration (the attributes, and any property set
1586
+ * before entry, which is the value the track enters with);
1587
+ * - live: the arrangement holds its id. Properties read the arrangement, and
1588
+ * setting one (or changing its attribute) is a request to it, one undo step;
1589
+ * - detached: the editor took it, and the arrangement no longer holds its id
1590
+ * (an Undo of its arrival, a removal made on the arrangement, a refusal).
1591
+ * Properties read the declaration; a change does nothing, with a warning.
1592
+ * The element carries the custom state `detached` (`:state(detached)`).
1593
+ *
1594
+ * Attributes are never written by the editor.
1595
+ */
1596
+
1597
+ type LinkState = 'pending' | 'live' | 'detached';
1598
+ /** The `<daw-track>` properties read from the arrangement while live. */
1599
+ interface TrackLinkValues {
1600
+ volume: number;
1601
+ pan: number;
1602
+ muted: boolean;
1603
+ soloed: boolean;
1604
+ name: string;
1605
+ }
1606
+ /** The `<daw-clip>` properties read from the arrangement while live. */
1607
+ interface ClipLinkValues {
1608
+ start: number;
1609
+ duration: number;
1610
+ offset: number;
1611
+ gain: number;
1612
+ name: string;
1613
+ midiNotes: MidiNoteData[] | null;
1614
+ midiChannel: number | null;
1615
+ midiProgram: number | null;
1466
1616
  }
1467
1617
 
1468
1618
  interface ExportOptions {
@@ -1504,6 +1654,18 @@ interface ExportAudioHost {
1504
1654
  getTrackEffectsState(trackId: string): Promise<SerializedEffectEntry[]>;
1505
1655
  }
1506
1656
 
1657
+ /**
1658
+ * A track registered and not in the arrangement yet (#848): a `<daw-track>`
1659
+ * (read when it enters, with clips `addClip()` gave it meanwhile), or a
1660
+ * declaration with no element (`addTrack()`, a dropped file) and its mix.
1661
+ */
1662
+ type PendingEntry = {
1663
+ element: DawTrackElement;
1664
+ extraClips: DropClipDescriptor[];
1665
+ } | {
1666
+ descriptor: StoredTrackDescriptor;
1667
+ mix: TrackMixerValues;
1668
+ };
1507
1669
  declare class DawEditorElement extends LitElement implements MidiLoaderHost {
1508
1670
  get samplesPerPixel(): number;
1509
1671
  set samplesPerPixel(value: number);
@@ -1640,14 +1802,54 @@ declare class DawEditorElement extends LitElement implements MidiLoaderHost {
1640
1802
  get sampleRate(): number;
1641
1803
  private _loadedClipSampleRate;
1642
1804
  /**
1643
- * The one owner of the tracks, the clips, the mix, the undo history and
1644
- * loading (#848). Made with the editor, kept across a disconnect; the
1645
- * engine plays it once there is an adapter.
1646
- */
1647
- _arrangement: Arrangement;
1648
- /** Sends the load events, read from the arrangement (#848). */
1805
+ * The editor's own arrangement (#848): the one owner of the tracks, the
1806
+ * clips, the mix, the undo history and loading of what the `<daw-track>`
1807
+ * children declare. Made with the editor, kept across a disconnect.
1808
+ */
1809
+ readonly _ownArrangement: Arrangement;
1810
+ /** An arrangement the app handed in (`editor.arrangement`), played alone; null: the own one. */
1811
+ _handedIn: Arrangement | null;
1812
+ /** The arrangement played now: a handed-in one, else the editor's own. */
1813
+ get _arrangement(): Arrangement;
1814
+ /**
1815
+ * The arrangement the editor plays (#848 PR 3): one handed in by the app,
1816
+ * or else the editor's own, whose content the `<daw-track>` children
1817
+ * declare. Setting one plays it alone, like `video.srcObject`: the
1818
+ * children are not added to it and show `:state(detached)` while it is
1819
+ * set; `null` (or the editor's own) goes back to the own arrangement with
1820
+ * what it held. A swap keeps the adapter: playback stops, a new engine is
1821
+ * built on the new arrangement. Refused (with a warning) during a take.
1822
+ * The editor never disposes or clears an arrangement it was handed.
1823
+ * Throws a `TypeError` for a value that is not an arrangement.
1824
+ */
1825
+ get arrangement(): Arrangement;
1826
+ set arrangement(value: Arrangement | null);
1827
+ /** Sends the load events, read from the arrangement played (#848; a new one per swap). */
1649
1828
  private _announcer;
1829
+ /** Stops following the arrangement played (its sources and its tracks). */
1830
+ private _unfollow;
1650
1831
  constructor();
1832
+ /**
1833
+ * Follow the arrangement played: a source that fails changes no track,
1834
+ * only `sources` tells of it (the events, the failed look); the elements'
1835
+ * link states follow its tracks (a structural change only, not every
1836
+ * mixer frame).
1837
+ */
1838
+ private _follow;
1839
+ /**
1840
+ * A change to the arrangement while a drag is in progress came from
1841
+ * elsewhere (a drag writes nothing until its release): cancel the drag
1842
+ * when it changed what is dragged (#848 P2, interactions/drag-watch.ts).
1843
+ */
1844
+ private _watchDrags;
1845
+ /** @internal */
1846
+ _releaseEngine(): void;
1847
+ /** @internal */
1848
+ _disposeTrackChain(trackId: string): void;
1849
+ /** @internal */
1850
+ _playArrangement(next: Arrangement | null): void;
1851
+ /** @internal */
1852
+ _buildEngineIfReady(): void;
1651
1853
  /**
1652
1854
  * Ids of tracks registered (a `<daw-track>` connected, a file dropped) and
1653
1855
  * not yet in the arrangement: they enter at the next flush, once there is
@@ -1663,15 +1865,19 @@ declare class DawEditorElement extends LitElement implements MidiLoaderHost {
1663
1865
  private _awaitedClips;
1664
1866
  /** Reject the `addClip()` calls waiting for clips that match `which`. */
1665
1867
  private _rejectAwaitedClips;
1666
- /** `<daw-track>` elements `addTrack()` made: every other one is the page's (the history rule). */
1667
- private _editorMadeTracks;
1668
1868
  /** `.dat` peaks drawn for a clip still loading, by clip id (an editor-only render cache). */
1669
1869
  _previewPeaks: Map<string, PeakData>;
1670
1870
  /** The `.dat` data of those clips, handed to the peak pipeline when the audio arrives. */
1671
1871
  private _previewWaveforms;
1672
- /** Per-track descriptors, without the mix: the arrangement owns that (#843). */
1673
- _tracks: Map<string, StoredTrackDescriptor>;
1674
- _engineTracks: Map<string, ClipTrack>;
1872
+ /**
1873
+ * Tracks registered and not in the arrangement yet, with their declaration
1874
+ * (#848): a `<daw-track>` is read when it enters (its clips and attributes
1875
+ * as they are then); a dropped file carries its descriptor. The one place a
1876
+ * track's state lives until it enters.
1877
+ */
1878
+ _pending: Map<string, PendingEntry>;
1879
+ /** What the arrangement has no field for, by track id (#848; render mode, `peaks-src`). */
1880
+ _extras: Map<string, TrackExtras>;
1675
1881
  _peaksData: Map<string, PeakData>;
1676
1882
  _isPlaying: boolean;
1677
1883
  _duration: number;
@@ -1815,6 +2021,10 @@ declare class DawEditorElement extends LitElement implements MidiLoaderHost {
1815
2021
  * Returns false for unknown track/clip IDs (defensive).
1816
2022
  */
1817
2023
  isMidiClip(trackId: string, clipId: string): boolean;
2024
+ /** The arrangement's tracks as they are played: loaded clips, the current mix (#848). */
2025
+ _loadedTracks(): ClipTrack[];
2026
+ /** A loaded clip of a track of the arrangement, or undefined. */
2027
+ private _loadedClip;
1818
2028
  private _pointer;
1819
2029
  private _viewport;
1820
2030
  private _scrollSync;
@@ -1843,6 +2053,14 @@ declare class DawEditorElement extends LitElement implements MidiLoaderHost {
1843
2053
  * the arrangement is not listed (its descriptor stays for a Redo).
1844
2054
  */
1845
2055
  get tracks(): TrackWithId[];
2056
+ /** A track of the arrangement as `editor.tracks` lists it: everything read from the arrangement. */
2057
+ private _listTrack;
2058
+ /** A pending track's declaration: its element's attributes and clips now, or its descriptor. */
2059
+ private _pendingDescriptor;
2060
+ /** The extras a track of the arrangement takes when the editor has none for it. */
2061
+ private _defaultExtras;
2062
+ /** How a track is drawn: its extras, else from its kind (an undo-restored track has none). */
2063
+ _renderModeOf(trackId: string): TrackRenderMode;
1846
2064
  /**
1847
2065
  * A track's mix, from its one owner, the arrangement (#843), as the engine
1848
2066
  * plays it: its projection carries the take's mute, which `getMixer()`
@@ -1850,6 +2068,48 @@ declare class DawEditorElement extends LitElement implements MidiLoaderHost {
1850
2068
  * waiting to enter shows what its element declares.
1851
2069
  */
1852
2070
  _mixOf(trackId: string): TrackMixerValues;
2071
+ /** @internal */
2072
+ _trackLinkState(trackId: string): LinkState;
2073
+ /** @internal */
2074
+ _clipLinkState(trackId: string, clipId: string): LinkState;
2075
+ /** @internal The stored mix (not a take's mute) and the name. */
2076
+ _trackValues(trackId: string): TrackLinkValues | null;
2077
+ /** @internal */
2078
+ _clipValues(trackId: string, clipId: string): ClipLinkValues | null;
2079
+ /** @internal A property or attribute set on a live `<daw-track>`: one undo step per field kind. */
2080
+ _requestTrackChange(trackId: string, partial: Partial<TrackLinkValues>): void;
2081
+ /** One gesture id per track for the rest of this task: mix sets made together are one step (#843). */
2082
+ private _taskGestures;
2083
+ private _taskGesture;
2084
+ /** @internal A property or attribute set on a live `<daw-clip>`: one undo step. */
2085
+ _requestClipChange(trackId: string, clipId: string, partial: Partial<ClipLinkValues>): void;
2086
+ /**
2087
+ * The clips of an entering track that another track of the arrangement
2088
+ * holds (the page moved their `<daw-clip>` here while the track waited):
2089
+ * the track takes the held clip as it is, and `from` names what leaves
2090
+ * where. A held clip of the other kind is refused and stays.
2091
+ */
2092
+ private _takeOverMovedClips;
2093
+ /** Run `fn` as one undo step of each arrangement it changes. */
2094
+ private _inOneStep;
2095
+ /** The `peaks-src` some track took for a clip element, if any. */
2096
+ private _takenPeaksSrc;
2097
+ /**
2098
+ * The arrangement whose history holds a track: the one that holds it now,
2099
+ * or else, for a page track, the own one (an Undo took it out there; a
2100
+ * handed-in arrangement may be played meanwhile), or else the one played.
2101
+ */
2102
+ private _historyOf;
2103
+ /** The track of the arrangement played that holds a clip: `trackId` when it does, or else the one that does. */
2104
+ private _clipHolderId;
2105
+ /** @internal */
2106
+ _trackKind(trackId: string): TrackKind | null;
2107
+ /** @internal */
2108
+ _trackIndex(trackId: string): number;
2109
+ /** @internal */
2110
+ _detachedReason(): string;
2111
+ /** Set or clear `:state(detached)` on every registered element (#848). */
2112
+ private _refreshLinkStates;
1853
2113
  /**
1854
2114
  * Change one mixer field of a track: the arrangement's setter with
1855
2115
  * `options` (an undo step; changes with one `gesture` id are one step). A
@@ -1888,28 +2148,24 @@ declare class DawEditorElement extends LitElement implements MidiLoaderHost {
1888
2148
  private _onTrackConnected;
1889
2149
  private _onTrackRemoved;
1890
2150
  private _onTrackUpdate;
2151
+ /** The arrangement that holds a track: the one played, else the own one (a page track while handed in). */
2152
+ private _arrangementOf;
2153
+ /** Rename a track in the arrangement (an undo step); the same name changes nothing. */
2154
+ private _renameTrack;
1891
2155
  /** Drop the controller when no spectrogram tracks remain. */
1892
2156
  private _disposeSpectrogramControllerIfEmpty;
1893
- /** Reconcile `_tracks` descriptors with the engine's track list.
1894
- *
1895
- * ADD: engine.undo() restores removed tracks in ENGINE state only —
1896
- * without a synthesized descriptor the track plays and renders but shows
1897
- * "Untitled" controls and is missing from `editor.tracks`.
1898
- * PRUNE (the symmetric half): redo removes the track from engine state
1899
- * again — without pruning, the synthesized descriptor is a permanent
1900
- * ghost that even removeTrack() can't clean (no element, no engine
1901
- * entry). Never prunes tracks that are mid-load or element-backed —
1902
- * their descriptors legitimately precede their engine entries. */
1903
- _reconcileDescriptorsWithEngineTracks(tracks: readonly ClipTrack[]): void;
1904
- /** Prune id-bearing drop descriptors the engine no longer has, and refresh
1905
- * the rest from their engine clip. Returns the SAME array when nothing
1906
- * changed, so an unchanged track never triggers a re-render. */
1907
- private _reconcileIdentifiedDropClips;
1908
2157
  private static _CONTROL_PROPS;
1909
2158
  private _onTrackControl;
1910
2159
  private _onTrackRemoveRequest;
1911
2160
  private _onClipConnected;
1912
- private _onClipUpdate;
2161
+ /**
2162
+ * A `<daw-clip>` now under `trackId` whose clip another track holds: the
2163
+ * clip moves to this track (one undo step) when both have entered the same
2164
+ * arrangement; a clip of the other kind stays with `daw-clip-error`.
2165
+ * Otherwise the old track lets it go and the element goes on as a new
2166
+ * arrival. Returns true when nothing more is to be done.
2167
+ */
2168
+ private _rehomeClip;
1913
2169
  private _onClipRemovedFromDom;
1914
2170
  /**
1915
2171
  * A `<daw-clip>` appended to a track that has entered: the clip goes in as
@@ -1933,8 +2189,29 @@ declare class DawEditorElement extends LitElement implements MidiLoaderHost {
1933
2189
  */
1934
2190
  private _replaceClip;
1935
2191
  private _applyClipUpdate;
2192
+ /**
2193
+ * A change to a clip still loading (#848 P10): its times, gain and name in
2194
+ * seconds on the `LoadingClip`, one undo step; the audio loads into it.
2195
+ */
2196
+ private _updateLoadingClip;
1936
2197
  /** Remove a clip (loaded or still loading) from a track of the arrangement: an undo step. */
2198
+ /**
2199
+ * An aborted addClip (D3): its clip leaves for good, from the track it
2200
+ * entered or from what a waiting track will enter with.
2201
+ */
2202
+ private _discardAddedClip;
1937
2203
  private _removeClipFromTrack;
2204
+ /** Record that the editor took a clip of a track (with its `peaks-src`, '' when none). */
2205
+ private _takeClip;
2206
+ /**
2207
+ * A `<daw-clip>` the editor took is removed while the arrangement does not
2208
+ * hold its clip (its track or its own arrival undone, or refused): it is
2209
+ * gone for good, also from the undo and redo states, so no Redo brings it
2210
+ * back (maintainer's choice, #848).
2211
+ */
2212
+ private _dropUnheldClip;
2213
+ /** The editor no longer holds anything for a clip of a track. */
2214
+ private _forgetClip;
1938
2215
  private _readTrackDescriptor;
1939
2216
  private _readClipDescriptor;
1940
2217
  private _isEntered;
@@ -1949,9 +2226,6 @@ declare class DawEditorElement extends LitElement implements MidiLoaderHost {
1949
2226
  * next page track finds it empty again).
1950
2227
  */
1951
2228
  _flushTrackEntries(): void;
1952
- private _waitingForDragEnd;
1953
- /** Flush the queue once the drag in progress has ended (its pointer or key is released). */
1954
- private _flushAfterDrag;
1955
2229
  /** Enter one registered track. False when it is gone, already in, or refused. */
1956
2230
  private _enterTrack;
1957
2231
  /**
@@ -1974,7 +2248,7 @@ declare class DawEditorElement extends LitElement implements MidiLoaderHost {
1974
2248
  /** Who waits for a track to enter (addTrack, a dropped file). */
1975
2249
  private _entryWaiters;
1976
2250
  private _waitForEntry;
1977
- /** Settle the wait for a track's entry: entered (`null`), or refused or gone. */
2251
+ /** Settle the wait for a track's entry: entered (`ENTERED`), or refused or gone (the reason).*/
1978
2252
  private _settleEntry;
1979
2253
  /**
1980
2254
  * A dropped file as a track with no element (a File cannot be an attribute):
@@ -1986,9 +2260,15 @@ declare class DawEditorElement extends LitElement implements MidiLoaderHost {
1986
2260
  * Take a track out for good: no undo step, and no undo or redo brings it
1987
2261
  * back (a dropped file that could not be loaded was never a declaration).
1988
2262
  */
1989
- _discardTrack(trackId: string): void;
1990
- /** Ends the waits of `_whenTrackLoaded` (as loaded) when the editor is disconnected. */
1991
- private _loadWaitEnds;
2263
+ _discardTrack(trackId: string, from?: Arrangement): void;
2264
+ /** One AbortController per arrangement while it is played (D2, interactions/abort.ts). */
2265
+ private _playSignals;
2266
+ /** The signal of the arrangement played now: aborted when it is swapped out. */
2267
+ private get _playSignal();
2268
+ /** @internal A caller's signal combined with the arrangement played now (loadMidi, D6). */
2269
+ _operationSignal(signal?: AbortSignal): AbortSignal;
2270
+ /** One AbortController per connection: aborted in disconnectedCallback (D8). */
2271
+ private _connection;
1992
2272
  /**
1993
2273
  * Resolves once the track has loaded (`daw-track-ready`), or when the
1994
2274
  * editor is disconnected meanwhile (the track is kept and loads after a
@@ -2028,22 +2308,23 @@ declare class DawEditorElement extends LitElement implements MidiLoaderHost {
2028
2308
  * peak sync then makes their peaks.
2029
2309
  */
2030
2310
  private _adoptLoadedClips;
2031
- /** The engine's state changed: follow it (the one writer of `_engineTracks`). */
2311
+ /** The engine's state changed: draw it (the rows are read from the arrangement). */
2032
2312
  private _onEngineState;
2033
2313
  private _onEngineStop;
2034
2314
  private _disposeEngine;
2035
2315
  private _onDragOver;
2036
2316
  private _onDragLeave;
2037
2317
  private _onDrop;
2038
- loadFiles(files: FileList | File[]): Promise<LoadFilesResult>;
2318
+ loadFiles(files: FileList | File[], options?: EditorCallOptions): Promise<LoadFilesResult>;
2039
2319
  /**
2040
- * Imperatively load a `.mid` file (URL or File) and create N `<daw-track>`
2041
- * elements — one per note-bearing MIDI track. On any per-track failure,
2042
- * every `<daw-track>` appended during the call is removed (both successful
2043
- * and failed) so the editor returns to its pre-call state.
2320
+ * Imperatively load a `.mid` file (URL or File) and add N tracks (no
2321
+ * element, #848), one per note-bearing MIDI track. On any per-track
2322
+ * failure, every track the call added is removed with no undo step, so the
2323
+ * editor is as before the call.
2044
2324
  *
2045
- * `options.signal` is forwarded to `fetch()` only for URL sources; aborting
2046
- * after parsing does not cancel in-flight `addTrack` calls.
2325
+ * `options.signal` cancels the fetch, the parse and the tracks still
2326
+ * waiting to enter (combined with the arrangement played: a swap cancels
2327
+ * too); the call rejects with its `reason` and removes the tracks it added.
2047
2328
  *
2048
2329
  * Requires the optional `@dawcore/midi` peer dep — throws with an install
2049
2330
  * hint (and `console.warn`s the original error) when the dynamic import
@@ -2057,67 +2338,91 @@ declare class DawEditorElement extends LitElement implements MidiLoaderHost {
2057
2338
  */
2058
2339
  ready(): Promise<PlaylistEngine>;
2059
2340
  /**
2060
- * Append a `<daw-track>` element built from `config` and resolve with its
2061
- * track id once the track has entered the arrangement (#848), before its
2062
- * audio has loaded. To follow loading, add the `daw-track-ready` /
2063
- * `daw-track-error` listener BEFORE calling: for a track with nothing to
2064
- * fetch, or whose audio is already loaded, it fires before this resolves.
2065
- * Without `editor.adapter` it waits for one. Rejects when the track is
2066
- * refused by the arrangement or removed before it enters.
2341
+ * Add a track built from `config` to the arrangement the editor plays when
2342
+ * it is called, and resolve with its id once it has entered (#848), before
2343
+ * its audio has loaded. A swap of `editor.arrangement` before it enters
2344
+ * rejects with an `AbortError` and the track enters nowhere; to add to
2345
+ * another arrangement, call that arrangement's own `addTrack`. No element is created: the track is drawn and listed like any
2346
+ * other, and `<daw-track>` children stay the page's declaration. To follow
2347
+ * loading, add the `daw-track-ready` / `daw-track-error` listener BEFORE
2348
+ * calling: for a track with nothing to fetch it fires before this
2349
+ * resolves. Without `editor.adapter` it waits for one. Rejects when the
2350
+ * arrangement refuses the track, when it is removed before it enters, or
2351
+ * when the engine cannot be built.
2352
+ *
2353
+ * `options.signal` (#848): aborting it before the track has entered takes
2354
+ * it out of the queue (it never enters) and rejects with its `reason`;
2355
+ * after that it changes nothing (the audio goes on loading). A signal
2356
+ * already aborted rejects at once and queues nothing.
2067
2357
  */
2068
- addTrack(config?: TrackConfig): Promise<string>;
2358
+ addTrack(config?: TrackConfig, options?: EditorCallOptions): Promise<string>;
2069
2359
  /**
2070
- * Remove a track by id. Equivalent to `trackElement.remove()` —
2071
- * the editor's MutationObserver handles engine and cache cleanup.
2072
- * No-op if no matching track exists.
2360
+ * A queued track goes into the arrangement played when it was queued: when
2361
+ * that one is swapped out first, the track leaves the queue and its wait
2362
+ * rejects with the swap's AbortError (addTrack, a dropped file).
2363
+ */
2364
+ private _endEntryOnSwap;
2365
+ /** A track that has not entered leaves the queue and its wait rejects with `reason` (D4). */
2366
+ private _abortEntry;
2367
+ /**
2368
+ * Remove a track by id: its `<daw-track>` element is removed (the
2369
+ * MutationObserver does the rest), or, for a track with no element
2370
+ * (`addTrack`, a dropped file, an Undo), the track itself. One undo step.
2371
+ * Warns when no track has the id.
2073
2372
  */
2074
2373
  removeTrack(trackId: string): void;
2075
2374
  /**
2076
- * Move a track to a new position in the vertical order (0-based index among
2077
- * `<daw-track>` elements). Element-backed tracks move their DOM element —
2078
- * the MutationObserver syncs the engine (single write path). Element-less
2079
- * tracks (undo-resurrected) reorder the engine directly.
2375
+ * Move a track to a 0-based position in the arrangement's order (every
2376
+ * track counts, those with no element too; `trackEl.index` and
2377
+ * `editor.tracks` give the positions). One undo step; no element moves.
2080
2378
  */
2081
2379
  reorderTrack(trackId: string, toIndex: number): void;
2082
2380
  private _onTrackReorder;
2083
2381
  private _onTrackReorderGrab;
2084
2382
  /**
2085
- * Update reflected attributes on a track. The mixer fields go to their
2086
- * owner, the arrangement, as one undo step (#843; also while the track
2087
- * loads, #848). For DOM-element tracks the
2088
- * changes are also written to the `<daw-track>` element; for tracks
2089
- * without a DOM element (file drops) the descriptor is updated in place.
2383
+ * Change a track: the mix (one undo step, #843), the name (an undo step),
2384
+ * the render mode and spectrogram config (the editor's). The arrangement
2385
+ * is changed, never an element's attributes (#848): a `<daw-track>`'s
2386
+ * properties show the change. A track that has not entered yet gets it as
2387
+ * the value it enters with.
2090
2388
  */
2091
2389
  updateTrack(trackId: string, partial: Partial<TrackConfig>): void;
2390
+ /** `updateTrack` on a track waiting to enter: the values it will enter with. */
2391
+ private _updatePendingTrack;
2092
2392
  /**
2093
- * Append a clip to an existing track. Builds a `<daw-clip>` from `config`
2094
- * and appends it to the track's DOM element; resolves with the new clip's
2393
+ * Add a clip to a track (with or without an element) and resolve with its
2095
2394
  * id once its audio has loaded (`daw-clip-ready`, before its peaks are
2096
- * drawn); rejects when it fails to load, is refused, or leaves the
2097
- * arrangement before it loads (a removal, an Undo).
2395
+ * drawn). The clip enters the arrangement as a loading clip, one undo
2396
+ * step; no `<daw-clip>` is created (#848). Rejects when it fails to load,
2397
+ * is refused (its kind), or leaves the arrangement before it loads (a
2398
+ * removal, an Undo). A clip added while the editor is detached loads once
2399
+ * a fresh adapter is set.
2400
+ *
2401
+ * `options.signal` (#848): aborting it before the clip has loaded rejects
2402
+ * with its `reason` and removes the clip for good (no undo step); after it
2403
+ * has loaded it changes nothing. A signal already aborted rejects at once
2404
+ * and adds nothing. A swap of `editor.arrangement` rejects the call with an
2405
+ * `AbortError`; its loading clip stays in the arrangement swapped out.
2098
2406
  */
2099
- addClip(trackId: string, config: ClipConfig): Promise<string>;
2407
+ addClip(trackId: string, config: ClipConfig, options?: EditorCallOptions): Promise<string>;
2100
2408
  /**
2101
- * Remove a clip by id. Removes the matching `<daw-clip>` DOM element when
2102
- * present (MutationObserver handles cleanup); otherwise updates engine
2103
- * state directly. No-op if no matching clip exists.
2409
+ * Remove a clip by id: its `<daw-clip>` when there is one (the observer
2410
+ * removes the clip, as `select.remove(i)` removes an option), otherwise
2411
+ * the clip itself, one undo step. Undo brings the clip back with no
2412
+ * element. No-op with a warning when there is no such clip.
2104
2413
  */
2105
2414
  removeClip(trackId: string, clipId: string): void;
2106
2415
  /**
2107
- * Update a clip's position (start/duration/offset) or properties (gain/name).
2108
- * For DOM-element clips, writes properties on the `<daw-clip>` element which
2109
- * fires `daw-clip-update`; otherwise applies directly via `_applyClipUpdate`.
2416
+ * Change a clip's position (start/duration/offset), gain or name: one undo
2417
+ * step on the arrangement (#848; a clip still loading changes its loading
2418
+ * clip). A `<daw-clip>`'s properties show the change, its attributes do
2419
+ * not. Fades are a `<daw-clip>` declaration only (engine-side fades are
2420
+ * #489): `fadeIn` / `fadeOut` / `fadeType` here change nothing.
2110
2421
  *
2111
2422
  * Re-decoding (changing `src`) is not supported via this method — remove and
2112
2423
  * re-add the clip instead.
2113
- *
2114
- * Note: `fadeIn` / `fadeOut` / `fadeType` on the partial are written to the
2115
- * `<daw-clip>` element (so they round-trip in the descriptor), but engine-side
2116
- * fade application from `<daw-clip>` properties is not yet implemented — see
2117
- * the broader fade-engine integration tracked separately.
2118
2424
  */
2119
2425
  updateClip(trackId: string, clipId: string, partial: Partial<ClipConfig>): void;
2120
- private _buildClipElement;
2121
2426
  /**
2122
2427
  * Start playback, optionally seeking to `startTime` first. When `endTime`
2123
2428
  * is provided, playback stops at that time (selection/annotation playback).
@@ -2208,28 +2513,14 @@ declare class DawEditorElement extends LitElement implements MidiLoaderHost {
2208
2513
  private get _showControls();
2209
2514
  /** True when the ruler header band should be rendered (and its selector is valid). */
2210
2515
  private get _showRuler();
2211
- /** Guards the statechange handler's engine→DOM sync (Task: reorder #612)
2212
- * while the observer is pushing DOM order INTO the engine — the intermediate
2213
- * statechange emissions during the transaction would otherwise bounce
2214
- * half-applied orders back into the DOM. */
2215
- _inOrderSync: boolean;
2216
- /**
2217
- * DOM → engine: make the engine's track order match the light-DOM
2218
- * `<daw-track>` order. Single write path for reorders — editor-initiated
2219
- * (buttons/drag move the element) and consumer-initiated (insertBefore)
2220
- * mutations both land here via the MutationObserver. Element-less tracks
2221
- * (undo-resurrected) keep their engine positions (stable sort).
2222
- * Write-only-on-change: a no-op when orders already match, so the
2223
- * engine→DOM direction (statechange handler) converges in one pass.
2224
- */
2225
- _syncEngineOrderToDom(): void;
2226
2516
  /**
2227
- * Engine → DOM: after an engine-initiated order change (undo/redo), move
2228
- * `<daw-track>` elements to match engine order. The resulting mutations fire
2229
- * the observer's _syncEngineOrderToDom, which finds the orders equal and
2230
- * no-ops — converges in one pass (write-only-on-change).
2517
+ * `<daw-track>` elements the page moved (one MutationObserver batch): each
2518
+ * is placed after the arrangement track of the nearest `<daw-track>` before
2519
+ * it, in DOM order, as one undo step (#848 P13). Elements whose track is
2520
+ * not in the arrangement are left alone (a queued one enters at its DOM
2521
+ * position). The arrangement's own order changes (an Undo) move no element.
2231
2522
  */
2232
- _syncDomToEngineOrder(tracks: readonly ClipTrack[]): void;
2523
+ private _placeMovedTracks;
2233
2524
  /**
2234
2525
  * The rows, in the arrangement's order (#848): each track's loaded clips
2235
2526
  * (the engine's projection, with the current mix) and the clips still loading.
@@ -2265,6 +2556,8 @@ declare class DawRecordButtonElement extends DawTransportButton {
2265
2556
  protected static requiredTargetMethods: readonly string[];
2266
2557
  private _isRecording;
2267
2558
  private _targetRef;
2559
+ /** The listeners on `_targetRef`, aborted when the target changes or the button disconnects. */
2560
+ private _targetListeners;
2268
2561
  private _onStart;
2269
2562
  private _onComplete;
2270
2563
  private _onError;
@@ -2331,6 +2624,8 @@ declare class DawKeyboardShortcutsElement extends LitElement {
2331
2624
  get shortcuts(): KeyboardShortcut[];
2332
2625
  /** Invalidate cached shortcuts when Lit properties change. */
2333
2626
  updated(): void;
2627
+ /** The listeners of this connection, aborted in disconnectedCallback. */
2628
+ private _listeners;
2334
2629
  connectedCallback(): void;
2335
2630
  disconnectedCallback(): void;
2336
2631
  createRenderRoot(): this;
@@ -2403,6 +2698,8 @@ declare class DawTimeDisplayElement extends LitElement {
2403
2698
  private get target();
2404
2699
  private _onTimeUpdate;
2405
2700
  private _onFormatChange;
2701
+ /** The listeners of this connection, aborted in disconnectedCallback. */
2702
+ private _listeners;
2406
2703
  connectedCallback(): void;
2407
2704
  disconnectedCallback(): void;
2408
2705
  private _syncFromTarget;
@@ -2435,6 +2732,8 @@ declare class DawTimeFormatElement extends LitElement {
2435
2732
  private _onFormatChange;
2436
2733
  private _onPointerEnter;
2437
2734
  private _onPointerDown;
2735
+ /** The listeners of this connection, aborted in disconnectedCallback. */
2736
+ private _listeners;
2438
2737
  connectedCallback(): void;
2439
2738
  disconnectedCallback(): void;
2440
2739
  protected updated(): void;
@@ -2483,6 +2782,8 @@ declare class DawPlayerElement extends LitElement {
2483
2782
  connectedCallback(): void;
2484
2783
  render(): lit.TemplateResult<1>;
2485
2784
  protected updated(changed: PropertyValues): void;
2785
+ /** The peaks fetch in flight: a newer peaks-src or a disconnect aborts it (#848, D7). */
2786
+ private _peaksFetch;
2486
2787
  private _loadPeaks;
2487
2788
  /** Recompute fit-to-width peaks from the loaded WaveformData. No-op without data. */
2488
2789
  private _renderWaveform;
@@ -2579,6 +2880,8 @@ interface AudioResumeHost extends ReactiveControllerHost, HTMLElement {
2579
2880
  declare class AudioResumeController implements ReactiveController {
2580
2881
  private _host;
2581
2882
  private _target;
2883
+ /** The gesture listeners on `_target`: one controller per attach. */
2884
+ private _listeners;
2582
2885
  private _attached;
2583
2886
  private _generation;
2584
2887
  /** CSS selector, or 'document'. When undefined, controller is inert. */
@@ -2706,4 +3009,4 @@ interface SplitHost {
2706
3009
  */
2707
3010
  declare function splitAtPlayhead(host: SplitHost): boolean;
2708
3011
 
2709
- export { ANNOTATION_LANE_HEIGHT, AudioResumeController, type ClipConfig, type ClipDescriptor, type ClipEngineContract, ClipPointerHandler, type ClipPointerHost, type DawAnnotationConnectedDetail, DawAnnotationElement, DawAnnotationListElement, type DawAnnotationSelectDetail, type DawAnnotationTrackConnectedDetail, DawAnnotationTrackElement, type DawAnnotationUpdateDetail, type DawClipConnectedDetail, DawClipElement, type DawClipErrorDetail, type DawClipIdDetail, type DawClipMoveDetail, type DawClipSplitDetail, type DawClipTrimDetail, type DawClipUpdateDetail, DawEditorElement, type DawEffectAddDetail, type DawEffectBypassDetail, type DawEffectChangeDetail, type DawEffectErrorDetail, type DawEffectRemoveDetail, type DawEffectReorderDetail, type DawErrorDetail, type DawEvent, type DawEventMap, type DawFilesLoadErrorDetail, DawGridElement, DawKeyboardShortcutsElement, DawPauseButtonElement, DawPianoRollElement, DawPlayButtonElement, DawPlayerElement, DawPlayheadElement, DawRecordButtonElement, type DawRecordingClipAddDetail, type DawRecordingCompleteDetail, type DawRecordingErrorDetail, type DawRecordingStartDetail, DawRulerElement, type DawSeekDetail, type DawSelectionDetail, DawSelectionElement, DawSpectrogramElement, DawStopButtonElement, DawTimeDisplayElement, type DawTimeFormatChangeDetail, DawTimeFormatElement, type DawTimeUpdateDetail, type DawTrackConnectedDetail, type DawTrackControlDetail, DawTrackControlsElement, DawTrackElement, type DawTrackErrorDetail, type DawTrackIdDetail, type DawTrackRemoveDetail, type DawTrackSelectDetail, type DawTrackUpdateDetail, DawTransportButton, DawTransportElement, DawWaveformElement, type DomClipDescriptor, type DropClipDescriptor, type EffectState, type ExportAudioHost, type ExportOptions, type KeyBinding, type LoadFilesResult, PlaybackAnimationController, type PlaybackAnimationOptions, type PlaybackShortcutMap, type PlayheadLike, type PointerEngineContract, RecordingController, type RecordingOptions, type RecordingSession, type SerializedEffectEntry, SpectrogramController, type SplitEngineContract, type SplitHost, type SplittingShortcutMap, TIME_DISPLAY_FORMATS, type TimeDisplayFormat, type TrackConfig, type TrackDescriptor, type TrackRenderMode, type TrackWithId, type UndoShortcutMap, type WaveformSegment, formatDisplayTime, isDomClip, isTimeDisplayFormat, parseDisplayTime, resolveTransportTarget, splitAtPlayhead, targetSupports, warnOnce, warnUnsupportedOnce };
3012
+ export { ANNOTATION_LANE_HEIGHT, AudioResumeController, type ClipConfig, type ClipDescriptor, type ClipEngineContract, ClipPointerHandler, type ClipPointerHost, type DawAnnotationConnectedDetail, DawAnnotationElement, DawAnnotationListElement, type DawAnnotationSelectDetail, type DawAnnotationTrackConnectedDetail, DawAnnotationTrackElement, type DawAnnotationUpdateDetail, type DawClipConnectedDetail, DawClipElement, type DawClipErrorDetail, type DawClipIdDetail, type DawClipMoveDetail, type DawClipSplitDetail, type DawClipTrimDetail, type DawClipUpdateDetail, DawEditorElement, type DawEffectAddDetail, type DawEffectBypassDetail, type DawEffectChangeDetail, type DawEffectErrorDetail, type DawEffectRemoveDetail, type DawEffectReorderDetail, type DawErrorDetail, type DawEvent, type DawEventMap, type DawFilesLoadErrorDetail, DawGridElement, DawKeyboardShortcutsElement, DawPauseButtonElement, DawPianoRollElement, DawPlayButtonElement, DawPlayerElement, DawPlayheadElement, DawRecordButtonElement, type DawRecordingClipAddDetail, type DawRecordingCompleteDetail, type DawRecordingErrorDetail, type DawRecordingStartDetail, DawRulerElement, type DawSeekDetail, type DawSelectionDetail, DawSelectionElement, DawSpectrogramElement, DawStopButtonElement, DawTimeDisplayElement, type DawTimeFormatChangeDetail, DawTimeFormatElement, type DawTimeUpdateDetail, type DawTrackConnectedDetail, type DawTrackControlDetail, DawTrackControlsElement, DawTrackElement, type DawTrackErrorDetail, type DawTrackIdDetail, type DawTrackRemoveDetail, type DawTrackSelectDetail, type DawTrackUpdateDetail, DawTransportButton, DawTransportElement, DawWaveformElement, type DomClipDescriptor, type DropClipDescriptor, type EditorCallOptions, type EffectState, type ExportAudioHost, type ExportOptions, type KeyBinding, type LoadFilesResult, PlaybackAnimationController, type PlaybackAnimationOptions, type PlaybackShortcutMap, type PlayheadLike, type PointerEngineContract, RecordingController, type RecordingOptions, type RecordingSession, type SerializedEffectEntry, SpectrogramController, type SplitEngineContract, type SplitHost, type SplittingShortcutMap, TIME_DISPLAY_FORMATS, type TimeDisplayFormat, type TrackConfig, type TrackDescriptor, type TrackRenderMode, type TrackWithId, type UndoShortcutMap, type WaveformSegment, formatDisplayTime, isDomClip, isTimeDisplayFormat, parseDisplayTime, resolveTransportTarget, splitAtPlayhead, targetSupports, warnOnce, warnUnsupportedOnce };