fix: realtime note display + MIDI key sound via refs

This commit is contained in:
2026-07-25 18:58:30 +07:00
parent da760dbb86
commit e6dd7ff13c
2 changed files with 38 additions and 37 deletions
+8 -7
View File
@@ -6287,10 +6287,12 @@ const App = () => {
setLastMidiNote({ pitch, velocity, length: 0, time: Date.now() }); setLastMidiNote({ pitch, velocity, length: 0, time: Date.now() });
activeMidiPitchesRef.current.add(pitch); activeMidiPitchesRef.current.add(pitch);
setActiveMidiPitches(new Set(activeMidiPitchesRef.current)); setActiveMidiPitches(new Set(activeMidiPitchesRef.current));
const activeTabInfo = subTabs.find(s => s.id === activeTab && s.type === 'PIANO_ROLL' && s.isArmed); try {
if (activeTabInfo && window.SonicSF) { const ar = activeTabRef && subTabsRef && subTabsRef.current.find(s => s.id === activeTabRef.current && s.type === 'PIANO_ROLL' && s.isArmed);
try { window.SonicSF.playNote(pitch, velocity, 500, undefined, activeTabInfo.instrumentProgram, null); } catch (e) {} if (ar && window.SonicSF) {
window.SonicSF.playNote(pitch, velocity, 500, undefined, ar.instrumentProgram, null);
} }
} catch (e) {}
} else if (cmd === 0x8 || (cmd === 0x9 && velocity === 0)) { } else if (cmd === 0x8 || (cmd === 0x9 && velocity === 0)) {
activeMidiPitchesRef.current.delete(pitch); activeMidiPitchesRef.current.delete(pitch);
setActiveMidiPitches(new Set(activeMidiPitchesRef.current)); setActiveMidiPitches(new Set(activeMidiPitchesRef.current));
@@ -9867,8 +9869,6 @@ const App = () => {
midiRec.onNoteOn = (pitch, currentBeat) => { midiRec.onNoteOn = (pitch, currentBeat) => {
const elapsedBeats = Math.max(0, currentBeat); const elapsedBeats = Math.max(0, currentBeat);
const sec = elapsedBeats * (60.0 / (parseInt(bpm) || 120)); const sec = elapsedBeats * (60.0 / (parseInt(bpm) || 120));
setSubTabs(prev => prev.map(s => {
if (s.id !== tab.id) return s;
const activeNotes = Array.from(midiRec.activeNotes.values()).map(n => ({ const activeNotes = Array.from(midiRec.activeNotes.values()).map(n => ({
id: 'rec_' + n.pitch + '_' + currentBeat, id: 'rec_' + n.pitch + '_' + currentBeat,
pitch: n.pitch, pitch: n.pitch,
@@ -9888,8 +9888,9 @@ const App = () => {
const allNotes = [...rec, ...activeNotes]; const allNotes = [...rec, ...activeNotes];
setRecTempMidiNotes(allNotes); setRecTempMidiNotes(allNotes);
setCanvasRedrawCount(n => n + 1); setCanvasRedrawCount(n => n + 1);
return { ...s, currentTime: startTime + sec, isDirty: true }; setSubTabs(prev => prev.map(s =>
})); s.id === tab.id ? { ...s, currentTime: startTime + sec, isDirty: true } : s
));
}; };
showToast('Recording MIDI to Piano Roll...', 'info'); showToast('Recording MIDI to Piano Roll...', 'info');
}; };
File diff suppressed because one or more lines are too long