feat: added zoom-in/out feature for piano roll window.

This commit is contained in:
Xiaohan-Tian
2026-05-01 23:26:39 -07:00
parent d59ad68f72
commit 811b3a0936
3 changed files with 85 additions and 0 deletions
+16
View File
@@ -49,6 +49,9 @@ const PianoRoll: React.FC<PianoRollProps> = ({
// Spectrogram controls (only used in spectrogram mode)
const [spectrogramThresholdDb, setSpectrogramThresholdDb] = useState<number>(-25);
const [spectrogramPower, setSpectrogramPower] = useState<number>(0.5);
// Piano roll zoom (1x8x); updates --region-grid-beat-width CSS variable
const [pianoRollZoom, setPianoRollZoom] = useState<number>(1);
// Quantization state
const [quantPosition, setQuantPosition] = useState<string>('1/8');
@@ -686,6 +689,17 @@ const PianoRoll: React.FC<PianoRollProps> = ({
container.scrollLeft = clampedScrollLeft;
}, [playheadPosition, isPlaying, autoScrollEnabled]);
// Update --region-grid-beat-width when zoom changes; reset on unmount
useEffect(() => {
document.documentElement.style.setProperty('--region-grid-beat-width', `${40 * pianoRollZoom}px`);
if (triggerNoteUpdateRef.current) {
triggerNoteUpdateRef.current(prev => prev + 1);
}
return () => {
document.documentElement.style.setProperty('--region-grid-beat-width', '40px');
};
}, [pianoRollZoom]);
// Scroll horizontally to the active region's starting bar
useEffect(() => {
if (pianoRollContentRef.current && activeRegion) {
@@ -927,6 +941,8 @@ const PianoRoll: React.FC<PianoRollProps> = ({
onThresholdChange={setSpectrogramThresholdDb}
power={spectrogramPower}
onPowerChange={setSpectrogramPower}
zoom={pianoRollZoom}
onZoomChange={setPianoRollZoom}
/>
<PianoRollContent