feat: added shortcut N for sheet music view
This commit is contained in:
@@ -35,6 +35,8 @@ const storeState = {
|
||||
storeState.activeRegionId = regionId;
|
||||
}),
|
||||
pianoRollMode: 'midi-edit' as const,
|
||||
requestedSheetMusicViewEnabled: false,
|
||||
pianoRollViewRequestVersion: 0,
|
||||
openMidiPianoRoll: vi.fn(),
|
||||
openSpectrogramViewer: vi.fn(),
|
||||
openHybridMode: vi.fn(),
|
||||
|
||||
@@ -46,6 +46,8 @@ const MainContent: React.FC<MainContentProps> = ({
|
||||
setShowPianoRoll,
|
||||
setActiveRegionId,
|
||||
pianoRollMode,
|
||||
requestedSheetMusicViewEnabled,
|
||||
pianoRollViewRequestVersion,
|
||||
openMidiPianoRoll,
|
||||
openSpectrogramViewer,
|
||||
openHybridMode,
|
||||
@@ -1052,6 +1054,8 @@ const MainContent: React.FC<MainContentProps> = ({
|
||||
onClose={handlePianoRollClose}
|
||||
regionId={activeRegionId}
|
||||
mode={pianoRollMode}
|
||||
requestedSheetMusicViewEnabled={requestedSheetMusicViewEnabled}
|
||||
pianoRollViewRequestVersion={pianoRollViewRequestVersion}
|
||||
audioRegion={(() => {
|
||||
// spectrogram mode: audio region IS the activeRegionId
|
||||
// hybrid mode: audio region is hybridAudioRegionId
|
||||
|
||||
@@ -63,6 +63,8 @@ interface PianoRollProps {
|
||||
initialPosition?: { x: number; y: number };
|
||||
initialSize?: { width: number; height: number };
|
||||
mode?: 'midi-edit' | 'spectrogram' | 'hybrid';
|
||||
requestedSheetMusicViewEnabled?: boolean;
|
||||
pianoRollViewRequestVersion?: number;
|
||||
audioRegion?: KGAudioRegion;
|
||||
trackId?: string;
|
||||
projectName?: string;
|
||||
@@ -74,6 +76,8 @@ const PianoRoll: React.FC<PianoRollProps> = ({
|
||||
initialPosition,
|
||||
initialSize,
|
||||
mode = 'midi-edit',
|
||||
requestedSheetMusicViewEnabled = false,
|
||||
pianoRollViewRequestVersion = 0,
|
||||
audioRegion,
|
||||
trackId,
|
||||
projectName,
|
||||
@@ -153,6 +157,7 @@ const PianoRoll: React.FC<PianoRollProps> = ({
|
||||
const pendingModeSwitchRequestRef = useRef<PendingModeSwitchRequest | null>(null);
|
||||
const previousSheetMusicViewEnabledRef = useRef<boolean>(false);
|
||||
const previousActiveRegionIdRef = useRef<string | null>(null);
|
||||
const lastAppliedViewRequestVersionRef = useRef<number>(0);
|
||||
|
||||
// Ref for storing the setNoteUpdateCounter function
|
||||
const triggerNoteUpdateRef = useRef<React.Dispatch<React.SetStateAction<number>> | null>(null);
|
||||
@@ -268,6 +273,42 @@ const PianoRoll: React.FC<PianoRollProps> = ({
|
||||
}
|
||||
}, []); // Empty dependency array means this runs once on mount
|
||||
|
||||
useEffect(() => {
|
||||
if (isSpectrogram) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (pianoRollViewRequestVersion === 0 || lastAppliedViewRequestVersionRef.current === pianoRollViewRequestVersion) {
|
||||
return;
|
||||
}
|
||||
|
||||
lastAppliedViewRequestVersionRef.current = pianoRollViewRequestVersion;
|
||||
|
||||
if (activeRegion) {
|
||||
pendingModeSwitchRequestRef.current = createPendingModeSwitchRequest({
|
||||
playheadBeat: playheadPosition,
|
||||
regionStartBeat: activeRegion.getStartFromBeat(),
|
||||
regionEndBeat: activeRegion.getStartFromBeat() + activeRegion.getLength(),
|
||||
sourceSheetMusicViewEnabled: sheetMusicViewEnabled,
|
||||
destinationSheetMusicViewEnabled: requestedSheetMusicViewEnabled,
|
||||
destinationSheetMusicTrackScopeEnabled: requestedSheetMusicViewEnabled && sheetMusicTrackScopeEnabled,
|
||||
});
|
||||
} else {
|
||||
pendingModeSwitchRequestRef.current = null;
|
||||
}
|
||||
|
||||
setSheetMusicViewEnabled(requestedSheetMusicViewEnabled);
|
||||
KGPianoRollState.instance().setSheetMusicViewEnabled(requestedSheetMusicViewEnabled);
|
||||
}, [
|
||||
activeRegion,
|
||||
isSpectrogram,
|
||||
pianoRollViewRequestVersion,
|
||||
playheadPosition,
|
||||
requestedSheetMusicViewEnabled,
|
||||
sheetMusicTrackScopeEnabled,
|
||||
sheetMusicViewEnabled,
|
||||
]);
|
||||
|
||||
useEffect(() => {
|
||||
let unsubscribe: (() => void) | undefined;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user