import { createPortal } from 'react-dom' import { useEffect } from 'react' import { useCaps } from '../lib/capabilities' interface Props { onClose: () => void } // Cmd on macOS, Ctrl elsewhere — the handlers accept either, but a list that // says "Cmd/Ctrl" everywhere is harder to scan than one that names your key. const IS_MAC = /Mac|iPhone|iPad/.test(navigator.userAgent) const MOD = IS_MAC ? '⌘' : 'Ctrl' const ALT_KEY = IS_MAC ? '⌥' : 'Alt' type Row = { keys: string[][]; action: string } type Section = { title: string; rows: Row[] } /** Hotcue keys are digits in pad order, 0 being the tenth, so the list follows * the loaded library's bank size rather than hard-coding eight. */ function hotcueKeys(slots: number): string { const n = Math.min(slots, 10) if (n <= 0) return '1' if (n <= 9) return `1–${n}` return '1–9, 0' } function sections(slots: number): Section[] { const pads = hotcueKeys(slots) return [ { title: 'Deck', rows: [ { keys: [['Space']], action: 'Play / pause' }, { keys: [['C']], action: 'CUE — jump back, set, or hold to preview' }, { keys: [['←'], ['→']], action: 'Beat jump back / forward — or move the loop, while one plays' }, { keys: [[MOD, '↓'], [MOD, '↑']], action: 'Halve / double the loop and jump size' }, { keys: [['Shift', '←'], ['Shift', '→']], action: 'Previous / next grid marker' }, { keys: [[pads]], action: 'Hotcue — set if empty, else jump (hold to preview)' }, { keys: [['Shift', pads]], action: 'Delete hotcue' }, { keys: [['Q'], ['W'], ['E'], ['R']], action: 'Stem track: mute / unmute stem 1–4' }, { keys: [['Shift', 'Q–R']], action: 'Stem track: solo — mute every other stem (again to unmute all)' }, { keys: [[ALT_KEY, 'Click', 'stem']], action: 'Solo a stem from its lane button' }, { keys: [['Drag waveform']], action: 'Scratch' }, { keys: [[MOD, 'Scroll']], action: 'Zoom the waveform' }, { keys: [['Right-click', 'pad']], action: 'Hotcue type, rename, delete' }, ], }, { title: 'Track list', rows: [ { keys: [['Enter']], action: 'Load and play the highlighted track' }, { keys: [['↑'], ['↓']], action: 'Move the selection' }, { keys: [['Shift', '↑'], ['Shift', '↓']], action: 'Extend the selection' }, { keys: [[MOD, 'A']], action: 'Select all' }, { keys: [['Esc']], action: 'Clear the selection' }, { keys: [['Delete']], action: 'Remove from this playlist' }, { keys: [['Shift', 'Click']], action: 'Select a range' }, { keys: [[MOD, 'Click']], action: 'Add to / remove from the selection' }, { keys: [['Double-click']], action: 'Edit a cell' }, { keys: [['Right-click']], action: 'Track menu (header: choose columns)' }, ], }, { title: 'Sidebar', rows: [{ keys: [['Right-click']], action: 'New playlist or folder, rename, delete' }], }, { title: 'Fields & dialogs', rows: [ { keys: [['Enter']], action: 'Save the edit / confirm' }, { keys: [['Esc']], action: 'Cancel / close' }, ], }, ] } function Keys({ combo }: { combo: string[] }) { return ( {combo.map((k, i) => ( {k} ))} ) } /** Every keyboard shortcut (and the mouse gestures that go with them), from the * settings menu. Keep in step with the handlers in `PrepStrip` and `TrackTable` * — this list is written out by hand, not derived from them. */ export function ShortcutsDialog({ onClose }: Props) { const slots = useCaps().cues.hotcue_slots useEffect(() => { const onKey = (e: KeyboardEvent) => e.key === 'Escape' && onClose() window.addEventListener('keydown', onKey) return () => window.removeEventListener('keydown', onKey) }, [onClose]) return createPortal(