feat: added a shortcut E to open/close piano roll
This commit is contained in:
@@ -8,13 +8,14 @@ import { selectAllNotesInActiveRegion } from '../util/selectionUtil';
|
|||||||
import { KGCore } from '../core/KGCore';
|
import { KGCore } from '../core/KGCore';
|
||||||
import { KGMidiInput } from '../core/midi-input/KGMidiInput';
|
import { KGMidiInput } from '../core/midi-input/KGMidiInput';
|
||||||
import { KGMidiRegion } from '../core/region/KGMidiRegion';
|
import { KGMidiRegion } from '../core/region/KGMidiRegion';
|
||||||
|
import { showAlert } from '../util/dialogUtil';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Global keyboard handler for copy/paste, undo/redo, play/pause, and save operations
|
* Global keyboard handler for copy/paste, undo/redo, play/pause, and save operations
|
||||||
* Handles keyboard shortcuts defined in the configuration
|
* Handles keyboard shortcuts defined in the configuration
|
||||||
*/
|
*/
|
||||||
export const useGlobalKeyboardHandler = () => {
|
export const useGlobalKeyboardHandler = () => {
|
||||||
const { undo, redo, setStatus, isPlaying, startPlaying, stopTransport, toggleLoop, projectName, savedProjectName, setSavedProjectName, setProjectName, isRecording, startRecording, stopRecording, activeRegionId, selectedRegionIds, setActiveRegionId, setShowPianoRoll } = useProjectStore();
|
const { undo, redo, setStatus, isPlaying, startPlaying, stopTransport, toggleLoop, projectName, savedProjectName, setSavedProjectName, setProjectName, isRecording, startRecording, stopRecording, activeRegionId, selectedRegionIds, setActiveRegionId, setShowPianoRoll, showPianoRoll, openMidiPianoRoll, openSpectrogramViewer } = useProjectStore();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handleKeyDown = (event: KeyboardEvent) => {
|
const handleKeyDown = (event: KeyboardEvent) => {
|
||||||
@@ -193,6 +194,37 @@ export const useGlobalKeyboardHandler = () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check for edit/view shortcut (E) — open piano roll for MIDI, spectrogram for audio
|
||||||
|
if (event.key.toLowerCase() === 'e' && !event.ctrlKey && !event.metaKey && !event.altKey && !event.shiftKey) {
|
||||||
|
event.preventDefault();
|
||||||
|
if (showPianoRoll) {
|
||||||
|
setShowPianoRoll(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const candidateId = activeRegionId ?? (selectedRegionIds[0] ?? null);
|
||||||
|
if (!candidateId) {
|
||||||
|
void showAlert('Please select a region to open the editor.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const tracks = KGCore.instance().getCurrentProject().getTracks();
|
||||||
|
let foundMidi = false;
|
||||||
|
let foundAudio = false;
|
||||||
|
for (const track of tracks) {
|
||||||
|
const region = track.getRegions().find(r => r.getId() === candidateId);
|
||||||
|
if (region) {
|
||||||
|
if (region instanceof KGMidiRegion) foundMidi = true;
|
||||||
|
else foundAudio = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (foundMidi) {
|
||||||
|
openMidiPianoRoll(candidateId);
|
||||||
|
} else if (foundAudio) {
|
||||||
|
openSpectrogramViewer(candidateId);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Check for save shortcut
|
// Check for save shortcut
|
||||||
if (saveShortcut && matchesKeyboardShortcut(event, saveShortcut)) {
|
if (saveShortcut && matchesKeyboardShortcut(event, saveShortcut)) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
@@ -216,5 +248,27 @@ export const useGlobalKeyboardHandler = () => {
|
|||||||
return () => {
|
return () => {
|
||||||
document.removeEventListener('keydown', handleKeyDown, { capture: true });
|
document.removeEventListener('keydown', handleKeyDown, { capture: true });
|
||||||
};
|
};
|
||||||
}, [undo, redo, setStatus, isPlaying, startPlaying, stopTransport, toggleLoop, projectName, savedProjectName, setSavedProjectName, setProjectName, isRecording, startRecording, stopRecording, activeRegionId, selectedRegionIds, setActiveRegionId, setShowPianoRoll]); // Include dependencies for store actions
|
}, [
|
||||||
|
undo,
|
||||||
|
redo,
|
||||||
|
setStatus,
|
||||||
|
isPlaying,
|
||||||
|
startPlaying,
|
||||||
|
stopTransport,
|
||||||
|
toggleLoop,
|
||||||
|
projectName,
|
||||||
|
savedProjectName,
|
||||||
|
setSavedProjectName,
|
||||||
|
setProjectName,
|
||||||
|
isRecording,
|
||||||
|
startRecording,
|
||||||
|
stopRecording,
|
||||||
|
activeRegionId,
|
||||||
|
selectedRegionIds,
|
||||||
|
setActiveRegionId,
|
||||||
|
setShowPianoRoll,
|
||||||
|
showPianoRoll,
|
||||||
|
openMidiPianoRoll,
|
||||||
|
openSpectrogramViewer,
|
||||||
|
]); // Include dependencies for store actions
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user