@dawcore/components 0.0.39-next.2 → 0.0.39-next.20

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, PanLaw, TrackKind, RenderMode, SpectrogramConfig, Peaks, Bits, FadeType, PeakData, MeterEntry, SnapTo, ColorMapValue, ClipTrack, KeyBinding, KeyboardShortcut } from '@waveform-playlist/core';
4
4
  import WaveformData from 'waveform-data';
5
- import { PlayoutAdapter, PlaylistEngine } from '@waveform-playlist/engine';
5
+ import { Arrangement, TrackMixerValues, PlayoutAdapter, EditorEngine } 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,47 @@ 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
+ /**
302
+ * The track's pan law (#684): `'mono'` (equal power, −3 dB per side at
303
+ * centre) or `'stereo'` (unity at centre, panning folds one channel into
304
+ * the other). `pan-law` declares the law the track enters with; without
305
+ * it the track's first decoded audio decides, and the track then keeps
306
+ * that law whatever clips follow. Live: reads the arrangement's value
307
+ * (`'auto'` while the track has no audio), and the editor writes no
308
+ * attribute. Setting `'mono'` or `'stereo'` on an entered track is a
309
+ * request (an undo step); `'auto'` there changes nothing.
310
+ */
311
+ get panLaw(): PanLaw;
312
+ set panLaw(value: PanLaw);
313
+ /** The stored mute (a take's mute is not shown here). */
314
+ get muted(): boolean;
315
+ set muted(value: boolean);
316
+ get soloed(): boolean;
317
+ set soloed(value: boolean);
318
+ /** The track's position in the arrangement the editor plays; -1 when it is not there. */
319
+ get index(): number;
320
+ /** What the page declared: the attributes, and a property set before the track entered. */
321
+ private _declared;
322
+ private _fromAttribute;
323
+ private _internals;
324
+ attributeChangedCallback(name: string, old: string | null, value: string | null): void;
325
+ private _linked;
326
+ private _request;
327
+ /** @internal Shown as `:state(detached)` (#848). */
328
+ _setDetached(detached: boolean): void;
274
329
  /**
275
330
  * 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.
331
+ * child must be of this kind (#756). Set it before the track enters: the
332
+ * editor reads it then. Live (#848): once the track has entered, it reads
333
+ * the track's kind, which cannot change; a later change keeps the attribute
334
+ * (the page's declaration) and warns.
278
335
  */
279
336
  get kind(): TrackKind;
280
337
  set kind(value: TrackKind);
@@ -314,7 +371,19 @@ declare class DawTrackElement extends LitElement {
314
371
  moveEffect(effectId: string, newIndex: number): void;
315
372
  get effects(): EffectState[];
316
373
  private _effectsEditor;
374
+ /**
375
+ * A move with `Node.moveBefore()` (#848; modern-web-guidance
376
+ * `custom-elements`): the browser calls this instead of
377
+ * `disconnectedCallback` → `connectedCallback`, so the element stays
378
+ * connected, and Lit's disconnect and connect do not run. It announces
379
+ * itself again, as a connect does, so the editor sees its new place: a
380
+ * clip in another track, a track back in an editor (#848; a real-Chromium
381
+ * check found both missed with an empty hook).
382
+ */
383
+ connectedMoveCallback(): void;
317
384
  connectedCallback(): void;
385
+ /** Tell the editor this element is here (a connect or a moveBefore() move). */
386
+ private _announceConnected;
318
387
  private _hasRendered;
319
388
  updated(changed: PropertyValues): void;
320
389
  }
@@ -480,6 +549,8 @@ declare class DawTransportButton extends LitElement {
480
549
  * warns if it's still unusable.
481
550
  */
482
551
  protected get targetSupported(): boolean;
552
+ /** The host's capability listeners, one controller per connection. */
553
+ private _capabilityListeners;
483
554
  connectedCallback(): void;
484
555
  disconnectedCallback(): void;
485
556
  private _onCapabilityPointerEnter;
@@ -490,6 +561,8 @@ declare class DawTransportButton extends LitElement {
490
561
  declare class DawPlayButtonElement extends DawTransportButton {
491
562
  private _isRecording;
492
563
  private _targetRef;
564
+ /** The listeners on `_targetRef`, aborted when the target changes or the button disconnects. */
565
+ private _targetListeners;
493
566
  private _onRecStart;
494
567
  private _onRecEnd;
495
568
  connectedCallback(): void;
@@ -510,6 +583,8 @@ declare class DawPauseButtonElement extends DawTransportButton {
510
583
  private _isPaused;
511
584
  private _isRecording;
512
585
  private _targetRef;
586
+ /** The listeners on `_targetRef`, aborted when the target changes or the button disconnects. */
587
+ private _targetListeners;
513
588
  private _onRecStart;
514
589
  private _onRecEnd;
515
590
  private _onRecPause;
@@ -545,6 +620,8 @@ interface TrackDescriptor {
545
620
  src: string;
546
621
  volume: number;
547
622
  pan: number;
623
+ /** The pan law: `'auto'` until the track's first decoded audio decides it (#684). */
624
+ panLaw: PanLaw;
548
625
  muted: boolean;
549
626
  soloed: boolean;
550
627
  /** What the track holds: audio clips or MIDI clips, never both (#756). */
@@ -555,6 +632,29 @@ interface TrackDescriptor {
555
632
  spectrogramConfig?: SpectrogramConfig | null;
556
633
  clips: ClipDescriptor[];
557
634
  }
635
+ /** The mixer fields of a `TrackDescriptor`. */
636
+ type TrackMixFields = 'volume' | 'pan' | 'muted' | 'soloed' | 'panLaw';
637
+ /**
638
+ * What `<daw-editor>` stores per track (internal, not exported from the
639
+ * package): a `TrackDescriptor` without its mix. The mix is the arrangement's
640
+ * (#843); `editor.tracks` fills the mix fields in from it.
641
+ */
642
+ type StoredTrackDescriptor = Omit<TrackDescriptor, TrackMixFields>;
643
+ /**
644
+ * What `<daw-editor>` keeps per track that the arrangement has no field for
645
+ * (internal, #848): how the track is drawn, the `<daw-track src>` shorthand
646
+ * as declared, and each clip's `peaks-src`. Names, times, gains and the mix
647
+ * are read from the arrangement; nothing here is written back to it.
648
+ */
649
+ interface TrackExtras {
650
+ kind: TrackKind;
651
+ renderMode: TrackRenderMode;
652
+ spectrogramConfig?: SpectrogramConfig | null;
653
+ /** The `<daw-track src>` shorthand as declared ('' when none). */
654
+ src: string;
655
+ /** A clip's `peaks-src`, by clip id. */
656
+ peaksSrc: ReadonlyMap<string, string>;
657
+ }
558
658
  /** A `TrackDescriptor` plus its `trackId` — the shape returned by `editor.tracks`
559
659
  * so consumers can map a track's name to the `trackId` the per-track APIs
560
660
  * (`addTrackEffect`, `removeTrack`, `updateTrack`, …) are keyed by. */
@@ -582,8 +682,8 @@ interface BaseClipDescriptor {
582
682
  /**
583
683
  * A clip descriptor sourced from a `<daw-clip>` DOM element. `clipId` is
584
684
  * always set — `<daw-clip>.clipId` is a `crypto.randomUUID()` generated at
585
- * construction. Engine `clip.id` is aligned with this id in `_loadTrack`
586
- * and `_loadAndAppendClip` so DOM and engine reference the same clip.
685
+ * construction. The arrangement clip's id is this id (`buildArrangementTrack`,
686
+ * `_loadAndAppendClip`), so the DOM and the arrangement name the same clip.
587
687
  */
588
688
  interface DomClipDescriptor extends BaseClipDescriptor {
589
689
  kind: 'dom';
@@ -592,16 +692,18 @@ interface DomClipDescriptor extends BaseClipDescriptor {
592
692
  /**
593
693
  * A clip descriptor synthesized from a non-DOM source — file drops, the
594
694
  * `<daw-track src>` shorthand fallback, or recording-clip insertion. There
595
- * is no DOM element to align with; the engine generates its own id at
596
- * clip-creation time.
695
+ * is no DOM element to align with.
597
696
  *
598
- * `clipId` is that engine clip id when the editor knows it at descriptor
599
- * creation — currently recorded takes (#659). Pass it to
600
- * `editor.updateClip()` / `removeClip()` to address the clip.
697
+ * `clipId` is the arrangement clip's id: set at creation for a recorded take
698
+ * (#659), and written in when a dropped file or the shorthand enters the
699
+ * arrangement (#848). Pass it to `editor.updateClip()` / `removeClip()` to
700
+ * address the clip.
601
701
  */
602
702
  interface DropClipDescriptor extends BaseClipDescriptor {
603
703
  kind: 'drop';
604
704
  clipId?: string;
705
+ /** A dropped file the clip loads (`src` is then ''): a File cannot be an attribute (#848). */
706
+ file?: File;
605
707
  }
606
708
  type ClipDescriptor = DomClipDescriptor | DropClipDescriptor;
607
709
  /**
@@ -610,6 +712,16 @@ type ClipDescriptor = DomClipDescriptor | DropClipDescriptor;
610
712
  * inline `c.kind === 'dom'` repetition.
611
713
  */
612
714
  declare function isDomClip(desc: ClipDescriptor): desc is DomClipDescriptor;
715
+ /**
716
+ * Options of `addTrack`, `addClip` and `loadFiles` (#848). `signal` cancels
717
+ * the call: it rejects with the signal's `reason`, and what it added is
718
+ * taken out for good (see each method), with no undo step left. A Redo list
719
+ * its arrival cleared stays cleared, as after any edit. A signal already
720
+ * aborted rejects at once and adds nothing.
721
+ */
722
+ interface EditorCallOptions {
723
+ signal?: AbortSignal;
724
+ }
613
725
  /**
614
726
  * Public input shape for `editor.addTrack(config)`. All fields optional —
615
727
  * defaults match the declarative `<daw-track>` defaults.
@@ -618,6 +730,13 @@ interface TrackConfig {
618
730
  name?: string;
619
731
  volume?: number;
620
732
  pan?: number;
733
+ /**
734
+ * The pan law (#684): `'mono'` or `'stereo'`. In `addTrack` it is the law
735
+ * the track enters with (default: decided by its first decoded audio); in
736
+ * `updateTrack` it sets the law of an entered track. `'auto'` there, or a
737
+ * value that is not a law, changes nothing.
738
+ */
739
+ panLaw?: PanLaw;
621
740
  muted?: boolean;
622
741
  soloed?: boolean;
623
742
  /**
@@ -767,19 +886,35 @@ declare class DawTrackControlsElement extends LitElement {
767
886
  volume: number;
768
887
  pan: number;
769
888
  muted: boolean;
889
+ /** A take is recording onto the track: it plays muted, and the M button is disabled. */
890
+ recording: boolean;
770
891
  soloed: boolean;
771
892
  /** Show the reorder grip + move up/down buttons (set by the editor from
772
893
  * its track-reordering attribute). */
773
894
  reorderable: boolean;
774
895
  trackIndex: number;
775
896
  trackCount: number;
897
+ /**
898
+ * One gesture per slider (#843): the `daw-track-control` events of one
899
+ * drag, or of one key press (a held key included), carry the same
900
+ * `gesture` id, and the editor makes them one undo step. Each gesture is
901
+ * attached to its range input while the element is connected.
902
+ */
903
+ private readonly _volumeGesture;
904
+ private readonly _panGesture;
905
+ private _detachGestures;
776
906
  static styles: lit.CSSResult;
907
+ connectedCallback(): void;
908
+ disconnectedCallback(): void;
909
+ private _attachGestures;
910
+ private _detachAllGestures;
777
911
  protected firstUpdated(): void;
778
912
  private _onVolumeInput;
779
913
  private _onPanInput;
780
914
  private _onMuteClick;
781
915
  private _onSoloClick;
782
916
  private _onRemoveClick;
917
+ /** `gesture` for the sliders only: each mute or solo click is a step. */
783
918
  private _dispatchControl;
784
919
  private _dispatchReorder;
785
920
  private _onMoveUp;
@@ -880,13 +1015,7 @@ interface RecordingSession {
880
1015
  readonly latencySamples: number;
881
1016
  /** Display name for the take (preview header + finalized clip name). */
882
1017
  readonly clipName?: string;
883
- /** Pre-session mute state of the armed track — restored when the session
884
- * ends. null = mute never engaged (no engine on the host). */
885
- armedPrevMuted: boolean | null;
886
1018
  readonly wasOverdub: boolean;
887
- /** Stored so it can be removed on stop/cleanup — not just when stream ends. */
888
- readonly _onTrackEnded: (() => void) | null;
889
- readonly _audioTrack: MediaStreamTrack | null;
890
1019
  /** Set during stopRecording, cleared by the done message from the worklet. */
891
1020
  stopAckResolve: (() => void) | null;
892
1021
  /** In-flight stop completion — re-entrant stopRecording calls await this
@@ -898,7 +1027,7 @@ interface RecordingSession {
898
1027
  stopping: boolean;
899
1028
  }
900
1029
  /** Readonly view of a recording session for external consumers. */
901
- type ReadonlyRecordingSession = Readonly<Omit<RecordingSession, 'chunks' | 'peaks' | '_onTrackEnded' | '_audioTrack' | 'latencySamples'>> & {
1030
+ type ReadonlyRecordingSession = Readonly<Omit<RecordingSession, 'chunks' | 'peaks' | 'latencySamples'>> & {
902
1031
  readonly latencySamples: number;
903
1032
  readonly chunks: ReadonlyArray<ReadonlyArray<Float32Array>>;
904
1033
  readonly peaks: ReadonlyArray<Int8Array | Int16Array>;
@@ -919,20 +1048,15 @@ interface RecordingHost extends ReactiveControllerHost {
919
1048
  * position and misplaces punch-in (record-during-playback) clips. */
920
1049
  readonly currentTime: number;
921
1050
  readonly shadowRoot: ShadowRoot | null;
922
- resolveAudioContextSampleRate(rate: number): void;
923
1051
  _addRecordedClip?(trackId: string, buf: AudioBuffer, startSample: number, durSamples: number, offsetSamples?: number, clipName?: string): void;
924
- /** Structural view of the editor's engine for the armed-track transient
925
- * mute (punch-in replaces the overlapped content, so the recorded-over
926
- * track's existing material must not play under the take). Optional —
927
- * hosts without an engine skip the mute. */
1052
+ /** Structural view of the editor's engine for the take's mute (#843):
1053
+ * punch-in replaces the overlapped content, so the recorded-over track's
1054
+ * existing material must not play under the take. The track a take is
1055
+ * recording onto plays muted; that mute is outside the undo history and
1056
+ * leaves the stored mute alone. Optional — hosts without an engine skip
1057
+ * it. */
928
1058
  _engine?: {
929
- setTrackMute(trackId: string, muted: boolean): void;
930
- getState(): {
931
- tracks: ReadonlyArray<{
932
- id: string;
933
- muted: boolean;
934
- }>;
935
- };
1059
+ setTrackRecording(trackId: string, recording: boolean): void;
936
1060
  } | null;
937
1061
  play?(startTime?: number): Promise<void>;
938
1062
  stop?(): void;
@@ -957,6 +1081,8 @@ interface RecordingHost extends ReactiveControllerHost {
957
1081
  declare class RecordingController implements ReactiveController {
958
1082
  private _host;
959
1083
  private _sessions;
1084
+ /** Each session's mic-unplug listener, aborted when the session ends. */
1085
+ private _trackEndedListeners;
960
1086
  /** Track IDs with a startRecording in flight (session not yet in _sessions).
961
1087
  * The session is only set after several awaits — without this, two rapid
962
1088
  * start calls both pass the _sessions guard and build two capture
@@ -994,19 +1120,31 @@ declare class RecordingController implements ReactiveController {
994
1120
  private _removeTrackEndedListener;
995
1121
  private _dispatchRecordingError;
996
1122
  /** Shared teardown for finalize paths that end without a take (no data
997
- * captured / too short after latency compensation): restore the armed-track
998
- * mute, drop the session, and notify via daw-recording-error so record
999
- * buttons reset their state. */
1123
+ * captured / too short after latency compensation): clear the take's mute, drop
1124
+ * the session, and notify via daw-recording-error so record buttons reset
1125
+ * their state. */
1000
1126
  private _abandonFinalize;
1001
- /** Restore the armed track's pre-session mute state (idempotent — safe to
1002
- * call from both the finalize path and _cleanupSession). */
1003
- private _restoreArmedTrackMute;
1127
+ /** Clear the take's mute on the session's track, by its id. Each teardown
1128
+ * path calls this once, right before it drops the session from the map, so
1129
+ * a later path never reaches the same session; clearing an id that is not
1130
+ * set is a no-op in the engine. Another session's mute on another track is
1131
+ * left alone. */
1132
+ private _clearTakeMute;
1004
1133
  /** @param notifyError dispatch daw-recording-error after cleanup — used by
1005
1134
  * disposal paths that would otherwise discard the session silently. The
1006
1135
  * startRecording catch path passes false (it dispatches its own error). */
1007
1136
  private _cleanupSession;
1008
1137
  }
1009
1138
 
1139
+ /** A clip drag past its threshold, with the clip's bounds when it started. */
1140
+ interface DraggedClip {
1141
+ trackId: string;
1142
+ clipId: string;
1143
+ startSample: number;
1144
+ durationSamples: number;
1145
+ offsetSamples: number;
1146
+ }
1147
+
1010
1148
  /** Snapshot of a clip's bounds for trim constraint computation. */
1011
1149
  interface ClipBounds {
1012
1150
  readonly offsetSamples: number;
@@ -1016,19 +1154,13 @@ interface ClipBounds {
1016
1154
  }
1017
1155
  /** Narrow engine contract for clip move/trim interactions. */
1018
1156
  interface ClipEngineContract {
1019
- moveClip(trackId: string, clipId: string, deltaSamples: number, skipAdapter?: boolean): number;
1020
- trimClip(trackId: string, clipId: string, boundary: 'left' | 'right', deltaSamples: number, skipAdapter?: boolean): void;
1021
- updateTrack(trackId: string): void;
1157
+ /** Move a clip; returns the delta actually applied. One undo step. */
1158
+ moveClip(trackId: string, clipId: string, deltaSamples: number): number;
1159
+ trimClip(trackId: string, clipId: string, boundary: 'left' | 'right', deltaSamples: number): void;
1022
1160
  /** Get a clip's full bounds for trim constraint computation. */
1023
1161
  getClipBounds(trackId: string, clipId: string): ClipBounds | null;
1024
1162
  /** Constrain a trim delta using the engine's collision/bounds logic. */
1025
1163
  constrainTrimDelta(trackId: string, clipId: string, boundary: 'left' | 'right', deltaSamples: number): number;
1026
- /** Begin a transaction — groups mutations into one undo step. */
1027
- beginTransaction(): void;
1028
- /** Commit the transaction — pushes one undo step for all grouped mutations. */
1029
- commitTransaction(): void;
1030
- /** Abort the transaction — restores pre-transaction state without pushing to undo. */
1031
- abortTransaction(): void;
1032
1164
  }
1033
1165
  /** Peak data returned by reextractClipPeaks for imperative waveform updates. */
1034
1166
  interface ClipPeakSlice {
@@ -1043,6 +1175,11 @@ interface ClipPointerHost {
1043
1175
  readonly effectiveSampleRate: number;
1044
1176
  readonly interactiveClips: boolean;
1045
1177
  readonly engine: ClipEngineContract | null;
1178
+ /**
1179
+ * The arrangement played: a move collides with its clips, loading ones
1180
+ * included, as `moveClip` does (#859), and a drag follows its changes.
1181
+ */
1182
+ readonly arrangement: Pick<Arrangement, 'getTracks' | 'subscribe'>;
1046
1183
  readonly shadowRoot: ShadowRoot | null;
1047
1184
  readonly scaleMode: 'temporal' | 'beats';
1048
1185
  readonly ticksPerPixel: number;
@@ -1065,11 +1202,18 @@ interface ClipPointerHost {
1065
1202
  * Handles pointer interactions for clip move and trim drag operations.
1066
1203
  * Converts pixel deltas to sample deltas and delegates to the engine.
1067
1204
  *
1068
- * Move: sends incremental deltas per-frame with skipAdapter=true (engine shifts
1069
- * startSample additively without touching audio adapter). Adapter synced once
1070
- * via updateTrack() at drag end.
1071
- * Trim: updates clip container CSS imperatively during drag for visual feedback,
1072
- * then applies cumulative delta to engine once at drag end.
1205
+ * Both show the drag in the view and change the arrangement once, on release
1206
+ * (#848): nothing is written while the pointer moves, so an arrangement change
1207
+ * during a drag always came from outside.
1208
+ *
1209
+ * Move: the clip container's `left` follows the pointer, constrained by the
1210
+ * track's other clips, loading ones included, as `moveClip` will be; one
1211
+ * `moveClip` on release.
1212
+ * A change of the arrangement during a drag (audio arriving next to the clip)
1213
+ * draws the drag again from the last pointer position (#859), so a release
1214
+ * with no move after it commits what is drawn.
1215
+ * Trim: updates clip container CSS and peaks imperatively during drag, then
1216
+ * applies the cumulative delta to the engine once on release.
1073
1217
  */
1074
1218
  declare class ClipPointerHandler {
1075
1219
  private _host;
@@ -1086,6 +1230,10 @@ declare class ClipPointerHandler {
1086
1230
  private _originalOffsetSamples;
1087
1231
  private _originalDurationSamples;
1088
1232
  private _originalStartSample;
1233
+ private _moveClip;
1234
+ private _moveSorted;
1235
+ private _lastDeltaPx;
1236
+ private _stopFollowing;
1089
1237
  constructor(host: ClipPointerHost);
1090
1238
  /**
1091
1239
  * Convert a pixel delta to samples, snapping in tick space when in beats mode.
@@ -1096,36 +1244,61 @@ declare class ClipPointerHandler {
1096
1244
  * even if they started off-grid.
1097
1245
  */
1098
1246
  private _snapDeltaToSamples;
1247
+ /** A sample delta from `anchorSample` in pixels: in tick space in beats mode,
1248
+ * so the drawn position does not drift from the sample round-trip. */
1249
+ private _samplesToPx;
1099
1250
  /** Returns true if a drag interaction is currently in progress. */
1100
1251
  get isActive(): boolean;
1252
+ /** True once the pointer of the current press has moved past the drag
1253
+ * threshold: a press that has not moved is not a drag (#848). */
1254
+ get isDragging(): boolean;
1255
+ /**
1256
+ * The clip being dragged (past the threshold) with its bounds at the drag's
1257
+ * start, or null; null too while the release makes its one arrangement
1258
+ * call, so that call is not taken for an outside change (#848).
1259
+ */
1260
+ get draggedClip(): DraggedClip | null;
1261
+ private _committing;
1101
1262
  /**
1102
1263
  * Attempts to handle a pointerdown event on the given target element.
1103
1264
  * Returns true if the target is a recognized clip interaction element.
1104
1265
  */
1105
1266
  tryHandle(target: Element, e: PointerEvent): boolean;
1106
1267
  private _beginDrag;
1268
+ /**
1269
+ * The press has become a drag (the pointer passed the threshold): take the
1270
+ * clip's bounds now, not at the press, so a drag after an undo made during
1271
+ * the press starts from the clip as the undo left it (#848, review of
1272
+ * #915). Returns false when the clip is gone (the undo removed it): the
1273
+ * press is dropped.
1274
+ */
1275
+ private _startDrag;
1276
+ /** The dragged clip and its neighbours, read from the arrangement now. False when gone. */
1277
+ private _readMoveNeighbours;
1278
+ /** The tracks changed under the drag: draw it again from the last pointer position. */
1279
+ private _onArrangementChange;
1107
1280
  /** Processes pointermove events during an active drag. */
1108
1281
  onPointerMove(e: PointerEvent): void;
1282
+ /** Draw the drag `totalDeltaPx` from its start, constrained as the release will be. */
1283
+ private _applyDrag;
1109
1284
  /** Processes pointerup events to finalize and dispatch result events. */
1110
1285
  onPointerUp(_e: PointerEvent): void;
1111
1286
  /** Processes pointercancel — reverts the in-progress drag.
1112
1287
  *
1113
1288
  * pointercancel fires INSTEAD of pointerup on touch interruption, pen
1114
1289
  * leaving hover range, or OS gestures. Without this handler the drag stays
1115
- * armed (hover keeps moving the clip), the engine transaction stays open
1116
- * (every later edit becomes un-undoable until some drag commits), and the
1117
- * per-frame skipAdapter moveClip mutations are never synced or rolled back
1118
- * (waveform and audio permanently disagree). */
1290
+ * armed (hover keeps moving the clip). The drag wrote nothing to the
1291
+ * arrangement, so reverting is putting the view back. */
1119
1292
  onPointerCancel(_e: PointerEvent): void;
1120
1293
  /** Re-extract peaks from cache and set on waveform elements during trim drag.
1121
1294
  * Returns true if peaks were successfully updated. */
1122
1295
  private _updateWaveformPeaks;
1123
1296
  /** Restore clip container CSS AND waveform peaks to original values after
1124
- * a trim visual preview. Peaks matter: the drag wrote re-extracted peak
1297
+ * a drag's visual preview. Peaks matter: a trim wrote re-extracted peak
1125
1298
  * arrays imperatively onto the <daw-waveform> elements (bypassing Lit), and
1126
- * a cancelled/zero-delta trim makes no engine mutation — so no statechange
1299
+ * a cancelled/zero-delta drag makes no engine mutation — so no statechange
1127
1300
  * re-render will ever repair them. */
1128
- private _restoreTrimVisual;
1301
+ private _restoreVisual;
1129
1302
  private _reset;
1130
1303
  }
1131
1304
 
@@ -1140,8 +1313,16 @@ declare const TIME_DISPLAY_FORMATS: readonly TimeDisplayFormat[];
1140
1313
  declare function isTimeDisplayFormat(value: unknown): value is TimeDisplayFormat;
1141
1314
  /** Format seconds for display. Non-finite or negative input renders as 0. */
1142
1315
  declare function formatDisplayTime(seconds: number, format: TimeDisplayFormat): string;
1143
- /** Parse a formatted time string back to seconds. Lenient: returns 0 for empty/unparseable input; does not validate segment ranges. */
1144
- declare function parseDisplayTime(value: string, format: TimeDisplayFormat): number;
1316
+ /**
1317
+ * Parse text typed for a time back to seconds, or `null` when it is not a
1318
+ * time: empty text, a negative number, letters, a number followed by
1319
+ * anything else, a number too large to be finite, or a value that is not a
1320
+ * string. Spaces around the text are ignored. `seconds` reads a plain
1321
+ * number; the clock formats also read `1.5` (seconds) and `1:30` (minutes and
1322
+ * seconds) besides `01:02:03.500`. Segment ranges are checked: `00:75:00` is
1323
+ * not a time.
1324
+ */
1325
+ declare function parseDisplayTime(value: string, format: TimeDisplayFormat): number | null;
1145
1326
 
1146
1327
  interface DawSelectionDetail {
1147
1328
  start: number;
@@ -1167,14 +1348,24 @@ interface DawTrackConnectedDetail {
1167
1348
  interface DawTrackIdDetail {
1168
1349
  trackId: string;
1169
1350
  }
1351
+ interface DawTrackUpdateDetail {
1352
+ trackId: string;
1353
+ /**
1354
+ * The `<daw-track>` properties this update changed, by property name
1355
+ * (`'volume'`, `'pan'`, `'muted'`, `'soloed'`, `'src'`, `'name'`, `'kind'`,
1356
+ * `'renderMode'`, `'spectrogramConfig'`). The editor sends a mixer property
1357
+ * to the engine only when it is in this list, and one update is one undo
1358
+ * step (#843).
1359
+ */
1360
+ changed: readonly string[];
1361
+ }
1362
+ /**
1363
+ * `daw-track-error`: every clip of the track failed to load or was refused
1364
+ * for its kind. The track stays in the editor; `retryTrack` loads it again.
1365
+ */
1170
1366
  interface DawTrackErrorDetail {
1171
1367
  trackId: string;
1172
1368
  error: unknown;
1173
- /** Present when the load was CANCELLED rather than failed: the track was
1174
- * removed (or the editor disconnected) while its clips were still loading.
1175
- * Consumer error UIs should filter these — nothing actually failed; the
1176
- * event exists so addTrack()/loadMidi() awaiters settle. */
1177
- reason?: 'removed' | 'disconnected';
1178
1369
  }
1179
1370
  interface DawFilesLoadErrorDetail {
1180
1371
  file: File;
@@ -1188,6 +1379,12 @@ interface DawTrackControlDetail {
1188
1379
  trackId: string;
1189
1380
  prop: string;
1190
1381
  value: number | boolean;
1382
+ /**
1383
+ * The slider's gesture id (#843): events of one volume or pan drag, or of
1384
+ * one key press, carry the same id and are one undo step. Mute and solo
1385
+ * send none: each click is a step.
1386
+ */
1387
+ gesture?: string;
1191
1388
  }
1192
1389
  interface DawTrackRemoveDetail {
1193
1390
  trackId: string;
@@ -1343,7 +1540,7 @@ interface DawEventMap {
1343
1540
  'daw-time-format-change': CustomEvent<DawTimeFormatChangeDetail>;
1344
1541
  'daw-track-select': CustomEvent<DawTrackSelectDetail>;
1345
1542
  'daw-track-connected': CustomEvent<DawTrackConnectedDetail>;
1346
- 'daw-track-update': CustomEvent<DawTrackIdDetail>;
1543
+ 'daw-track-update': CustomEvent<DawTrackUpdateDetail>;
1347
1544
  'daw-track-ready': CustomEvent<DawTrackIdDetail>;
1348
1545
  'daw-track-removed': CustomEvent<DawTrackIdDetail>;
1349
1546
  'daw-track-error': CustomEvent<DawTrackErrorDetail>;
@@ -1395,8 +1592,8 @@ interface LoadFilesResult {
1395
1592
 
1396
1593
  /**
1397
1594
  * MIDI loading logic extracted from daw-editor. Operates on the editor via a
1398
- * narrow host interface (`addTrack` + `querySelectorAll`) — `<daw-editor>`
1399
- * satisfies it without any new public surface.
1595
+ * narrow host interface (`addTrack`, `_discardTrack`, `_operationSignal`) —
1596
+ * `<daw-editor>` satisfies it.
1400
1597
  *
1401
1598
  * Numbered steps below match the Data Flow diagram in
1402
1599
  * `docs/specs/2026-05-23-dawcore-load-midi-design.md`.
@@ -1404,15 +1601,59 @@ interface LoadFilesResult {
1404
1601
 
1405
1602
  /**
1406
1603
  * Minimal host surface needed by `loadMidiImpl`. `<daw-editor>` satisfies this
1407
- * structurally. `querySelectorAll` is needed for cleanup-on-failure so the
1408
- * loader can identify `<daw-track>` elements appended during this call (both
1409
- * those whose `addTrack` resolved and those that rejected after `_loadTrack`
1410
- * fired `daw-track-error` — the latter aren't in the `addTrack` resolution
1411
- * value, so we need DOM observation to find them).
1604
+ * structurally. A track `addTrack` added is taken out for good on a failure
1605
+ * or an abort; a track whose entry was refused never entered, so there is
1606
+ * nothing to remove (#848: `addTrack` makes no element).
1412
1607
  */
1413
1608
  interface MidiLoaderHost {
1414
- addTrack(config: TrackConfig): Promise<DawTrackElement>;
1415
- querySelectorAll(selector: string): NodeListOf<Element>;
1609
+ /** Resolves with the track id once the track has entered (#848). */
1610
+ addTrack(config: TrackConfig, options?: EditorCallOptions): Promise<string>;
1611
+ /** Take a track out for good: no undo step, and no undo brings it back. */
1612
+ _discardTrack(trackId: string, from?: Arrangement): void;
1613
+ /** The arrangement played (the tracks enter it). */
1614
+ readonly arrangement: Arrangement;
1615
+ /** The caller's signal combined with the arrangement played (D6). */
1616
+ _operationSignal(signal?: AbortSignal): AbortSignal;
1617
+ }
1618
+
1619
+ /**
1620
+ * How `<daw-track>` and `<daw-clip>` are linked to the arrangement the editor
1621
+ * plays (#848 PR 3): by id. An element is
1622
+ *
1623
+ * - pending: not in an editor, or registered and not entered yet. Its
1624
+ * properties are its own declaration (the attributes, and any property set
1625
+ * before entry, which is the value the track enters with);
1626
+ * - live: the arrangement holds its id. Properties read the arrangement, and
1627
+ * setting one (or changing its attribute) is a request to it, one undo step;
1628
+ * - detached: the editor took it, and the arrangement no longer holds its id
1629
+ * (an Undo of its arrival, a removal made on the arrangement, a refusal).
1630
+ * Properties read the declaration; a change does nothing, with a warning.
1631
+ * The element carries the custom state `detached` (`:state(detached)`).
1632
+ *
1633
+ * Attributes are never written by the editor.
1634
+ */
1635
+
1636
+ type LinkState = 'pending' | 'live' | 'detached';
1637
+ /** The `<daw-track>` properties read from the arrangement while live. */
1638
+ interface TrackLinkValues {
1639
+ volume: number;
1640
+ pan: number;
1641
+ muted: boolean;
1642
+ soloed: boolean;
1643
+ /** `'auto'` until the track's first decoded audio decides it (#684). */
1644
+ panLaw: PanLaw;
1645
+ name: string;
1646
+ }
1647
+ /** The `<daw-clip>` properties read from the arrangement while live. */
1648
+ interface ClipLinkValues {
1649
+ start: number;
1650
+ duration: number;
1651
+ offset: number;
1652
+ gain: number;
1653
+ name: string;
1654
+ midiNotes: MidiNoteData[] | null;
1655
+ midiChannel: number | null;
1656
+ midiProgram: number | null;
1416
1657
  }
1417
1658
 
1418
1659
  interface ExportOptions {
@@ -1437,6 +1678,8 @@ interface ExportTrack {
1437
1678
  id: string;
1438
1679
  volume: number;
1439
1680
  pan: number;
1681
+ /** The track's pan law (the arrangement's mixer value). `'auto'` or none: from its clips. */
1682
+ panLaw?: PanLaw;
1440
1683
  muted: boolean;
1441
1684
  soloed: boolean;
1442
1685
  clips: ExportClip[];
@@ -1454,6 +1697,18 @@ interface ExportAudioHost {
1454
1697
  getTrackEffectsState(trackId: string): Promise<SerializedEffectEntry[]>;
1455
1698
  }
1456
1699
 
1700
+ /**
1701
+ * A track registered and not in the arrangement yet (#848): a `<daw-track>`
1702
+ * (read when it enters, with clips `addClip()` gave it meanwhile), or a
1703
+ * declaration with no element (`addTrack()`, a dropped file) and its mix.
1704
+ */
1705
+ type PendingEntry = {
1706
+ element: DawTrackElement;
1707
+ extraClips: DropClipDescriptor[];
1708
+ } | {
1709
+ descriptor: StoredTrackDescriptor;
1710
+ mix: TrackMixerValues;
1711
+ };
1457
1712
  declare class DawEditorElement extends LitElement implements MidiLoaderHost {
1458
1713
  get samplesPerPixel(): number;
1459
1714
  set samplesPerPixel(value: number);
@@ -1582,12 +1837,97 @@ declare class DawEditorElement extends LitElement implements MidiLoaderHost {
1582
1837
  /** True when the consumer provided BOTH tick conversion callbacks — the
1583
1838
  * external tempo map is authoritative and `bpm` is display/grid-only (#407). */
1584
1839
  get _hasTickCallbacks(): boolean;
1585
- /** Sample rate — reads from adapter's AudioContext when available, otherwise falls back to 48000. */
1840
+ /**
1841
+ * Sample rate: the adapter's AudioContext rate. Without an adapter (after a
1842
+ * disconnect let it go), the rate of the loaded clips the arrangement holds,
1843
+ * else 48000. Decoded audio is at the context's rate, so the two agree.
1844
+ */
1586
1845
  get sampleRate(): number;
1587
- /** Resolved sample rate — falls back to sampleRate property until first audio decode. */
1588
- _resolvedSampleRate: number | null;
1589
- _tracks: Map<string, TrackDescriptor>;
1590
- _engineTracks: Map<string, ClipTrack>;
1846
+ private _loadedClipSampleRate;
1847
+ /**
1848
+ * The editor's own arrangement (#848): the one owner of the tracks, the
1849
+ * clips, the mix, the undo history and loading of what the `<daw-track>`
1850
+ * children declare. Made with the editor, kept across a disconnect.
1851
+ */
1852
+ readonly _ownArrangement: Arrangement;
1853
+ /** An arrangement the app handed in (`editor.arrangement`), played alone; null: the own one. */
1854
+ _handedIn: Arrangement | null;
1855
+ /** The arrangement played now: a handed-in one, else the editor's own. */
1856
+ get _arrangement(): Arrangement;
1857
+ /**
1858
+ * The arrangement the editor plays (#848 PR 3): one handed in by the app,
1859
+ * or else the editor's own, whose content the `<daw-track>` children
1860
+ * declare. Setting one plays it alone, like `video.srcObject`: the
1861
+ * children are not added to it and show `:state(detached)` while it is
1862
+ * set; `null` (or the editor's own) goes back to the own arrangement with
1863
+ * what it held. A swap keeps the adapter: playback stops, a new engine is
1864
+ * built on the new arrangement. Refused (with a warning) during a take.
1865
+ * The editor never disposes or clears an arrangement it was handed.
1866
+ * Throws a `TypeError` for a value that is not an arrangement.
1867
+ */
1868
+ get arrangement(): Arrangement;
1869
+ set arrangement(value: Arrangement | null);
1870
+ /** Sends the load events, read from the arrangement played (#848; a new one per swap). */
1871
+ private _announcer;
1872
+ /** Stops following the arrangement played (its sources and its tracks). */
1873
+ private _unfollow;
1874
+ constructor();
1875
+ /**
1876
+ * Follow the arrangement played: a source that fails changes no track,
1877
+ * only `sources` tells of it (the events, the failed look); the elements'
1878
+ * link states follow its tracks (a structural change only, not every
1879
+ * mixer frame).
1880
+ */
1881
+ private _follow;
1882
+ /**
1883
+ * The clips the arrangement took out by itself because nothing of their
1884
+ * audio was left after their offset (#859, maintainer's choice "remove"),
1885
+ * as its change says (`removedClips`), reported with `daw-clip-error`
1886
+ * (maintainer, "a"). Their `<daw-clip>` stays on the page.
1887
+ */
1888
+ private _reportRemovedOnArrival;
1889
+ /**
1890
+ * A change to the arrangement while a drag is in progress came from
1891
+ * elsewhere (a drag writes nothing until its release): cancel the drag
1892
+ * when it changed what is dragged (#848 P2, interactions/drag-watch.ts).
1893
+ */
1894
+ private _watchDrags;
1895
+ /** @internal */
1896
+ _releaseEngine(): void;
1897
+ /** @internal */
1898
+ _disposeTrackChain(trackId: string): void;
1899
+ /** @internal */
1900
+ _playArrangement(next: Arrangement | null): void;
1901
+ /** @internal */
1902
+ _buildEngineIfReady(): void;
1903
+ /**
1904
+ * Ids of tracks registered (a `<daw-track>` connected, a file dropped) and
1905
+ * not yet in the arrangement: they enter at the next flush, once there is
1906
+ * an engine (#848).
1907
+ */
1908
+ private _entryQueue;
1909
+ private _entryFlushScheduled;
1910
+ /**
1911
+ * Clips an `addClip()` is waiting for, with their track and the way to
1912
+ * reject the call: a removal of the clip or of its track before the clip
1913
+ * loads settles it here, without a public event (#917).
1914
+ */
1915
+ private _awaitedClips;
1916
+ /** Reject the `addClip()` calls waiting for clips that match `which`. */
1917
+ private _rejectAwaitedClips;
1918
+ /** `.dat` peaks drawn for a clip still loading, by clip id (an editor-only render cache). */
1919
+ _previewPeaks: Map<string, PeakData>;
1920
+ /** The `.dat` data of those clips, handed to the peak pipeline when the audio arrives. */
1921
+ private _previewWaveforms;
1922
+ /**
1923
+ * Tracks registered and not in the arrangement yet, with their declaration
1924
+ * (#848): a `<daw-track>` is read when it enters (its clips and attributes
1925
+ * as they are then); a dropped file carries its descriptor. The one place a
1926
+ * track's state lives until it enters.
1927
+ */
1928
+ _pending: Map<string, PendingEntry>;
1929
+ /** What the arrangement has no field for, by track id (#848; render mode, `peaks-src`). */
1930
+ _extras: Map<string, TrackExtras>;
1591
1931
  _peaksData: Map<string, PeakData>;
1592
1932
  _isPlaying: boolean;
1593
1933
  _duration: number;
@@ -1600,9 +1940,6 @@ declare class DawEditorElement extends LitElement implements MidiLoaderHost {
1600
1940
  set adapter(value: PlayoutAdapter | null);
1601
1941
  get adapter(): PlayoutAdapter | null;
1602
1942
  private _externalAdapter;
1603
- /** True after a disconnect disposed the consumer's adapter via the engine
1604
- * — rebuild attempts fail loudly until a fresh adapter is set. */
1605
- private _adapterConsumedByDispose;
1606
1943
  private _effectsManager;
1607
1944
  private get _effects();
1608
1945
  /**
@@ -1682,11 +2019,9 @@ declare class DawEditorElement extends LitElement implements MidiLoaderHost {
1682
2019
  */
1683
2020
  private _trackEventTarget;
1684
2021
  get audioContext(): AudioContext;
1685
- _engine: PlaylistEngine | null;
2022
+ _engine: EditorEngine | null;
1686
2023
  private _warnedMissingTicksToSeconds;
1687
2024
  private _warnedMissingSecondsToTicks;
1688
- private _enginePromise;
1689
- _audioCache: Map<string, Promise<AudioBuffer>>;
1690
2025
  private _peaksCache;
1691
2026
  _clipBuffers: Map<string, AudioBuffer>;
1692
2027
  _clipOffsets: Map<string, {
@@ -1697,11 +2032,6 @@ declare class DawEditorElement extends LitElement implements MidiLoaderHost {
1697
2032
  /** Coarsest scale from pre-computed peaks — zoom cannot go finer than this. 0 = no limit. */
1698
2033
  private _minSamplesPerPixel;
1699
2034
  private _trackElements;
1700
- /** Track ids with a _loadTrack in flight. Distinct from `_engineTracks`
1701
- * membership: the peaks-first path inserts a render-only PREVIEW track
1702
- * into _engineTracks mid-load, so `has()` alone cannot answer "is this
1703
- * track still loading?". */
1704
- private _loadingTracks;
1705
2035
  private _childObserver;
1706
2036
  private _audioResume;
1707
2037
  eagerResume?: string;
@@ -1731,7 +2061,7 @@ declare class DawEditorElement extends LitElement implements MidiLoaderHost {
1731
2061
  private _annotationDrag;
1732
2062
  private _trackReorderDrag;
1733
2063
  get _clipHandler(): ClipPointerHandler | null;
1734
- get engine(): PlaylistEngine | null;
2064
+ get engine(): EditorEngine | null;
1735
2065
  get renderSamplesPerPixel(): number;
1736
2066
  /** Re-extract peaks for a clip at new offset/duration from cached WaveformData. */
1737
2067
  reextractClipPeaks(clipId: string, offsetSamples: number, durationSamples: number): PeakData | null;
@@ -1741,12 +2071,15 @@ declare class DawEditorElement extends LitElement implements MidiLoaderHost {
1741
2071
  * Returns false for unknown track/clip IDs (defensive).
1742
2072
  */
1743
2073
  isMidiClip(trackId: string, clipId: string): boolean;
2074
+ /** The arrangement's tracks as they are played: loaded clips, the current mix (#848). */
2075
+ _loadedTracks(): ClipTrack[];
2076
+ /** A loaded clip of a track of the arrangement, or undefined. */
2077
+ private _loadedClip;
1744
2078
  private _pointer;
1745
2079
  private _viewport;
1746
2080
  private _scrollSync;
1747
2081
  static styles: lit.CSSResult[];
1748
2082
  get effectiveSampleRate(): number;
1749
- resolveAudioContextSampleRate(rate: number): void;
1750
2083
  /**
1751
2084
  * In beats mode, derive samplesPerPixel from ticksPerPixel so that
1752
2085
  * clip positions, waveforms, and the tick-space grid all align.
@@ -1764,7 +2097,83 @@ declare class DawEditorElement extends LitElement implements MidiLoaderHost {
1764
2097
  /** Grid height when no tracks exist — matches scroll area's rendered height. */
1765
2098
  private get _emptyGridHeight();
1766
2099
  _setSelectedTrackId(trackId: string | null): void;
2100
+ /**
2101
+ * Every track: those in the arrangement, in its order, then those still
2102
+ * waiting to enter (#848). A `<daw-track>` whose track an Undo took out of
2103
+ * the arrangement is not listed (its descriptor stays for a Redo).
2104
+ */
1767
2105
  get tracks(): TrackWithId[];
2106
+ /** A track of the arrangement as `editor.tracks` lists it: everything read from the arrangement. */
2107
+ private _listTrack;
2108
+ /** A pending track's declaration: its element's attributes and clips now, or its descriptor. */
2109
+ private _pendingDescriptor;
2110
+ /** The extras a track of the arrangement takes when the editor has none for it. */
2111
+ private _defaultExtras;
2112
+ /** How a track is drawn: its extras, else from its kind (an undo-restored track has none). */
2113
+ _renderModeOf(trackId: string): TrackRenderMode;
2114
+ /**
2115
+ * A track's mix, from its one owner, the arrangement (#843), as the engine
2116
+ * plays it: its projection carries the take's mute, which `getMixer()`
2117
+ * leaves out (the stored mute comes back when the take ends). A track still
2118
+ * waiting to enter shows what its element declares.
2119
+ */
2120
+ _mixOf(trackId: string): TrackMixerValues;
2121
+ /** @internal */
2122
+ _trackLinkState(trackId: string): LinkState;
2123
+ /** @internal */
2124
+ _clipLinkState(trackId: string, clipId: string): LinkState;
2125
+ /** @internal The stored mix (not a take's mute) and the name. */
2126
+ _trackValues(trackId: string): TrackLinkValues | null;
2127
+ /** @internal */
2128
+ _clipValues(trackId: string, clipId: string): ClipLinkValues | null;
2129
+ /** @internal A property or attribute set on a live `<daw-track>`: one undo step per field kind. */
2130
+ _requestTrackChange(trackId: string, partial: Partial<TrackLinkValues>): void;
2131
+ /** One gesture id per track for the rest of this task: mix sets made together are one step (#843). */
2132
+ private _taskGestures;
2133
+ private _taskGesture;
2134
+ /** @internal A property or attribute set on a live `<daw-clip>`: one undo step. */
2135
+ _requestClipChange(trackId: string, clipId: string, partial: Partial<ClipLinkValues>): void;
2136
+ /** The clip of that id another track of the arrangement holds (a `<daw-clip>` the page moved here), if any. */
2137
+ private _heldElsewhere;
2138
+ /**
2139
+ * The clips of an entering track that another track of the arrangement
2140
+ * holds (the page moved their `<daw-clip>` here while the track waited):
2141
+ * the track takes the held clip as it is, and `from` names what leaves
2142
+ * where. A held clip of the other kind, or one that would overlap a clip of
2143
+ * the entering track (#859), is refused and stays.
2144
+ */
2145
+ private _takeOverMovedClips;
2146
+ /** Run `fn` as one undo step of each arrangement it changes. */
2147
+ private _inOneStep;
2148
+ /** The `peaks-src` some track took for a clip element, if any. */
2149
+ private _takenPeaksSrc;
2150
+ /**
2151
+ * The arrangement whose history holds a track: the one that holds it now,
2152
+ * or else, for a page track, the own one (an Undo took it out there; a
2153
+ * handed-in arrangement may be played meanwhile), or else the one played.
2154
+ */
2155
+ private _historyOf;
2156
+ /** The track of the arrangement played that holds a clip: `trackId` when it does, or else the one that does. */
2157
+ private _clipHolderId;
2158
+ /** @internal */
2159
+ _trackKind(trackId: string): TrackKind | null;
2160
+ /** @internal */
2161
+ _trackIndex(trackId: string): number;
2162
+ /** @internal */
2163
+ _detachedReason(): string;
2164
+ /** Set or clear `:state(detached)` on every registered element (#848). */
2165
+ private _refreshLinkStates;
2166
+ /**
2167
+ * Change one mixer field of a track: the arrangement's setter with
2168
+ * `options` (an undo step; changes with one `gesture` id are one step). A
2169
+ * track that has not entered yet changes nothing.
2170
+ */
2171
+ private _writeMix;
2172
+ /**
2173
+ * Change the given mixer fields of a track as ONE undo step (#843): all
2174
+ * of them carry one fresh gesture id. A field left out is not sent.
2175
+ */
2176
+ private _writeMixFields;
1768
2177
  get selectedTrackId(): string | null;
1769
2178
  get selection(): {
1770
2179
  start: number;
@@ -1792,108 +2201,189 @@ declare class DawEditorElement extends LitElement implements MidiLoaderHost {
1792
2201
  private _onTrackConnected;
1793
2202
  private _onTrackRemoved;
1794
2203
  private _onTrackUpdate;
2204
+ /** The arrangement that holds a track: the one played, else the own one (a page track while handed in). */
2205
+ private _arrangementOf;
2206
+ /** Rename a track in the arrangement (an undo step); the same name changes nothing. */
2207
+ private _renameTrack;
1795
2208
  /** Drop the controller when no spectrogram tracks remain. */
1796
2209
  private _disposeSpectrogramControllerIfEmpty;
1797
- /** Reconcile `_tracks` descriptors with the engine's track list.
1798
- *
1799
- * ADD: engine.undo() restores removed tracks in ENGINE state only —
1800
- * without a synthesized descriptor the track plays and renders but shows
1801
- * "Untitled" controls and is missing from `editor.tracks`.
1802
- * PRUNE (the symmetric half): redo removes the track from engine state
1803
- * again — without pruning, the synthesized descriptor is a permanent
1804
- * ghost that even removeTrack() can't clean (no element, no engine
1805
- * entry). Never prunes tracks that are mid-load or element-backed —
1806
- * their descriptors legitimately precede their engine entries. */
1807
- _reconcileDescriptorsWithEngineTracks(tracks: readonly ClipTrack[]): void;
1808
- /** Prune id-bearing drop descriptors the engine no longer has, and refresh
1809
- * the rest from their engine clip. Returns the SAME array when nothing
1810
- * changed, so an unchanged track never triggers a re-render. */
1811
- private _reconcileIdentifiedDropClips;
1812
2210
  private static _CONTROL_PROPS;
1813
2211
  private _onTrackControl;
1814
2212
  private _onTrackRemoveRequest;
1815
2213
  private _onClipConnected;
1816
- private _onClipUpdate;
2214
+ /**
2215
+ * A `<daw-clip>` now under `trackId` whose clip another track holds: the
2216
+ * clip moves to this track (one undo step) when both have entered the same
2217
+ * arrangement; a clip of the other kind stays with `daw-clip-error`.
2218
+ * Otherwise the old track lets it go and the element goes on as a new
2219
+ * arrival. Returns true when nothing more is to be done.
2220
+ */
2221
+ private _rehomeClip;
1817
2222
  private _onClipRemovedFromDom;
2223
+ /**
2224
+ * A `<daw-clip>` appended to a track that has entered: the clip goes in as
2225
+ * a loading clip (a loaded one for MIDI), one undo step. Its audio loads
2226
+ * like any other; `daw-clip-ready` or `daw-clip-error` follows (#848).
2227
+ */
1818
2228
  private _loadAndAppendClip;
1819
2229
  /**
1820
2230
  * Resolve pre-computed peaks for a clip: fetch the .dat/.json, validate the
1821
2231
  * sample rate matches the AudioContext, return the WaveformData or null.
1822
2232
  * Warns on fetch failure and on sample-rate mismatch — never silent.
1823
2233
  *
1824
- * Shared between `_loadTrack` (peaks-first preview path) and
1825
- * `_loadAndAppendClip` (incremental late-append).
2234
+ * Used by `_requestPreview` for a clip that is still loading.
1826
2235
  */
1827
2236
  private _resolvePeaks;
2237
+ /** Remove a single clip from all per-clip caches. Used by error rollbacks. */
2238
+ private _purgeClipCaches;
1828
2239
  /**
1829
- * Construct an AudioClip from a decoded buffer (and optional WaveformData),
1830
- * align its id with the source `<daw-clip>.clipId` when present, populate
1831
- * `_clipBuffers` / `_clipOffsets`, generate peaks via the worker pipeline,
1832
- * and populate `_peaksData`. Returns the finished AudioClip.
1833
- *
1834
- * Shared between `_loadTrack`'s standard path and `_loadAndAppendClip`.
1835
- * Not used by `_loadTrack`'s peaks-first preview path because that path
1836
- * uses sync `extractPeaks` and inserts a preview track BEFORE audio decode.
2240
+ * Replace one loaded clip of a track in the arrangement: an undo step. The
2241
+ * function form, so the track's loading clips stay as they are (#848).
1837
2242
  */
1838
- private _finalizeAudioClip;
2243
+ private _replaceClip;
1839
2244
  /**
1840
- * Filter MIDI notes to only those with finite, in-range fields. Logs a
1841
- * warning for each dropped note. Used by _buildMidiClip and the
1842
- * _applyClipUpdate MIDI branch to prevent NaN propagation through the
1843
- * timeline.
2245
+ * A clip change that would make `clip` overlap another clip of its track
2246
+ * (#859) changes nothing and is reported with `daw-clip-error`, as a change
2247
+ * that would give it the other kind is. True when refused.
1844
2248
  */
1845
- private _validMidiNotes;
2249
+ private _refusedForOverlap;
2250
+ private _applyClipUpdate;
1846
2251
  /**
1847
- * A clip descriptor is treated as MIDI when it has no audio src.
1848
- * Includes placeholder MIDI clips (no notes, no duration yet — registered
1849
- * with a 1s default span; notes upgrade via _applyClipUpdate). Warns when
1850
- * a clip ambiguously has both src and midiNotes — the audio path runs
1851
- * and notes would be silently ignored.
2252
+ * A change to a clip still loading (#848 P10): its times, gain and name in
2253
+ * seconds on the `LoadingClip`, one undo step; the audio loads into it.
1852
2254
  */
1853
- private _isMidiDescriptor;
2255
+ private _updateLoadingClip;
2256
+ /** Remove a clip (loaded or still loading) from a track of the arrangement: an undo step. */
1854
2257
  /**
1855
- * Build an engine clip from a MIDI clip descriptor. Always returns a clip
1856
- * — empty notes / no declared duration get a 1-second placeholder span so
1857
- * the clip is reachable via `engine.updateTrack` once notes arrive.
2258
+ * An aborted addClip (D3): its clip leaves for good, from the track it
2259
+ * entered or from what a waiting track will enter with.
1858
2260
  */
1859
- private _buildMidiClip;
1860
- /** Remove a single clip from all per-clip caches. Used by error rollbacks. */
1861
- private _purgeClipCaches;
2261
+ private _discardAddedClip;
2262
+ private _removeClipFromTrack;
2263
+ /** Record that the editor took a clip of a track (with its `peaks-src`, '' when none). */
2264
+ private _takeClip;
1862
2265
  /**
1863
- * Recompute duration and forward an updated track to the engine. Single
1864
- * source of truth for the incremental-vs-full-rebuild policy used by every
1865
- * clip-level mutation (addClip, updateClip, removeClip, _applyClipUpdate).
1866
- * Use the engine's incremental updateTrack when available; otherwise fall
1867
- * back to full setTracks (legacy adapters).
2266
+ * A `<daw-clip>` the editor took is removed while the arrangement does not
2267
+ * hold its clip (its track or its own arrival undone, or refused): it is
2268
+ * gone for good, also from the undo and redo states, so no Redo brings it
2269
+ * back (maintainer's choice, #848).
1868
2270
  */
1869
- private _commitTrackChange;
1870
- private _applyClipUpdate;
1871
- private _removeClipFromTrack;
2271
+ private _dropUnheldClip;
2272
+ /** The editor no longer holds anything for a clip of a track. */
2273
+ private _forgetClip;
1872
2274
  private _readTrackDescriptor;
2275
+ private _readClipDescriptor;
2276
+ private _isEntered;
2277
+ /** Queue a registered track for the next flush. */
2278
+ _queueEntry(trackId: string): void;
2279
+ /**
2280
+ * Enter the queued tracks into the arrangement, in DOM order. Without an
2281
+ * engine they wait (the sample rate of a MIDI clip comes from the
2282
+ * adapter); the engine's build flushes again. The page's tracks entering
2283
+ * while the arrangement has no history are not undo steps: the history is
2284
+ * cleared after them, so Undo right after load removes nothing (and the
2285
+ * next page track finds it empty again).
2286
+ */
2287
+ _flushTrackEntries(): void;
2288
+ /** Enter one registered track. False when it is gone, already in, or refused. */
2289
+ private _enterTrack;
2290
+ /**
2291
+ * The `<daw-track src>` shorthand changed its src: the entered track gets a
2292
+ * new loading clip for it, one undo step. A track whose clips are
2293
+ * `<daw-clip>` children keeps them. A track still queued reads the new
2294
+ * descriptor when it enters.
2295
+ */
2296
+ private _replaceShorthandClips;
2297
+ /** Run the load announcements over the arrangement's current state. */
2298
+ private _announceLoading;
2299
+ /**
2300
+ * Fetch a loading clip's `.dat` peaks and draw them until its audio
2301
+ * arrives (an editor-only cache, not the arrangement: writing the clip
2302
+ * after it entered would be an undo step).
2303
+ */
2304
+ private _requestPreview;
2305
+ /** The peak sync made a clip's peaks: its zoom floor holds, its preview goes. */
2306
+ _clipPeaksReady(clipId: string, audioBuffer: AudioBuffer): void;
2307
+ /** Who waits for a track to enter (addTrack, a dropped file). */
2308
+ private _entryWaiters;
2309
+ private _waitForEntry;
2310
+ /** Settle the wait for a track's entry: entered (`ENTERED`), or refused or gone (the reason).*/
2311
+ private _settleEntry;
2312
+ /**
2313
+ * A dropped file as a track with no element (a File cannot be an attribute):
2314
+ * one loading clip whose source is the file. Resolves with the track id once
2315
+ * it has entered, an undo step like any track an editor method adds.
2316
+ */
2317
+ _addDroppedFile(file: File): Promise<string>;
2318
+ /**
2319
+ * Take a track out for good: no undo step, and no undo or redo brings it
2320
+ * back (a dropped file that could not be loaded was never a declaration).
2321
+ */
2322
+ _discardTrack(trackId: string, from?: Arrangement): void;
2323
+ /** One AbortController per arrangement while it is played (D2, interactions/abort.ts). */
2324
+ private _playSignals;
2325
+ /** The signal of the arrangement played now: aborted when it is swapped out. */
2326
+ private get _playSignal();
2327
+ /** @internal A caller's signal combined with the arrangement played now (loadMidi, D6). */
2328
+ _operationSignal(signal?: AbortSignal): AbortSignal;
2329
+ /** One AbortController per connection: aborted in disconnectedCallback (D8). */
2330
+ private _connection;
2331
+ /**
2332
+ * Resolves once the track has loaded (`daw-track-ready`), or when the
2333
+ * editor is disconnected meanwhile (the track is kept and loads after a
2334
+ * reparent); rejects when its audio failed (`daw-track-error`).
2335
+ */
2336
+ _whenTrackLoaded(trackId: string): Promise<void>;
2337
+ /**
2338
+ * Load again every failed source the track's clips name (#848). A track
2339
+ * whose audio failed stays in the editor, like a broken `<img>`;
2340
+ * `daw-track-ready` follows when it loads.
2341
+ */
2342
+ retryTrack(trackId: string): void;
2343
+ private _fetchPeaks;
1873
2344
  /**
1874
- * The error for a clip whose kind is not its track's (#756), or null. A clip
1875
- * with no `src` is a MIDI clip (see _isMidiDescriptor).
2345
+ * The timeline's duration, the one writer of `_duration`: the loaded clips,
2346
+ * and the clips still loading whose length is known (a duration, or `.dat`
2347
+ * peaks), so the timeline is as wide as what is drawn (#848).
1876
2348
  */
1877
- private _clipKindError;
1878
- private _loadTrack;
1879
- _fetchAndDecode(src: string): Promise<AudioBuffer>;
1880
- private _fetchPeaks;
1881
2349
  _recomputeDuration(): void;
1882
- _ensureEngine(): Promise<PlaylistEngine>;
2350
+ /** How long a loading clip is drawn: its duration, else what its `.dat` peaks cover; null when unknown. */
2351
+ private _placeholderSeconds;
2352
+ /**
2353
+ * The engine, built now when the editor is connected with an adapter.
2354
+ * Rejects without an adapter, and on a detached editor (an engine built
2355
+ * there would hold the adapter's graph with nothing to dispose it).
2356
+ */
2357
+ _ensureEngine(): Promise<EditorEngine>;
2358
+ /** Build the engine from the adapter setter or a connect: a failure is reported, not thrown. */
2359
+ private _buildEngineReporting;
2360
+ /** Last versions the statechange handler worked from; reset for each engine. */
2361
+ private _lastTracksVersion;
2362
+ private _lastMixerVersion;
1883
2363
  private _buildEngine;
2364
+ /**
2365
+ * Clips whose audio has just arrived: a `.dat` preview's data goes to the
2366
+ * peak pipeline (no worker run), a spectrogram track gets the audio. The
2367
+ * peak sync then makes their peaks.
2368
+ */
2369
+ private _adoptLoadedClips;
2370
+ /** The engine's state changed: draw it (the rows are read from the arrangement). */
2371
+ private _onEngineState;
2372
+ private _onEngineStop;
1884
2373
  private _disposeEngine;
1885
2374
  private _onDragOver;
1886
2375
  private _onDragLeave;
1887
2376
  private _onDrop;
1888
- loadFiles(files: FileList | File[]): Promise<LoadFilesResult>;
2377
+ loadFiles(files: FileList | File[], options?: EditorCallOptions): Promise<LoadFilesResult>;
1889
2378
  /**
1890
- * Imperatively load a `.mid` file (URL or File) and create N `<daw-track>`
1891
- * elements — one per note-bearing MIDI track. On any per-track failure,
1892
- * every `<daw-track>` appended during the call is removed (both successful
1893
- * and failed) so the editor returns to its pre-call state.
2379
+ * Imperatively load a `.mid` file (URL or File) and add N tracks (no
2380
+ * element, #848), one per note-bearing MIDI track. On any per-track
2381
+ * failure, every track the call added is removed with no undo step, so the
2382
+ * editor is as before the call.
1894
2383
  *
1895
- * `options.signal` is forwarded to `fetch()` only for URL sources; aborting
1896
- * after parsing does not cancel in-flight `addTrack` calls.
2384
+ * `options.signal` cancels the fetch, the parse and the tracks still
2385
+ * waiting to enter (combined with the arrangement played: a swap cancels
2386
+ * too); the call rejects with its `reason` and removes the tracks it added.
1897
2387
  *
1898
2388
  * Requires the optional `@dawcore/midi` peer dep — throws with an install
1899
2389
  * hint (and `console.warn`s the original error) when the dynamic import
@@ -1905,71 +2395,93 @@ declare class DawEditorElement extends LitElement implements MidiLoaderHost {
1905
2395
  * non-null `editor.engine` before any track has been loaded — useful for
1906
2396
  * wiring analyzers, effects, or master taps before content arrives.
1907
2397
  */
1908
- ready(): Promise<PlaylistEngine>;
1909
- /**
1910
- * Wait for either `readyEvent` or `errorEvent` to fire on this editor for
1911
- * the entity matching `matchesId`. Listeners are wired synchronously, then
1912
- * `setup` is called (typical: appendChild). Resolves with `resolveValue`
1913
- * on ready; rejects with a normalized Error on error. Used by addTrack and
1914
- * addClip to share their Promise-with-listener-cleanup machinery.
2398
+ ready(): Promise<EditorEngine>;
2399
+ /**
2400
+ * Add a track built from `config` to the arrangement the editor plays when
2401
+ * it is called, and resolve with its id once it has entered (#848), before
2402
+ * its audio has loaded. A swap of `editor.arrangement` before it enters
2403
+ * rejects with an `AbortError` and the track enters nowhere; to add to
2404
+ * another arrangement, call that arrangement's own `addTrack`. No element is created: the track is drawn and listed like any
2405
+ * other, and `<daw-track>` children stay the page's declaration. To follow
2406
+ * loading, add the `daw-track-ready` / `daw-track-error` listener BEFORE
2407
+ * calling: for a track with nothing to fetch it fires before this
2408
+ * resolves. Without `editor.adapter` it waits for one. Rejects when the
2409
+ * arrangement refuses the track, when it is removed before it enters, or
2410
+ * when the engine cannot be built.
2411
+ *
2412
+ * `options.signal` (#848): aborting it before the track has entered takes
2413
+ * it out of the queue (it never enters) and rejects with its `reason`;
2414
+ * after that it changes nothing (the audio goes on loading). A signal
2415
+ * already aborted rejects at once and queues nothing.
1915
2416
  */
1916
- private _awaitId;
2417
+ addTrack(config?: TrackConfig, options?: EditorCallOptions): Promise<string>;
1917
2418
  /**
1918
- * Append a `<daw-track>` element built from `config` and resolve once the
1919
- * track finishes loading (or reject on `daw-track-error`). Goes through
1920
- * the same `_loadTrack` pipeline as declarative tracks, so descriptors,
1921
- * peaks, and clip buffers are populated correctly.
2419
+ * A queued track goes into the arrangement played when it was queued: when
2420
+ * that one is swapped out first, the track leaves the queue and its wait
2421
+ * rejects with the swap's AbortError (addTrack, a dropped file).
1922
2422
  */
1923
- addTrack(config?: TrackConfig): Promise<DawTrackElement>;
2423
+ private _endEntryOnSwap;
2424
+ /** A track that has not entered leaves the queue and its wait rejects with `reason` (D4). */
2425
+ private _abortEntry;
1924
2426
  /**
1925
- * Remove a track by id. Equivalent to `trackElement.remove()` —
1926
- * the editor's MutationObserver handles engine and cache cleanup.
1927
- * No-op if no matching track exists.
2427
+ * Remove a track by id: its `<daw-track>` element is removed (the
2428
+ * MutationObserver does the rest), or, for a track with no element
2429
+ * (`addTrack`, a dropped file, an Undo), the track itself. One undo step.
2430
+ * Warns when no track has the id.
1928
2431
  */
1929
2432
  removeTrack(trackId: string): void;
1930
2433
  /**
1931
- * Move a track to a new position in the vertical order (0-based index among
1932
- * `<daw-track>` elements). Element-backed tracks move their DOM element —
1933
- * the MutationObserver syncs the engine (single write path). Element-less
1934
- * tracks (undo-resurrected) reorder the engine directly.
2434
+ * Move a track to a 0-based position in the arrangement's order (every
2435
+ * track counts, those with no element too; `trackEl.index` and
2436
+ * `editor.tracks` give the positions). One undo step; no element moves.
1935
2437
  */
1936
2438
  reorderTrack(trackId: string, toIndex: number): void;
1937
2439
  private _onTrackReorder;
1938
2440
  private _onTrackReorderGrab;
1939
2441
  /**
1940
- * Update reflected attributes on a track. For DOM-element tracks the changes
1941
- * are written to the `<daw-track>` element (which fires `daw-track-update`);
1942
- * for tracks without a DOM element (file drops) the descriptor and engine
1943
- * state are updated in place.
2442
+ * Change a track: the mix (one undo step, #843), the name (an undo step),
2443
+ * the render mode and spectrogram config (the editor's). The arrangement
2444
+ * is changed, never an element's attributes (#848): a `<daw-track>`'s
2445
+ * properties show the change. A track that has not entered yet gets it as
2446
+ * the value it enters with.
1944
2447
  */
1945
2448
  updateTrack(trackId: string, partial: Partial<TrackConfig>): void;
1946
- /**
1947
- * Append a clip to an existing track. Builds a `<daw-clip>` from `config`
1948
- * and appends it to the track's DOM element when one exists; resolves with
1949
- * the new clip's id once the audio decode + peak generation finish.
2449
+ /** `updateTrack` on a track waiting to enter: the values it will enter with. */
2450
+ private _updatePendingTrack;
2451
+ /**
2452
+ * Add a clip to a track (with or without an element) and resolve with its
2453
+ * id once its audio has loaded (`daw-clip-ready`, before its peaks are
2454
+ * drawn). The clip enters the arrangement as a loading clip, one undo
2455
+ * step; no `<daw-clip>` is created (#848). Rejects when it fails to load,
2456
+ * is refused (its kind), or leaves the arrangement before it loads (a
2457
+ * removal, an Undo). A clip added while the editor is detached loads once
2458
+ * a fresh adapter is set.
2459
+ *
2460
+ * `options.signal` (#848): aborting it before the clip has loaded rejects
2461
+ * with its `reason` and removes the clip for good (no undo step); after it
2462
+ * has loaded it changes nothing. A signal already aborted rejects at once
2463
+ * and adds nothing. A swap of `editor.arrangement` rejects the call with an
2464
+ * `AbortError`; its loading clip stays in the arrangement swapped out.
1950
2465
  */
1951
- addClip(trackId: string, config: ClipConfig): Promise<string>;
2466
+ addClip(trackId: string, config: ClipConfig, options?: EditorCallOptions): Promise<string>;
1952
2467
  /**
1953
- * Remove a clip by id. Removes the matching `<daw-clip>` DOM element when
1954
- * present (MutationObserver handles cleanup); otherwise updates engine
1955
- * state directly. No-op if no matching clip exists.
2468
+ * Remove a clip by id: its `<daw-clip>` when there is one (the observer
2469
+ * removes the clip, as `select.remove(i)` removes an option), otherwise
2470
+ * the clip itself, one undo step. Undo brings the clip back with no
2471
+ * element. No-op with a warning when there is no such clip.
1956
2472
  */
1957
2473
  removeClip(trackId: string, clipId: string): void;
1958
2474
  /**
1959
- * Update a clip's position (start/duration/offset) or properties (gain/name).
1960
- * For DOM-element clips, writes properties on the `<daw-clip>` element which
1961
- * fires `daw-clip-update`; otherwise applies directly via `_applyClipUpdate`.
2475
+ * Change a clip's position (start/duration/offset), gain or name: one undo
2476
+ * step on the arrangement (#848; a clip still loading changes its loading
2477
+ * clip). A `<daw-clip>`'s properties show the change, its attributes do
2478
+ * not. Fades are a `<daw-clip>` declaration only (engine-side fades are
2479
+ * #489): `fadeIn` / `fadeOut` / `fadeType` here change nothing.
1962
2480
  *
1963
2481
  * Re-decoding (changing `src`) is not supported via this method — remove and
1964
2482
  * re-add the clip instead.
1965
- *
1966
- * Note: `fadeIn` / `fadeOut` / `fadeType` on the partial are written to the
1967
- * `<daw-clip>` element (so they round-trip in the descriptor), but engine-side
1968
- * fade application from `<daw-clip>` properties is not yet implemented — see
1969
- * the broader fade-engine integration tracked separately.
1970
2483
  */
1971
2484
  updateClip(trackId: string, clipId: string, partial: Partial<ClipConfig>): void;
1972
- private _buildClipElement;
1973
2485
  /**
1974
2486
  * Start playback, optionally seeking to `startTime` first. When `endTime`
1975
2487
  * is provided, playback stops at that time (selection/annotation playback).
@@ -1988,9 +2500,30 @@ declare class DawEditorElement extends LitElement implements MidiLoaderHost {
1988
2500
  * subsequent stop-settle dispatch. */
1989
2501
  private _withSeekSuppression;
1990
2502
  seekTo(time: number): void;
1991
- /** Undo the last structural edit. */
2503
+ /**
2504
+ * A clip or track drag is in progress: undo and redo do nothing until it
2505
+ * ends (#848). A clip counts once its pointer has moved past the drag
2506
+ * threshold; annotation drags do not count (annotations are not in the
2507
+ * undo history).
2508
+ */
2509
+ get _dragInProgress(): boolean;
2510
+ /**
2511
+ * Cancel every drag in progress, as a `pointercancel` would. Returns whether
2512
+ * one was. A clip or annotation press that has not moved is not a drag and
2513
+ * is left alone, unless `includePresses` (the editor's disconnect, which
2514
+ * ends every pointer interaction).
2515
+ */
2516
+ _cancelDrags(includePresses?: boolean): boolean;
2517
+ /**
2518
+ * Escape during a drag cancels it and does nothing else: the default is
2519
+ * prevented, so `<daw-keyboard-shortcuts>` (core's `handleKeyboardEvent`)
2520
+ * does not also stop playback. No `stopPropagation`: an app's own listener
2521
+ * can read `defaultPrevented`.
2522
+ */
2523
+ private _onDragEscape;
2524
+ /** Undo the last edit. Does nothing while a drag is in progress. */
1992
2525
  undo(): void;
1993
- /** Redo the last undone edit. */
2526
+ /** Redo the last undone edit. Does nothing while a drag is in progress. */
1994
2527
  redo(): void;
1995
2528
  /** Whether undo is available. */
1996
2529
  get canUndo(): boolean;
@@ -2039,29 +2572,25 @@ declare class DawEditorElement extends LitElement implements MidiLoaderHost {
2039
2572
  private get _showControls();
2040
2573
  /** True when the ruler header band should be rendered (and its selector is valid). */
2041
2574
  private get _showRuler();
2042
- /** Guards the statechange handler's engine→DOM sync (Task: reorder #612)
2043
- * while the observer is pushing DOM order INTO the engine — the intermediate
2044
- * statechange emissions during the transaction would otherwise bounce
2045
- * half-applied orders back into the DOM. */
2046
- _inOrderSync: boolean;
2047
- /**
2048
- * DOM → engine: make the engine's track order match the light-DOM
2049
- * `<daw-track>` order. Single write path for reorders — editor-initiated
2050
- * (buttons/drag move the element) and consumer-initiated (insertBefore)
2051
- * mutations both land here via the MutationObserver. Element-less tracks
2052
- * (undo-resurrected) keep their engine positions (stable sort).
2053
- * Write-only-on-change: a no-op when orders already match, so the
2054
- * engine→DOM direction (statechange handler) converges in one pass.
2055
- */
2056
- _syncEngineOrderToDom(): void;
2057
- /**
2058
- * Engine → DOM: after an engine-initiated order change (undo/redo), move
2059
- * `<daw-track>` elements to match engine order. The resulting mutations fire
2060
- * the observer's _syncEngineOrderToDom, which finds the orders equal and
2061
- * no-ops — converges in one pass (write-only-on-change).
2062
- */
2063
- _syncDomToEngineOrder(tracks: readonly ClipTrack[]): void;
2575
+ /**
2576
+ * `<daw-track>` elements the page moved (one MutationObserver batch): each
2577
+ * is placed after the arrangement track of the nearest `<daw-track>` before
2578
+ * it, in DOM order, as one undo step (#848 P13). Elements whose track is
2579
+ * not in the arrangement are left alone (a queued one enters at its DOM
2580
+ * position). The arrangement's own order changes (an Undo) move no element.
2581
+ */
2582
+ private _placeMovedTracks;
2583
+ /**
2584
+ * The rows, in the arrangement's order (#848): each track's loaded clips
2585
+ * (the engine's projection, with the current mix) and the clips still loading.
2586
+ */
2064
2587
  private _getOrderedTracks;
2588
+ /**
2589
+ * A clip still loading: a placeholder box where its length is known, with
2590
+ * its `.dat` peaks when they came, drawn failed when its source failed. Its
2591
+ * header carries no clip id, so it cannot be dragged.
2592
+ */
2593
+ private _renderPlaceholder;
2065
2594
  render(): lit.TemplateResult<1>;
2066
2595
  }
2067
2596
  declare global {
@@ -2086,6 +2615,8 @@ declare class DawRecordButtonElement extends DawTransportButton {
2086
2615
  protected static requiredTargetMethods: readonly string[];
2087
2616
  private _isRecording;
2088
2617
  private _targetRef;
2618
+ /** The listeners on `_targetRef`, aborted when the target changes or the button disconnects. */
2619
+ private _targetListeners;
2089
2620
  private _onStart;
2090
2621
  private _onComplete;
2091
2622
  private _onError;
@@ -2104,8 +2635,6 @@ declare global {
2104
2635
  }
2105
2636
  }
2106
2637
 
2107
- /** Key binding for remapping — derived from KeyboardShortcut to stay in sync. */
2108
- type KeyBinding = Pick<KeyboardShortcut, 'key' | 'ctrlKey' | 'shiftKey' | 'metaKey' | 'altKey'>;
2109
2638
  interface PlaybackShortcutMap {
2110
2639
  playPause?: KeyBinding;
2111
2640
  stop?: KeyBinding;
@@ -2152,6 +2681,8 @@ declare class DawKeyboardShortcutsElement extends LitElement {
2152
2681
  get shortcuts(): KeyboardShortcut[];
2153
2682
  /** Invalidate cached shortcuts when Lit properties change. */
2154
2683
  updated(): void;
2684
+ /** The listeners of this connection, aborted in disconnectedCallback. */
2685
+ private _listeners;
2155
2686
  connectedCallback(): void;
2156
2687
  disconnectedCallback(): void;
2157
2688
  createRenderRoot(): this;
@@ -2224,6 +2755,8 @@ declare class DawTimeDisplayElement extends LitElement {
2224
2755
  private get target();
2225
2756
  private _onTimeUpdate;
2226
2757
  private _onFormatChange;
2758
+ /** The listeners of this connection, aborted in disconnectedCallback. */
2759
+ private _listeners;
2227
2760
  connectedCallback(): void;
2228
2761
  disconnectedCallback(): void;
2229
2762
  private _syncFromTarget;
@@ -2256,6 +2789,8 @@ declare class DawTimeFormatElement extends LitElement {
2256
2789
  private _onFormatChange;
2257
2790
  private _onPointerEnter;
2258
2791
  private _onPointerDown;
2792
+ /** The listeners of this connection, aborted in disconnectedCallback. */
2793
+ private _listeners;
2259
2794
  connectedCallback(): void;
2260
2795
  disconnectedCallback(): void;
2261
2796
  protected updated(): void;
@@ -2271,7 +2806,7 @@ declare global {
2271
2806
  /**
2272
2807
  * `<daw-player>` — lightweight single-track HTMLMediaElement player.
2273
2808
  * Wraps a MediaElementPlayout engine for playback and composes
2274
- * <daw-ruler>/<daw-waveform>/<daw-playhead> for visuals. No PlaylistEngine,
2809
+ * <daw-ruler>/<daw-waveform>/<daw-playhead> for visuals. No EditorEngine,
2275
2810
  * no adapter, no AudioContext. See docs/specs/2026-06-29-daw-player-core-design.md.
2276
2811
  */
2277
2812
  declare class DawPlayerElement extends LitElement {
@@ -2304,6 +2839,8 @@ declare class DawPlayerElement extends LitElement {
2304
2839
  connectedCallback(): void;
2305
2840
  render(): lit.TemplateResult<1>;
2306
2841
  protected updated(changed: PropertyValues): void;
2842
+ /** The peaks fetch in flight: a newer peaks-src or a disconnect aborts it (#848, D7). */
2843
+ private _peaksFetch;
2307
2844
  private _loadPeaks;
2308
2845
  /** Recompute fit-to-width peaks from the loaded WaveformData. No-op without data. */
2309
2846
  private _renderWaveform;
@@ -2400,6 +2937,8 @@ interface AudioResumeHost extends ReactiveControllerHost, HTMLElement {
2400
2937
  declare class AudioResumeController implements ReactiveController {
2401
2938
  private _host;
2402
2939
  private _target;
2940
+ /** The gesture listeners on `_target`: one controller per attach. */
2941
+ private _listeners;
2403
2942
  private _attached;
2404
2943
  private _generation;
2405
2944
  /** CSS selector, or 'document'. When undefined, controller is inert. */
@@ -2527,4 +3066,4 @@ interface SplitHost {
2527
3066
  */
2528
3067
  declare function splitAtPlayhead(host: SplitHost): boolean;
2529
3068
 
2530
- 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, 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 };
3069
+ 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 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 };