fix: piano roll spectrogram is not being zoomed correctly; switching from MIDI region to audio region with piano roll open might cause residual notes.

This commit is contained in:
Xiaohan-Tian
2026-05-01 23:56:12 -07:00
parent 811b3a0936
commit 5890a6d0b9
4 changed files with 42 additions and 16 deletions
+13 -12
View File
@@ -157,23 +157,23 @@ const PianoRoll: React.FC<PianoRollProps> = ({
setActiveRegion(null);
return;
}
// Find the region in the tracks
let found: KGMidiRegion | null = null;
for (const track of tracks) {
const regions = track.getRegions();
const region = regions.find(r => r.getId() === regionId);
const region = track.getRegions().find(r => r.getId() === regionId);
if (region && region instanceof KGMidiRegion) {
setActiveRegion(region);
if (DEBUG_MODE.PIANO_ROLL) {
console.log(`Active region set in PianoRoll: ${region.getId()}`);
console.log(`Region details: name=${region.getName()}, trackId=${region.getTrackId()}, trackIndex=${region.getTrackIndex()}`);
}
found = region;
break;
}
}
// Always update — clears stale MIDI region when switching to an audio region
setActiveRegion(found);
if (found && DEBUG_MODE.PIANO_ROLL) {
console.log(`Active region set in PianoRoll: ${found.getId()}`);
console.log(`Region details: name=${found.getName()}, trackId=${found.getTrackId()}, trackIndex=${found.getTrackIndex()}`);
}
}, [regionId, tracks]);
// Sync local state with KGPianoRollState on mount
@@ -965,6 +965,7 @@ const PianoRoll: React.FC<PianoRollProps> = ({
bpm={bpm}
spectrogramThresholdDb={spectrogramThresholdDb}
spectrogramPower={spectrogramPower}
pianoRollZoom={pianoRollZoom}
/>
<div