mirror of
https://github.com/MrPatben8/konduktor.git
synced 2026-11-27 10:22:51 +01:00
Dj deck is now a reusable component
This commit is contained in:
1 parent
2fcf6e7070
commit
063463efdd
9 files changed
+2310
-1784
No files matched your search
@@ -1174,7 +1174,7 @@ Two independent apps that talk over HTTP:
|
|||||||
/ Try again (`backend_restart`). The shell has no timeout of its own. Before
|
/ Try again (`backend_restart`). The shell has no timeout of its own. Before
|
||||||
ready it answers quit requests itself — nothing can be unsaved — and stops
|
ready it answers quit requests itself — nothing can be unsaved — and stops
|
||||||
at ready so it never races `QuitGuard`), `SaveBar` (+ "Discard changes…" when
|
at ready so it never races `QuitGuard`), `SaveBar` (+ "Discard changes…" when
|
||||||
dirty, and the settings gear beside it, whose menu (or `?` anywhere) opens `ShortcutsDialog` — a KEYBOARD MAP (decided 2026-10-15): keys lit in the colour of what they do, a caption explaining the key pointed at or pressed (pressing explains, it never acts: a capture-phase listener keeps the deck's and table's keys from firing), holding or picking ⇧ / Cmd-Ctrl relights it with that layer, mouse gestures listed beneath. It shrinks to fit the dialog and drops the words on the keys when too small. Its content is `lib/shortcuts.ts`, written out BY HAND, so a new or changed shortcut in `PrepStrip` / `TrackTable` must be added there too — and `AppSettings` ("Konduktor Settings…": app-level prefs, each with its default in `APP_SETTING_DEFAULTS` and read through `useAppSetting`; today `expandPlaylistFolders` and `exportRootFolder`, both default off — the latter read by the backend at `run_export` and passed down as `ExportPayload.root_folder` — and `timeReadoutDecimals` (0–3, default 1: the deck's ELAPSED / REMAIN, truncated, never rounded). The Sidebar holds folder open state as per-id overrides of that setting, reset on a new library or a change of the setting, and carried to the new ids when a rename/move changes a folder's path id)), `Toolbar` (search/filters; columns are chosen by right-clicking the table header),
|
dirty, and the settings gear beside it, whose menu (or `?` anywhere) opens `ShortcutsDialog` — a KEYBOARD MAP (decided 2026-10-15): keys lit in the colour of what they do, a caption explaining the key pointed at or pressed (pressing explains, it never acts: a capture-phase listener keeps the deck's and table's keys from firing), holding or picking ⇧ / Cmd-Ctrl relights it with that layer, mouse gestures listed beneath. It shrinks to fit the dialog and drops the words on the keys when too small. Its content is `lib/shortcuts.ts`, written out BY HAND, so a new or changed shortcut in `lib/deckKeys.ts` / `TrackTable` must be added there too — and `AppSettings` ("Konduktor Settings…": app-level prefs, each with its default in `APP_SETTING_DEFAULTS` and read through `useAppSetting`; today `expandPlaylistFolders` and `exportRootFolder`, both default off — the latter read by the backend at `run_export` and passed down as `ExportPayload.root_folder` — and `timeReadoutDecimals` (0–3, default 1: the deck's ELAPSED / REMAIN, truncated, never rounded). The Sidebar holds folder open state as per-id overrides of that setting, reset on a new library or a change of the setting, and carried to the new ids when a rename/move changes a folder's path id)), `Toolbar` (search/filters; columns are chosen by right-clicking the table header),
|
||||||
`TrackTable` (**the one track list** — All Tracks, playlists, exports and
|
`TrackTable` (**the one track list** — All Tracks, playlists, exports and
|
||||||
devices. TanStack Table + **virtualized** grid; per-row play button,
|
devices. TanStack Table + **virtualized** grid; per-row play button,
|
||||||
configurable columns, header sorting, inline double-click editing, and
|
configurable columns, header sorting, inline double-click editing, and
|
||||||
@@ -1350,8 +1350,20 @@ Two independent apps that talk over HTTP:
|
|||||||
plus a half-size mono copy each on the main thread for the raw waveform —
|
plus a half-size mono copy each on the main thread for the raw waveform —
|
||||||
~6 stereo-track units for a stem track (it was 5: four buffers plus a
|
~6 stereo-track units for a stem track (it was 5: four buffers plus a
|
||||||
summed scratch copy), 1.5 for a plain track (it was 2).
|
summed scratch copy), 1.5 for a plain track (it was 2).
|
||||||
- **Prep strip** (DJ deck across the top of the window): `PrepStrip` owns it,
|
- **Prep strip** (DJ deck across the top of the window), in three rows.
|
||||||
in three rows. **Header**: cover, title/artist · album · genre, a Read-only
|
**The deck is `components/deck/`** (split out 2026-11-02 for performance
|
||||||
|
mode's second deck): `useDeck` holds everything a deck DOES — engine,
|
||||||
|
transport, CUE, hotcues, memory cues, loops, grid editing, stems,
|
||||||
|
analysis — and takes its capabilities as a PARAMETER (each deck may hold
|
||||||
|
a different library's track), returning a `Deck` that `DeckHeader`,
|
||||||
|
`DeckMainWave` / `DeckOverview`, `DeckControls` and `DeckOverlays` (its
|
||||||
|
menus and dialogs, under the deck's own `CapabilitiesContext`) render.
|
||||||
|
`PrepStrip` lays one deck out and owns what decks SHARE: the main view's
|
||||||
|
zoom + raw toggle (`DeckView`, persisted) and the keyboard —
|
||||||
|
`lib/deckKeys.ts`, ONE window listener routing each key to the focused
|
||||||
|
deck (Alt/Option = the other deck, in performance mode; a key-up goes to
|
||||||
|
the deck its key-down went to). A deck's `persist` (loop size, cue bank)
|
||||||
|
and `leadsAmbient` (cover colours) are for deck A. **Header**: cover, title/artist · album · genre, a Read-only
|
||||||
badge, the readout well (ELAPSED / REMAIN to tenths, KEY, and `BpmReadout` —
|
badge, the readout well (ELAPSED / REMAIN to tenths, KEY, and `BpmReadout` —
|
||||||
click to type an exact BPM; with no grid, a typed or tapped BPM CREATES one at the playhead, and
|
click to type an exact BPM; with no grid, a typed or tapped BPM CREATES one at the playhead, and
|
||||||
Set grid on a track with no BPM opens the readout to ask rather than failing), SNAP, Analyze, Auto hotcues. **Waveforms**:
|
Set grid on a track with no BPM opens the readout to ask rather than failing), SNAP, Analyze, Auto hotcues. **Waveforms**:
|
||||||
|
|||||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,232 @@
|
|||||||
|
import { Icon } from '../../lib/icons'
|
||||||
|
import { GridEditStrip, TempoControls, TempoFold } from '../GridControls'
|
||||||
|
import { HotcueBar } from '../HotcueBar'
|
||||||
|
import { LoopControls } from '../LoopControls'
|
||||||
|
import { MemoryCueStrip } from '../MemoryCueStrip'
|
||||||
|
import { ModeSwitch } from '../ModeSwitch'
|
||||||
|
import type { Deck } from './useDeck'
|
||||||
|
|
||||||
|
const DIVIDER = <span aria-hidden className="h-7 w-px shrink-0 bg-line" />
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The deck's controls row: transport · loop/jump · pads or grid · tempo.
|
||||||
|
*
|
||||||
|
* A container, so the row gives way in stages as it narrows instead of the
|
||||||
|
* pads sliding under the tempo group: the pads drop their names first (each pad
|
||||||
|
* queries its own width, see HotcueBar), then below 77rem the tempo group folds
|
||||||
|
* into one BPM button. That is the row's measured width just before the pad
|
||||||
|
* bank would hit its minimum (with a lockable grid's extra Lock button, and the
|
||||||
|
* Hot / Mem toggle's ~3rem with its gap), so move it with the controls.
|
||||||
|
*/
|
||||||
|
export function DeckControls({ deck }: { deck: Deck }) {
|
||||||
|
const {
|
||||||
|
caps,
|
||||||
|
track,
|
||||||
|
toggle,
|
||||||
|
ready,
|
||||||
|
previewing,
|
||||||
|
playing,
|
||||||
|
onCuePress,
|
||||||
|
onCueRelease,
|
||||||
|
cueHeld,
|
||||||
|
loopMode,
|
||||||
|
setLoopMode,
|
||||||
|
grid,
|
||||||
|
beatSize,
|
||||||
|
stepSize,
|
||||||
|
loopActive,
|
||||||
|
activeBeats,
|
||||||
|
toggleSizeLoop,
|
||||||
|
loopRegion,
|
||||||
|
loopInPoint,
|
||||||
|
loopIn,
|
||||||
|
loopOut,
|
||||||
|
toggleLoop,
|
||||||
|
moveOrJump,
|
||||||
|
gridMode,
|
||||||
|
setGridMode,
|
||||||
|
bankMode,
|
||||||
|
setBankMode,
|
||||||
|
setPadMenu,
|
||||||
|
setMemoryMenu,
|
||||||
|
setRenamingSlot,
|
||||||
|
setRenamingMemory,
|
||||||
|
activeMarkerIndex,
|
||||||
|
markerCount,
|
||||||
|
activeMarker,
|
||||||
|
atMarker,
|
||||||
|
beforeFirstMarker,
|
||||||
|
originalGridRef,
|
||||||
|
prevMarker,
|
||||||
|
nextMarker,
|
||||||
|
nudgeGrid,
|
||||||
|
nudgeGridBeats,
|
||||||
|
addMarkerHere,
|
||||||
|
deleteMarkerHere,
|
||||||
|
deleteGrid,
|
||||||
|
resetGrid,
|
||||||
|
showMemory,
|
||||||
|
cueData,
|
||||||
|
cuePoint,
|
||||||
|
callMemoryCue,
|
||||||
|
addMemoryCue,
|
||||||
|
memoryAddRefusal,
|
||||||
|
renamingMemory,
|
||||||
|
renameMemoryCue,
|
||||||
|
slotCount,
|
||||||
|
slotLabel,
|
||||||
|
selectedSlot,
|
||||||
|
setSelectedSlot,
|
||||||
|
onSlotPress,
|
||||||
|
onSlotRelease,
|
||||||
|
hotcueAt,
|
||||||
|
renamingSlot,
|
||||||
|
renameSlot,
|
||||||
|
tempoProps,
|
||||||
|
} = deck
|
||||||
|
return (
|
||||||
|
<div className="@container flex h-11 shrink-0 items-center gap-3">
|
||||||
|
<button
|
||||||
|
onClick={toggle}
|
||||||
|
disabled={!ready}
|
||||||
|
className={
|
||||||
|
'flex h-10 w-10 shrink-0 items-center justify-center rounded-full transition-all active:scale-95 disabled:cursor-not-allowed disabled:opacity-40 ' +
|
||||||
|
(previewing
|
||||||
|
? 'bg-gradient-to-b from-white to-gold text-ink-950 shadow-[0_0_0_4px_rgb(255_200_97/0.22),0_8px_24px_-4px_var(--color-gold)]'
|
||||||
|
: playing
|
||||||
|
? 'btn-primary shadow-[0_0_0_4px_color-mix(in_oklab,var(--color-accent)_22%,transparent),0_8px_24px_-4px_var(--color-accent)]'
|
||||||
|
: 'btn-glass text-text')
|
||||||
|
}
|
||||||
|
title={playing ? 'Pause (Space)' : 'Play (Space)'}
|
||||||
|
>
|
||||||
|
<Icon name={playing ? 'pause' : 'play'} size={16} />
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onPointerDown={(e) => {
|
||||||
|
e.preventDefault()
|
||||||
|
e.currentTarget.setPointerCapture(e.pointerId)
|
||||||
|
onCuePress()
|
||||||
|
}}
|
||||||
|
onPointerUp={onCueRelease}
|
||||||
|
onPointerCancel={onCueRelease}
|
||||||
|
disabled={!ready}
|
||||||
|
aria-pressed={cueHeld}
|
||||||
|
className={`flex h-10 w-14 shrink-0 items-center justify-center rounded-xl font-mono text-[13px] font-semibold tracking-wider transition-[background-color,box-shadow,transform,color] duration-75 disabled:cursor-not-allowed disabled:opacity-40 ${
|
||||||
|
cueHeld
|
||||||
|
? // Held: lit like a pressed controller button — brighter fill,
|
||||||
|
// solid gold rim, a glow, and a slight press-in.
|
||||||
|
'scale-[0.96] bg-gold/35 text-[#fff1cc] shadow-[inset_0_1px_0_rgb(255_255_255/0.3),inset_0_0_0_1px_rgb(255_200_97/0.9),0_0_20px_-2px_rgb(255_200_97/0.75)]'
|
||||||
|
: 'bg-gold/10 text-gold shadow-[inset_0_1px_0_rgb(255_255_255/0.12),inset_0_0_0_1px_rgb(255_200_97/0.4)] hover:bg-gold/15'
|
||||||
|
}`}
|
||||||
|
title="Cue — set the cue point (paused), hold to preview from it, or jump back to it (playing) (C)"
|
||||||
|
>
|
||||||
|
CUE
|
||||||
|
</button>
|
||||||
|
{DIVIDER}
|
||||||
|
<LoopControls
|
||||||
|
mode={loopMode}
|
||||||
|
onMode={setLoopMode}
|
||||||
|
hasGrid={grid != null}
|
||||||
|
ready={ready}
|
||||||
|
size={beatSize}
|
||||||
|
onSmaller={() => stepSize(-1)}
|
||||||
|
onBigger={() => stepSize(1)}
|
||||||
|
loopActive={loopActive}
|
||||||
|
sizeLit={loopActive && activeBeats === beatSize}
|
||||||
|
onToggleSize={toggleSizeLoop}
|
||||||
|
canToggle={loopRegion != null}
|
||||||
|
inArmed={loopInPoint != null}
|
||||||
|
manualSet={loopRegion != null && activeBeats == null}
|
||||||
|
onLoopIn={loopIn}
|
||||||
|
onLoopOut={loopOut}
|
||||||
|
onToggleLoop={toggleLoop}
|
||||||
|
onMove={moveOrJump}
|
||||||
|
/>
|
||||||
|
{DIVIDER}
|
||||||
|
{caps.cues.memory_cues && !gridMode && (
|
||||||
|
<ModeSwitch
|
||||||
|
label="Cue bank"
|
||||||
|
value={bankMode}
|
||||||
|
options={[
|
||||||
|
{ value: 'hot', text: 'HOT', title: 'Hot cues: the pads' },
|
||||||
|
{ value: 'memory', text: 'MEM', title: 'Memory cues: call one to make it the CUE point' },
|
||||||
|
]}
|
||||||
|
onChange={(m) => {
|
||||||
|
setBankMode(m)
|
||||||
|
setPadMenu(null)
|
||||||
|
setMemoryMenu(null)
|
||||||
|
setRenamingSlot(null)
|
||||||
|
setRenamingMemory(null)
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
{gridMode ? (
|
||||||
|
<GridEditStrip
|
||||||
|
markerIndex={activeMarkerIndex}
|
||||||
|
markerCount={markerCount}
|
||||||
|
markerStart={activeMarker?.start ?? null}
|
||||||
|
atMarker={atMarker}
|
||||||
|
beforeFirst={beforeFirstMarker}
|
||||||
|
canReset={originalGridRef.current != null}
|
||||||
|
onPrevMarker={prevMarker}
|
||||||
|
onNextMarker={nextMarker}
|
||||||
|
onNudgeMarker={nudgeGrid}
|
||||||
|
onNudgeMarkerBeats={nudgeGridBeats}
|
||||||
|
onAddMarker={addMarkerHere}
|
||||||
|
onDeleteMarker={deleteMarkerHere}
|
||||||
|
onDeleteGrid={deleteGrid}
|
||||||
|
onReset={resetGrid}
|
||||||
|
/>
|
||||||
|
) : showMemory ? (
|
||||||
|
<MemoryCueStrip
|
||||||
|
cues={cueData?.cues ?? []}
|
||||||
|
cuePoint={cuePoint}
|
||||||
|
onCall={callMemoryCue}
|
||||||
|
onMenu={(cue, x, y) => setMemoryMenu({ cue, x, y })}
|
||||||
|
onAdd={() => void addMemoryCue()}
|
||||||
|
addRefusal={memoryAddRefusal}
|
||||||
|
renamingId={renamingMemory}
|
||||||
|
onRenameCommit={renameMemoryCue}
|
||||||
|
onRenameCancel={() => setRenamingMemory(null)}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<HotcueBar
|
||||||
|
cues={cueData?.cues ?? []}
|
||||||
|
slotCount={slotCount}
|
||||||
|
slotLabel={slotLabel}
|
||||||
|
selectedSlot={selectedSlot}
|
||||||
|
onSlotPress={onSlotPress}
|
||||||
|
onSlotRelease={onSlotRelease}
|
||||||
|
onSlotMenu={(slot, x, y) => {
|
||||||
|
setSelectedSlot(slot)
|
||||||
|
if (hotcueAt(slot)) setPadMenu({ slot, x, y })
|
||||||
|
}}
|
||||||
|
renamingSlot={renamingSlot}
|
||||||
|
onRenameCommit={renameSlot}
|
||||||
|
onRenameCancel={() => setRenamingSlot(null)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
{DIVIDER}
|
||||||
|
<ModeSwitch
|
||||||
|
label="Deck mode"
|
||||||
|
value={gridMode ? 'grid' : 'cues'}
|
||||||
|
options={[
|
||||||
|
{ value: 'cues', text: 'CUES', title: 'Cues: the hotcue pads or memory cues' },
|
||||||
|
{ value: 'grid', text: 'GRID', title: 'Edit the beatgrid: markers, phase, reset' },
|
||||||
|
]}
|
||||||
|
disabled={!track}
|
||||||
|
onChange={(m) => {
|
||||||
|
setGridMode(m === 'grid')
|
||||||
|
setPadMenu(null)
|
||||||
|
setRenamingSlot(null)
|
||||||
|
setMemoryMenu(null)
|
||||||
|
setRenamingMemory(null)
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<TempoControls {...tempoProps} className="@max-[77rem]:hidden" />
|
||||||
|
<TempoFold locked={tempoProps.locked} className="hidden @max-[77rem]:flex">
|
||||||
|
<TempoControls {...tempoProps} />
|
||||||
|
</TempoFold>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,182 @@
|
|||||||
|
import { useState, type ReactNode } from 'react'
|
||||||
|
import { api } from '../../api'
|
||||||
|
import { keyColor } from '../../lib/format'
|
||||||
|
import { Icon } from '../../lib/icons'
|
||||||
|
import { readOnlyNotice, readOnlyShort } from '../../lib/platformCopy'
|
||||||
|
import { useAppSetting } from '../AppSettings'
|
||||||
|
import { BpmReadout } from '../GridControls'
|
||||||
|
import type { Deck } from './useDeck'
|
||||||
|
|
||||||
|
/** mm:ss.f — tenths by default, as a CDJ does; `places` is the
|
||||||
|
* `timeReadoutDecimals` setting (0 drops the fraction). Truncates, never
|
||||||
|
* rounds, so the readout never shows a second before it has been reached. */
|
||||||
|
function fmtTime(secs: number, places: number): string {
|
||||||
|
if (!isFinite(secs) || secs < 0) secs = 0
|
||||||
|
const scale = 10 ** places
|
||||||
|
// The epsilon keeps e.g. 0.3 s from reading 0.299 at 3 places.
|
||||||
|
const units = Math.floor(secs * scale + 1e-6)
|
||||||
|
const whole = Math.floor(units / scale)
|
||||||
|
const m = Math.floor(whole / 60)
|
||||||
|
const s = whole % 60
|
||||||
|
const frac = places > 0 ? `.${(units % scale).toString().padStart(places, '0')}` : ''
|
||||||
|
return `${m.toString().padStart(2, '0')}:${s.toString().padStart(2, '0')}${frac}`
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The deck's header: the track, its readouts, the analysis actions — and
|
||||||
|
* `actions`, anything the layout adds after them. */
|
||||||
|
export function DeckHeader({ deck, actions }: { deck: Deck; actions?: ReactNode }) {
|
||||||
|
const {
|
||||||
|
caps,
|
||||||
|
track,
|
||||||
|
origin,
|
||||||
|
subtitle,
|
||||||
|
setInfoOpen,
|
||||||
|
current,
|
||||||
|
duration,
|
||||||
|
activeMarker,
|
||||||
|
canEditGrid,
|
||||||
|
commitBpm,
|
||||||
|
gridAnchorRef,
|
||||||
|
playheadNow,
|
||||||
|
bpmEntryRequest,
|
||||||
|
snap,
|
||||||
|
setSnap,
|
||||||
|
runAnalyzeGrid,
|
||||||
|
gridBusy,
|
||||||
|
openAutoHotcues,
|
||||||
|
canAutoCue,
|
||||||
|
} = deck
|
||||||
|
const timeDecimals = useAppSetting('timeReadoutDecimals')
|
||||||
|
return (
|
||||||
|
<div className="flex h-12 shrink-0 items-center gap-3">
|
||||||
|
<CoverThumb
|
||||||
|
trackId={track && origin === 'collection' ? track.id : null}
|
||||||
|
onOpen={track ? () => setInfoOpen(true) : undefined}
|
||||||
|
/>
|
||||||
|
<div className="min-w-0 flex-1">
|
||||||
|
{track ? (
|
||||||
|
<>
|
||||||
|
<div className="flex min-w-0 items-center gap-2">
|
||||||
|
<span className="truncate text-[17px] font-semibold tracking-tight text-text" title={track.title ?? ''}>
|
||||||
|
{track.title ?? 'Untitled'}
|
||||||
|
</span>
|
||||||
|
{/* The deck stays usable for listening on a read-only library,
|
||||||
|
so say which it is rather than leaving the edit controls
|
||||||
|
looking live. The controls report the reason when pressed. */}
|
||||||
|
{readOnlyShort(caps) && (
|
||||||
|
<span
|
||||||
|
className="shrink-0 rounded-md bg-ink-800 px-1.5 py-0.5 text-[10px] uppercase tracking-wider text-muted"
|
||||||
|
title={readOnlyNotice(caps) ?? ''}
|
||||||
|
>
|
||||||
|
{readOnlyShort(caps)}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="truncate text-[13px] text-muted" title={subtitle}>
|
||||||
|
{subtitle}
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<div className="text-xs uppercase tracking-wider text-faint">No track loaded</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="well flex h-11 shrink-0 items-stretch rounded-xl">
|
||||||
|
<div className="flex flex-col justify-center gap-px px-4">
|
||||||
|
<span className="text-[10px] tracking-[0.08em] text-faint">ELAPSED</span>
|
||||||
|
<span className="font-mono text-[17px] font-medium">{fmtTime(current, timeDecimals)}</span>
|
||||||
|
</div>
|
||||||
|
<span aria-hidden className="my-2 w-px bg-line" />
|
||||||
|
<div className="flex flex-col justify-center gap-px px-4">
|
||||||
|
<span className="text-[10px] tracking-[0.08em] text-faint">REMAIN</span>
|
||||||
|
<span className="font-mono text-[17px] font-medium">−{fmtTime(Math.max(0, duration - current), timeDecimals)}</span>
|
||||||
|
</div>
|
||||||
|
<span aria-hidden className="my-2 w-px bg-line" />
|
||||||
|
<div className="flex flex-col justify-center gap-px px-4">
|
||||||
|
<span className="text-[10px] tracking-[0.08em] text-faint">KEY</span>
|
||||||
|
<span
|
||||||
|
className="font-mono text-[17px] font-semibold"
|
||||||
|
style={{ color: keyColor(track?.key_wheel ?? null) }}
|
||||||
|
>
|
||||||
|
{track?.key || '—'}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<span aria-hidden className="my-2 w-px bg-line" />
|
||||||
|
<BpmReadout
|
||||||
|
bpm={activeMarker?.bpm ?? null}
|
||||||
|
editable={canEditGrid}
|
||||||
|
onSetBpm={(bpm) => commitBpm(bpm, gridAnchorRef.current ?? playheadNow())}
|
||||||
|
onClose={() => (gridAnchorRef.current = null)}
|
||||||
|
openRequest={bpmEntryRequest}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button
|
||||||
|
onClick={() => setSnap((v) => !v)}
|
||||||
|
aria-pressed={snap}
|
||||||
|
title="Snap cues and loops to the nearest beat"
|
||||||
|
className={`h-9 shrink-0 rounded-full px-3.5 text-xs font-semibold tracking-[0.08em] ${
|
||||||
|
snap ? 'is-selected text-text' : 'btn-glass text-muted'
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
SNAP
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={runAnalyzeGrid}
|
||||||
|
disabled={!track || gridBusy}
|
||||||
|
title={canEditGrid
|
||||||
|
? 'Detect BPM and first beat, then set the grid + hotcue 1 (fix the octave with ÷2 / ×2); measure loudness'
|
||||||
|
: 'Measure loudness (this track’s grid cannot be edited here)'}
|
||||||
|
className="btn-glass flex h-9 shrink-0 items-center gap-2 rounded-full px-3.5 text-[13px] font-medium disabled:opacity-40"
|
||||||
|
>
|
||||||
|
<Icon name="wave" size={16} />
|
||||||
|
{gridBusy ? 'Analyzing…' : 'Analyze'}
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={openAutoHotcues}
|
||||||
|
disabled={!track || !canAutoCue}
|
||||||
|
title={
|
||||||
|
canAutoCue
|
||||||
|
? "Place hotcues on the track's drops, breakdowns and other sections"
|
||||||
|
: 'Set a beatgrid first'
|
||||||
|
}
|
||||||
|
className="btn-glass flex h-9 shrink-0 items-center gap-2 rounded-full px-3.5 text-[13px] font-medium disabled:opacity-40"
|
||||||
|
>
|
||||||
|
<Icon name="sparkle" size={16} />
|
||||||
|
Auto hotcues
|
||||||
|
</button>
|
||||||
|
{actions}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The loaded track's sleeve. Until it loads — and for a track with no art — a
|
||||||
|
* swatch of the ambient colours stands in, so the header never has a hole in it.
|
||||||
|
* With a track loaded it is a button that opens the track-info popup.
|
||||||
|
*/
|
||||||
|
function CoverThumb({ trackId, onOpen }: { trackId: string | null; onOpen?: () => void }) {
|
||||||
|
const [failed, setFailed] = useState<string | null>(null)
|
||||||
|
const showArt = trackId != null && failed !== trackId
|
||||||
|
return (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={onOpen}
|
||||||
|
disabled={!onOpen}
|
||||||
|
title={onOpen ? 'Track info' : undefined}
|
||||||
|
aria-label="Track info"
|
||||||
|
className="relative h-11 w-11 shrink-0 overflow-hidden rounded-xl shadow-[inset_0_1px_0_rgb(255_255_255/0.35),0_8px_24px_-6px_var(--amb-2)] transition-transform enabled:cursor-zoom-in enabled:hover:scale-105 enabled:active:scale-95 disabled:cursor-default"
|
||||||
|
style={{ background: 'linear-gradient(135deg, var(--amb-1), var(--amb-2) 55%, var(--amb-3))' }}
|
||||||
|
>
|
||||||
|
{showArt && (
|
||||||
|
<img
|
||||||
|
key={trackId}
|
||||||
|
src={api.artUrl(trackId)}
|
||||||
|
alt=""
|
||||||
|
className="absolute inset-0 h-full w-full object-cover"
|
||||||
|
onError={() => setFailed(trackId)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
import { api } from '../../api'
|
||||||
|
import { CapabilitiesContext } from '../../lib/capabilities'
|
||||||
|
import { AutoCueDialog } from '../AutoCueDialog'
|
||||||
|
import { ContextMenu } from '../ContextMenu'
|
||||||
|
import { TrackInfoDialog } from '../TrackInfoDialog'
|
||||||
|
import type { Deck } from './useDeck'
|
||||||
|
|
||||||
|
/** The deck's menus and dialogs (all portalled, so where this renders does not
|
||||||
|
* matter). Under the deck's OWN capabilities: the track-info dialog reads
|
||||||
|
* them from context. */
|
||||||
|
export function DeckOverlays({ deck }: { deck: Deck }) {
|
||||||
|
const {
|
||||||
|
caps,
|
||||||
|
track,
|
||||||
|
origin,
|
||||||
|
onError,
|
||||||
|
onEditTags,
|
||||||
|
memoryMenu,
|
||||||
|
setMemoryMenu,
|
||||||
|
memoryMenuItems,
|
||||||
|
padMenu,
|
||||||
|
setPadMenu,
|
||||||
|
padMenuItems,
|
||||||
|
infoOpen,
|
||||||
|
setInfoOpen,
|
||||||
|
autoOpen,
|
||||||
|
setAutoOpen,
|
||||||
|
slotCount,
|
||||||
|
slotLabel,
|
||||||
|
existingHotcues,
|
||||||
|
autoHotcuesDone,
|
||||||
|
} = deck
|
||||||
|
return (
|
||||||
|
<CapabilitiesContext.Provider value={caps}>
|
||||||
|
{memoryMenu && (
|
||||||
|
<ContextMenu
|
||||||
|
key={`m:${memoryMenu.cue.id}:${memoryMenu.x}:${memoryMenu.y}`}
|
||||||
|
x={memoryMenu.x}
|
||||||
|
y={memoryMenu.y}
|
||||||
|
items={memoryMenuItems(memoryMenu.cue)}
|
||||||
|
onClose={() => setMemoryMenu(null)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
{padMenu && (
|
||||||
|
<ContextMenu
|
||||||
|
key={`${padMenu.slot}:${padMenu.x}:${padMenu.y}`}
|
||||||
|
x={padMenu.x}
|
||||||
|
y={padMenu.y}
|
||||||
|
items={padMenuItems(padMenu.slot)}
|
||||||
|
onClose={() => setPadMenu(null)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
{infoOpen && track && (
|
||||||
|
<TrackInfoDialog
|
||||||
|
track={track}
|
||||||
|
artUrl={origin === 'collection' ? api.artUrl(track.id) : null}
|
||||||
|
onClose={() => setInfoOpen(false)}
|
||||||
|
onEditTags={
|
||||||
|
onEditTags
|
||||||
|
? () => {
|
||||||
|
setInfoOpen(false)
|
||||||
|
onEditTags(track)
|
||||||
|
}
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
{autoOpen && track && (
|
||||||
|
<AutoCueDialog
|
||||||
|
track={track}
|
||||||
|
slotCount={slotCount}
|
||||||
|
slotLabel={slotLabel}
|
||||||
|
existing={existingHotcues}
|
||||||
|
onClose={() => setAutoOpen(false)}
|
||||||
|
onDone={autoHotcuesDone}
|
||||||
|
onError={(msg) => onError?.(msg)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</CapabilitiesContext.Provider>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,112 @@
|
|||||||
|
import { MainWaveform } from '../MainWaveform'
|
||||||
|
import { OverviewWaveform } from '../OverviewWaveform'
|
||||||
|
import type { Deck } from './useDeck'
|
||||||
|
|
||||||
|
/** The main view's zoom and raw/bars toggle — shared by every deck's lane
|
||||||
|
* (so beats line up between them), owned by the deck area. */
|
||||||
|
export interface DeckView {
|
||||||
|
secPerView: number
|
||||||
|
setSecPerView: (sec: number) => void
|
||||||
|
rawWave: boolean
|
||||||
|
setRawWave: (raw: boolean) => void
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The scrolling main waveform, in its well — or what stands in for it: no
|
||||||
|
* track, a load error, the analysis running. */
|
||||||
|
export function DeckMainWave({ deck, view, empty = 'Load a track to prep it' }: { deck: Deck; view: DeckView; empty?: string }) {
|
||||||
|
const {
|
||||||
|
track,
|
||||||
|
waveStatus,
|
||||||
|
showWaves,
|
||||||
|
cols,
|
||||||
|
raw,
|
||||||
|
current,
|
||||||
|
duration,
|
||||||
|
cueData,
|
||||||
|
cuePoint,
|
||||||
|
grid,
|
||||||
|
activeMarkerIndex,
|
||||||
|
gridMode,
|
||||||
|
activeLoop,
|
||||||
|
loopActive,
|
||||||
|
loopRegion,
|
||||||
|
loopInPoint,
|
||||||
|
seekManual,
|
||||||
|
onScratchStart,
|
||||||
|
onScratchMove,
|
||||||
|
onScratchEnd,
|
||||||
|
lanes,
|
||||||
|
toggleStem,
|
||||||
|
} = deck
|
||||||
|
if (!track) {
|
||||||
|
return (
|
||||||
|
<div className="well flex min-h-0 flex-1 items-center justify-center rounded-2xl text-xs text-faint">
|
||||||
|
{empty}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (waveStatus === 'error') {
|
||||||
|
return (
|
||||||
|
<div className="well flex min-h-0 flex-1 items-center justify-center rounded-2xl text-xs text-pink">
|
||||||
|
Could not load audio — file may be missing or an unsupported format.
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<div className="well relative min-h-0 flex-1 overflow-hidden rounded-2xl">
|
||||||
|
{showWaves && cols ? (
|
||||||
|
<MainWaveform
|
||||||
|
cols={cols}
|
||||||
|
raw={raw}
|
||||||
|
rawMode={view.rawWave}
|
||||||
|
onRawModeChange={view.setRawWave}
|
||||||
|
currentTime={current}
|
||||||
|
duration={duration}
|
||||||
|
cues={cueData?.cues ?? []}
|
||||||
|
cuePoint={cuePoint}
|
||||||
|
grid={grid}
|
||||||
|
activeMarker={activeMarkerIndex}
|
||||||
|
emphasizeGrid={gridMode}
|
||||||
|
loop={activeLoop}
|
||||||
|
idleLoop={!loopActive ? loopRegion : null}
|
||||||
|
loopIn={loopInPoint}
|
||||||
|
secPerView={view.secPerView}
|
||||||
|
onZoomChange={view.setSecPerView}
|
||||||
|
onSeek={seekManual}
|
||||||
|
onScratchStart={onScratchStart}
|
||||||
|
onScratchMove={onScratchMove}
|
||||||
|
onScratchEnd={onScratchEnd}
|
||||||
|
lanes={lanes}
|
||||||
|
onStemToggle={toggleStem}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<div className="flex h-full items-center justify-center text-xs text-faint">
|
||||||
|
Analysing waveform…
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The whole-track overview, framing the main view's range. Nothing without a
|
||||||
|
* playable track (the main well says why). */
|
||||||
|
export function DeckOverview({ deck, view }: { deck: Deck; view: DeckView }) {
|
||||||
|
const { track, waveStatus, showWaves, cols, current, duration, cueData, cuePoint, activeLoop, seekManual } = deck
|
||||||
|
if (!track || waveStatus === 'error') return null
|
||||||
|
return (
|
||||||
|
<div className="well h-7 shrink-0 overflow-hidden rounded-[9px]">
|
||||||
|
{showWaves && cols && (
|
||||||
|
<OverviewWaveform
|
||||||
|
cols={cols}
|
||||||
|
currentTime={current}
|
||||||
|
duration={duration}
|
||||||
|
cues={cueData?.cues ?? []}
|
||||||
|
cuePoint={cuePoint}
|
||||||
|
loop={activeLoop}
|
||||||
|
secPerView={view.secPerView}
|
||||||
|
onSeek={seekManual}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,60 @@
|
|||||||
|
import { describe, expect, it } from 'vitest'
|
||||||
|
import { keyAction, slotForDigit, type KeyLike } from './deckKeys'
|
||||||
|
|
||||||
|
const key = (code: string, mods: Partial<KeyLike> = {}): KeyLike => ({
|
||||||
|
code,
|
||||||
|
shiftKey: false,
|
||||||
|
altKey: false,
|
||||||
|
metaKey: false,
|
||||||
|
ctrlKey: false,
|
||||||
|
repeat: false,
|
||||||
|
...mods,
|
||||||
|
})
|
||||||
|
const eight = () => 8
|
||||||
|
|
||||||
|
describe('keyAction', () => {
|
||||||
|
it('maps the deck keys', () => {
|
||||||
|
expect(keyAction(key('Space'), eight, false)).toEqual({ action: { kind: 'toggle' }, toOther: false })
|
||||||
|
expect(keyAction(key('KeyC'), eight, false)?.action).toEqual({ kind: 'cue' })
|
||||||
|
expect(keyAction(key('KeyE', { shiftKey: true }), eight, false)?.action).toEqual({ kind: 'stem', index: 2, solo: true })
|
||||||
|
expect(keyAction(key('ArrowLeft'), eight, false)?.action).toEqual({ kind: 'move', dir: -1 })
|
||||||
|
expect(keyAction(key('ArrowRight', { shiftKey: true }), eight, false)?.action).toEqual({ kind: 'marker', dir: 1 })
|
||||||
|
expect(keyAction(key('Digit3'), eight, false)?.action).toEqual({ kind: 'slot', slot: 2, remove: false })
|
||||||
|
expect(keyAction(key('Numpad1', { shiftKey: true }), eight, false)?.action).toEqual({ kind: 'slot', slot: 0, remove: true })
|
||||||
|
expect(keyAction(key('ArrowUp', { metaKey: true }), eight, false)?.action).toEqual({ kind: 'stepSize', dir: 1 })
|
||||||
|
expect(keyAction(key('ArrowDown', { ctrlKey: true }), eight, false)?.action).toEqual({ kind: 'stepSize', dir: -1 })
|
||||||
|
})
|
||||||
|
|
||||||
|
it('leaves other keys and modified keys alone', () => {
|
||||||
|
expect(keyAction(key('KeyZ'), eight, false)).toBeNull()
|
||||||
|
expect(keyAction(key('Space', { metaKey: true }), eight, false)).toBeNull()
|
||||||
|
expect(keyAction(key('ArrowUp', { metaKey: true, shiftKey: true }), eight, false)).toBeNull()
|
||||||
|
expect(keyAction(key('Digit9'), eight, false)).toBeNull() // beyond an 8-pad bank
|
||||||
|
})
|
||||||
|
|
||||||
|
it('treats an auto-repeat as one press, except the size sweep', () => {
|
||||||
|
expect(keyAction(key('Space', { repeat: true }), eight, false)).toBeNull()
|
||||||
|
expect(keyAction(key('ArrowUp', { metaKey: true, repeat: true }), eight, false)?.action.kind).toBe('stepSize')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Alt sends the key to the other deck — and does nothing with one deck', () => {
|
||||||
|
expect(keyAction(key('Space', { altKey: true }), eight, true)).toEqual({ action: { kind: 'toggle' }, toOther: true })
|
||||||
|
expect(keyAction(key('ArrowUp', { altKey: true, metaKey: true }), eight, true)?.toOther).toBe(true)
|
||||||
|
expect(keyAction(key('Space', { altKey: true }), eight, false)).toBeNull()
|
||||||
|
})
|
||||||
|
|
||||||
|
it("reads the TARGET deck's bank size for digits", () => {
|
||||||
|
const banks = (toOther: boolean) => (toOther ? 4 : 8)
|
||||||
|
expect(keyAction(key('Digit6'), banks, true)?.action).toEqual({ kind: 'slot', slot: 5, remove: false })
|
||||||
|
expect(keyAction(key('Digit6', { altKey: true }), banks, true)).toBeNull()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('slotForDigit', () => {
|
||||||
|
it('maps 1..9 to 0..8 and 0 to 9', () => {
|
||||||
|
expect(slotForDigit('Digit1', 16)).toBe(0)
|
||||||
|
expect(slotForDigit('Digit9', 16)).toBe(8)
|
||||||
|
expect(slotForDigit('Digit0', 16)).toBe(9)
|
||||||
|
expect(slotForDigit('KeyA', 16)).toBeNull()
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -0,0 +1,169 @@
|
|||||||
|
// The decks' keyboard shortcuts: ONE window listener for every deck, routing
|
||||||
|
// each key to the deck it is meant for. Keys act on the FOCUSED deck; in
|
||||||
|
// performance mode, holding Alt/Option sends them to the OTHER deck instead
|
||||||
|
// (decided 2026-11-02 — Shift and Cmd/Ctrl were already taken by the keys
|
||||||
|
// themselves). With one deck, Alt does nothing, as before.
|
||||||
|
//
|
||||||
|
// Space play / pause
|
||||||
|
// C CUE (held = preview)
|
||||||
|
// 1–9, 0 hotcue slot (held = preview); Shift+ deletes it
|
||||||
|
// Q W E R mute stem 1–4; Shift+ solos it
|
||||||
|
// ← / → beat jump, or move an engaged loop
|
||||||
|
// Shift+← / → step between grid markers
|
||||||
|
// Cmd/Ctrl+↑ / ↓ loop / jump size (Shift+↑/↓ is the track table's)
|
||||||
|
//
|
||||||
|
// Keys are read from `e.code` (layout- and Shift-independent). A new or changed
|
||||||
|
// key needs `lib/shortcuts.ts` (the keyboard map) updating by hand.
|
||||||
|
|
||||||
|
import { useEffect, type RefObject } from 'react'
|
||||||
|
|
||||||
|
/** Keys that mute stems 1-4 (Shift = solo), by `KeyboardEvent.code`. */
|
||||||
|
export const STEM_KEYS = ['KeyQ', 'KeyW', 'KeyE', 'KeyR']
|
||||||
|
|
||||||
|
/** What a deck offers the keyboard (its latest handlers). */
|
||||||
|
export interface DeckShortcuts {
|
||||||
|
slotCount: number
|
||||||
|
toggle(): void
|
||||||
|
onCuePress(): void
|
||||||
|
onCueRelease(): void
|
||||||
|
onSlotPress(slot: number): void | Promise<void>
|
||||||
|
onSlotRelease(slot: number): void
|
||||||
|
deleteHotcueSlot(slot: number): void | Promise<void>
|
||||||
|
toggleStem(index: number, solo: boolean): void
|
||||||
|
moveOrJump(dir: -1 | 1): void
|
||||||
|
prevMarker(): void
|
||||||
|
nextMarker(): void
|
||||||
|
stepSize(dir: -1 | 1): void
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface DeckKeyTargets {
|
||||||
|
focused: DeckShortcuts | null
|
||||||
|
/** The other deck, in performance mode (else null: Alt does nothing). */
|
||||||
|
other: DeckShortcuts | null
|
||||||
|
}
|
||||||
|
|
||||||
|
export type DeckKeyAction =
|
||||||
|
| { kind: 'stepSize'; dir: -1 | 1 }
|
||||||
|
| { kind: 'toggle' }
|
||||||
|
| { kind: 'cue' }
|
||||||
|
| { kind: 'stem'; index: number; solo: boolean }
|
||||||
|
| { kind: 'move'; dir: -1 | 1 }
|
||||||
|
| { kind: 'marker'; dir: -1 | 1 }
|
||||||
|
| { kind: 'slot'; slot: number; remove: boolean }
|
||||||
|
|
||||||
|
export interface KeyLike {
|
||||||
|
code: string
|
||||||
|
shiftKey: boolean
|
||||||
|
altKey: boolean
|
||||||
|
metaKey: boolean
|
||||||
|
ctrlKey: boolean
|
||||||
|
repeat: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
const DIGIT_RE = /^(?:Digit|Numpad)([0-9])$/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Digit key -> bank slot: 1..9 map to slots 0..8 and 0 maps to slot 10.
|
||||||
|
*
|
||||||
|
* Ten digits is the physical ceiling, so a bank larger than that simply has no
|
||||||
|
* shortcut for its tail. Returns null when the key is not a digit or the slot is
|
||||||
|
* beyond this platform's bank — an 8-slot bank behaves exactly as before.
|
||||||
|
*/
|
||||||
|
export function slotForDigit(code: string, slotCount: number): number | null {
|
||||||
|
const m = code.match(DIGIT_RE)
|
||||||
|
if (!m) return null
|
||||||
|
const slot = m[1] === '0' ? 9 : Number(m[1]) - 1
|
||||||
|
return slot < slotCount ? slot : null
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* What a key-down means, and whether it goes to the other deck. Null = not a
|
||||||
|
* deck key (or Alt with no other deck). `slotCount` is the TARGET deck's bank.
|
||||||
|
*/
|
||||||
|
export function keyAction(
|
||||||
|
e: KeyLike,
|
||||||
|
slotCount: (toOther: boolean) => number,
|
||||||
|
hasOther: boolean,
|
||||||
|
): { action: DeckKeyAction; toOther: boolean } | null {
|
||||||
|
const toOther = e.altKey
|
||||||
|
if (toOther && !hasOther) return null
|
||||||
|
const meta = e.metaKey || e.ctrlKey
|
||||||
|
// Cmd (macOS) / Ctrl (Windows, Linux), either accepted as Cmd/Ctrl+A is.
|
||||||
|
// Repeats allowed: holding it sweeps through the sizes.
|
||||||
|
if (meta && !e.shiftKey && (e.code === 'ArrowUp' || e.code === 'ArrowDown')) {
|
||||||
|
return { action: { kind: 'stepSize', dir: e.code === 'ArrowUp' ? 1 : -1 }, toOther }
|
||||||
|
}
|
||||||
|
if (meta) return null
|
||||||
|
if (e.repeat) return null // a held key auto-repeats — one press + hold
|
||||||
|
const done = (action: DeckKeyAction) => ({ action, toOther })
|
||||||
|
if (e.code === 'Space') return done({ kind: 'toggle' })
|
||||||
|
if (e.code === 'KeyC') return done({ kind: 'cue' })
|
||||||
|
const stem = STEM_KEYS.indexOf(e.code)
|
||||||
|
if (stem >= 0) return done({ kind: 'stem', index: stem, solo: e.shiftKey })
|
||||||
|
if (e.code === 'ArrowLeft' || e.code === 'ArrowRight') {
|
||||||
|
const dir = e.code === 'ArrowLeft' ? -1 : 1
|
||||||
|
return done(e.shiftKey ? { kind: 'marker', dir } : { kind: 'move', dir })
|
||||||
|
}
|
||||||
|
const slot = slotForDigit(e.code, slotCount(toOther))
|
||||||
|
if (slot != null) return done({ kind: 'slot', slot, remove: e.shiftKey })
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
export function runKeyAction(a: DeckKeyAction, sc: DeckShortcuts): void {
|
||||||
|
switch (a.kind) {
|
||||||
|
case 'stepSize':
|
||||||
|
return sc.stepSize(a.dir)
|
||||||
|
case 'toggle':
|
||||||
|
return sc.toggle()
|
||||||
|
case 'cue':
|
||||||
|
return sc.onCuePress()
|
||||||
|
case 'stem':
|
||||||
|
return sc.toggleStem(a.index, a.solo)
|
||||||
|
case 'move':
|
||||||
|
return sc.moveOrJump(a.dir)
|
||||||
|
case 'marker':
|
||||||
|
return a.dir < 0 ? sc.prevMarker() : sc.nextMarker()
|
||||||
|
case 'slot':
|
||||||
|
void (a.remove ? sc.deleteHotcueSlot(a.slot) : sc.onSlotPress(a.slot))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attach the listener once; `targets` is read at each key event, so it always
|
||||||
|
* routes to the decks as they are now. A key-up goes to the deck its key-down
|
||||||
|
* went to, so letting go of Alt first cannot strand a held preview.
|
||||||
|
*/
|
||||||
|
export function useDeckKeys(targets: RefObject<DeckKeyTargets>): void {
|
||||||
|
useEffect(() => {
|
||||||
|
const held = new Map<string, DeckShortcuts>()
|
||||||
|
const onKey = (e: KeyboardEvent) => {
|
||||||
|
// Ignore while typing in a field.
|
||||||
|
const t = e.target as HTMLElement | null
|
||||||
|
if (t && (t.tagName === 'INPUT' || t.tagName === 'TEXTAREA' || t.isContentEditable)) return
|
||||||
|
const { focused, other } = targets.current
|
||||||
|
const r = keyAction(e, (toOther) => (toOther ? other : focused)?.slotCount ?? 0, other != null)
|
||||||
|
const sc = r && (r.toOther ? other : focused)
|
||||||
|
if (!r || !sc) return
|
||||||
|
e.preventDefault()
|
||||||
|
if (r.action.kind === 'cue' || (r.action.kind === 'slot' && !r.action.remove)) held.set(e.code, sc)
|
||||||
|
runKeyAction(r.action, sc)
|
||||||
|
}
|
||||||
|
// keyup ends a held CUE / hotcue's momentary preview (release).
|
||||||
|
const onKeyUp = (e: KeyboardEvent) => {
|
||||||
|
const sc = held.get(e.code)
|
||||||
|
if (!sc) return
|
||||||
|
held.delete(e.code)
|
||||||
|
if (e.code === 'KeyC') sc.onCueRelease()
|
||||||
|
else {
|
||||||
|
const slot = slotForDigit(e.code, sc.slotCount)
|
||||||
|
if (slot != null) sc.onSlotRelease(slot)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
window.addEventListener('keydown', onKey)
|
||||||
|
window.addEventListener('keyup', onKeyUp)
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener('keydown', onKey)
|
||||||
|
window.removeEventListener('keyup', onKeyUp)
|
||||||
|
}
|
||||||
|
}, [targets])
|
||||||
|
}
|
||||||
Reference in new issue
Block a user