fix: velocity start position + shift-scroll play on note start + canvas redraw deps

This commit is contained in:
2026-07-25 08:07:49 +07:00
parent 8dee5c8cdb
commit 893f42c36c
2 changed files with 8 additions and 8 deletions
+5 -5
View File
@@ -4551,11 +4551,11 @@ const PianoRollTabEditor = ({ st, zoom, bpm, viewportWidth, onClose, onUpdateNot
const newBeat = Math.max(0, Math.min(maxBeats, currentBeat + step));
const newTime = newBeat * beatSec;
setSubTabs(prev => prev.map(s => s.id === st.id ? { ...s, currentTime: newTime } : s));
// Play notes at the new beat position
// Play notes only when playhead crosses a note start
if (window.SonicSF) {
const ctx = getAudioContext();
const playing = notes.filter(n =>
newBeat >= n.start_beat && newBeat < n.start_beat + n.duration_beats
currentBeat < n.start_beat && newBeat >= n.start_beat
);
playing.forEach(n => {
window.SonicSF.playNote(n.pitch, (n.velocity || 0.8) * 127, 200, ctx.currentTime, st.instrumentProgram, null);
@@ -4676,7 +4676,7 @@ const PianoRollTabEditor = ({ st, zoom, bpm, viewportWidth, onClose, onUpdateNot
ctx.stroke();
}
}
}, [notes, snapVal, rollZoom, selectedNoteIds, selectionMarquee, st.currentTime, bpm]);
}, [notes, snapVal, rollZoom, selectedNoteIds, selectionMarquee, st.currentTime, bpm, viewWidth, viewBeats]);
React.useEffect(() => {
const canvas = ccCanvasRef.current;
@@ -4699,7 +4699,7 @@ const PianoRollTabEditor = ({ st, zoom, bpm, viewportWidth, onClose, onUpdateNot
ctx.stroke();
notes.forEach((note) => {
const x = note.start_beat * pixelsPerBeat + (note.duration_beats * pixelsPerBeat) / 2;
const x = note.start_beat * pixelsPerBeat;
let val = note.velocity !== undefined ? note.velocity : 0.8;
if (ccMode === 'pan') {
val = (note.pan !== undefined ? note.pan : 0.0) * 0.5 + 0.5;
@@ -4720,7 +4720,7 @@ const PianoRollTabEditor = ({ st, zoom, bpm, viewportWidth, onClose, onUpdateNot
ctx.arc(x, y, 3.5, 0, 2 * Math.PI);
ctx.fill();
});
}, [notes, ccMode, rollZoom]);
}, [notes, ccMode, rollZoom, viewWidth]);
React.useEffect(() => {
const scrollToC3 = () => {