fix: brush scroll speed + CC snap + non-selected flicker

This commit is contained in:
2026-07-26 10:21:31 +07:00
parent 8ec4b05e21
commit 7107a0cc14
3 changed files with 22 additions and 18 deletions
+15 -16
View File
@@ -5250,7 +5250,7 @@ const PianoRollTabEditor = ({ st, zoom, bpm, viewportWidth, onClose, onUpdateNot
brushAutoScrollRef.current = {
direction: 'up',
id: setInterval(() => {
if (gridScrollRef.current) gridScrollRef.current.scrollTop = Math.max(0, gridScrollRef.current.scrollTop - NoteHeight * 2);
if (gridScrollRef.current) gridScrollRef.current.scrollTop = Math.max(0, gridScrollRef.current.scrollTop - Math.max(1, Math.floor(NoteHeight * 0.5)));
}, 30)
};
}
@@ -5260,7 +5260,7 @@ const PianoRollTabEditor = ({ st, zoom, bpm, viewportWidth, onClose, onUpdateNot
brushAutoScrollRef.current = {
direction: 'down',
id: setInterval(() => {
if (gridScrollRef.current) gridScrollRef.current.scrollTop = Math.min(gridScrollRef.current.scrollHeight - gridScrollRef.current.clientHeight, gridScrollRef.current.scrollTop + NoteHeight * 2);
if (gridScrollRef.current) gridScrollRef.current.scrollTop = Math.min(gridScrollRef.current.scrollHeight - gridScrollRef.current.clientHeight, gridScrollRef.current.scrollTop + Math.max(1, Math.floor(NoteHeight * 0.5)));
}, 30)
};
}
@@ -5376,12 +5376,13 @@ const PianoRollTabEditor = ({ st, zoom, bpm, viewportWidth, onClose, onUpdateNot
const h = rect.height;
const beat = x / pixelsPerBeat;
let noteIdx = notes.findIndex(n => beat >= n.start_beat && beat <= n.start_beat + n.duration_beats);
const snappedBeat = getSnapBeat(beat, snapVal);
let noteIdx = notes.findIndex(n => snappedBeat >= n.start_beat && snappedBeat <= n.start_beat + n.duration_beats);
if (noteIdx === -1) {
let minDistance = Infinity;
notes.forEach((n, idx) => {
const center = n.start_beat + n.duration_beats / 2;
const dist = Math.abs(center - beat);
const dist = Math.abs(center - snappedBeat);
if (dist < minDistance) {
minDistance = dist;
noteIdx = idx;
@@ -5390,14 +5391,6 @@ const PianoRollTabEditor = ({ st, zoom, bpm, viewportWidth, onClose, onUpdateNot
}
const val = Math.max(0, Math.min(1, (h - y) / h));
const paintNote = (idx, v) => {
if (idx === -1) return;
setNotes(prev => prev.map((n, i) => {
if (i !== idx) return n;
if (ccMode === 'pan') { return { ...n, pan: (v - 0.5) * 2.0 }; }
return { ...n, velocity: v };
}));
};
if (e.ctrlKey) {
if (selectedNoteIds.length > 0) {
@@ -5421,13 +5414,18 @@ const PianoRollTabEditor = ({ st, zoom, bpm, viewportWidth, onClose, onUpdateNot
ccDragRef.current = { active: true, lastBeat: beat, selectedMode: true, lastPainted: [] };
}
} else {
if (noteIdx !== -1) paintNote(noteIdx, val);
ccDragRef.current = { active: true, lastBeat: beat, lastPainted: noteIdx !== -1 ? [noteIdx] : [] };
}
return;
}
if (noteIdx !== -1) paintNote(noteIdx, val);
if (noteIdx !== -1) {
setNotes(prev => prev.map((n, i) => {
if (i !== noteIdx) return n;
if (ccMode === 'pan') return { ...n, pan: (val - 0.5) * 2.0 };
return { ...n, velocity: val };
}));
}
};
const handleCCMouseMove = (e) => {
@@ -5468,7 +5466,8 @@ const PianoRollTabEditor = ({ st, zoom, bpm, viewportWidth, onClose, onUpdateNot
return;
}
const candidateIdx = notes.findIndex(n => beat >= n.start_beat && beat <= n.start_beat + n.duration_beats);
const snappedBeat = getSnapBeat(beat, snapVal);
const candidateIdx = notes.findIndex(n => snappedBeat >= n.start_beat && snappedBeat <= n.start_beat + n.duration_beats);
if (candidateIdx !== -1 && !painted.includes(candidateIdx)) {
setNotes(prev => prev.map((n, i) => {
@@ -5482,7 +5481,7 @@ const PianoRollTabEditor = ({ st, zoom, bpm, viewportWidth, onClose, onUpdateNot
let minDist = Infinity;
notes.forEach((n, idx) => {
const center = n.start_beat + n.duration_beats / 2;
const d = Math.abs(center - beat);
const d = Math.abs(center - snappedBeat);
if (d < minDist) { minDist = d; nearest = idx; }
});
if (nearest !== -1 && !painted.includes(nearest)) {