improved zone handling

This commit is contained in:
2026-04-15 18:00:34 -06:00
parent 84edddded8
commit 17874587a4
6 changed files with 124 additions and 36 deletions

View File

@ -147,6 +147,7 @@ export default function WaveformTimeline({
const isDraggingRef = useRef(false);
const [isDragging, setIsDragging] = useState(false);
const selectionStartRef = useRef<number | null>(null);
const selectionEndRef = useRef<number | null>(null);
const [selectionStart, setSelectionStart] = useState<number | null>(null);
const [selectionEnd, setSelectionEnd] = useState<number | null>(null);
const [selectedZone, setSelectedZone] = useState<{type: 'cut' | 'mute' | 'gain', id: string} | null>(null);
@ -809,6 +810,7 @@ export default function WaveformTimeline({
// Range selection mode
const startTime = clientXToTime(e.clientX);
selectionStartRef.current = startTime;
selectionEndRef.current = startTime;
setSelectionStart(startTime);
setSelectionEnd(startTime);
isDraggingRef.current = true;
@ -817,6 +819,7 @@ export default function WaveformTimeline({
const onMove = (ev: MouseEvent) => {
if (!isDraggingRef.current) return;
const currentTime = clientXToTime(ev.clientX);
selectionEndRef.current = currentTime;
setSelectionEnd(currentTime);
};
@ -824,21 +827,23 @@ export default function WaveformTimeline({
isDraggingRef.current = false;
setIsDragging(false);
if (selectionStartRef.current !== null && selectionEnd !== null) {
const start = Math.min(selectionStartRef.current, selectionEnd);
const end = Math.max(selectionStartRef.current, selectionEnd);
if (selectionStartRef.current !== null && selectionEndRef.current !== null) {
const start = Math.min(selectionStartRef.current, selectionEndRef.current);
const end = Math.max(selectionStartRef.current, selectionEndRef.current);
const minDuration = 0.01;
if (cutMode) {
if (end - start >= minDuration && cutMode) {
addCutRange(start, end);
} else if (muteMode) {
} else if (end - start >= minDuration && muteMode) {
addMuteRange(start, end);
} else if (gainMode) {
} else if (end - start >= minDuration && gainMode) {
addGainRange(start, end, gainModeDb);
}
}
// Reset selection
selectionStartRef.current = null;
selectionEndRef.current = null;
setSelectionStart(null);
setSelectionEnd(null);
@ -868,7 +873,7 @@ export default function WaveformTimeline({
window.addEventListener('mouseup', onUp);
}
},
[cutMode, muteMode, gainMode, gainModeDb, clientXToTime, seekToClientX, addCutRange, addMuteRange, addGainRange, selectionEnd, getZoneAtPosition, cutRanges, muteRanges, gainRanges, duration, updateCutRange, updateMuteRange, updateGainRangeBounds],
[cutMode, muteMode, gainMode, gainModeDb, clientXToTime, seekToClientX, addCutRange, addMuteRange, addGainRange, getZoneAtPosition, cutRanges, muteRanges, gainRanges, duration, updateCutRange, updateMuteRange, updateGainRangeBounds],
);
// Handle keyboard shortcuts for zone editing