fix: drag clamp, pitch anchor, Ctrl+A, marquee dir, resize snap
This commit is contained in:
+32
-5
@@ -4563,6 +4563,18 @@ const PianoRollTabEditor = ({ st, zoom, bpm, viewportWidth, onClose, onUpdateNot
|
||||
window.addEventListener('mouseup', up);
|
||||
return () => window.removeEventListener('mouseup', up);
|
||||
}, []);
|
||||
React.useEffect(() => {
|
||||
const handler = (e) => {
|
||||
if ((e.ctrlKey || e.metaKey) && e.key === 'a') {
|
||||
const target = e.target;
|
||||
if (target && (target.tagName === 'INPUT' || target.tagName === 'TEXTAREA' || target.isContentEditable)) return;
|
||||
e.preventDefault();
|
||||
setSelectedNoteIds(notes.map(n => n.id));
|
||||
}
|
||||
};
|
||||
window.addEventListener('keydown', handler);
|
||||
return () => window.removeEventListener('keydown', handler);
|
||||
}, [notes, setSelectedNoteIds]);
|
||||
|
||||
const NoteHeight = 18;
|
||||
const PITCH_START = 0; // C0 (render all 128 keys)
|
||||
@@ -5065,7 +5077,7 @@ const PianoRollTabEditor = ({ st, zoom, bpm, viewportWidth, onClose, onUpdateNot
|
||||
mode: 'move',
|
||||
idx: clickedNoteIdx,
|
||||
startOffsetBeat: beat - clickedNote.start_beat,
|
||||
startOffsetPitch: pitch - clickedNote.pitch,
|
||||
startOffsetPitch: pitch,
|
||||
selectedNotesOffset: selectedNotesOffset
|
||||
});
|
||||
} else {
|
||||
@@ -5127,7 +5139,18 @@ const PianoRollTabEditor = ({ st, zoom, bpm, viewportWidth, onClose, onUpdateNot
|
||||
const maxPitch = Math.max(marquee.startPitch, marquee.currentPitch);
|
||||
|
||||
const insideIds = notes
|
||||
.filter(n => n.start_beat >= minBeat && n.start_beat <= maxBeat && n.pitch >= minPitch && n.pitch <= maxPitch)
|
||||
.filter(n => {
|
||||
const withinPitch = n.pitch >= minPitch && n.pitch <= maxPitch;
|
||||
if (!withinPitch) return false;
|
||||
const noteEnd = n.start_beat + n.duration_beats;
|
||||
if (marquee.startBeat <= marquee.currentBeat) {
|
||||
// Left to right: select if any overlap
|
||||
return n.start_beat <= maxBeat && noteEnd >= minBeat;
|
||||
} else {
|
||||
// Right to left: select only if fully covered
|
||||
return n.start_beat >= minBeat && noteEnd <= maxBeat;
|
||||
}
|
||||
})
|
||||
.map(n => n.id);
|
||||
|
||||
setSelectedNoteIds(insideIds);
|
||||
@@ -5252,14 +5275,17 @@ const PianoRollTabEditor = ({ st, zoom, bpm, viewportWidth, onClose, onUpdateNot
|
||||
const firstNote = notes.find(n => n.id === firstOffset.id);
|
||||
if (!firstNote) return;
|
||||
const deltaBeat = getSnapBeat(beat - draggedNote.startOffsetBeat, snapVal) - firstOffset.originalStartBeat;
|
||||
const deltaPitch = Math.round(pitch - draggedNote.startOffsetPitch) - firstOffset.originalPitch;
|
||||
// Clamp so no note goes past beat 0
|
||||
const minOrigStart = Math.min(...draggedNote.selectedNotesOffset.map(o => o.originalStartBeat));
|
||||
const clampedDeltaBeat = minOrigStart + deltaBeat < 0 ? -minOrigStart : deltaBeat;
|
||||
const deltaPitch = Math.round(pitch - draggedNote.startOffsetPitch);
|
||||
|
||||
setNotes(prev => prev.map(n => {
|
||||
const offset = draggedNote.selectedNotesOffset.find(o => o.id === n.id);
|
||||
if (!offset) return n;
|
||||
return {
|
||||
...n,
|
||||
start_beat: getSnapBeat(Math.max(0, offset.originalStartBeat + deltaBeat), snapVal),
|
||||
start_beat: getSnapBeat(Math.max(0, offset.originalStartBeat + clampedDeltaBeat), snapVal),
|
||||
pitch: Math.max(0, Math.min(127, offset.originalPitch + deltaPitch))
|
||||
};
|
||||
}));
|
||||
@@ -10836,7 +10862,8 @@ const App = () => {
|
||||
const secondsPerBar = (60.0 / (parseInt(bpm) || 120)) * 4;
|
||||
const marginBar = maxDurationRef.current - secondsPerBar;
|
||||
const clampedTime = Math.min(time, marginBar);
|
||||
const newDuration = Math.max(0.1, clampedTime - resize.originalStart);
|
||||
const snappedDuration = snapValueRef.current !== 'free' ? snapTime(clampedTime - resize.originalStart, snapValueRef.current, bpm) : clampedTime - resize.originalStart;
|
||||
const newDuration = Math.max(0.1, snappedDuration);
|
||||
items[idx] = { ...item, duration: newDuration };
|
||||
}
|
||||
return resize.itemType === 'section'
|
||||
|
||||
Reference in New Issue
Block a user