@waveform-playlist/browser 17.0.0-next.7 → 17.0.0-next.9

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.js CHANGED
@@ -184,7 +184,7 @@ __export(index_exports, {
184
184
  module.exports = __toCommonJS(index_exports);
185
185
 
186
186
  // <define:__INSTALL_SPECS__>
187
- var define_INSTALL_SPECS_default = { "@dawcore/wam": "@dawcore/wam@^0.0.5-next.0", "@dnd-kit/abstract": "@dnd-kit/abstract@^0.5.0", "@dnd-kit/dom": "@dnd-kit/dom@^0.5.0", "@dnd-kit/react": "@dnd-kit/react@^0.5.0", "@waveform-playlist/annotations": "@waveform-playlist/annotations@^14.0.0-next.4", "@waveform-playlist/media-element-playout": "@waveform-playlist/media-element-playout@^12.4.0-next.2", "@waveform-playlist/playout": "@waveform-playlist/playout@^13.0.0-next.2", "@waveform-playlist/recording": "@waveform-playlist/recording@^14.0.0-next.4", react: "react@^19.0.0", "react-dom": "react-dom@^19.0.0", "styled-components": "styled-components@^6.0.0", tone: "tone@^15.0.0", "@waveform-playlist/spectrogram": "@waveform-playlist/spectrogram@^15.0.0-next.2" };
187
+ var define_INSTALL_SPECS_default = { "@dawcore/wam": "@dawcore/wam@^0.0.5-next.0", "@dnd-kit/abstract": "@dnd-kit/abstract@^0.5.0", "@dnd-kit/dom": "@dnd-kit/dom@^0.5.0", "@dnd-kit/react": "@dnd-kit/react@^0.5.0", "@waveform-playlist/annotations": "@waveform-playlist/annotations@^14.0.0-next.6", "@waveform-playlist/media-element-playout": "@waveform-playlist/media-element-playout@^12.4.0-next.4", "@waveform-playlist/playout": "@waveform-playlist/playout@^13.0.0-next.4", "@waveform-playlist/recording": "@waveform-playlist/recording@^14.0.0-next.6", react: "react@^19.0.0", "react-dom": "react-dom@^19.0.0", "styled-components": "styled-components@^6.0.0", tone: "tone@^15.0.0", "@waveform-playlist/spectrogram": "@waveform-playlist/spectrogram@^15.0.0-next.4" };
188
188
 
189
189
  // src/WaveformPlaylistContext.tsx
190
190
  var import_react35 = require("react");
@@ -541,7 +541,8 @@ var PlaylistMixerContext = slot();
541
541
  var TrackReorderPreviewContext = slot();
542
542
  var TrimPreviewContext = slot();
543
543
  var TrimPreviewPeaksContext = slot();
544
- var RecordingArmContext = slot();
544
+ var DragGuardContext = slot();
545
+ var RecordingTrackContext = slot();
545
546
  var PlaybackRateContext = slot();
546
547
  var MediaElementTrackContext = slot();
547
548
  function useSlot(context, hookName, needs) {
@@ -579,7 +580,7 @@ var useUndoRedo = () => useSlot(UndoRedoContext, "useUndoRedo", WEB_AUDIO);
579
580
  var usePlaylistTimeline = () => useSlot(PlaylistTimelineContext, "usePlaylistTimeline", WEB_AUDIO);
580
581
  var usePlaylistMixer = () => useSlot(PlaylistMixerContext, "usePlaylistMixer", WEB_AUDIO);
581
582
  var useTrackReorderPreview = () => useSlot(TrackReorderPreviewContext, "useTrackReorderPreview", WEB_AUDIO);
582
- var useRecordingArm = () => useSlot(RecordingArmContext, "useRecordingArm", WEB_AUDIO);
583
+ var useRecordingTrack = () => useSlot(RecordingTrackContext, "useRecordingTrack", WEB_AUDIO);
583
584
  var usePlaybackRate = () => useSlot(PlaybackRateContext, "usePlaybackRate", MEDIA_ELEMENT);
584
585
  var useMediaElementTrack = () => useSlot(MediaElementTrackContext, "useMediaElementTrack", MEDIA_ELEMENT);
585
586
  var useWebAudioProviderOnly = (hookName) => {
@@ -594,6 +595,7 @@ var usePlaylistViewOptional = () => orNull((0, import_react7.use)(PlaylistViewCo
594
595
  var usePlaylistZoomOptional = () => orNull((0, import_react7.use)(PlaylistZoomContext));
595
596
  var useTrimPreviewOptional = () => orNull((0, import_react7.use)(TrimPreviewContext));
596
597
  var useTrimPreviewPeaksOptional = () => orNull((0, import_react7.use)(TrimPreviewPeaksContext));
598
+ var useDragGuardOptional = () => orNull((0, import_react7.use)(DragGuardContext));
597
599
 
598
600
  // src/hooks/useClipDragHandlers.ts
599
601
  function trimOrderFor(clips, clip) {
@@ -656,6 +658,14 @@ function useClipDragHandlers({
656
658
  const trimDragRef = import_react8.default.useRef(null);
657
659
  const lastBoundaryDeltaRef = import_react8.default.useRef(0);
658
660
  const moveDragRef = import_react8.default.useRef(null);
661
+ const dragGuard = useDragGuardOptional();
662
+ const endGuardRef = import_react8.default.useRef(null);
663
+ const endGuard = import_react8.default.useCallback(() => {
664
+ var _a;
665
+ (_a = endGuardRef.current) == null ? void 0 : _a.call(endGuardRef);
666
+ endGuardRef.current = null;
667
+ }, []);
668
+ import_react8.default.useEffect(() => endGuard, [endGuard]);
659
669
  import_react8.default.useEffect(() => {
660
670
  if (!preview) return;
661
671
  return () => {
@@ -667,9 +677,11 @@ function useClipDragHandlers({
667
677
  }, [preview]);
668
678
  const onDragStart = import_react8.default.useCallback(
669
679
  (event) => {
670
- var _a;
680
+ var _a, _b;
671
681
  const data = (_a = event.operation.source) == null ? void 0 : _a.data;
672
682
  if (!data || data.kind === "track-reorder") return;
683
+ endGuard();
684
+ endGuardRef.current = (_b = dragGuard == null ? void 0 : dragGuard.begin()) != null ? _b : null;
673
685
  trimDragRef.current = null;
674
686
  trimOrderRef.current = null;
675
687
  moveDragRef.current = null;
@@ -695,7 +707,7 @@ function useClipDragHandlers({
695
707
  };
696
708
  trimOrderRef.current = trimOrderFor(clips, clip);
697
709
  },
698
- [arrangement]
710
+ [arrangement, dragGuard, endGuard]
699
711
  );
700
712
  const onDragMove = import_react8.default.useCallback(
701
713
  (event) => {
@@ -747,6 +759,7 @@ function useClipDragHandlers({
747
759
  var _a, _b;
748
760
  const data = (_a = event.operation.source) == null ? void 0 : _a.data;
749
761
  if ((data == null ? void 0 : data.kind) === "track-reorder") return;
762
+ endGuard();
750
763
  const drag = trimDragRef.current;
751
764
  const move = moveDragRef.current;
752
765
  const delta = lastBoundaryDeltaRef.current;
@@ -779,7 +792,7 @@ function useClipDragHandlers({
779
792
  arrangement.moveClip(track.id, clipId, Math.floor(sampleDelta));
780
793
  }
781
794
  },
782
- [samplesPerPixel, arrangement, preview, commitTrim]
795
+ [samplesPerPixel, arrangement, preview, commitTrim, endGuard]
783
796
  );
784
797
  return {
785
798
  onDragStart,
@@ -2827,19 +2840,20 @@ function deriveRows(tracks, inputs, previous) {
2827
2840
  });
2828
2841
  return { byTrackId, result: sameItems(previous.result, rows) ? previous.result : rows };
2829
2842
  }
2830
- function sameState(a, name, mix) {
2831
- return a.name === name && a.volume === mix.volume && a.muted === mix.muted && a.soloed === mix.soloed && a.pan === mix.pan;
2843
+ function sameState(a, name, mix, muted) {
2844
+ return a.name === name && a.volume === mix.volume && a.muted === muted && a.soloed === mix.soloed && a.pan === mix.pan;
2832
2845
  }
2833
- function deriveTrackStates(tracks, mixer, previous) {
2846
+ function deriveTrackStates(tracks, mixer, recordingTrackIds, previous) {
2834
2847
  const byTrackId = /* @__PURE__ */ new Map();
2835
2848
  const states = tracks.map((track) => {
2836
2849
  var _a;
2837
2850
  const mix = (_a = mixer.get(track.id)) != null ? _a : DEFAULT_MIX;
2851
+ const muted = mix.muted || recordingTrackIds.has(track.id);
2838
2852
  const before = previous.byTrackId.get(track.id);
2839
- const state = before && sameState(before, track.name, mix) ? before : {
2853
+ const state = before && sameState(before, track.name, mix, muted) ? before : {
2840
2854
  name: track.name,
2841
2855
  volume: mix.volume,
2842
- muted: mix.muted,
2856
+ muted,
2843
2857
  soloed: mix.soloed,
2844
2858
  pan: mix.pan
2845
2859
  };
@@ -2859,12 +2873,14 @@ function useArrangementValue(arrangement, read) {
2859
2873
  return (0, import_react31.useSyncExternalStore)(store.subscribe, store.getSnapshot, store.getSnapshot);
2860
2874
  }
2861
2875
  var readMixer = (arrangement) => arrangement.getMixer();
2876
+ var readRecordingTrackIds = (arrangement) => arrangement.recordingTrackIds;
2862
2877
  var readCanUndo = (arrangement) => arrangement.canUndo;
2863
2878
  var readCanRedo = (arrangement) => arrangement.canRedo;
2864
2879
  function useArrangementView(arrangement, options) {
2865
2880
  const { samplesPerPixel, mono, baseScale, placeholderSampleRate } = options;
2866
2881
  const arrangementTracks = useArrangementTracks(arrangement);
2867
2882
  const mixer = useArrangementValue(arrangement, readMixer);
2883
+ const recordingTrackIds = useArrangementValue(arrangement, readRecordingTrackIds);
2868
2884
  const canUndo = useArrangementValue(arrangement, readCanUndo);
2869
2885
  const canRedo = useArrangementValue(arrangement, readCanRedo);
2870
2886
  const loadedCacheRef = (0, import_react31.useRef)(EMPTY_LOADED_TRACKS);
@@ -2894,10 +2910,15 @@ function useArrangementView(arrangement, options) {
2894
2910
  const duration = (0, import_react31.useMemo)(() => timelineDuration(tracks), [tracks]);
2895
2911
  const statesCacheRef = (0, import_react31.useRef)(EMPTY_STATES);
2896
2912
  const trackStates = (0, import_react31.useMemo)(() => {
2897
- const next = deriveTrackStates(arrangementTracks, mixer, statesCacheRef.current);
2913
+ const next = deriveTrackStates(
2914
+ arrangementTracks,
2915
+ mixer,
2916
+ recordingTrackIds,
2917
+ statesCacheRef.current
2918
+ );
2898
2919
  statesCacheRef.current = next;
2899
2920
  return next.result;
2900
- }, [arrangementTracks, mixer]);
2921
+ }, [arrangementTracks, mixer, recordingTrackIds]);
2901
2922
  return {
2902
2923
  tracks,
2903
2924
  peaksDataArray,
@@ -2970,7 +2991,6 @@ function useReadyOnce(options) {
2970
2991
 
2971
2992
  // src/providerInternals/useArrangementEditing.ts
2972
2993
  var import_react33 = require("react");
2973
- var import_core8 = require("@waveform-playlist/core");
2974
2994
 
2975
2995
  // src/components/partWarnings.ts
2976
2996
  var warned = /* @__PURE__ */ new Set();
@@ -2990,63 +3010,71 @@ function isTrackId(setter, trackId) {
2990
3010
  );
2991
3011
  return false;
2992
3012
  }
3013
+ var readRecordingTrackId = (arrangement) => {
3014
+ for (const id of arrangement.recordingTrackIds) return id;
3015
+ return null;
3016
+ };
3017
+ function clearRecordingTracks(arrangement, keep = null) {
3018
+ for (const id of [...arrangement.recordingTrackIds]) {
3019
+ if (id !== keep) arrangement.setTrackRecording(id, false);
3020
+ }
3021
+ }
2993
3022
  function useRecordingActive(arrangement) {
2994
3023
  const recordingActiveRef = (0, import_react33.useRef)(false);
2995
- const [armed] = (0, import_react33.useState)(() => (0, import_core8.createValueSource)(null));
2996
3024
  const setRecordingActive = (0, import_react33.useCallback)(
2997
- (active, armedTrackId2) => {
2998
- var _a, _b;
3025
+ (active, recordingTrackId2) => {
2999
3026
  recordingActiveRef.current = active;
3000
- const current = armed.source.getSnapshot();
3001
- if (active && armedTrackId2) {
3002
- if ((current == null ? void 0 : current.trackId) === armedTrackId2) return;
3003
- if (current) arrangement.setTrackMute(current.trackId, current.prevMuted);
3004
- const prevMuted = (_b = (_a = arrangement.getMixer().get(armedTrackId2)) == null ? void 0 : _a.muted) != null ? _b : false;
3005
- armed.publish({ trackId: armedTrackId2, prevMuted });
3006
- arrangement.setTrackMute(armedTrackId2, true);
3007
- } else if (!active && current) {
3008
- arrangement.setTrackMute(current.trackId, current.prevMuted);
3009
- armed.publish(null);
3027
+ if (active && recordingTrackId2) {
3028
+ clearRecordingTracks(arrangement, recordingTrackId2);
3029
+ arrangement.setTrackRecording(recordingTrackId2, true);
3030
+ } else if (!active) {
3031
+ clearRecordingTracks(arrangement);
3010
3032
  }
3011
3033
  },
3012
- [arrangement, armed]
3034
+ [arrangement]
3013
3035
  );
3014
3036
  (0, import_react33.useEffect)(
3015
3037
  () => () => {
3016
- if (armed.source.getSnapshot()) setRecordingActive(false);
3038
+ if (arrangement.recordingTrackIds.size > 0) setRecordingActive(false);
3017
3039
  },
3018
- [armed, setRecordingActive]
3040
+ [arrangement, setRecordingActive]
3019
3041
  );
3020
- const getArmedTrackId = (0, import_react33.useCallback)(() => {
3021
- var _a, _b;
3022
- return (_b = (_a = armed.source.getSnapshot()) == null ? void 0 : _a.trackId) != null ? _b : null;
3023
- }, [armed]);
3024
- const armedTrackId = (0, import_react33.useSyncExternalStore)(armed.source.subscribe, getArmedTrackId);
3025
- const recordingArm = (0, import_react33.useMemo)(() => ({ armedTrackId }), [armedTrackId]);
3026
- return { setRecordingActive, recordingActiveRef, recordingArm };
3042
+ const subscribe = (0, import_react33.useCallback)(
3043
+ (listener) => arrangement.subscribe(listener),
3044
+ [arrangement]
3045
+ );
3046
+ const getRecordingTrackId = (0, import_react33.useCallback)(() => readRecordingTrackId(arrangement), [arrangement]);
3047
+ const recordingTrackId = (0, import_react33.useSyncExternalStore)(
3048
+ subscribe,
3049
+ getRecordingTrackId,
3050
+ getRecordingTrackId
3051
+ );
3052
+ const recordingTrack = (0, import_react33.useMemo)(() => ({ recordingTrackId }), [recordingTrackId]);
3053
+ return { setRecordingActive, recordingActiveRef, recordingTrack };
3027
3054
  }
3028
- function useArrangementEditing(arrangement) {
3055
+ function useArrangementEditing(arrangement, dragGuard) {
3029
3056
  const setTrackMute = (0, import_react33.useCallback)(
3030
- (trackId, muted) => {
3031
- if (isTrackId("setTrackMute", trackId)) arrangement.setTrackMute(trackId, muted);
3057
+ (trackId, muted, options) => {
3058
+ if (isTrackId("setTrackMute", trackId)) arrangement.setTrackMute(trackId, muted, options);
3032
3059
  },
3033
3060
  [arrangement]
3034
3061
  );
3035
3062
  const setTrackSolo = (0, import_react33.useCallback)(
3036
- (trackId, soloed) => {
3037
- if (isTrackId("setTrackSolo", trackId)) arrangement.setTrackSolo(trackId, soloed);
3063
+ (trackId, soloed, options) => {
3064
+ if (isTrackId("setTrackSolo", trackId)) arrangement.setTrackSolo(trackId, soloed, options);
3038
3065
  },
3039
3066
  [arrangement]
3040
3067
  );
3041
3068
  const setTrackVolume = (0, import_react33.useCallback)(
3042
- (trackId, volume) => {
3043
- if (isTrackId("setTrackVolume", trackId)) arrangement.setTrackVolume(trackId, volume);
3069
+ (trackId, volume, options) => {
3070
+ if (isTrackId("setTrackVolume", trackId))
3071
+ arrangement.setTrackVolume(trackId, volume, options);
3044
3072
  },
3045
3073
  [arrangement]
3046
3074
  );
3047
3075
  const setTrackPan = (0, import_react33.useCallback)(
3048
- (trackId, pan) => {
3049
- if (isTrackId("setTrackPan", trackId)) arrangement.setTrackPan(trackId, pan);
3076
+ (trackId, pan, options) => {
3077
+ if (isTrackId("setTrackPan", trackId)) arrangement.setTrackPan(trackId, pan, options);
3050
3078
  },
3051
3079
  [arrangement]
3052
3080
  );
@@ -3054,9 +3082,13 @@ function useArrangementEditing(arrangement) {
3054
3082
  (trackId, toIndex) => arrangement.reorderTrack(trackId, toIndex),
3055
3083
  [arrangement]
3056
3084
  );
3057
- const undo = (0, import_react33.useCallback)(() => arrangement.undo(), [arrangement]);
3058
- const redo = (0, import_react33.useCallback)(() => arrangement.redo(), [arrangement]);
3059
- const { setRecordingActive, recordingActiveRef, recordingArm } = useRecordingActive(arrangement);
3085
+ const undo = (0, import_react33.useCallback)(() => {
3086
+ if (!dragGuard.active) arrangement.undo();
3087
+ }, [arrangement, dragGuard]);
3088
+ const redo = (0, import_react33.useCallback)(() => {
3089
+ if (!dragGuard.active) arrangement.redo();
3090
+ }, [arrangement, dragGuard]);
3091
+ const { setRecordingActive, recordingActiveRef, recordingTrack } = useRecordingActive(arrangement);
3060
3092
  return {
3061
3093
  setTrackMute,
3062
3094
  setTrackSolo,
@@ -3067,7 +3099,26 @@ function useArrangementEditing(arrangement) {
3067
3099
  redo,
3068
3100
  setRecordingActive,
3069
3101
  recordingActiveRef,
3070
- recordingArm
3102
+ recordingTrack
3103
+ };
3104
+ }
3105
+
3106
+ // src/providerInternals/dragGuard.ts
3107
+ function createDragGuard() {
3108
+ let count = 0;
3109
+ return {
3110
+ begin() {
3111
+ count++;
3112
+ let ended = false;
3113
+ return () => {
3114
+ if (ended) return;
3115
+ ended = true;
3116
+ count--;
3117
+ };
3118
+ },
3119
+ get active() {
3120
+ return count > 0;
3121
+ }
3071
3122
  };
3072
3123
  }
3073
3124
 
@@ -3317,7 +3368,8 @@ var ProviderOnArrangement = ({
3317
3368
  peaksOptions: view.peaksOptions,
3318
3369
  peaksCacheRef: view.peaksCacheRef
3319
3370
  });
3320
- const editing = useArrangementEditing(arrangement);
3371
+ const [dragGuard] = (0, import_react35.useState)(createDragGuard);
3372
+ const editing = useArrangementEditing(arrangement, dragGuard);
3321
3373
  const { recordingActiveRef } = editing;
3322
3374
  const setLoopRegionFromSelection = (0, import_react35.useCallback)(() => {
3323
3375
  var _a, _b;
@@ -3935,25 +3987,31 @@ var ProviderOnArrangement = ({
3935
3987
  () => ({ trackDragPreview }),
3936
3988
  [trackDragPreview]
3937
3989
  );
3938
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_styled_components.ThemeProvider, { theme: mergedTheme, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PlaybackRateContext, { value: BLOCKED, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MediaElementTrackContext, { value: BLOCKED, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ArrangementContext, { value: arrangement, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PlaybackRefsContext, { value: refsValue, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EngineRefsContext, { value: engineRefsValue, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TrimPreviewContext, { value: trimPreview, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TrimPreviewPeaksContext, { value: trimPreviewPeaks, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PlaybackControlsContext, { value: controlsValue, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EditorControlsContext, { value: editorControlsValue, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PlaylistViewContext, { value: viewValue, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PlaylistSettingsContext, { value: settingsValue, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PlaylistZoomContext, { value: zoomValue, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(UndoRedoContext, { value: undoRedoValue, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectedTrackIdContext, { value: selectedTrackIdValue, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectedRowContext, { value: selectedTrackIdValue, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LoopContext, { value: loopValue, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AnnotationOptionsContext, { value: annotationOptionsValue, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AnnotationsContext, { value: annotationsValue, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(IsPlayingContext, { value: isPlayingValue, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ActiveAnnotationContext, { value: activeAnnotationValue, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CurrentTimeContext, { value: currentTimeValue, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectionContext, { value: selectionValue, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
3939
- TrackReorderPreviewContext,
3990
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_styled_components.ThemeProvider, { theme: mergedTheme, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PlaybackRateContext, { value: BLOCKED, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MediaElementTrackContext, { value: BLOCKED, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ArrangementContext, { value: arrangement, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PlaybackRefsContext, { value: refsValue, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EngineRefsContext, { value: engineRefsValue, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DragGuardContext, { value: dragGuard, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TrimPreviewContext, { value: trimPreview, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TrimPreviewPeaksContext, { value: trimPreviewPeaks, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PlaybackControlsContext, { value: controlsValue, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EditorControlsContext, { value: editorControlsValue, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PlaylistViewContext, { value: viewValue, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PlaylistSettingsContext, { value: settingsValue, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PlaylistZoomContext, { value: zoomValue, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(UndoRedoContext, { value: undoRedoValue, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectedTrackIdContext, { value: selectedTrackIdValue, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectedRowContext, { value: selectedTrackIdValue, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LoopContext, { value: loopValue, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AnnotationOptionsContext, { value: annotationOptionsValue, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AnnotationsContext, { value: annotationsValue, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(IsPlayingContext, { value: isPlayingValue, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
3991
+ ActiveAnnotationContext,
3940
3992
  {
3941
- value: reorderPreviewValue,
3942
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PlaylistMixerContext, { value: mixerValue, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
3943
- PlaylistTimelineContext,
3993
+ value: activeAnnotationValue,
3994
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CurrentTimeContext, { value: currentTimeValue, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectionContext, { value: selectionValue, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
3995
+ TrackReorderPreviewContext,
3944
3996
  {
3945
- value: timelineValue,
3946
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
3947
- RecordingArmContext,
3997
+ value: reorderPreviewValue,
3998
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PlaylistMixerContext, { value: mixerValue, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
3999
+ PlaylistTimelineContext,
3948
4000
  {
3949
- value: editing.recordingArm,
3950
- children
4001
+ value: timelineValue,
4002
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
4003
+ RecordingTrackContext,
4004
+ {
4005
+ value: editing.recordingTrack,
4006
+ children
4007
+ }
4008
+ )
3951
4009
  }
3952
- )
4010
+ ) })
3953
4011
  }
3954
- ) })
4012
+ ) }) })
3955
4013
  }
3956
- ) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) });
4014
+ ) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) });
3957
4015
  };
3958
4016
 
3959
4017
  // src/MediaElementPlaylistContext.tsx
@@ -4530,7 +4588,7 @@ var MediaElementPlaylistProvider = ({
4530
4588
  ActiveAnnotationContext,
4531
4589
  {
4532
4590
  value: activeAnnotationValue,
4533
- children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(CurrentTimeContext, { value: currentTimeValue, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(SelectionContext, { value: selection, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(SelectedRowContext, { value: ONLY_ROW_SELECTED, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(RecordingArmContext, { value: BLOCKED, children }) }) }) })
4591
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(CurrentTimeContext, { value: currentTimeValue, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(SelectionContext, { value: selection, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(SelectedRowContext, { value: ONLY_ROW_SELECTED, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(RecordingTrackContext, { value: BLOCKED, children }) }) }) })
4534
4592
  }
4535
4593
  ) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) });
4536
4594
  };
@@ -4914,10 +4972,10 @@ function useSpectrogramIntegration() {
4914
4972
  }
4915
4973
 
4916
4974
  // src/utils/trackRenderMode.ts
4917
- var import_core9 = require("@waveform-playlist/core");
4975
+ var import_core8 = require("@waveform-playlist/core");
4918
4976
  function trackRenderMode(track, override) {
4919
4977
  var _a;
4920
- if ((0, import_core9.trackKind)(track) === "midi") return "waveform";
4978
+ if ((0, import_core8.trackKind)(track) === "midi") return "waveform";
4921
4979
  return (_a = override != null ? override : track.renderMode) != null ? _a : "waveform";
4922
4980
  }
4923
4981
 
@@ -4971,7 +5029,7 @@ var import_ui_components14 = require("@waveform-playlist/ui-components");
4971
5029
 
4972
5030
  // src/hooks/useSelectionDrag.ts
4973
5031
  var import_react44 = require("react");
4974
- var import_core10 = require("@waveform-playlist/core");
5032
+ var import_core9 = require("@waveform-playlist/core");
4975
5033
 
4976
5034
  // src/hooks/useWindowDrag.ts
4977
5035
  var import_react43 = require("react");
@@ -5056,7 +5114,7 @@ function useSelectionDrag({
5056
5114
  const { setSelection } = usePlaybackControls();
5057
5115
  const [isSelecting, setIsSelecting] = (0, import_react44.useState)(false);
5058
5116
  const automaticScrollRef = (0, import_react44.useRef)(false);
5059
- const previewHandle = (0, import_react44.useMemo)(() => (0, import_core10.createValueSource)(null), []);
5117
+ const previewHandle = (0, import_react44.useMemo)(() => (0, import_core9.createValueSource)(null), []);
5060
5118
  const pressTimeRef = (0, import_react44.useRef)(0);
5061
5119
  const wroteSelectionRef = (0, import_react44.useRef)(false);
5062
5120
  const dragElementRef = (0, import_react44.useRef)(null);
@@ -5148,7 +5206,7 @@ var import_ui_components13 = require("@waveform-playlist/ui-components");
5148
5206
  // src/components/TrackRows.tsx
5149
5207
  var import_react48 = __toESM(require("react"));
5150
5208
  var import_ui_components7 = require("@waveform-playlist/ui-components");
5151
- var import_core12 = require("@waveform-playlist/core");
5209
+ var import_core11 = require("@waveform-playlist/core");
5152
5210
 
5153
5211
  // src/contexts/ClipInteractionContext.tsx
5154
5212
  var import_react46 = require("react");
@@ -5176,7 +5234,7 @@ function useClipInteractionEnabled() {
5176
5234
  // src/components/ChannelWithProgress.tsx
5177
5235
  var import_react47 = require("react");
5178
5236
  var import_styled_components5 = __toESM(require("styled-components"));
5179
- var import_core11 = require("@waveform-playlist/core");
5237
+ var import_core10 = require("@waveform-playlist/core");
5180
5238
  var import_ui_components6 = require("@waveform-playlist/ui-components");
5181
5239
  var import_jsx_runtime7 = require("react/jsx-runtime");
5182
5240
  var ChannelWrapper = import_styled_components5.default.div`
@@ -5238,7 +5296,7 @@ var ClipProgress = ({
5238
5296
  useCurrentTime();
5239
5297
  const { sampleRate } = usePlaylistView();
5240
5298
  const { samplesPerPixel } = usePlaylistZoom();
5241
- const clipPixelWidth = (0, import_core11.clipPixelWidth)(
5299
+ const clipPixelWidth = (0, import_core10.clipPixelWidth)(
5242
5300
  clipStartSample,
5243
5301
  clipDurationSamples,
5244
5302
  samplesPerPixel
@@ -5469,7 +5527,7 @@ var RecordingPreviewClip = ({
5469
5527
  const getSnapshot = (0, import_react48.useCallback)(() => source.getSnapshot(), [source]);
5470
5528
  const progress = (0, import_react48.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
5471
5529
  const durationSamples = Math.floor(progress.duration * sampleRate);
5472
- const latencyOffsetSamples = (0, import_core12.resolveRecordingOffsetSamples)({
5530
+ const latencyOffsetSamples = (0, import_core11.resolveRecordingOffsetSamples)({
5473
5531
  overrideSeconds: recordingState.latencyOffset,
5474
5532
  outputLatency: getOutputLatency(),
5475
5533
  lookAhead: getLookAhead(),
@@ -5691,8 +5749,8 @@ var WaveformTracks = ({ gainScaled = false, children }) => {
5691
5749
  var _a, _b;
5692
5750
  const track = rowList[trackIndex];
5693
5751
  if (!track) return null;
5694
- const isArmed = (recordingState == null ? void 0 : recordingState.isRecording) === true && recordingState.trackId === track.id;
5695
- const recordingChannels = isArmed ? recordingChannelCount : 0;
5752
+ const isRecordingTrack = (recordingState == null ? void 0 : recordingState.isRecording) === true && recordingState.trackId === track.id;
5753
+ const recordingChannels = isRecordingTrack ? recordingChannelCount : 0;
5696
5754
  const helpers = spectrogramHelpersById.get(track.id);
5697
5755
  return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
5698
5756
  TrackRow,
@@ -5710,7 +5768,7 @@ var WaveformTracks = ({ gainScaled = false, children }) => {
5710
5768
  numChannels: getTrackChannelCount(trackClipPeaks, recordingChannels),
5711
5769
  waveHeight,
5712
5770
  mono,
5713
- recordingState: isArmed ? recordingState : void 0,
5771
+ recordingState: isRecordingTrack ? recordingState : void 0,
5714
5772
  spectrogramConfig: helpers == null ? void 0 : helpers.config,
5715
5773
  frequencyScaleFn: helpers == null ? void 0 : helpers.frequencyScaleFn,
5716
5774
  samplesPerPixel,
@@ -5732,6 +5790,7 @@ var import_ui_components9 = require("@waveform-playlist/ui-components");
5732
5790
 
5733
5791
  // src/components/TrackControlPieces.tsx
5734
5792
  var import_react51 = require("react");
5793
+ var import_core12 = require("@waveform-playlist/core");
5735
5794
  var import_ui_components8 = require("@waveform-playlist/ui-components");
5736
5795
 
5737
5796
  // src/components/trackContext.ts
@@ -5876,13 +5935,13 @@ var TrackName = () => {
5876
5935
  return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { "data-track-name": "", style: NAME_STYLE, children: name });
5877
5936
  };
5878
5937
  var TrackMuteButton = () => {
5879
- const { muted, setMuted, isRecordingArmed } = useTrack();
5938
+ const { muted, setMuted, isRecording } = useTrack();
5880
5939
  return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
5881
5940
  import_ui_components8.Button,
5882
5941
  {
5883
5942
  $variant: muted ? "danger" : "outline",
5884
5943
  "aria-pressed": muted,
5885
- disabled: isRecordingArmed,
5944
+ disabled: isRecording,
5886
5945
  onClick: () => setMuted(!muted),
5887
5946
  children: "Mute"
5888
5947
  }
@@ -5900,8 +5959,18 @@ var TrackSoloButton = () => {
5900
5959
  }
5901
5960
  );
5902
5961
  };
5962
+ function useSliderGesture() {
5963
+ const [gesture] = (0, import_react51.useState)(import_core12.createMixerGesture);
5964
+ const ref = (0, import_react51.useRef)(null);
5965
+ (0, import_react51.useEffect)(() => {
5966
+ const input = ref.current;
5967
+ return input ? gesture.attach(input) : void 0;
5968
+ }, [gesture]);
5969
+ return { gesture, ref };
5970
+ }
5903
5971
  var TrackVolumeSlider = () => {
5904
5972
  const { volume, setVolume } = useTrack();
5973
+ const { gesture, ref } = useSliderGesture();
5905
5974
  return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_ui_components8.SliderWrapper, { children: [
5906
5975
  /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_ui_components8.VolumeDownIcon, {}),
5907
5976
  /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
@@ -5910,9 +5979,10 @@ var TrackVolumeSlider = () => {
5910
5979
  min: "0",
5911
5980
  max: "1",
5912
5981
  step: "0.01",
5982
+ ref,
5913
5983
  value: volume,
5914
5984
  "aria-label": "Volume",
5915
- onChange: (e) => setVolume(parseFloat(e.target.value))
5985
+ onChange: (e) => setVolume(parseFloat(e.target.value), { gesture: gesture.id })
5916
5986
  }
5917
5987
  ),
5918
5988
  /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_ui_components8.VolumeUpIcon, {})
@@ -5920,6 +5990,7 @@ var TrackVolumeSlider = () => {
5920
5990
  };
5921
5991
  var TrackPanSlider = () => {
5922
5992
  const { pan, setPan } = useTrack();
5993
+ const { gesture, ref } = useSliderGesture();
5923
5994
  return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_ui_components8.SliderWrapper, { children: [
5924
5995
  /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { children: "L" }),
5925
5996
  /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
@@ -5928,9 +5999,10 @@ var TrackPanSlider = () => {
5928
5999
  min: "-1",
5929
6000
  max: "1",
5930
6001
  step: "0.01",
6002
+ ref,
5931
6003
  value: pan,
5932
6004
  "aria-label": "Pan",
5933
- onChange: (e) => setPan(parseFloat(e.target.value))
6005
+ onChange: (e) => setPan(parseFloat(e.target.value), { gesture: gesture.id })
5934
6006
  }
5935
6007
  ),
5936
6008
  /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { children: "R" })
@@ -6077,7 +6149,7 @@ function TrackControlsSlotImpl({
6077
6149
  isLast,
6078
6150
  renderMode,
6079
6151
  hasSpectrogram,
6080
- isRecordingArmed,
6152
+ isRecording,
6081
6153
  height,
6082
6154
  top,
6083
6155
  animate,
@@ -6096,10 +6168,10 @@ function TrackControlsSlotImpl({
6096
6168
  indexRef.current = index;
6097
6169
  const actions = (0, import_react54.useMemo)(
6098
6170
  () => ({
6099
- setMuted: (value2) => setTrackMute(trackId, value2),
6100
- setSoloed: (value2) => setTrackSolo(trackId, value2),
6101
- setVolume: (value2) => setTrackVolume(trackId, value2),
6102
- setPan: (value2) => setTrackPan(trackId, value2),
6171
+ setMuted: (value2, options) => setTrackMute(trackId, value2, options),
6172
+ setSoloed: (value2, options) => setTrackSolo(trackId, value2, options),
6173
+ setVolume: (value2, options) => setTrackVolume(trackId, value2, options),
6174
+ setPan: (value2, options) => setTrackPan(trackId, value2, options),
6103
6175
  select: () => setSelectedTrackId(trackId),
6104
6176
  // The engine clamps the target and ignores a move to the same place.
6105
6177
  moveUp: () => reorderTrack(trackId, indexRef.current - 1),
@@ -6133,7 +6205,7 @@ function TrackControlsSlotImpl({
6133
6205
  isFirst,
6134
6206
  isLast,
6135
6207
  hasSpectrogram,
6136
- isRecordingArmed
6208
+ isRecording
6137
6209
  }, actions),
6138
6210
  [
6139
6211
  trackId,
@@ -6149,7 +6221,7 @@ function TrackControlsSlotImpl({
6149
6221
  isFirst,
6150
6222
  isLast,
6151
6223
  hasSpectrogram,
6152
- isRecordingArmed,
6224
+ isRecording,
6153
6225
  actions
6154
6226
  ]
6155
6227
  );
@@ -6190,7 +6262,7 @@ function WaveformTrackControlsImpl({ children }) {
6190
6262
  );
6191
6263
  }
6192
6264
  const { selectedTrackId } = useSelectedTrackId();
6193
- const { armedTrackId } = useRecordingArm();
6265
+ const { recordingTrackId } = useRecordingTrack();
6194
6266
  const spectrogram = (0, import_react54.use)(SpectrogramIntegrationContext);
6195
6267
  const { trackStates } = usePlaylistMixer();
6196
6268
  const template = useStableTemplate(children != null ? children : DEFAULT_TEMPLATE);
@@ -6233,7 +6305,7 @@ function WaveformTrackControlsImpl({ children }) {
6233
6305
  isLast: trackIndex === tracks.length - 1,
6234
6306
  renderMode: (_a = renderModeById.get(track.id)) != null ? _a : "waveform",
6235
6307
  hasSpectrogram: spectrogram !== null && track.kind !== "midi",
6236
- isRecordingArmed: track.id === armedTrackId,
6308
+ isRecording: track.id === recordingTrackId,
6237
6309
  height: (_b = trackHeightById.get(track.id)) != null ? _b : 0,
6238
6310
  top: (_c = trackLayout.topById.get(track.id)) != null ? _c : 0,
6239
6311
  animate: animateTrackLayout && dragSourceTrackId !== null,
@@ -7246,12 +7318,12 @@ var KeyboardShortcuts = ({
7246
7318
  var import_react67 = require("react");
7247
7319
  function useRecordingSession({ isRecording, trackId }) {
7248
7320
  const { setRecordingActive } = useEditorControls();
7249
- const armedTrackId = trackId != null ? trackId : null;
7321
+ const recordingTrackId = trackId != null ? trackId : null;
7250
7322
  (0, import_react67.useEffect)(() => {
7251
7323
  if (!isRecording) return void 0;
7252
- setRecordingActive(true, armedTrackId);
7324
+ setRecordingActive(true, recordingTrackId);
7253
7325
  return () => setRecordingActive(false);
7254
- }, [isRecording, armedTrackId, setRecordingActive]);
7326
+ }, [isRecording, recordingTrackId, setRecordingActive]);
7255
7327
  }
7256
7328
 
7257
7329
  // src/components/ClipInteractionProvider.tsx
@@ -7369,11 +7441,21 @@ var ClipInteractionProvider = ({
7369
7441
  onDragMove,
7370
7442
  onDragEnd
7371
7443
  } = useClipDragHandlers({ samplesPerPixel, snapSamplePosition });
7444
+ const dragGuard = useDragGuardOptional();
7445
+ const endReorderGuardRef = (0, import_react68.useRef)(null);
7446
+ const endReorderGuard = (0, import_react68.useCallback)(() => {
7447
+ var _a;
7448
+ (_a = endReorderGuardRef.current) == null ? void 0 : _a.call(endReorderGuardRef);
7449
+ endReorderGuardRef.current = null;
7450
+ }, []);
7451
+ import_react68.default.useEffect(() => endReorderGuard, [endReorderGuard]);
7372
7452
  const onDragStart = import_react68.default.useCallback(
7373
7453
  (event) => {
7374
- var _a, _b;
7454
+ var _a, _b, _c;
7375
7455
  const data = (_b = (_a = event.operation) == null ? void 0 : _a.source) == null ? void 0 : _b.data;
7376
7456
  if ((data == null ? void 0 : data.kind) === "track-reorder") {
7457
+ endReorderGuard();
7458
+ endReorderGuardRef.current = (_c = dragGuard == null ? void 0 : dragGuard.begin()) != null ? _c : null;
7377
7459
  if (data.trackId) setSelectedTrackId(data.trackId);
7378
7460
  return;
7379
7461
  }
@@ -7384,7 +7466,7 @@ var ClipInteractionProvider = ({
7384
7466
  }
7385
7467
  handleDragStart(event);
7386
7468
  },
7387
- [handleDragStart, setSelectedTrackId]
7469
+ [handleDragStart, setSelectedTrackId, dragGuard, endReorderGuard]
7388
7470
  );
7389
7471
  const handleDragOver = import_react68.default.useCallback(
7390
7472
  (event) => {
@@ -7406,6 +7488,7 @@ var ClipInteractionProvider = ({
7406
7488
  var _a;
7407
7489
  const data = (_a = event.operation.source) == null ? void 0 : _a.data;
7408
7490
  if ((data == null ? void 0 : data.kind) === "track-reorder") {
7491
+ endReorderGuard();
7409
7492
  const sortable = event.operation.source.sortable;
7410
7493
  const trackId = data.trackId;
7411
7494
  const moves = !event.canceled && trackId && sortable && sortable.index !== sortable.initialIndex;
@@ -7417,7 +7500,7 @@ var ClipInteractionProvider = ({
7417
7500
  }
7418
7501
  onDragEnd(event);
7419
7502
  },
7420
- [onDragEnd, reorderTrack, setTrackDragPreview]
7503
+ [onDragEnd, reorderTrack, setTrackDragPreview, endReorderGuard]
7421
7504
  );
7422
7505
  const modifiers = (0, import_react68.useMemo)(() => {
7423
7506
  const mods = [import_modifiers3.RestrictToHorizontalAxis];