@dawcore/components 0.0.39-next.3 → 0.0.39-next.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -10,7 +10,7 @@ var __decorateClass = (decorators, target, key, kind) => {
10
10
  };
11
11
 
12
12
  // <define:__INSTALL_SPECS__>
13
- var define_INSTALL_SPECS_default = { "@dawcore/faust": "@dawcore/faust@^0.0.2-next.1", "@dawcore/midi": "@dawcore/midi@^0.0.6-next.2", "@dawcore/transport": "@dawcore/transport@^0.0.16-next.2", "@dawcore/wam": "@dawcore/wam@^0.0.5-next.0", "@waveform-playlist/core": "@waveform-playlist/core@^13.0.0-next.2", "@waveform-playlist/engine": "@waveform-playlist/engine@^14.0.0-next.1", "@waveform-playlist/worklets": "@waveform-playlist/worklets@^13.0.1-next.0", "@waveform-playlist/playout": "@waveform-playlist/playout@^13.0.0-next.2" };
13
+ var define_INSTALL_SPECS_default = { "@dawcore/faust": "@dawcore/faust@^0.0.2-next.1", "@dawcore/midi": "@dawcore/midi@^0.0.6-next.4", "@dawcore/transport": "@dawcore/transport@^0.0.16-next.4", "@dawcore/wam": "@dawcore/wam@^0.0.5-next.0", "@waveform-playlist/core": "@waveform-playlist/core@^13.0.0-next.4", "@waveform-playlist/engine": "@waveform-playlist/engine@^14.0.0-next.2", "@waveform-playlist/worklets": "@waveform-playlist/worklets@^13.0.1-next.0", "@waveform-playlist/playout": "@waveform-playlist/playout@^13.0.0-next.4" };
14
14
 
15
15
  // src/elements/daw-annotation.ts
16
16
  import { LitElement } from "lit";
@@ -241,6 +241,7 @@ var DawAnnotationTrackElement = class extends LitElement2 {
241
241
  this._onKeyDownCapture = (e) => {
242
242
  if (!this.keyboardControls) return;
243
243
  if (e.repeat) return;
244
+ if (e.key === "Escape" && e.defaultPrevented) return;
244
245
  if (keyBelongsToFocusedControl(e)) return;
245
246
  const match = this._shortcutEntries().find((entry) => matchesKeyBinding(e, entry.binding));
246
247
  if (!match) return;
@@ -997,6 +998,17 @@ function isDomClip(desc) {
997
998
  }
998
999
 
999
1000
  // src/elements/daw-track.ts
1001
+ var TRACK_PROPS = [
1002
+ "volume",
1003
+ "pan",
1004
+ "muted",
1005
+ "soloed",
1006
+ "src",
1007
+ "name",
1008
+ "kind",
1009
+ "renderMode",
1010
+ "spectrogramConfig"
1011
+ ];
1000
1012
  var DawTrackElement = class extends LitElement5 {
1001
1013
  constructor() {
1002
1014
  super(...arguments);
@@ -1127,24 +1139,14 @@ var DawTrackElement = class extends LitElement5 {
1127
1139
  this._hasRendered = true;
1128
1140
  return;
1129
1141
  }
1130
- const trackProps = [
1131
- "volume",
1132
- "pan",
1133
- "muted",
1134
- "soloed",
1135
- "src",
1136
- "name",
1137
- "kind",
1138
- "renderMode",
1139
- "spectrogramConfig"
1140
- ];
1141
- const hasTrackChange = trackProps.some((p) => changed.has(p));
1142
- if (hasTrackChange) {
1142
+ const trackChanged = TRACK_PROPS.filter((p) => changed.has(p));
1143
+ if (trackChanged.length > 0) {
1144
+ const detail = { trackId: this.trackId, changed: trackChanged };
1143
1145
  this.dispatchEvent(
1144
1146
  new CustomEvent("daw-track-update", {
1145
1147
  bubbles: true,
1146
1148
  composed: true,
1147
- detail: { trackId: this.trackId }
1149
+ detail
1148
1150
  })
1149
1151
  );
1150
1152
  }
@@ -2217,6 +2219,7 @@ import { customElement as customElement16, property as property12, state as stat
2217
2219
  import {
2218
2220
  createClip as createClip2,
2219
2221
  createClipFromSeconds,
2222
+ createMixerGesture as createMixerGesture2,
2220
2223
  createTrack,
2221
2224
  clipPixelWidth,
2222
2225
  trackKind
@@ -2964,9 +2967,39 @@ DawRulerElement = __decorateClass([
2964
2967
  customElement13("daw-ruler")
2965
2968
  ], DawRulerElement);
2966
2969
 
2970
+ // src/utils/track-mix.ts
2971
+ var DEFAULT_TRACK_MIX = Object.freeze({
2972
+ volume: 1,
2973
+ pan: 0,
2974
+ muted: false,
2975
+ soloed: false
2976
+ });
2977
+ function mixOfTrack(track) {
2978
+ return { volume: track.volume, pan: track.pan, muted: track.muted, soloed: track.soloed };
2979
+ }
2980
+ function mixOfElement(el) {
2981
+ return { volume: el.volume, pan: el.pan, muted: el.muted, soloed: el.soloed };
2982
+ }
2983
+ function pickMix(mix, names) {
2984
+ const named = new Set(names);
2985
+ return {
2986
+ ...named.has("volume") && { volume: mix.volume },
2987
+ ...named.has("pan") && { pan: mix.pan },
2988
+ ...named.has("muted") && { muted: mix.muted },
2989
+ ...named.has("soloed") && { soloed: mix.soloed }
2990
+ };
2991
+ }
2992
+ function withMix(track, mix) {
2993
+ return { ...track, ...mixOfElement(mix) };
2994
+ }
2995
+ function clampNumber(value, min, max) {
2996
+ return Math.max(min, Math.min(max, Number(value)));
2997
+ }
2998
+
2967
2999
  // src/elements/daw-track-controls.ts
2968
3000
  import { LitElement as LitElement12, html as html9, css as css8 } from "lit";
2969
3001
  import { customElement as customElement14, property as property10 } from "lit/decorators.js";
3002
+ import { createMixerGesture } from "@waveform-playlist/core";
2970
3003
  var DawTrackControlsElement = class extends LitElement12 {
2971
3004
  constructor() {
2972
3005
  super(...arguments);
@@ -2975,19 +3008,30 @@ var DawTrackControlsElement = class extends LitElement12 {
2975
3008
  this.volume = 1;
2976
3009
  this.pan = 0;
2977
3010
  this.muted = false;
3011
+ this.recording = false;
2978
3012
  this.soloed = false;
2979
3013
  this.reorderable = false;
2980
3014
  this.trackIndex = 0;
2981
3015
  this.trackCount = 1;
3016
+ /**
3017
+ * One gesture per slider (#843): the `daw-track-control` events of one
3018
+ * drag, or of one key press (a held key included), carry the same
3019
+ * `gesture` id, and the editor makes them one undo step. Each gesture is
3020
+ * attached to its range input while the element is connected.
3021
+ */
3022
+ this._volumeGesture = createMixerGesture();
3023
+ this._panGesture = createMixerGesture();
3024
+ this._detachGestures = [];
2982
3025
  this._onVolumeInput = (e) => {
2983
3026
  const value = Number(e.target.value);
2984
- if (Number.isFinite(value)) this._dispatchControl("volume", value);
3027
+ if (Number.isFinite(value)) this._dispatchControl("volume", value, this._volumeGesture.id);
2985
3028
  };
2986
3029
  this._onPanInput = (e) => {
2987
3030
  const value = Number(e.target.value);
2988
- if (Number.isFinite(value)) this._dispatchControl("pan", value);
3031
+ if (Number.isFinite(value)) this._dispatchControl("pan", value, this._panGesture.id);
2989
3032
  };
2990
3033
  this._onMuteClick = () => {
3034
+ if (this.recording) return;
2991
3035
  this._dispatchControl("muted", !this.muted);
2992
3036
  };
2993
3037
  this._onSoloClick = () => {
@@ -3021,7 +3065,29 @@ var DawTrackControlsElement = class extends LitElement12 {
3021
3065
  );
3022
3066
  };
3023
3067
  }
3068
+ connectedCallback() {
3069
+ super.connectedCallback();
3070
+ if (this.hasUpdated) this._attachGestures();
3071
+ }
3072
+ disconnectedCallback() {
3073
+ super.disconnectedCallback();
3074
+ this._detachAllGestures();
3075
+ }
3076
+ _attachGestures() {
3077
+ this._detachAllGestures();
3078
+ const volumeInput = this.shadowRoot?.querySelector(".vol-row input");
3079
+ const panInput = this.shadowRoot?.querySelector(".pan-row input");
3080
+ const detach = [];
3081
+ if (volumeInput) detach.push(this._volumeGesture.attach(volumeInput));
3082
+ if (panInput) detach.push(this._panGesture.attach(panInput));
3083
+ this._detachGestures = detach;
3084
+ }
3085
+ _detachAllGestures() {
3086
+ for (const detach of this._detachGestures) detach();
3087
+ this._detachGestures = [];
3088
+ }
3024
3089
  firstUpdated() {
3090
+ this._attachGestures();
3025
3091
  requestAnimationFrame(() => {
3026
3092
  if (!this.isConnected) return;
3027
3093
  const rect = this.getBoundingClientRect();
@@ -3032,13 +3098,15 @@ var DawTrackControlsElement = class extends LitElement12 {
3032
3098
  }
3033
3099
  });
3034
3100
  }
3035
- _dispatchControl(prop, value) {
3101
+ /** `gesture` for the sliders only: each mute or solo click is a step. */
3102
+ _dispatchControl(prop, value, gesture) {
3036
3103
  if (!this.trackId) return;
3104
+ const detail = gesture === void 0 ? { trackId: this.trackId, prop, value } : { trackId: this.trackId, prop, value, gesture };
3037
3105
  this.dispatchEvent(
3038
3106
  new CustomEvent("daw-track-control", {
3039
3107
  bubbles: true,
3040
3108
  composed: true,
3041
- detail: { trackId: this.trackId, prop, value }
3109
+ detail
3042
3110
  })
3043
3111
  );
3044
3112
  }
@@ -3075,6 +3143,7 @@ var DawTrackControlsElement = class extends LitElement12 {
3075
3143
  <button
3076
3144
  class="btn ${this.muted ? "muted-active" : ""}"
3077
3145
  @click=${this._onMuteClick}
3146
+ ?disabled=${this.recording}
3078
3147
  title="Mute"
3079
3148
  >
3080
3149
  M
@@ -3316,6 +3385,9 @@ __decorateClass([
3316
3385
  __decorateClass([
3317
3386
  property10({ type: Boolean, attribute: false })
3318
3387
  ], DawTrackControlsElement.prototype, "muted", 2);
3388
+ __decorateClass([
3389
+ property10({ type: Boolean, attribute: false })
3390
+ ], DawTrackControlsElement.prototype, "recording", 2);
3319
3391
  __decorateClass([
3320
3392
  property10({ type: Boolean, attribute: false })
3321
3393
  ], DawTrackControlsElement.prototype, "soloed", 2);
@@ -3885,7 +3957,6 @@ var RecordingController = class {
3885
3957
  isFirstMessage: true,
3886
3958
  latencySamples,
3887
3959
  clipName: options.clipName,
3888
- armedPrevMuted: null,
3889
3960
  wasOverdub: options.overdub ?? false,
3890
3961
  _onTrackEnded: onTrackEnded,
3891
3962
  _audioTrack: audioTrack,
@@ -3902,11 +3973,7 @@ var RecordingController = class {
3902
3973
  if (audioTrack && onTrackEnded) {
3903
3974
  audioTrack.addEventListener("ended", onTrackEnded);
3904
3975
  }
3905
- const engine = this._host._engine;
3906
- if (engine) {
3907
- session.armedPrevMuted = engine.getState().tracks.find((t) => t.id === trackId)?.muted ?? false;
3908
- engine.setTrackMute(trackId, true);
3909
- }
3976
+ this._host._engine?.setTrackRecording(trackId, true);
3910
3977
  this._host.dispatchEvent(
3911
3978
  new CustomEvent("daw-recording-start", {
3912
3979
  bubbles: true,
@@ -4052,7 +4119,7 @@ var RecordingController = class {
4052
4119
  }
4053
4120
  });
4054
4121
  const notPrevented = this._host.dispatchEvent(event);
4055
- this._restoreArmedTrackMute(session);
4122
+ this._clearTakeMute(session);
4056
4123
  this._sessions.delete(id);
4057
4124
  this._host.requestUpdate();
4058
4125
  if (notPrevented) {
@@ -4180,22 +4247,23 @@ var RecordingController = class {
4180
4247
  );
4181
4248
  }
4182
4249
  /** Shared teardown for finalize paths that end without a take (no data
4183
- * captured / too short after latency compensation): restore the armed-track
4184
- * mute, drop the session, and notify via daw-recording-error so record
4185
- * buttons reset their state. */
4250
+ * captured / too short after latency compensation): clear the take's mute, drop
4251
+ * the session, and notify via daw-recording-error so record buttons reset
4252
+ * their state. */
4186
4253
  _abandonFinalize(id, session, warnMessage, errorMessage = warnMessage) {
4187
4254
  console.warn("[dawcore] RecordingController: " + warnMessage);
4188
- this._restoreArmedTrackMute(session);
4255
+ this._clearTakeMute(session);
4189
4256
  this._sessions.delete(id);
4190
4257
  this._host.requestUpdate();
4191
4258
  this._dispatchRecordingError(id, new Error(errorMessage));
4192
4259
  }
4193
- /** Restore the armed track's pre-session mute state (idempotent — safe to
4194
- * call from both the finalize path and _cleanupSession). */
4195
- _restoreArmedTrackMute(session) {
4196
- if (session.armedPrevMuted === null) return;
4197
- this._host._engine?.setTrackMute(session.trackId, session.armedPrevMuted);
4198
- session.armedPrevMuted = null;
4260
+ /** Clear the take's mute on the session's track, by its id. Each teardown
4261
+ * path calls this once, right before it drops the session from the map, so
4262
+ * a later path never reaches the same session; clearing an id that is not
4263
+ * set is a no-op in the engine. Another session's mute on another track is
4264
+ * left alone. */
4265
+ _clearTakeMute(session) {
4266
+ this._host._engine?.setTrackRecording(session.trackId, false);
4199
4267
  }
4200
4268
  /** @param notifyError dispatch daw-recording-error after cleanup — used by
4201
4269
  * disposal paths that would otherwise discard the session silently. The
@@ -4204,7 +4272,7 @@ var RecordingController = class {
4204
4272
  const session = this._sessions.get(trackId);
4205
4273
  if (!session) return;
4206
4274
  try {
4207
- this._restoreArmedTrackMute(session);
4275
+ this._clearTakeMute(session);
4208
4276
  this._removeTrackEndedListener(session);
4209
4277
  session.workletNode.port.postMessage({ command: "stop" });
4210
4278
  session.source.disconnect();
@@ -4558,6 +4626,8 @@ var PointerHandler = class {
4558
4626
  // still holds; zeroing only the host would desync the two).
4559
4627
  this._preDragSelectionStart = 0;
4560
4628
  this._preDragSelectionEnd = 0;
4629
+ /** Cancels the armed clip drag; set while one is armed (#848). */
4630
+ this._cancelArmedClipDrag = null;
4561
4631
  this.onPointerDown = (e) => {
4562
4632
  const clipHandler = this._host._clipHandler;
4563
4633
  if (clipHandler) {
@@ -4572,12 +4642,13 @@ var PointerHandler = class {
4572
4642
  console.warn("[dawcore] setPointerCapture failed: " + String(err));
4573
4643
  }
4574
4644
  const onMove = (me) => clipHandler.onPointerMove(me);
4575
- const detach = (pe) => {
4645
+ const detach = (pointerId) => {
4646
+ this._cancelArmedClipDrag = null;
4576
4647
  this._timeline?.removeEventListener("pointermove", onMove);
4577
4648
  this._timeline?.removeEventListener("pointerup", onUp);
4578
4649
  this._timeline?.removeEventListener("pointercancel", onCancel);
4579
4650
  try {
4580
- this._timeline?.releasePointerCapture(pe.pointerId);
4651
+ this._timeline?.releasePointerCapture(pointerId);
4581
4652
  } catch (err) {
4582
4653
  console.warn(
4583
4654
  "[dawcore] releasePointerCapture failed (may already be released): " + String(err)
@@ -4587,13 +4658,19 @@ var PointerHandler = class {
4587
4658
  };
4588
4659
  const onUp = (ue) => {
4589
4660
  clipHandler.onPointerUp(ue);
4590
- detach(ue);
4661
+ detach(ue.pointerId);
4591
4662
  };
4592
4663
  const downPointerId = e.pointerId;
4593
4664
  const onCancel = (ce) => {
4594
4665
  if (ce.pointerId !== downPointerId) return;
4595
4666
  clipHandler.onPointerCancel(ce);
4596
- detach(ce);
4667
+ detach(ce.pointerId);
4668
+ };
4669
+ this._cancelArmedClipDrag = () => {
4670
+ clipHandler.onPointerCancel(
4671
+ new PointerEvent("pointercancel", { pointerId: downPointerId })
4672
+ );
4673
+ detach(downPointerId);
4597
4674
  };
4598
4675
  this._timeline.addEventListener("pointermove", onMove);
4599
4676
  this._timeline.addEventListener("pointerup", onUp);
@@ -4706,6 +4783,17 @@ var PointerHandler = class {
4706
4783
  }
4707
4784
  return time * h.effectiveSampleRate / h.samplesPerPixel;
4708
4785
  }
4786
+ /**
4787
+ * Cancel an armed clip move or trim as a `pointercancel` would: the clip
4788
+ * handler reverts it and the timeline's listeners and pointer capture are
4789
+ * released. Returns whether a clip drag was armed.
4790
+ */
4791
+ cancelClipDrag() {
4792
+ const cancel = this._cancelArmedClipDrag;
4793
+ if (!cancel) return false;
4794
+ cancel();
4795
+ return true;
4796
+ }
4709
4797
  /** Detach the drag listeners and release capture — shared by the up and
4710
4798
  * cancel terminals so a new listener added to onPointerDown can't be
4711
4799
  * missed on one of them. */
@@ -4860,6 +4948,11 @@ var ClipPointerHandler = class {
4860
4948
  get isActive() {
4861
4949
  return this._mode !== null;
4862
4950
  }
4951
+ /** True once the pointer of the current press has moved past the drag
4952
+ * threshold: a press that has not moved is not a drag (#848). */
4953
+ get isDragging() {
4954
+ return this._isDragging;
4955
+ }
4863
4956
  /**
4864
4957
  * Attempts to handle a pointerdown event on the given target element.
4865
4958
  * Returns true if the target is a recognized clip interaction element.
@@ -4894,21 +4987,32 @@ var ClipPointerHandler = class {
4894
4987
  this._startPx = e.clientX;
4895
4988
  this._isDragging = false;
4896
4989
  this._cumulativeDeltaSamples = 0;
4990
+ }
4991
+ /**
4992
+ * The press has become a drag (the pointer passed the threshold): take the
4993
+ * clip's bounds and open the transaction now, not at the press. An undo
4994
+ * made during the press (it is not a drag, so undo works) then has no
4995
+ * transaction to abort, and the drag that follows starts from the clip as
4996
+ * the undo left it, one undo step (#848, review of #915). Returns false
4997
+ * when the clip is gone (the undo removed it): the press is dropped.
4998
+ */
4999
+ _startDrag() {
4897
5000
  const engine = this._host.engine;
5001
+ const trackId = this._trackId;
5002
+ const clipId = this._clipId;
4898
5003
  if (engine) {
4899
5004
  const bounds = engine.getClipBounds(trackId, clipId);
4900
- if (bounds) {
4901
- this._originalStartSample = bounds.startSample;
4902
- }
4903
- }
4904
- if (engine) {
5005
+ if (!bounds) return false;
5006
+ this._originalStartSample = bounds.startSample;
5007
+ this._originalOffsetSamples = bounds.offsetSamples;
5008
+ this._originalDurationSamples = bounds.durationSamples;
4905
5009
  engine.beginTransaction();
4906
5010
  } else {
4907
5011
  console.warn(
4908
- "[dawcore] beginDrag: engine unavailable, drag mutations will not be grouped for undo"
5012
+ "[dawcore] drag start: engine unavailable, drag mutations will not be grouped for undo"
4909
5013
  );
4910
5014
  }
4911
- if (mode === "trim-left" || mode === "trim-right") {
5015
+ if (this._mode === "trim-left" || this._mode === "trim-right") {
4912
5016
  const container = this._host.shadowRoot?.querySelector(
4913
5017
  `.clip-container[data-clip-id="${clipId}"]`
4914
5018
  );
@@ -4919,21 +5023,18 @@ var ClipPointerHandler = class {
4919
5023
  } else {
4920
5024
  console.warn("[dawcore] clip container not found for trim visual feedback: " + clipId);
4921
5025
  }
4922
- const engine2 = this._host.engine;
4923
- if (engine2) {
4924
- const bounds = engine2.getClipBounds(trackId, clipId);
4925
- if (bounds) {
4926
- this._originalOffsetSamples = bounds.offsetSamples;
4927
- this._originalDurationSamples = bounds.durationSamples;
4928
- }
4929
- }
4930
5026
  }
5027
+ return true;
4931
5028
  }
4932
5029
  /** Processes pointermove events during an active drag. */
4933
5030
  onPointerMove(e) {
4934
5031
  if (this._mode === null) return;
4935
5032
  const totalDeltaPx = e.clientX - this._startPx;
4936
5033
  if (!this._isDragging && Math.abs(totalDeltaPx) > DRAG_THRESHOLD) {
5034
+ if (!this._startDrag()) {
5035
+ this._reset();
5036
+ return;
5037
+ }
4937
5038
  this._isDragging = true;
4938
5039
  if (this._boundaryEl) {
4939
5040
  this._boundaryEl.classList.add("dragging");
@@ -5055,10 +5156,12 @@ var ClipPointerHandler = class {
5055
5156
  }
5056
5157
  }
5057
5158
  } finally {
5058
- if (this._isDragging && this._cumulativeDeltaSamples !== 0) {
5059
- this._host.engine?.commitTransaction();
5060
- } else {
5061
- this._host.engine?.abortTransaction();
5159
+ if (this._isDragging) {
5160
+ if (this._cumulativeDeltaSamples !== 0) {
5161
+ this._host.engine?.commitTransaction();
5162
+ } else {
5163
+ this._host.engine?.abortTransaction();
5164
+ }
5062
5165
  }
5063
5166
  this._reset();
5064
5167
  }
@@ -5076,7 +5179,7 @@ var ClipPointerHandler = class {
5076
5179
  try {
5077
5180
  this._restoreTrimVisual();
5078
5181
  } finally {
5079
- this._host.engine?.abortTransaction();
5182
+ if (this._isDragging) this._host.engine?.abortTransaction();
5080
5183
  this._reset();
5081
5184
  }
5082
5185
  }
@@ -5251,16 +5354,35 @@ var AnnotationDragHandler = class {
5251
5354
  this._onPointerCancel = (e) => {
5252
5355
  const drag = this._drag;
5253
5356
  if (!drag || e.pointerId !== drag.pointerId) return;
5254
- const elements = drag.track.annotationElements;
5255
- if (drag.mode === "ticks") {
5256
- applyTickBoundaryResults(elements, drag.snapshot, (t) => this._host._ticksToSeconds(t));
5257
- } else {
5258
- applyBoundaryResults(elements, drag.snapshot);
5259
- }
5260
- this._teardown();
5357
+ this._restoreAndTeardown(drag);
5261
5358
  };
5262
5359
  this._host = host;
5263
5360
  }
5361
+ /** True from pointerdown on an annotation until the drag ends or is cancelled. */
5362
+ get isActive() {
5363
+ return this._drag !== null;
5364
+ }
5365
+ /** True once the pointer has moved at least `DRAG_THRESHOLD` px (an edge
5366
+ * drag, or a box press that moved): a press that has not moved (a click on
5367
+ * the box) is not a drag (#848). */
5368
+ get isDragging() {
5369
+ return this._drag?.moved ?? false;
5370
+ }
5371
+ /** Cancel the drag in progress (Escape, editor disconnect): the boundaries
5372
+ * go back to where they were when it began (#848). */
5373
+ cancel() {
5374
+ if (this._drag) this._restoreAndTeardown(this._drag);
5375
+ }
5376
+ /** Restore the drag-start snapshot — a cancelled drag must not commit. */
5377
+ _restoreAndTeardown(drag) {
5378
+ const elements = drag.track.annotationElements;
5379
+ if (drag.mode === "ticks") {
5380
+ applyTickBoundaryResults(elements, drag.snapshot, (t) => this._host._ticksToSeconds(t));
5381
+ } else {
5382
+ applyBoundaryResults(elements, drag.snapshot);
5383
+ }
5384
+ this._teardown();
5385
+ }
5264
5386
  _teardown() {
5265
5387
  const drag = this._drag;
5266
5388
  if (!drag) return;
@@ -5408,6 +5530,10 @@ var TrackReorderHandler = class _TrackReorderHandler {
5408
5530
  static _reducedMotion() {
5409
5531
  return typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
5410
5532
  }
5533
+ /** True from the grab until the drag ends or is cancelled. */
5534
+ get isActive() {
5535
+ return this._trackId !== null;
5536
+ }
5411
5537
  /** Abort any in-progress drag and reset state. Called by the editor on
5412
5538
  * disconnect — without this, a drag interrupted by editor removal (with no
5413
5539
  * pointercancel delivered) would leave the handler wedged and silently
@@ -7417,6 +7543,7 @@ var DawEditorElement = class extends LitElement14 {
7417
7543
  /** Resolved sample rate — falls back to sampleRate property until first audio decode. */
7418
7544
  this._resolvedSampleRate = null;
7419
7545
  this._tracks = /* @__PURE__ */ new Map();
7546
+ this._seedMix = /* @__PURE__ */ new Map();
7420
7547
  this._engineTracks = /* @__PURE__ */ new Map();
7421
7548
  this._peaksData = /* @__PURE__ */ new Map();
7422
7549
  this._isPlaying = false;
@@ -7539,6 +7666,7 @@ var DawEditorElement = class extends LitElement14 {
7539
7666
  }
7540
7667
  const descriptor = this._readTrackDescriptor(trackEl);
7541
7668
  this._tracks = new Map(this._tracks).set(trackId, descriptor);
7669
+ this._setSeedMix(trackId, mixOfElement(trackEl));
7542
7670
  this._trackElements.set(trackId, trackEl);
7543
7671
  this._loadTrack(trackId, descriptor);
7544
7672
  };
@@ -7564,15 +7692,8 @@ var DawEditorElement = class extends LitElement14 {
7564
7692
  });
7565
7693
  }
7566
7694
  this._tracks = new Map(this._tracks).set(trackId, descriptor);
7567
- if (this._engine) {
7568
- if (oldDescriptor?.volume !== descriptor.volume)
7569
- this._engine.setTrackVolume(trackId, descriptor.volume);
7570
- if (oldDescriptor?.pan !== descriptor.pan) this._engine.setTrackPan(trackId, descriptor.pan);
7571
- if (oldDescriptor?.muted !== descriptor.muted)
7572
- this._engine.setTrackMute(trackId, descriptor.muted);
7573
- if (oldDescriptor?.soloed !== descriptor.soloed)
7574
- this._engine.setTrackSolo(trackId, descriptor.soloed);
7575
- }
7695
+ const changed = Array.isArray(e.detail.changed) ? e.detail.changed : [];
7696
+ this._writeMixFields(trackId, pickMix(mixOfElement(trackEl), changed));
7576
7697
  if (oldDescriptor?.src !== descriptor.src) {
7577
7698
  this._loadTrack(trackId, descriptor);
7578
7699
  }
@@ -7598,7 +7719,7 @@ var DawEditorElement = class extends LitElement14 {
7598
7719
  }
7599
7720
  };
7600
7721
  this._onTrackControl = (e) => {
7601
- const { trackId, prop, value } = e.detail ?? {};
7722
+ const { trackId, prop, value, gesture } = e.detail ?? {};
7602
7723
  if (!trackId || !prop || !DawEditorElement._CONTROL_PROPS.has(prop)) return;
7603
7724
  if (this._selectedTrackId !== trackId) {
7604
7725
  this._setSelectedTrackId(trackId);
@@ -7613,18 +7734,12 @@ var DawEditorElement = class extends LitElement14 {
7613
7734
  })
7614
7735
  );
7615
7736
  }
7616
- const oldDescriptor = this._tracks.get(trackId);
7617
- if (oldDescriptor) {
7618
- const descriptor = { ...oldDescriptor, [prop]: value };
7619
- this._tracks = new Map(this._tracks).set(trackId, descriptor);
7620
- if (this._engine) {
7621
- if (prop === "volume")
7622
- this._engine.setTrackVolume(trackId, Math.max(0, Math.min(1, Number(value))));
7623
- if (prop === "pan")
7624
- this._engine.setTrackPan(trackId, Math.max(-1, Math.min(1, Number(value))));
7625
- if (prop === "muted") this._engine.setTrackMute(trackId, Boolean(value));
7626
- if (prop === "soloed") this._engine.setTrackSolo(trackId, Boolean(value));
7627
- }
7737
+ if (this._tracks.has(trackId)) {
7738
+ const options = typeof gesture === "string" ? { gesture } : void 0;
7739
+ if (prop === "volume") this._writeMix(trackId, "volume", clampNumber(value, 0, 1), options);
7740
+ if (prop === "pan") this._writeMix(trackId, "pan", clampNumber(value, -1, 1), options);
7741
+ if (prop === "muted") this._writeMix(trackId, "muted", Boolean(value), options);
7742
+ if (prop === "soloed") this._writeMix(trackId, "soloed", Boolean(value), options);
7628
7743
  }
7629
7744
  };
7630
7745
  this._onTrackRemoveRequest = (e) => {
@@ -7735,6 +7850,16 @@ var DawEditorElement = class extends LitElement14 {
7735
7850
  if (!this.trackReordering) return;
7736
7851
  this._trackReorderDrag.onGrab(e.detail.trackId, e.detail.pointerEvent, e.detail.gripElement);
7737
7852
  };
7853
+ /**
7854
+ * Escape during a drag cancels it and does nothing else: the default is
7855
+ * prevented, so `<daw-keyboard-shortcuts>` (core's `handleKeyboardEvent`)
7856
+ * does not also stop playback. No `stopPropagation`: an app's own listener
7857
+ * can read `defaultPrevented`.
7858
+ */
7859
+ this._onDragEscape = (e) => {
7860
+ if (e.key !== "Escape") return;
7861
+ if (this._cancelDrags()) e.preventDefault();
7862
+ };
7738
7863
  // --- Recording ---
7739
7864
  this.recordingStream = null;
7740
7865
  /** Set in togglePauseRecording when Transport is paused alongside the
@@ -8245,9 +8370,69 @@ var DawEditorElement = class extends LitElement14 {
8245
8370
  get tracks() {
8246
8371
  return [...this._tracks.entries()].map(([trackId, descriptor]) => ({
8247
8372
  trackId,
8248
- ...descriptor
8373
+ ...descriptor,
8374
+ ...this._mixOf(trackId)
8249
8375
  }));
8250
8376
  }
8377
+ /**
8378
+ * A track's mix, from its one owner: the arrangement (through
8379
+ * `_engineTracks`, which follows `mixerVersion`) for a track the engine
8380
+ * holds, the seed for one still on its way in (#843).
8381
+ */
8382
+ _mixOf(trackId) {
8383
+ const seed = this._seedMix.get(trackId);
8384
+ if (seed) return seed;
8385
+ const track = this._engineTracks.get(trackId);
8386
+ return track ? mixOfTrack(track) : DEFAULT_TRACK_MIX;
8387
+ }
8388
+ /** Replace a track's seed (a new Map: `_seedMix` is reactive state). */
8389
+ _setSeedMix(trackId, mix) {
8390
+ this._seedMix = new Map(this._seedMix).set(trackId, mix);
8391
+ }
8392
+ _deleteSeedMix(trackIds) {
8393
+ let next = null;
8394
+ for (const id of trackIds) {
8395
+ if (!this._seedMix.has(id)) continue;
8396
+ next ?? (next = new Map(this._seedMix));
8397
+ next.delete(id);
8398
+ }
8399
+ if (next) this._seedMix = next;
8400
+ }
8401
+ /**
8402
+ * Change one mixer field of a track: the seed while the track is loading
8403
+ * (not an undo step, nothing sent), else the engine's setter with
8404
+ * `options` (an undo step; changes with one `gesture` id are one step).
8405
+ */
8406
+ _writeMix(trackId, field, value, options) {
8407
+ const seed = this._seedMix.get(trackId);
8408
+ if (seed) {
8409
+ if (seed[field] !== value) this._setSeedMix(trackId, { ...seed, [field]: value });
8410
+ return;
8411
+ }
8412
+ if (!this._engine) return;
8413
+ if (field === "volume") this._engine.setTrackVolume(trackId, value, options);
8414
+ else if (field === "pan") this._engine.setTrackPan(trackId, value, options);
8415
+ else if (field === "muted") this._engine.setTrackMute(trackId, value, options);
8416
+ else this._engine.setTrackSolo(trackId, value, options);
8417
+ }
8418
+ /**
8419
+ * Change the given mixer fields of a track as ONE undo step (#843): all
8420
+ * of them carry one fresh gesture id. A field left out is not sent.
8421
+ */
8422
+ _writeMixFields(trackId, mix) {
8423
+ const options = { gesture: createMixerGesture2().id };
8424
+ if (mix.volume !== void 0) this._writeMix(trackId, "volume", mix.volume, options);
8425
+ if (mix.pan !== void 0) this._writeMix(trackId, "pan", mix.pan, options);
8426
+ if (mix.muted !== void 0) this._writeMix(trackId, "muted", mix.muted, options);
8427
+ if (mix.soloed !== void 0) this._writeMix(trackId, "soloed", mix.soloed, options);
8428
+ }
8429
+ /** The ordered tracks for `engine.setTracks`, a loading track with its seed. */
8430
+ _tracksForEngine() {
8431
+ return this._getOrderedTracks().map(([trackId, track]) => {
8432
+ const seed = this._seedMix.get(trackId);
8433
+ return seed ? withMix(track, seed) : track;
8434
+ });
8435
+ }
8251
8436
  get selectedTrackId() {
8252
8437
  return this._selectedTrackId;
8253
8438
  }
@@ -8273,6 +8458,7 @@ var DawEditorElement = class extends LitElement14 {
8273
8458
  // --- Lifecycle ---
8274
8459
  connectedCallback() {
8275
8460
  super.connectedCallback();
8461
+ window.addEventListener("keydown", this._onDragEscape, { capture: true });
8276
8462
  this.addEventListener("daw-track-connected", this._onTrackConnected);
8277
8463
  this.addEventListener("daw-track-update", this._onTrackUpdate);
8278
8464
  this.addEventListener("daw-track-control", this._onTrackControl);
@@ -8333,6 +8519,7 @@ var DawEditorElement = class extends LitElement14 {
8333
8519
  }
8334
8520
  disconnectedCallback() {
8335
8521
  super.disconnectedCallback();
8522
+ window.removeEventListener("keydown", this._onDragEscape, { capture: true });
8336
8523
  this._effectsManager?.disposeAll();
8337
8524
  this._effectsManager = null;
8338
8525
  this.removeEventListener("daw-track-connected", this._onTrackConnected);
@@ -8348,7 +8535,7 @@ var DawEditorElement = class extends LitElement14 {
8348
8535
  this.removeEventListener("daw-annotation-select", this._onAnnotationSelect);
8349
8536
  this.removeEventListener("daw-track-reorder", this._onTrackReorder);
8350
8537
  this.removeEventListener("daw-track-reorder-grab", this._onTrackReorderGrab);
8351
- this._trackReorderDrag.cancel();
8538
+ this._cancelDrags(true);
8352
8539
  this._childObserver?.disconnect();
8353
8540
  this._childObserver = null;
8354
8541
  this._trackElements.clear();
@@ -8371,6 +8558,7 @@ var DawEditorElement = class extends LitElement14 {
8371
8558
  this._adapterConsumedByDispose = true;
8372
8559
  }
8373
8560
  this._tracks = /* @__PURE__ */ new Map();
8561
+ this._seedMix = /* @__PURE__ */ new Map();
8374
8562
  this._engineTracks = /* @__PURE__ */ new Map();
8375
8563
  this._peaksData = /* @__PURE__ */ new Map();
8376
8564
  this._loadingTracks.clear();
@@ -8444,6 +8632,7 @@ var DawEditorElement = class extends LitElement14 {
8444
8632
  const nextTracks = new Map(this._tracks);
8445
8633
  nextTracks.delete(trackId);
8446
8634
  this._tracks = nextTracks;
8635
+ this._deleteSeedMix([trackId]);
8447
8636
  const nextEngine = new Map(this._engineTracks);
8448
8637
  nextEngine.delete(trackId);
8449
8638
  this._engineTracks = nextEngine;
@@ -8505,10 +8694,6 @@ var DawEditorElement = class extends LitElement14 {
8505
8694
  next.set(track.id, {
8506
8695
  name: track.name ?? "",
8507
8696
  src: "",
8508
- volume: track.volume ?? 1,
8509
- pan: track.pan ?? 0,
8510
- muted: track.muted ?? false,
8511
- soloed: track.soloed ?? false,
8512
8697
  kind: trackKind(track),
8513
8698
  renderMode: trackDescriptorRenderMode(trackKind(track), "waveform"),
8514
8699
  clips: []
@@ -8795,8 +8980,7 @@ var DawEditorElement = class extends LitElement14 {
8795
8980
  _commitTrackChange(trackId, updatedTrack) {
8796
8981
  this._recomputeDuration();
8797
8982
  if (this._engine?.updateTrack) this._engine.updateTrack(trackId, updatedTrack);
8798
- else if (this._engine)
8799
- this._engine.setTracks(this._getOrderedTracks().map(([, track]) => track));
8983
+ else if (this._engine) this._engine.setTracks(this._tracksForEngine());
8800
8984
  }
8801
8985
  _applyClipUpdate(trackId, clipId, clipEl) {
8802
8986
  const t = this._engineTracks.get(trackId);
@@ -8958,10 +9142,6 @@ var DawEditorElement = class extends LitElement14 {
8958
9142
  return {
8959
9143
  name: trackEl.name || "Untitled",
8960
9144
  src: trackEl.src,
8961
- volume: trackEl.volume,
8962
- pan: trackEl.pan,
8963
- muted: trackEl.muted,
8964
- soloed: trackEl.soloed,
8965
9145
  kind: trackEl.kind,
8966
9146
  renderMode: trackDescriptorRenderMode(trackEl.kind, trackEl.renderMode),
8967
9147
  clips
@@ -9050,10 +9230,7 @@ var DawEditorElement = class extends LitElement14 {
9050
9230
  name: descriptor.name,
9051
9231
  kind: descriptor.kind,
9052
9232
  clips: [clip2],
9053
- volume: descriptor.volume,
9054
- pan: descriptor.pan,
9055
- muted: descriptor.muted,
9056
- soloed: descriptor.soloed
9233
+ ...this._mixOf(trackId)
9057
9234
  });
9058
9235
  previewTrack.id = trackId;
9059
9236
  this._engineTracks = new Map(this._engineTracks).set(trackId, previewTrack);
@@ -9128,10 +9305,7 @@ var DawEditorElement = class extends LitElement14 {
9128
9305
  name: descriptor.name,
9129
9306
  kind: descriptor.kind,
9130
9307
  clips,
9131
- volume: descriptor.volume,
9132
- pan: descriptor.pan,
9133
- muted: descriptor.muted,
9134
- soloed: descriptor.soloed
9308
+ ...this._mixOf(trackId)
9135
9309
  });
9136
9310
  const requestedClips = descriptor.clips.filter((c) => c.src).length + refusedMidiClips;
9137
9311
  if (requestedClips > 0 && clips.length === 0) {
@@ -9146,7 +9320,7 @@ var DawEditorElement = class extends LitElement14 {
9146
9320
  this._maybeRegisterSpectrogramClipAudio(trackId, c);
9147
9321
  }
9148
9322
  const engine = await this._ensureEngine();
9149
- engine.setTracks(this._getOrderedTracks().map(([, track2]) => track2));
9323
+ engine.setTracks(this._tracksForEngine());
9150
9324
  this.dispatchEvent(
9151
9325
  new CustomEvent("daw-track-ready", {
9152
9326
  bubbles: true,
@@ -9271,6 +9445,7 @@ var DawEditorElement = class extends LitElement14 {
9271
9445
  nextTracks.set(track.id, track);
9272
9446
  }
9273
9447
  this._engineTracks = nextTracks;
9448
+ this._deleteSeedMix(nextTracks.keys());
9274
9449
  this._reconcileDescriptorsWithEngineTracks(engineState.tracks);
9275
9450
  }
9276
9451
  if (structuralChange) {
@@ -9444,14 +9619,22 @@ var DawEditorElement = class extends LitElement14 {
9444
9619
  }
9445
9620
  }
9446
9621
  /**
9447
- * Update reflected attributes on a track. For DOM-element tracks the changes
9448
- * are written to the `<daw-track>` element (which fires `daw-track-update`);
9449
- * for tracks without a DOM element (file drops) the descriptor and engine
9450
- * state are updated in place.
9622
+ * Update reflected attributes on a track. The mixer fields go to their
9623
+ * owner as one undo step (#843): the engine, or while the track is loading
9624
+ * the values it will enter with (not a step). For DOM-element tracks the
9625
+ * changes are also written to the `<daw-track>` element; for tracks
9626
+ * without a DOM element (file drops) the descriptor is updated in place.
9451
9627
  */
9452
9628
  updateTrack(trackId, partial) {
9629
+ const mix = {
9630
+ volume: partial.volume,
9631
+ pan: partial.pan,
9632
+ muted: partial.muted,
9633
+ soloed: partial.soloed
9634
+ };
9453
9635
  const trackEl = this._trackElements.get(trackId);
9454
9636
  if (trackEl) {
9637
+ this._writeMixFields(trackId, mix);
9455
9638
  if (partial.name !== void 0) trackEl.setAttribute("name", partial.name);
9456
9639
  if (partial.volume !== void 0) trackEl.volume = partial.volume;
9457
9640
  if (partial.pan !== void 0) trackEl.pan = partial.pan;
@@ -9478,21 +9661,12 @@ var DawEditorElement = class extends LitElement14 {
9478
9661
  const newDesc = {
9479
9662
  ...oldDesc,
9480
9663
  ...partial.name !== void 0 && { name: partial.name },
9481
- ...partial.volume !== void 0 && { volume: partial.volume },
9482
- ...partial.pan !== void 0 && { pan: partial.pan },
9483
- ...partial.muted !== void 0 && { muted: partial.muted },
9484
- ...partial.soloed !== void 0 && { soloed: partial.soloed },
9485
9664
  ...normalizedRenderMode !== void 0 && {
9486
9665
  renderMode: trackDescriptorRenderMode(oldDesc.kind, normalizedRenderMode)
9487
9666
  }
9488
9667
  };
9489
9668
  this._tracks = new Map(this._tracks).set(trackId, newDesc);
9490
- if (this._engine) {
9491
- if (partial.volume !== void 0) this._engine.setTrackVolume(trackId, partial.volume);
9492
- if (partial.pan !== void 0) this._engine.setTrackPan(trackId, partial.pan);
9493
- if (partial.muted !== void 0) this._engine.setTrackMute(trackId, partial.muted);
9494
- if (partial.soloed !== void 0) this._engine.setTrackSolo(trackId, partial.soloed);
9495
- }
9669
+ this._writeMixFields(trackId, mix);
9496
9670
  }
9497
9671
  /**
9498
9672
  * Append a clip to an existing track. Builds a `<daw-clip>` from `config`
@@ -9752,16 +9926,49 @@ var DawEditorElement = class extends LitElement14 {
9752
9926
  })
9753
9927
  );
9754
9928
  }
9755
- /** Undo the last structural edit. */
9929
+ /**
9930
+ * A clip or track drag is in progress: undo and redo do nothing until it
9931
+ * ends (#848). A clip counts once its pointer has moved past the drag
9932
+ * threshold; annotation drags do not count (annotations are not in the
9933
+ * undo history).
9934
+ */
9935
+ get _dragInProgress() {
9936
+ return this._clipPointer.isDragging || this._trackReorderDrag.isActive;
9937
+ }
9938
+ /**
9939
+ * Cancel every drag in progress, as a `pointercancel` would. Returns whether
9940
+ * one was. A clip or annotation press that has not moved is not a drag and
9941
+ * is left alone, unless `includePresses` (the editor's disconnect, which
9942
+ * ends every pointer interaction).
9943
+ */
9944
+ _cancelDrags(includePresses = false) {
9945
+ let cancelled = false;
9946
+ if (includePresses || this._clipPointer.isDragging) {
9947
+ cancelled = this._pointer.cancelClipDrag() || cancelled;
9948
+ }
9949
+ if (this._trackReorderDrag.isActive) {
9950
+ this._trackReorderDrag.cancel();
9951
+ cancelled = true;
9952
+ }
9953
+ const annotation = this._annotationDrag;
9954
+ if (includePresses ? annotation.isActive : annotation.isDragging) {
9955
+ annotation.cancel();
9956
+ cancelled = true;
9957
+ }
9958
+ return cancelled;
9959
+ }
9960
+ /** Undo the last edit. Does nothing while a drag is in progress. */
9756
9961
  undo() {
9962
+ if (this._dragInProgress) return;
9757
9963
  if (!this._engine) {
9758
9964
  console.warn("[dawcore] undo: engine not ready, call ignored");
9759
9965
  return;
9760
9966
  }
9761
9967
  this._engine.undo();
9762
9968
  }
9763
- /** Redo the last undone edit. */
9969
+ /** Redo the last undone edit. Does nothing while a drag is in progress. */
9764
9970
  redo() {
9971
+ if (this._dragInProgress) return;
9765
9972
  if (!this._engine) {
9766
9973
  console.warn("[dawcore] redo: engine not ready, call ignored");
9767
9974
  return;
@@ -10120,22 +10327,24 @@ var DawEditorElement = class extends LitElement14 {
10120
10327
  <span class="annotation-lane-name">${track.name}</span>
10121
10328
  </div>`
10122
10329
  )}
10123
- ${orderedTracks.map(
10124
- (t, i) => html12`
10330
+ ${orderedTracks.map((t, i) => {
10331
+ const mix = this._mixOf(t.trackId);
10332
+ return html12`
10125
10333
  <daw-track-controls
10126
10334
  style="height: ${t.trackHeight}px;"
10127
10335
  .trackId=${t.trackId}
10128
10336
  .trackName=${t.descriptor?.name ?? "Untitled"}
10129
- .volume=${t.descriptor?.volume ?? 1}
10130
- .pan=${t.descriptor?.pan ?? 0}
10131
- .muted=${t.descriptor?.muted ?? false}
10132
- .soloed=${t.descriptor?.soloed ?? false}
10337
+ .volume=${mix.volume}
10338
+ .pan=${mix.pan}
10339
+ .muted=${mix.muted}
10340
+ .recording=${this._engine?.recordingTrackIds.has(t.trackId) ?? false}
10341
+ .soloed=${mix.soloed}
10133
10342
  .reorderable=${this.trackReordering}
10134
10343
  .trackIndex=${i}
10135
10344
  .trackCount=${orderedTracks.length}
10136
10345
  ></daw-track-controls>
10137
- `
10138
- )}
10346
+ `;
10347
+ })}
10139
10348
  </div>
10140
10349
  </div>` : ""}
10141
10350
  <div class="scroll-area">
@@ -10545,6 +10754,9 @@ __decorateClass([
10545
10754
  __decorateClass([
10546
10755
  state4()
10547
10756
  ], DawEditorElement.prototype, "_tracks", 2);
10757
+ __decorateClass([
10758
+ state4()
10759
+ ], DawEditorElement.prototype, "_seedMix", 2);
10548
10760
  __decorateClass([
10549
10761
  state4()
10550
10762
  ], DawEditorElement.prototype, "_engineTracks", 2);