fix: auto-scroll continuous + batch CC velocity for selected notes

This commit is contained in:
2026-07-26 10:09:55 +07:00
parent a7417b9bfa
commit 9237d01f35
3 changed files with 61 additions and 11 deletions
+52 -8
View File
@@ -5243,9 +5243,30 @@ const PianoRollTabEditor = ({ st, zoom, bpm, viewportWidth, onClose, onUpdateNot
const edgeThreshold = 30;
const scrollStep = 6;
if (e.clientY < cr.top + edgeThreshold) {
container.scrollTop = Math.max(0, container.scrollTop - scrollStep);
if (!brushAutoScrollRef.current || brushAutoScrollRef.current.direction !== 'up') {
if (brushAutoScrollRef.current) clearInterval(brushAutoScrollRef.current.id);
brushAutoScrollRef.current = {
direction: 'up',
id: setInterval(() => {
if (gridScrollRef.current) gridScrollRef.current.scrollTop = Math.max(0, gridScrollRef.current.scrollTop - scrollStep);
}, 30)
};
}
} else if (e.clientY > cr.bottom - edgeThreshold) {
container.scrollTop = Math.min(container.scrollHeight - container.clientHeight, container.scrollTop + scrollStep);
if (!brushAutoScrollRef.current || brushAutoScrollRef.current.direction !== 'down') {
if (brushAutoScrollRef.current) clearInterval(brushAutoScrollRef.current.id);
brushAutoScrollRef.current = {
direction: 'down',
id: setInterval(() => {
if (gridScrollRef.current) gridScrollRef.current.scrollTop = Math.min(gridScrollRef.current.scrollHeight - gridScrollRef.current.clientHeight, gridScrollRef.current.scrollTop + scrollStep);
}, 30)
};
}
} else {
if (brushAutoScrollRef.current) {
clearInterval(brushAutoScrollRef.current.id);
brushAutoScrollRef.current = null;
}
}
}
return;
@@ -5322,6 +5343,10 @@ const PianoRollTabEditor = ({ st, zoom, bpm, viewportWidth, onClose, onUpdateNot
setDraggedNote(null);
setSelectionMarquee(null);
rightClickDragRef.current = { active: false, startX: 0, startY: 0 };
if (brushAutoScrollRef.current) {
clearInterval(brushAutoScrollRef.current.id);
brushAutoScrollRef.current = null;
}
};
const handleContextMenu = (e) => {
@@ -5336,6 +5361,7 @@ const PianoRollTabEditor = ({ st, zoom, bpm, viewportWidth, onClose, onUpdateNot
};
const ccDragRef = React.useRef(null);
const brushAutoScrollRef = React.useRef(null);
const rightClickDragRef = React.useRef({ active: false, startX: 0, startY: 0 });
const swallowContextMenuRef = React.useRef(false);
@@ -5373,10 +5399,21 @@ const PianoRollTabEditor = ({ st, zoom, bpm, viewportWidth, onClose, onUpdateNot
if (e.ctrlKey) {
if (selectedNoteIds.length > 0) {
const updates = {};
selectedNoteIds.forEach(id => {
const idx = notes.findIndex(n => n.id === id);
if (idx !== -1) paintNote(idx, val);
if (idx !== -1) updates[idx] = val;
});
const idxs = Object.keys(updates).map(Number);
if (idxs.length > 0) {
setNotes(prev => prev.map((n, i) => {
if (i in updates) {
if (ccMode === 'pan') return { ...n, pan: (updates[i] - 0.5) * 2.0 };
return { ...n, velocity: updates[i] };
}
return n;
}));
}
ccDragRef.current = { active: true, lastBeat: beat, selectedMode: true, lastPainted: selectedNoteIds.map(id => notes.findIndex(n => n.id === id)).filter(i => i !== -1) };
} else {
if (noteIdx !== -1) paintNote(noteIdx, val);
@@ -5403,16 +5440,23 @@ const PianoRollTabEditor = ({ st, zoom, bpm, viewportWidth, onClose, onUpdateNot
const painted = drag.lastPainted || [];
if (drag.selectedMode && selectedNoteIds.length > 0) {
const updates = {};
selectedNoteIds.forEach(id => {
const idx = notes.findIndex(n => n.id === id);
if (idx !== -1 && !painted.includes(idx)) {
setNotes(prev => prev.map((n, i) => {
if (i !== idx) return n;
if (ccMode === 'pan') return { ...n, pan: (val - 0.5) * 2.0 };
return { ...n, velocity: val };
}));
updates[idx] = val;
}
});
const idxs = Object.keys(updates).map(Number);
if (idxs.length > 0) {
setNotes(prev => prev.map((n, i) => {
if (i in updates) {
if (ccMode === 'pan') return { ...n, pan: (updates[i] - 0.5) * 2.0 };
return { ...n, velocity: updates[i] };
}
return n;
}));
}
const newPainted = selectedNoteIds
.map(id => notes.findIndex(n => n.id === id))
.filter(i => i !== -1 && !painted.includes(i));