Reworked deck UI

This commit is contained in:
patben8 committed 2026-09-25 16:17:06 +02:00
1 parent 0a9764ee89
commit 46d3978580
11 files changed
+915 -741

No files matched your search

+26 -9
View File
@@ -387,14 +387,31 @@ Two independent apps that talk over HTTP:
browser via `@tauri-apps/plugin-shell` `open` — falls back to `window.open` browser via `@tauri-apps/plugin-shell` `open` — falls back to `window.open`
outside Tauri; "Skip this version" persists `skippedUpdateVersion` to outside Tauri; "Skip this version" persists `skippedUpdateVersion` to
userprefs via `/api/prefs`; all failures are silent). userprefs via `/api/prefs`; all failures are silent).
- **Prep strip** (DJ deck across the top of the window): `PrepStrip` owns it — - **Prep strip** (DJ deck across the top of the window): `PrepStrip` owns it,
transport (play/pause, CUE), two waveforms (`MainWaveform` scrolling+zoomable in three rows. **Header**: cover, title/artist · album · genre, a Read-only
— its zoom is owned by `PrepStrip` so it survives track switches and persists, badge, the readout well (ELAPSED / REMAIN to tenths, KEY, and `BpmReadout` —
`OverviewWaveform` whole-track), `LoopControls`, `HotcueBar`, `GridControls` click to type an exact BPM), SNAP, Analyze, Auto hotcues. **Waveforms**:
(BPM readout/editor, fine ±0.01 / coarse ±0.25 BPM nudge, /2·×2, tap tempo, `MainWaveform` (scrolling; zoom +/− in its corner and Cmd/Ctrl+scroll, owned
marker nudge, add/delete marker, lock, delete grid (confirmed) — all on the by `PrepStrip` so it survives track switches and persists) over
marker **governing the playhead**, since a beatgrid is a marker list and `OverviewWaveform`. **Controls**: play, CUE, `LoopControls`, then EITHER
there is no separate marker selection; see "Beatgrid" below). `HotcueBar` OR — in **Grid mode** — `GridEditStrip`, then `TempoControls`
(±0.01 / ±0.25, ÷2 ×2, tap, lock) and the Grid toggle. Every grid control acts
on the marker **governing the playhead**, since a beatgrid is a marker list
and there is no separate marker selection; see "Beatgrid" below.
- **One size for loops AND beat jump** (`beatSize`, 1/32–32, persisted as
`beatSize`; the old `beatJumpBeats` pref is read once on upgrade).
`LoopControls` has a BEAT / MAN switch: BEAT shows `− size +` (the size
key sets or clears a loop of that length; −/+ halve/double, resizing an
engaged beat loop from its locked start), MAN shows IN / OUT / toggle.
**‹ › (and ←/→) MOVE an engaged loop by its own length**, Traktor-style,
and only jump the playhead when no loop is engaged. The move sets the new
loop BEFORE seeking: `PlaybackEngine.seek` honours the loop in force, so
seeking first wraps the playhead back into the old loop.
- **Hotcue edits live on the pad's right-click menu** (type as one-click
choices, Rename…, Delete); there is no standalone type dropdown or delete
button. Rename re-sets the slot with its own start/type/length plus the
new name, since `set_cue` replaces a slot. A non-editable cue gets the
same menu disabled, not no menu.
Prep libs live in `src/lib/`: `playbackEngine.ts` (Web Audio, seamless loops), Prep libs live in `src/lib/`: `playbackEngine.ts` (Web Audio, seamless loops),
`scratchEngine.ts` (drag-to-scratch), `waveform.ts` (frequency-colored `scratchEngine.ts` (drag-to-scratch), `waveform.ts` (frequency-colored
analysis + paint), `beatgrid.ts` (the marker-list beat math — every analysis + paint), `beatgrid.ts` (the marker-list beat math — every
@@ -752,7 +769,7 @@ that number and nothing else — everything derives from it:
- ✅ Track prep — audio playback, frequency-colored scrolling waveform, scratch, - ✅ Track prep — audio playback, frequency-colored scrolling waveform, scratch,
beatgrid display + editing, cue/hotcue create/jump/delete, loops; keyboard beatgrid display + editing, cue/hotcue create/jump/delete, loops; keyboard
shortcuts (Space = play/pause, 1–8 = hotcues, Shift+1–8 = delete, Cmd/Ctrl+↑/↓ = shortcuts (Space = play/pause, 1–8 = hotcues, Shift+1–8 = delete, Cmd/Ctrl+↑/↓ =
beat jump size). See "Prep engine". loop/jump size). See "Prep engine".
- ✅ Track prep Tier 2 — cue-point fine editing / audio export polish - ✅ Track prep Tier 2 — cue-point fine editing / audio export polish
- ✅ Flexible beatgrids — the grid is a marker list end to end (marker-level - ✅ Flexible beatgrids — the grid is a marker list end to end (marker-level
commands, piecewise beat math, playhead-derived marker editing). Step 1 of the commands, piecewise beat math, playhead-derived marker editing). Step 1 of the
@@ -1,80 +0,0 @@
import { Icon } from '../lib/icons'
/** Jump-size cycle, in beats. Fractional sizes allow fine micro-nudging. */
export const BEAT_JUMP_SIZES = [0.25, 0.5, 1, 2, 4, 8, 16, 32]
interface Props {
/** Current jump size (one of BEAT_JUMP_SIZES). */
beats: number
/** Step the jump size down (-1) / up (+1) through BEAT_JUMP_SIZES. */
onStep: (dir: -1 | 1) => void
/** Jump the playhead back (-1) / forward (+1) by `beats`. */
onJump: (dir: -1 | 1) => void
/** Disabled when the loaded track has no beatgrid. */
disabled: boolean
}
const BTN =
'btn-glass flex h-7 w-7 shrink-0 items-center justify-center rounded-lg ' +
'font-mono text-xs font-semibold text-text disabled:opacity-30'
/** Beats-only readout: 0.25 → "1/4", 0.5 → "1/2", else the integer. */
function sizeLabel(beats: number): string {
if (beats === 0.25) return '1/4'
if (beats === 0.5) return '1/2'
return String(beats)
}
/**
* Beat-jump control cluster (Traktor/Serato equivalent): step the jump size,
* then jump the playhead forward/back by that many beats — phase-preserving,
* playback-only. Presentational + controlled; PrepStrip owns the size state and
* performs the actual seek. Disabled wholesale when the track is ungridded.
*/
export function BeatJumpControls({ beats, onStep, onJump, disabled }: Props) {
const atMin = beats <= BEAT_JUMP_SIZES[0]
const atMax = beats >= BEAT_JUMP_SIZES[BEAT_JUMP_SIZES.length - 1]
return (
<div className="flex items-center gap-1">
<span className="mr-0.5 text-[10px] font-semibold uppercase tracking-wider text-faint">
Jump
</span>
<button
className={BTN}
onClick={() => onStep(-1)}
disabled={disabled || atMin}
title="Smaller jump size (Cmd/Ctrl+↓)"
>
−
</button>
<span className="w-9 text-center font-mono text-xs font-semibold text-text">
{sizeLabel(beats)}
</span>
<button
className={BTN}
onClick={() => onStep(1)}
disabled={disabled || atMax}
title="Larger jump size (Cmd/Ctrl+↑)"
>
+
</button>
<span className="mx-0.5 w-px self-stretch bg-line" aria-hidden />
<button
className={BTN}
onClick={() => onJump(-1)}
disabled={disabled}
title="Jump back (←)"
>
<Icon name="chevronLeft" size={14} strokeWidth={2.2} />
</button>
<button
className={BTN}
onClick={() => onJump(1)}
disabled={disabled}
title="Jump forward (→)"
>
<Icon name="chevronRight" size={14} strokeWidth={2.2} />
</button>
</div>
)
}
+225 -302
View File
@@ -1,45 +1,20 @@
import { memo, useRef, useState } from 'react' import { useRef, useState } from 'react'
import { Icon } from '../lib/icons' import { Icon } from '../lib/icons'
interface Props { // The deck's beatgrid controls, in three pieces that live in three places:
/** Tempo of the marker governing the playhead — what the tempo controls act //
* on. Null when the track has no grid. */ // BpmReadout — the header's BPM: shows the governing marker's tempo, and
bpm: number | null // is where an exact BPM is typed (click it).
/** Index of that marker; -1 when there is no grid. */ // TempoControls — the everyday tempo tools, always on the control row:
markerIndex: number // nudge ±0.01 / ±0.25, ÷2 ×2, tap tempo, lock.
/** 0 = no grid, 1 = constant tempo, >1 = a flexible (multi-tempo) grid. */ // GridEditStrip — only in Grid mode, in place of the hotcue pads: step
markerCount: number // between markers, nudge the marker ±1 / ±10 ms, add or
/** Position (s) of the governing marker; null when there is no grid. */ // delete a marker, delete the grid, reset it.
markerStart: number | null //
/** The playhead is sitting on the governing marker. */ // A beatgrid is a list of tempo markers, and the one being edited is derived
atMarker: boolean // from the playhead rather than selected separately — so every control acts on
/** The playhead precedes the first marker (whose tempo extrapolates back). */ // the marker governing what you are hearing. Presentational: PrepStrip owns the
beforeFirst: boolean // state and sends the commands.
locked: boolean
/** A snapshot of the grid as loaded exists to restore. */
canReset: boolean
onSetBpm: (bpm: number) => void
onNudgeBpm: (delta: number) => void
/** Octave fix for the governing marker (halve / double its BPM). */
onHalve: () => void
onDouble: () => void
/** Move the governing marker by ±ms. */
onNudgeMarker: (deltaMs: number) => void
/** Add a marker at the playhead (creates the grid when there is none). */
onAddMarker: () => void
/** Delete the governing marker (offered only while standing on it). */
onDeleteMarker: () => void
/** Seek to the adjacent marker — under playhead-derived selection this is
* how the user changes which marker they are editing. */
onPrevMarker: () => void
onNextMarker: () => void
onReset: () => void
onToggleLock: () => void
onDeleteGrid: () => void
/** Detect BPM + first beat and rebuild the grid as a single marker. */
onAnalyze: () => void
analyzing: boolean
}
/** m:ss.mmm — marker positions need millisecond precision to be useful. */ /** m:ss.mmm — marker positions need millisecond precision to be useful. */
function markerTime(t: number): string { function markerTime(t: number): string {
@@ -48,56 +23,95 @@ function markerTime(t: number): string {
return `${m}:${s < 10 ? '0' : ''}${s.toFixed(3)}` return `${m}:${s < 10 ? '0' : ''}${s.toFixed(3)}`
} }
const BTN = /** The header readout's BPM cell. Click to type an exact tempo. */
'btn-glass flex flex-1 items-center justify-center gap-1 rounded-lg py-1 font-mono text-[11px] ' + export function BpmReadout({
'font-semibold text-text disabled:opacity-30'
/**
* Beatgrid / tempo panel (Traktor grid-control equivalent): editable BPM, BPM
* nudge (fine ±0.01 / coarse ±0.25), half/double, tap tempo, grid-phase nudge
* (±1/±10 ms), add/delete markers, reset to the loaded grid, lock, delete grid.
*
* A beatgrid is a list of tempo markers, and the one being edited is derived
* from the playhead rather than selected separately — so the tempo controls
* always act on the marker governing what you are hearing. Memoised because the
* playhead updates every frame and most of those frames change nothing here.
*/
export const GridControls = memo(function GridControls({
bpm, bpm,
markerIndex, editable,
markerCount,
markerStart,
atMarker,
beforeFirst,
locked,
canReset,
onSetBpm, onSetBpm,
onNudgeBpm, }: {
onHalve, /** Tempo of the marker governing the playhead; null without a grid. */
onDouble, bpm: number | null
onNudgeMarker, editable: boolean
onAddMarker, onSetBpm: (bpm: number) => void
onDeleteMarker, }) {
onPrevMarker,
onNextMarker,
onReset,
onToggleLock,
onDeleteGrid,
onAnalyze,
analyzing,
}: Props) {
const hasGrid = markerCount > 0
const flexible = markerCount > 1
const [editing, setEditing] = useState(false) const [editing, setEditing] = useState(false)
const [val, setVal] = useState('') const [val, setVal] = useState('')
const tapsRef = useRef<number[]>([])
const commit = () => { const commit = () => {
const n = parseFloat(val) const n = parseFloat(val)
if (isFinite(n) && n > 0) onSetBpm(Math.round(n * 1000) / 1000) if (isFinite(n) && n > 0) onSetBpm(Math.round(n * 1000) / 1000)
setEditing(false) setEditing(false)
} }
const label = (
<span className="text-[10px] tracking-[0.08em] text-faint">
BPM{editable && bpm != null ? ' ✎' : ''}
</span>
)
if (editing) {
return (
<div className="flex flex-col justify-center gap-px px-4">
{label}
<input
autoFocus
value={val}
onChange={(e) => setVal(e.target.value)}
onBlur={commit}
onKeyDown={(e) => {
if (e.key === 'Enter') commit()
if (e.key === 'Escape') setEditing(false)
e.stopPropagation() // Space/arrows must not drive the deck while typing
}}
className="w-[5.5rem] rounded-md bg-ink-800 px-1 font-mono text-[17px] font-semibold text-accent outline-none ring-1 ring-accent"
/>
</div>
)
}
return (
<button
onClick={() => {
if (!editable || bpm == null) return
setVal(bpm.toFixed(3))
setEditing(true)
}}
title={editable && bpm != null ? 'Click to type an exact BPM' : undefined}
className="flex flex-col justify-center gap-px rounded-r-xl px-4 text-left hover:bg-ink-850"
>
{label}
<span className="font-mono text-[17px] font-semibold text-accent">
{bpm != null ? bpm.toFixed(2) : '––'}
</span>
</button>
)
}
const T_BTN =
'flex h-8 items-center justify-center rounded-lg font-mono text-xs text-text transition-colors ' +
'hover:bg-ink-800 disabled:opacity-30 disabled:hover:bg-transparent'
/** Nudge / octave / tap / lock — always visible on the control row. */
export function TempoControls({
bpm,
locked,
lockable,
flexible,
markerIndex,
onSetBpm,
onNudgeBpm,
onHalve,
onDouble,
onToggleLock,
}: {
bpm: number | null
locked: boolean
lockable: boolean
flexible: boolean
markerIndex: number
onSetBpm: (bpm: number) => void
onNudgeBpm: (delta: number) => void
onHalve: () => void
onDouble: () => void
onToggleLock: () => void
}) {
const tapsRef = useRef<number[]>([])
const tap = () => { const tap = () => {
const now = performance.now() const now = performance.now()
const taps = tapsRef.current const taps = tapsRef.current
@@ -105,231 +119,147 @@ export const GridControls = memo(function GridControls({
taps.push(now) taps.push(now)
if (taps.length > 8) taps.shift() if (taps.length > 8) taps.shift()
if (taps.length >= 2) { if (taps.length >= 2) {
const first = taps[0] const avg = (now - taps[0]) / (taps.length - 1)
const avg = (now - first) / (taps.length - 1)
onSetBpm(Math.round((60000 / avg) * 1000) / 1000) onSetBpm(Math.round((60000 / avg) * 1000) / 1000)
} }
} }
const off = bpm == null
const of = flexible ? ` of marker ${markerIndex + 1}` : ''
return ( return (
<div className="flex flex-col gap-2"> <div role="group" aria-label="Tempo" className="btn-glass flex h-10 shrink-0 items-center gap-0.5 rounded-xl px-1">
{/* BPM readout / editor */} <button className={`${T_BTN} w-7`} onClick={() => onNudgeBpm(-0.25)} disabled={off} title={`BPM −0.25${of}`}>−−</button>
<div className="well rounded-2xl px-3 py-2 text-center"> <button className={`${T_BTN} w-[22px]`} onClick={() => onNudgeBpm(-0.01)} disabled={off} title={`BPM −0.01${of}`}>−</button>
{editing ? ( <button className={`${T_BTN} w-[22px]`} onClick={() => onNudgeBpm(0.01)} disabled={off} title={`BPM +0.01${of}`}>+</button>
<input <button className={`${T_BTN} w-7`} onClick={() => onNudgeBpm(0.25)} disabled={off} title={`BPM +0.25${of}`}>++</button>
autoFocus <span aria-hidden className="mx-0.5 h-[18px] w-px bg-line" />
value={val} <button className={`${T_BTN} w-7`} onClick={onHalve} disabled={off} title={`Halve the BPM${of}`}>÷2</button>
onChange={(e) => setVal(e.target.value)} <button className={`${T_BTN} w-7`} onClick={onDouble} disabled={off} title={`Double the BPM${of}`}>×2</button>
onBlur={commit} <button
onKeyDown={(e) => { className={`${T_BTN} h-7 bg-ink-800 px-2 font-semibold tracking-[0.06em]`}
if (e.key === 'Enter') commit() onClick={tap}
if (e.key === 'Escape') setEditing(false) disabled={off}
}} title="Tap tempo"
className="w-32 rounded-lg bg-ink-800 py-0.5 text-center font-mono text-[26px] font-semibold text-accent outline-none" >
/> TAP
) : ( </button>
<button {lockable && (
onClick={() => {
setVal(bpm != null ? bpm.toFixed(3) : '')
setEditing(true)
}}
className="font-mono text-[26px] font-semibold leading-tight text-accent [text-shadow:0_0_18px_color-mix(in_oklab,var(--color-accent)_55%,transparent)] hover:brightness-110"
title="Click to type an exact BPM"
>
{bpm != null ? bpm.toFixed(2) : '––'}
</button>
)}
{!hasGrid ? (
<div className="text-[10px] font-semibold uppercase tracking-wider text-faint">
No grid
</div>
) : !flexible ? (
<div className="text-[10px] font-semibold uppercase tracking-wider text-faint">BPM</div>
) : (
// Flexible grid: show which marker is in charge and let the user step
// between them (which seeks — there is no separate selection).
<div
className={
'flex items-center justify-center gap-1 text-[10px] font-semibold tabular-nums ' +
(beforeFirst ? 'text-faint' : 'text-gold')
}
title={
beforeFirst
? "Playhead is before the first marker — marker 1's tempo extrapolates backwards"
: `Editing marker ${markerIndex + 1} of ${markerCount}`
}
>
<button onClick={onPrevMarker} className="px-1 hover:text-accent" title="Previous marker">
‹
</button>
<span>
{beforeFirst ? '↤ ' : '⊞ '}
{markerIndex + 1}/{markerCount}
{markerStart != null ? ` · ${markerTime(markerStart)}` : ''}
</span>
<button onClick={onNextMarker} className="px-1 hover:text-accent" title="Next marker">
›
</button>
</div>
)}
</div>
{/* BPM nudge — coarse ±0.25 (outer) / fine ±0.01 (inner) */}
<div className="flex items-center gap-1">
<span className="mr-0.5 text-[10px] font-semibold uppercase tracking-wider text-faint">
BPM
</span>
<button
className={BTN}
onClick={() => onNudgeBpm(-0.25)}
disabled={bpm == null}
title="Nudge BPM −0.25 (coarse)"
>
−.25
</button>
<button
className={BTN}
onClick={() => onNudgeBpm(-0.01)}
disabled={bpm == null}
title="Nudge BPM −0.01 (fine)"
>
−.01
</button>
<button
className={BTN}
onClick={() => onNudgeBpm(0.01)}
disabled={bpm == null}
title="Nudge BPM +0.01 (fine)"
>
+.01
</button>
<button
className={BTN}
onClick={() => onNudgeBpm(0.25)}
disabled={bpm == null}
title="Nudge BPM +0.25 (coarse)"
>
+.25
</button>
</div>
{/* halve / double / tap / reset */}
<div className="flex gap-1">
<button
className={BTN}
onClick={onHalve}
disabled={bpm == null}
title={flexible ? `Halve BPM of marker ${markerIndex + 1}` : 'Halve BPM'}
>
/2
</button>
<button
className={BTN}
onClick={onDouble}
disabled={bpm == null}
title={flexible ? `Double BPM of marker ${markerIndex + 1}` : 'Double BPM'}
>
×2
</button>
<button className={BTN} onClick={tap} title="Tap tempo">
TAP
</button>
<button
className={BTN}
onClick={onReset}
disabled={!canReset}
title="Restore the beatgrid as loaded"
>
Reset
</button>
</div>
{/* grid-phase nudge + set beat 1 */}
<div className="flex items-center gap-1">
<span className="mr-0.5 text-[10px] font-semibold uppercase tracking-wider text-faint">
Grid
</span>
{/* Phase nudges move the GOVERNING marker — deliberately not gated on
atMarker, since the drift is heard at the playhead, not at the marker. */}
<button
className={BTN}
onClick={() => onNudgeMarker(-10)}
disabled={!hasGrid}
title="Move this marker −10 ms"
>
◀◀
</button>
<button
className={BTN}
onClick={() => onNudgeMarker(-1)}
disabled={!hasGrid}
title="Move this marker −1 ms"
>
◀
</button>
<button
className={BTN}
onClick={onAddMarker}
title={
hasGrid
? 'Add a grid marker at the playhead'
: 'Set the beatgrid at the playhead'
}
>
{hasGrid ? '+ Mrk' : 'SET'}
</button>
<button
className={BTN}
onClick={() => onNudgeMarker(1)}
disabled={!hasGrid}
title="Move this marker +1 ms"
>
▶
</button>
<button
className={BTN}
onClick={() => onNudgeMarker(10)}
disabled={!hasGrid}
title="Move this marker +10 ms"
>
▶▶
</button>
</div>
{/* lock / delete grid */}
<div className="flex gap-1">
<button <button
onClick={onToggleLock} onClick={onToggleLock}
title={locked ? 'Unlock track' : 'Lock track'} aria-pressed={locked}
className={ title={locked ? 'Unlock the grid' : 'Lock the grid'}
'flex flex-1 items-center justify-center gap-1.5 rounded-lg py-1 text-xs font-semibold transition-colors ' + className={`${T_BTN} w-7 ${locked ? 'bg-gold/15 text-gold shadow-[inset_0_0_0_1px_rgb(255_200_97/0.45)]' : ''}`}
(locked >
? 'bg-gold/15 text-gold shadow-[inset_0_0_0_1px_rgb(255_200_97/0.45),0_0_16px_-4px_rgb(255_200_97/0.6)]' <Icon name={locked ? 'lock' : 'unlock'} size={14} />
: 'btn-glass text-text') </button>
)}
</div>
)
}
/** Grid mode: everything that fixes a grid, in place of the pads. */
export function GridEditStrip({
markerIndex,
markerCount,
markerStart,
atMarker,
beforeFirst,
canReset,
onPrevMarker,
onNextMarker,
onNudgeMarker,
onAddMarker,
onDeleteMarker,
onDeleteGrid,
onReset,
}: {
markerIndex: number
markerCount: number
markerStart: number | null
atMarker: boolean
beforeFirst: boolean
canReset: boolean
onPrevMarker: () => void
onNextMarker: () => void
onNudgeMarker: (deltaMs: number) => void
onAddMarker: () => void
onDeleteMarker: () => void
onDeleteGrid: () => void
onReset: () => void
}) {
const hasGrid = markerCount > 0
const flexible = markerCount > 1
const nudge = 'flex h-10 items-center px-2 font-mono text-[11px] text-text hover:bg-ink-800 disabled:opacity-30'
const pill = 'flex h-[34px] shrink-0 items-center gap-1.5 rounded-full px-3 text-xs disabled:opacity-35'
return (
// A container, so the three actions on the right can drop their labels
// rather than overflow when the window is narrow.
<div role="group" aria-label="Grid editing" className="@container flex min-w-0 flex-1">
<div className="flex min-w-0 flex-1 items-center gap-2">
{/* The spare width goes on the LEFT, so the tools sit together at the
right, next to the tempo controls, instead of splitting across the
row with a gap in the middle. */}
<div className="flex-1" />
<div
className="flex h-10 min-w-0 shrink items-center rounded-xl bg-gold/10 px-1 text-gold shadow-[inset_0_0_0_1px_rgb(255_200_97/0.35)]"
title={
!hasGrid
? 'No beatgrid yet — Set grid places one at the playhead'
: beforeFirst
? "Playhead is before the first marker — marker 1's tempo extrapolates backwards"
: `Editing marker ${markerIndex + 1} of ${markerCount} (Shift+←/→ to step)`
} }
> >
<Icon name={locked ? 'lock' : 'unlock'} size={13} /> <button onClick={onPrevMarker} disabled={!flexible} aria-label="Previous marker" className="flex h-10 w-6 items-center justify-center disabled:opacity-30">
{locked ? 'Locked' : 'Lock'} <Icon name="chevronLeft" size={13} strokeWidth={2.4} />
</button> </button>
{/* Only a marker you are standing on can be deleted, so one that is <span className="truncate px-1 font-mono text-xs font-semibold">
scrolled off-screen can never go by accident. Deleting the last {hasGrid
marker is "delete grid", not a second button doing the same thing. */} ? `${beforeFirst ? '↤ ' : ''}Marker ${markerIndex + 1}/${markerCount}${
markerStart != null ? ` · ${markerTime(markerStart)}` : ''
}`
: 'No grid'}
</span>
<button onClick={onNextMarker} disabled={!flexible} aria-label="Next marker" className="flex h-10 w-6 items-center justify-center disabled:opacity-30">
<Icon name="chevronRight" size={13} strokeWidth={2.4} />
</button>
</div>
<div className="btn-glass flex h-10 shrink-0 items-center overflow-hidden rounded-xl">
{/* Phase nudges move the GOVERNING marker — not gated on atMarker,
since the drift is heard at the playhead, not at the marker. */}
<button className={nudge} onClick={() => onNudgeMarker(-10)} disabled={!hasGrid} title="Move the marker −10 ms">−10</button>
<button className={nudge} onClick={() => onNudgeMarker(-1)} disabled={!hasGrid} title="Move the marker −1 ms">−1</button>
<button
onClick={onAddMarker}
title={hasGrid ? 'Add a grid marker at the playhead' : 'Start the beatgrid at the playhead'}
className="mx-1 flex h-[30px] items-center gap-1 rounded-lg bg-ink-800 px-2.5 text-xs font-semibold text-text hover:bg-ink-700"
>
<Icon name="plus" size={12} strokeWidth={2.4} />
{hasGrid ? 'Marker' : 'Set grid'}
</button>
<button className={nudge} onClick={() => onNudgeMarker(1)} disabled={!hasGrid} title="Move the marker +1 ms">+1</button>
<button className={nudge} onClick={() => onNudgeMarker(10)} disabled={!hasGrid} title="Move the marker +10 ms">+10</button>
</div>
{/* Only a marker you are standing on can be deleted, so one scrolled
off-screen can never go by accident. Deleting the last marker is
Delete grid, not a second button doing the same thing. */}
<button <button
className={BTN}
onClick={onDeleteMarker} onClick={onDeleteMarker}
disabled={!atMarker || !flexible} disabled={!atMarker || !flexible}
title={ title={
!flexible !flexible
? 'Use Delete grid to remove the last marker' ? 'A single marker is the whole grid — use Delete grid'
: atMarker : atMarker
? `Delete grid marker ${markerIndex + 1}` ? `Delete marker ${markerIndex + 1}`
: 'Park the playhead on a marker to delete it (‹ › to step)' : 'Park the playhead on a marker to delete it'
} }
className={`${pill} btn-glass text-text`}
> >
<Icon name="trash" size={12} /> Mrk <Icon name="trash" size={13} />
<span className="hidden @[34rem]:inline">Marker</span>
</button> </button>
<button <button
className={BTN}
onClick={() => { onClick={() => {
if ( if (
confirm( confirm(
@@ -342,24 +272,17 @@ export const GridControls = memo(function GridControls({
} }
}} }}
disabled={!hasGrid} disabled={!hasGrid}
title="Delete beatgrid" title="Delete the beatgrid"
className={`${pill} bg-pink/12 text-[#ffc2cf] shadow-[inset_0_0_0_1px_rgb(255_122_154/0.4)] hover:bg-pink/20`}
> >
<Icon name="trash" size={12} /> Grid <Icon name="trash" size={13} />
<span className="hidden @[34rem]:inline">Grid</span>
</button> </button>
</div> <button onClick={onReset} disabled={!canReset} title="Restore the grid as it was loaded" className={`${pill} btn-glass text-text`}>
<Icon name="history" size={13} />
{/* analyze: detect BPM + first beat, set hotcue 1 + grid anchor */} <span className="hidden @[34rem]:inline">Reset</span>
<div className="flex gap-1">
<button
className={BTN}
onClick={onAnalyze}
disabled={analyzing}
title="Detect BPM and first beat, then set the grid + hotcue 1 (fix octave with ÷2 / ×2)"
>
<Icon name="wave" size={13} />
{analyzing ? 'Analyzing…' : 'Analyze'}
</button> </button>
</div> </div>
</div> </div>
) )
}) }
+79 -7
View File
@@ -1,6 +1,6 @@
import type { CSSProperties } from 'react' import { useRef, useState, type CSSProperties } from 'react'
import type { CuePoint } from '../api' import type { CuePoint } from '../api'
import { cueColor, cueGlyph, withAlpha } from '../lib/cues' import { CUE_TYPE_LABELS, cueColor, cueGlyph, withAlpha } from '../lib/cues'
import { Icon } from '../lib/icons' import { Icon } from '../lib/icons'
interface Props { interface Props {
@@ -12,6 +12,12 @@ interface Props {
selectedSlot: number | null selectedSlot: number | null
onSlotPress: (slot: number) => void onSlotPress: (slot: number) => void
onSlotRelease: (slot: number) => void onSlotRelease: (slot: number) => void
/** Right-click on a pad: the deck opens its Type / Rename / Delete menu. */
onSlotMenu: (slot: number, x: number, y: number) => void
/** The pad whose name is being edited in place, if any. */
renamingSlot: number | null
onRenameCommit: (slot: number, name: string) => void
onRenameCancel: () => void
} }
const READONLY_LABELS: Record<string, string> = { const READONLY_LABELS: Record<string, string> = {
@@ -37,9 +43,16 @@ export function HotcueBar({
selectedSlot, selectedSlot,
onSlotPress, onSlotPress,
onSlotRelease, onSlotRelease,
onSlotMenu,
renamingSlot,
onRenameCommit,
onRenameCancel,
}: Props) { }: Props) {
return ( return (
<div className="flex min-w-0 flex-1 items-stretch gap-1.5"> // The group takes the row's spare width; each pad is capped, so on a wide
// window the pads keep a pad's proportions and the space is left empty
// rather than stretching them into bars.
<div className="flex min-w-0 flex-1 items-center gap-1.5">
{Array.from({ length: slotCount }, (_, i) => i).map((slot) => { {Array.from({ length: slotCount }, (_, i) => i).map((slot) => {
const cue = cues.find((c) => c.role === 'hotcue' && c.slot === slot) ?? null const cue = cues.find((c) => c.role === 'hotcue' && c.slot === slot) ?? null
// Gate on `editable`, never on why: a platform-owned cue is a read-only // Gate on `editable`, never on why: a platform-owned cue is a read-only
@@ -51,7 +64,13 @@ export function HotcueBar({
return ( return (
<button <button
key={slot} key={slot}
onContextMenu={(e) => {
e.preventDefault()
onSlotMenu(slot, e.clientX, e.clientY)
}}
onPointerDown={(e) => { onPointerDown={(e) => {
// Right button opens the menu; it must not also trigger the pad.
if (e.button !== 0) return
e.preventDefault() e.preventDefault()
// Capture so the matching release fires even if the pointer drifts // Capture so the matching release fires even if the pointer drifts
// off the button before it's let go. // off the button before it's let go.
@@ -72,7 +91,7 @@ export function HotcueBar({
} }
style={color ? padStyle(color, selected) : undefined} style={color ? padStyle(color, selected) : undefined}
className={ className={
'relative flex min-w-0 flex-1 flex-col items-start justify-center rounded-[11px] px-2 text-left transition-[filter,background-color] ' + 'relative flex h-11 min-w-0 max-w-[7.5rem] flex-1 flex-col items-start justify-center gap-1 rounded-xl px-2.5 text-left transition-[filter,background-color] ' +
(color (color
? 'hover:brightness-115' ? 'hover:brightness-115'
: 'bg-white/[0.035] text-faint shadow-[inset_0_0_0_1px_rgb(255_255_255/0.07)] hover:bg-ink-800') + : 'bg-white/[0.035] text-faint shadow-[inset_0_0_0_1px_rgb(255_255_255/0.07)] hover:bg-ink-800') +
@@ -85,9 +104,23 @@ export function HotcueBar({
> >
{locked ? <Icon name="lock" size={11} strokeWidth={2.2} /> : slotLabel(slot)} {locked ? <Icon name="lock" size={11} strokeWidth={2.2} /> : slotLabel(slot)}
</span> </span>
<span className="mt-1 w-full truncate text-[11px] leading-none text-text/85"> {renamingSlot === slot && cue ? (
{cue ? (cue.name && cue.name !== 'n.n.' ? cue.name : ' ') : ''} <RenameField
</span> initial={cue.name && cue.name !== 'n.n.' ? cue.name : ''}
onCommit={(name) => onRenameCommit(slot, name)}
onCancel={onRenameCancel}
/>
) : (
// A cue without a name shows its type, dimmed, rather than a
// blank line — the pad still says what it holds.
<span
className={`w-full truncate text-[11px] leading-none ${
cue && cue.name && cue.name !== 'n.n.' ? 'text-text/85' : 'text-text/50'
}`}
>
{cue ? (cue.name && cue.name !== 'n.n.' ? cue.name : CUE_TYPE_LABELS[cue.type]) : 'Empty'}
</span>
)}
{glyph && ( {glyph && (
<span <span
className="absolute right-1.5 top-1 text-[9px] leading-none opacity-90" className="absolute right-1.5 top-1 text-[9px] leading-none opacity-90"
@@ -121,3 +154,42 @@ function padStyle(color: string, selected: boolean): CSSProperties {
].join(', '), ].join(', '),
} }
} }
/** The pad's name, edited in place. Enter or clicking away commits; Esc cancels. */
function RenameField({
initial,
onCommit,
onCancel,
}: {
initial: string
onCommit: (name: string) => void
onCancel: () => void
}) {
const [val, setVal] = useState(initial)
// Enter commits and unmounts the field, which can fire a trailing blur.
const done = useRef(false)
const finish = (commit: boolean) => {
if (done.current) return
done.current = true
if (commit && val.trim() !== initial) onCommit(val.trim())
else onCancel()
}
return (
<input
autoFocus
value={val}
onChange={(e) => setVal(e.target.value)}
onFocus={(e) => e.currentTarget.select()}
onBlur={() => finish(true)}
// The pad is a button: keep its press/preview handlers out of the field.
onPointerDown={(e) => e.stopPropagation()}
onPointerUp={(e) => e.stopPropagation()}
onKeyDown={(e) => {
e.stopPropagation() // digits and Space must type, not trigger the deck
if (e.key === 'Enter') finish(true)
else if (e.key === 'Escape') finish(false)
}}
className="w-full min-w-0 rounded bg-well px-1 text-[11px] leading-4 text-text outline-none ring-1 ring-accent"
/>
)
}
+140 -72
View File
@@ -1,94 +1,162 @@
import { Icon } from '../lib/icons' import { Icon } from '../lib/icons'
interface Props { /** One size, 1/32 → 32 beats, shared by beat loops AND beat jump: the number a
hasGrid: boolean // beat-loops need a beatgrid; buttons disable without one * DJ has in their head ("4 beats") should not differ between the two. */
active: boolean // a loop is currently engaged export const LOOP_SIZES = [1 / 32, 1 / 16, 1 / 8, 1 / 4, 1 / 2, 1, 2, 4, 8, 16, 32]
activeBeats: number | null // size of the active loop (null for a manual loop)
canToggle: boolean // a loop region exists to enable/disable
snap: boolean
onToggleSnap: () => void
onSetLoop: (beats: number) => void
onLoopIn: () => void
onLoopOut: () => void
onToggleActive: () => void
}
// All fixed beat-loop sizes, 1/32 → 32 beats, shown at once. export function sizeLabel(size: number): string {
const SIZES = [1 / 32, 1 / 16, 1 / 8, 1 / 4, 1 / 2, 1, 2, 4, 8, 16, 32]
function label(size: number): string {
return size < 1 ? `1/${Math.round(1 / size)}` : String(size) return size < 1 ? `1/${Math.round(1 / size)}` : String(size)
} }
const CELL = export type LoopMode = 'beat' | 'manual'
'flex items-center justify-center rounded-lg font-mono text-xs font-semibold transition-colors select-none'
const IDLE = 'btn-glass text-text' interface Props {
const OFF = 'disabled:opacity-30' mode: LoopMode
// A lit green key: an engaged loop should read as ON from across the room. onMode: (mode: LoopMode) => void
hasGrid: boolean // beat loops and jumps are sized in beats; inert without a grid
ready: boolean
/** The shared loop/jump size, in beats. */
size: number
onSmaller: () => void
onBigger: () => void
/** A loop is engaged right now (either kind). */
loopActive: boolean
/** The engaged loop is a beat loop of exactly `size` — the size key is lit. */
sizeLit: boolean
onToggleSize: () => void
// manual mode
canToggle: boolean // a loop region exists to switch on/off
onLoopIn: () => void
onLoopOut: () => void
onToggleLoop: () => void
/** ‹ ›: move an engaged loop by its own length, else jump by `size`. */
onMove: (dir: -1 | 1) => void
}
const LIT = const LIT =
'bg-gradient-to-b from-[#7bf0ad] to-mint text-ink-950 shadow-[inset_0_1px_0_rgb(255_255_255/0.6),0_0_14px_rgb(61_220_132/0.55)]' 'bg-gradient-to-b from-[#7bf0ad] to-mint text-ink-950 shadow-[inset_0_1px_0_rgb(255_255_255/0.6),0_0_14px_rgb(61_220_132/0.55)]'
const KEY = 'flex items-center justify-center rounded-[9px] transition-colors disabled:opacity-30'
// BOTH modes' clusters are this wide, so switching BEAT ⇄ MAN never shifts
// the pads and tempo controls to their right.
const CLUSTER = 'well flex h-10 w-[8.5rem] shrink-0 items-center gap-0.5 rounded-xl p-[3px]'
/**
* The deck's loop + jump cluster: a BEAT / MAN switch, then either the beat
* size (− size +, the size itself toggling a loop of that length) or the manual
* IN / OUT / toggle, then ‹ › which move an engaged loop or jump the playhead.
*
* Presentational: PrepStrip owns every piece of state and does the seeking.
*/
export function LoopControls({ export function LoopControls({
mode,
onMode,
hasGrid, hasGrid,
active, ready,
activeBeats, size,
onSmaller,
onBigger,
loopActive,
sizeLit,
onToggleSize,
canToggle, canToggle,
snap,
onToggleSnap,
onSetLoop,
onLoopIn, onLoopIn,
onLoopOut, onLoopOut,
onToggleActive, onToggleLoop,
onMove,
}: Props) { }: Props) {
const atMin = size <= LOOP_SIZES[0]
const atMax = size >= LOOP_SIZES[LOOP_SIZES.length - 1]
const what = loopActive ? 'Move the loop' : `Jump ${sizeLabel(size)} beat${size === 1 ? '' : 's'}`
// A beat jump needs a grid; moving a manual loop does not.
const canMove = ready && (loopActive || hasGrid)
const tab = (m: LoopMode, text: string, title: string) => (
<button
onClick={() => onMode(m)}
title={title}
aria-pressed={mode === m}
className={`h-[17px] rounded-[7px] px-[7px] text-[9px] font-bold tracking-[0.08em] transition-colors ${
mode === m ? 'btn-primary' : 'text-faint hover:text-text'
}`}
>
{text}
</button>
)
return ( return (
<div className="flex h-10 shrink-0 items-center gap-1.5 pt-2"> <div className="flex shrink-0 items-center gap-2">
<span className="flex w-12 shrink-0 items-center text-[10px] font-semibold uppercase tracking-wider text-faint"> <div role="group" aria-label="Loop mode" className="well flex h-10 flex-col justify-center gap-0.5 rounded-[10px] p-0.5">
Loop {tab('beat', 'BEAT', 'Beat loops, sized in beats')}
</span> {tab('manual', 'MAN', 'Manual loops: set IN and OUT')}
<div className="well flex h-full min-w-0 flex-1 items-stretch gap-0.5 rounded-xl p-[3px]">
{SIZES.map((size) => {
const isActive = active && activeBeats === size
return (
<button
key={size}
onClick={() => onSetLoop(size)}
disabled={!hasGrid}
title={hasGrid ? `${label(size)}-beat loop` : 'No beatgrid'}
className={`${CELL} ${OFF} flex-1 ${
isActive ? LIT : 'text-muted hover:bg-ink-800 hover:text-text'
}`}
>
{label(size)}
</button>
)
})}
</div> </div>
<button onClick={onLoopIn} className={`${CELL} ${IDLE} h-full w-11`} title="Loop in at playhead"> {mode === 'beat' ? (
IN <div role="group" aria-label="Loop size" className={`${CLUSTER} font-mono`}>
</button> <button
<button onClick={onLoopOut} className={`${CELL} ${IDLE} h-full w-11`} title="Loop out at playhead"> onClick={onSmaller}
OUT disabled={atMin}
</button> title="Halve the size (Cmd/Ctrl+↓)"
<button className={`${KEY} h-[34px] w-7 text-[15px] text-muted hover:bg-ink-800 hover:text-text`}
onClick={onToggleActive} >
disabled={!canToggle} −
title={active ? 'Disable loop' : 'Enable loop'} </button>
className={`${CELL} ${OFF} h-full w-11 ${active ? LIT : IDLE}`} <button
> onClick={onToggleSize}
<Icon name="loop" size={15} /> disabled={!hasGrid || !ready}
</button> title={hasGrid ? `${sizeLabel(size)}-beat loop — click to switch on or off` : 'No beatgrid'}
<button className={`${KEY} h-[34px] min-w-0 flex-1 px-2 text-sm font-semibold ${
onClick={onToggleSnap} sizeLit ? LIT : 'btn-glass text-text'
title="Snap to the nearest beat" }`}
className={`${CELL} h-full w-14 font-sans text-[11px] uppercase tracking-wider ${ >
snap ? 'is-selected text-text' : `${IDLE} text-muted` {sizeLabel(size)}
}`} </button>
> <button
Snap onClick={onBigger}
</button> disabled={atMax}
title="Double the size (Cmd/Ctrl+↑)"
className={`${KEY} h-[34px] w-7 text-[15px] text-muted hover:bg-ink-800 hover:text-text`}
>
+
</button>
</div>
) : (
<div role="group" aria-label="Manual loop" className={`${CLUSTER} text-xs font-semibold`}>
<button onClick={onLoopIn} disabled={!ready} title="Loop in at the playhead" className={`${KEY} btn-glass h-[34px] min-w-0 flex-1 text-text`}>
IN
</button>
<button onClick={onLoopOut} disabled={!ready} title="Loop out at the playhead" className={`${KEY} btn-glass h-[34px] min-w-0 flex-1 text-text`}>
OUT
</button>
<button
onClick={onToggleLoop}
disabled={!canToggle}
title={loopActive ? 'Switch the loop off' : 'Switch the loop on'}
aria-pressed={loopActive}
className={`${KEY} h-[34px] min-w-0 flex-1 ${loopActive ? LIT : 'btn-glass text-text'}`}
>
<Icon name="loop" size={15} />
</button>
</div>
)}
<div role="group" aria-label="Jump or move loop" className="btn-glass flex h-10 items-center rounded-xl">
<button
onClick={() => onMove(-1)}
disabled={!canMove}
title={`${what} back (←)`}
className="flex h-10 w-[34px] items-center justify-center text-text disabled:opacity-30"
>
<Icon name="chevronLeft" size={15} strokeWidth={2.2} />
</button>
<button
onClick={() => onMove(1)}
disabled={!canMove}
title={`${what} forward (→)`}
className="flex h-10 w-[34px] items-center justify-center text-text disabled:opacity-30"
>
<Icon name="chevronRight" size={15} strokeWidth={2.2} />
</button>
</div>
</div> </div>
) )
} }
+27 -1
View File
@@ -13,6 +13,8 @@ interface Props {
grid: BeatGrid | null grid: BeatGrid | null
/** Marker governing the playhead — drawn gold, its segment tinted. */ /** Marker governing the playhead — drawn gold, its segment tinted. */
activeMarker: number activeMarker: number
/** Grid mode is on: draw the beat lines brighter. */
emphasizeGrid?: boolean
loop: { start: number; end: number } | null loop: { start: number; end: number } | null
/** Seconds across the view — the zoom level, owned by the parent so it /** Seconds across the view — the zoom level, owned by the parent so it
survives track switches and persists to prefs. */ survives track switches and persists to prefs. */
@@ -44,6 +46,7 @@ export function MainWaveform({
cuePoint, cuePoint,
grid, grid,
activeMarker, activeMarker,
emphasizeGrid = false,
loop, loop,
secPerView, secPerView,
onZoomChange, onZoomChange,
@@ -92,7 +95,7 @@ export function MainWaveform({
drawLoop(ctx, timeToX(loop.start), timeToX(loop.end), h, dpr) drawLoop(ctx, timeToX(loop.start), timeToX(loop.end), h, dpr)
} }
if (grid) { if (grid) {
drawBeatgrid(ctx, grid, startSec, endSec, w, h, dpr, activeMarker) drawBeatgrid(ctx, grid, startSec, endSec, w, h, dpr, activeMarker, emphasizeGrid)
} }
if (cues.length) { if (cues.length) {
drawCues(ctx, cues, w, h, dpr, timeToX, true) drawCues(ctx, cues, w, h, dpr, timeToX, true)
@@ -121,6 +124,29 @@ export function MainWaveform({
return () => ro.disconnect() return () => ro.disconnect()
}, []) }, [])
// Cmd/Ctrl + scroll zooms (a trackpad pinch arrives as ctrl+wheel too).
// Attached by hand because React's onWheel is passive, so it could not stop
// the page scrolling. Accumulated so a trackpad's many tiny deltas step the
// zoom as evenly as a mouse wheel's notches do.
const zoomRef = useRef({ secPerView, onZoomChange })
zoomRef.current = { secPerView, onZoomChange }
useEffect(() => {
const wrap = wrapRef.current
if (!wrap) return
let acc = 0
const onWheel = (e: WheelEvent) => {
if (!e.ctrlKey && !e.metaKey) return
e.preventDefault()
acc += e.deltaY
if (Math.abs(acc) < 40) return
const { secPerView: sec, onZoomChange: set } = zoomRef.current
set(Math.min(MAX_SEC, Math.max(MIN_SEC, acc > 0 ? sec * 2 : sec / 2)))
acc = 0
}
wrap.addEventListener('wheel', onWheel, { passive: false })
return () => wrap.removeEventListener('wheel', onWheel)
}, [])
// A press that doesn't move is a seek (map offset from centre to a time); // A press that doesn't move is a seek (map offset from centre to a time);
// a press that moves is a scratch (map movement to a target time). // a press that moves is a scratch (map movement to a target time).
const timeAtClientX = (clientX: number, rect: DOMRect) => { const timeAtClientX = (clientX: number, rect: DOMRect) => {
+400 -267
View File
@@ -11,7 +11,8 @@ import {
} from '../api' } from '../api'
import { buildBeatGrid, GRID_EPS } from '../lib/beatgrid' import { buildBeatGrid, GRID_EPS } from '../lib/beatgrid'
import { slotLabeller, useCaps } from '../lib/capabilities' import { slotLabeller, useCaps } from '../lib/capabilities'
import { CUE_TYPE_LABELS } from '../lib/cues' import { CUE_TYPE_LABELS, cueTypeColor } from '../lib/cues'
import { keyColor } from '../lib/format'
import { readOnlyShort, readOnlyNotice } from '../lib/platformCopy' import { readOnlyShort, readOnlyNotice } from '../lib/platformCopy'
import { analyzeWaveform, type WaveColumn } from '../lib/waveform' import { analyzeWaveform, type WaveColumn } from '../lib/waveform'
import { setAmbientFromArt } from '../lib/ambient' import { setAmbientFromArt } from '../lib/ambient'
@@ -19,10 +20,10 @@ import { Icon } from '../lib/icons'
import { ScratchEngine } from '../lib/scratchEngine' import { ScratchEngine } from '../lib/scratchEngine'
import { PlaybackEngine } from '../lib/playbackEngine' import { PlaybackEngine } from '../lib/playbackEngine'
import { AutoCueDialog, eventLabel } from './AutoCueDialog' import { AutoCueDialog, eventLabel } from './AutoCueDialog'
import { BeatJumpControls, BEAT_JUMP_SIZES } from './BeatJumpControls' import { ContextMenu, type MenuItem } from './ContextMenu'
import { GridControls } from './GridControls' import { BpmReadout, GridEditStrip, TempoControls } from './GridControls'
import { HotcueBar } from './HotcueBar' import { HotcueBar } from './HotcueBar'
import { LoopControls } from './LoopControls' import { LoopControls, LOOP_SIZES, type LoopMode } from './LoopControls'
import { MainWaveform, MIN_SEC, MAX_SEC, DEFAULT_SEC } from './MainWaveform' import { MainWaveform, MIN_SEC, MAX_SEC, DEFAULT_SEC } from './MainWaveform'
import { OverviewWaveform } from './OverviewWaveform' import { OverviewWaveform } from './OverviewWaveform'
@@ -46,11 +47,13 @@ interface Props {
cuesRefresh?: number cuesRefresh?: number
} }
function fmt(secs: number): string { /** m:ss.t — the deck's readouts show tenths, as a CDJ does. */
if (!isFinite(secs) || secs < 0) return '0:00' function fmtTenths(secs: number): string {
const m = Math.floor(secs / 60) if (!isFinite(secs) || secs < 0) secs = 0
const s = Math.floor(secs % 60) const tenths = Math.floor(secs * 10)
return `${m}:${s.toString().padStart(2, '0')}` const m = Math.floor(tenths / 600)
const s = Math.floor((tenths % 600) / 10)
return `${m.toString().padStart(2, '0')}:${s.toString().padStart(2, '0')}.${tenths % 10}`
} }
/** /**
@@ -69,7 +72,6 @@ function slotForDigit(code: string, slotCount: number): number | null {
return slot < slotCount ? slot : null return slot < slotCount ? slot : null
} }
const LOOP_SIZES = [1 / 32, 1 / 16, 1 / 8, 1 / 4, 1 / 2, 1, 2, 4, 8, 16, 32]
/** /**
* The DJ-style "prep strip" across the top of the window: transport controls on * The DJ-style "prep strip" across the top of the window: transport controls on
@@ -102,7 +104,13 @@ export function PrepStrip({
const [selectedSlot, setSelectedSlot] = useState<number | null>(null) const [selectedSlot, setSelectedSlot] = useState<number | null>(null)
const [cuePoint, setCuePoint] = useState(0) // floating "CUE" point (frontend-only) const [cuePoint, setCuePoint] = useState(0) // floating "CUE" point (frontend-only)
const [secPerView, setSecPerView] = useState(DEFAULT_SEC) // main-waveform zoom (persisted) const [secPerView, setSecPerView] = useState(DEFAULT_SEC) // main-waveform zoom (persisted)
const [jumpBeats, setJumpBeats] = useState(4) // beat-jump size in beats (persisted) // ONE size, in beats, for beat loops and beat jump alike (persisted).
const [beatSize, setBeatSize] = useState(4)
const [loopMode, setLoopMode] = useState<LoopMode>('beat')
// Grid mode swaps the hotcue pads for the grid-editing strip.
const [gridMode, setGridMode] = useState(false)
const [padMenu, setPadMenu] = useState<{ slot: number; x: number; y: number } | null>(null)
const [renamingSlot, setRenamingSlot] = useState<number | null>(null)
// Loop state (transient — persisted only when saved as a hotcue later). // Loop state (transient — persisted only when saved as a hotcue later).
const [loopRegion, setLoopRegion] = useState<{ start: number; end: number } | null>(null) const [loopRegion, setLoopRegion] = useState<{ start: number; end: number } | null>(null)
@@ -154,25 +162,28 @@ export function PrepStrip({
} }
}, [secPerView]) }, [secPerView])
// Beat-jump size persists the same way (survives track switches + restarts). // The loop/jump size persists the same way (survives track switches +
const jumpHydratedRef = useRef(false) // restarts). `beatJumpBeats` is its name from when only beat jump had a size;
const jumpSaveTimer = useRef<number | null>(null) // it is read once so an upgrade keeps the user's choice.
const sizeHydratedRef = useRef(false)
const sizeSaveTimer = useRef<number | null>(null)
useEffect(() => { useEffect(() => {
if (jumpHydratedRef.current || !prefsQuery.data) return if (sizeHydratedRef.current || !prefsQuery.data) return
jumpHydratedRef.current = true sizeHydratedRef.current = true
const b = (prefsQuery.data as { beatJumpBeats?: unknown }).beatJumpBeats const prefs = prefsQuery.data as { beatSize?: unknown; beatJumpBeats?: unknown }
if (typeof b === 'number' && BEAT_JUMP_SIZES.includes(b)) setJumpBeats(b) const b = prefs.beatSize ?? prefs.beatJumpBeats
if (typeof b === 'number' && LOOP_SIZES.includes(b)) setBeatSize(b)
}, [prefsQuery.data]) }, [prefsQuery.data])
useEffect(() => { useEffect(() => {
if (!jumpHydratedRef.current) return // don't clobber saved prefs pre-hydration if (!sizeHydratedRef.current) return // don't clobber saved prefs pre-hydration
if (jumpSaveTimer.current) window.clearTimeout(jumpSaveTimer.current) if (sizeSaveTimer.current) window.clearTimeout(sizeSaveTimer.current)
jumpSaveTimer.current = window.setTimeout(() => { sizeSaveTimer.current = window.setTimeout(() => {
api.patchPrefs({ beatJumpBeats: jumpBeats }).catch(() => {}) api.patchPrefs({ beatSize }).catch(() => {})
}, 500) }, 500)
return () => { return () => {
if (jumpSaveTimer.current) window.clearTimeout(jumpSaveTimer.current) if (sizeSaveTimer.current) window.clearTimeout(sizeSaveTimer.current)
} }
}, [jumpBeats]) }, [beatSize])
const getCtx = (): AudioContext => { const getCtx = (): AudioContext => {
if (!audioCtxRef.current) { if (!audioCtxRef.current) {
@@ -219,6 +230,8 @@ export function PrepStrip({
setDuration(0) setDuration(0)
setReady(false) setReady(false)
setSelectedSlot(null) setSelectedSlot(null)
setPadMenu(null)
setRenamingSlot(null)
setLoopRegion(null) setLoopRegion(null)
setLoopActive(false) setLoopActive(false)
setActiveBeats(null) setActiveBeats(null)
@@ -445,29 +458,42 @@ export function PrepStrip({
seek(t) seek(t)
} }
// ---- beat jump -------------------------------------------------------- // ---- beat jump / loop move ------------------------------------------
// Step the jump size through BEAT_JUMP_SIZES, clamping at both ends (no wrap). // ‹ › (and ←/→): an engaged loop MOVES by its own length and keeps playing,
const stepJumpSize = (dir: -1 | 1) => { // Traktor-style; otherwise the playhead jumps `beatSize` beats. Both preserve
setJumpBeats((b) => { // sub-beat phase (pure translation, no grid snap), and seek() keeps the
const i = BEAT_JUMP_SIZES.indexOf(b) // play/pause state.
const next = Math.min(BEAT_JUMP_SIZES.length - 1, Math.max(0, (i < 0 ? 4 : i) + dir)) const moveOrJump = (dir: -1 | 1) => {
return BEAT_JUMP_SIZES[next]
})
}
// Move the playhead exactly `jumpBeats` beats fwd/back, preserving sub-beat
// phase (pure translation, no grid snap). Like seekManual, jumping escapes an
// active loop. seek() clamps to [0, duration], preserves play/pause state.
const beatJump = (dir: -1 | 1) => {
const eng = playbackRef.current const eng = playbackRef.current
if (!eng || !grid) return if (!eng || !eng.ready) return
if (loopActive) { if (loopActive && loopRegion) {
eng.setLoopEnabled(false) const { start, end } = loopRegion
setLoopActive(false) // A beat loop moves in BEATS, so it lands right across a tempo change; a
// manual loop has no beat length, so it moves by its duration.
let nStart: number
let nEnd: number
if (activeBeats != null && grid) {
nStart = grid.advanceBeats(start, dir * activeBeats)
nEnd = grid.advanceBeats(nStart, activeBeats)
} else {
const len = end - start
nStart = start + dir * len
nEnd = nStart + len
}
if (nStart < 0 || nEnd > duration) return // would leave the track
// The playhead travels with the loop, keeping its place inside it. The
// NEW loop is set first: the engine's seek honours the loop in force, so
// seeking first would wrap the playhead straight back into the old one.
const pos = eng.getPosition() + (nStart - start)
engagLoop(nStart, nEnd, activeBeats)
eng.seek(Math.min(nEnd - 0.001, Math.max(nStart, pos)))
setCurrent(eng.getPosition())
return
} }
if (!grid) return
// Phase is preserved in BEAT space, so a jump crossing a tempo change lands // Phase is preserved in BEAT space, so a jump crossing a tempo change lands
// on the musically right beat rather than a fixed number of seconds away. // on the musically right beat rather than a fixed number of seconds away.
eng.seek(grid.advanceBeats(eng.getPosition(), dir * jumpBeats)) eng.seek(grid.advanceBeats(eng.getPosition(), dir * beatSize))
setCurrent(eng.getPosition()) setCurrent(eng.getPosition())
} }
@@ -593,6 +619,21 @@ export function PrepStrip({
setCurrent(eng.getPosition()) setCurrent(eng.getPosition())
} }
// − / + (and Cmd/Ctrl+↓/↑): step the shared size, clamping at both ends. An
// engaged BEAT loop follows it — halving or doubling from its locked start, as
// on a CDJ. A manual loop has no beat size to follow, so it is left alone.
const stepSize = (dir: -1 | 1) => {
const i = LOOP_SIZES.indexOf(beatSize)
const next = LOOP_SIZES[Math.min(LOOP_SIZES.length - 1, Math.max(0, (i < 0 ? 7 : i) + dir))]
if (next === beatSize) return
setBeatSize(next)
if (loopActive && activeBeats != null) setBeatLoop(next)
}
// The size key: a loop of exactly this size switches off; otherwise a loop of
// this size is set (from the playhead, or resized from an engaged loop's start).
const toggleSizeLoop = () => setBeatLoop(beatSize)
// A beat loop's end is stored in seconds, so editing the tempo of a marker // A beat loop's end is stored in seconds, so editing the tempo of a marker
// inside it would silently detune it. Re-derive the end whenever the grid // inside it would silently detune it. Re-derive the end whenever the grid
// changes, keeping the loop the beat length the user actually asked for. // changes, keeping the loop the beat length the user actually asked for.
@@ -745,22 +786,26 @@ export function PrepStrip({
onNotify?.(placed ? 'success' : 'error', parts.join(' · ')) onNotify?.(placed ? 'success' : 'error', parts.join(' · '))
} }
const changeSelectedType = async (type: CueType) => { const setSlotType = async (slot: number, type: CueType) => {
if (!track || selectedSlot == null) return if (!track) return
if (refuseCueEdit()) return if (refuseCueEdit()) return
try { try {
applyCueEdit(await api.setCueType(track.id, selectedSlot, type)) applyCueEdit(await api.setCueType(track.id, slot, type))
} catch (e) { } catch (e) {
onError?.((e as Error).message) onError?.((e as Error).message)
} }
} }
const deleteSelected = async () => { // Renaming re-sets the slot with its own position, type and length plus the
if (!track || selectedSlot == null) return // new name — the adapter's set_cue replaces a slot, and keeps a name only
// when called without one. An empty name clears it.
const renameSlot = async (slot: number, name: string) => {
setRenamingSlot(null)
const cue = hotcueAt(slot)
if (!track || !cue) return
if (refuseCueEdit()) return if (refuseCueEdit()) return
try { try {
applyCueEdit(await api.deleteCue(track.id, selectedSlot)) applyCueEdit(await api.createCue(track.id, slot, cue.start, cue.type, cue.length, name))
setSelectedSlot(null)
} catch (e) { } catch (e) {
onError?.((e as Error).message) onError?.((e as Error).message)
} }
@@ -788,8 +833,6 @@ export function PrepStrip({
const markerHitSec = Math.max(0.01, secPerView / 250) const markerHitSec = Math.max(0.01, secPerView / 250)
const atMarker = !!grid && grid.isOnMarker(current, markerHitSec) const atMarker = !!grid && grid.isOnMarker(current, markerHitSec)
const beforeFirstMarker = !!grid && current < grid.markers[0].start - GRID_EPS const beforeFirstMarker = !!grid && current < grid.markers[0].start - GRID_EPS
// Beat jump needs a grid to size beats; disabled on ungridded tracks.
const canBeatJump = ready && grid != null
const playheadNow = () => playbackRef.current?.getPosition() ?? current const playheadNow = () => playbackRef.current?.getPosition() ?? current
@@ -885,8 +928,9 @@ export function PrepStrip({
// ---- keyboard shortcuts ---------------------------------------------- // ---- keyboard shortcuts ----------------------------------------------
// Space → play/pause; 1–8 → the matching hotcue slot; Shift+1–8 → delete it. // Space → play/pause; 1–8 → the matching hotcue slot; Shift+1–8 → delete it.
// ←/→ → beat jump; Shift+←/→ → step between grid markers; Cmd/Ctrl+↑/↓ → // ←/→ → beat jump, or move an engaged loop; Shift+←/→ → step between grid
// beat jump size (Shift+↑/↓ is the track table's extend-selection). // markers; Cmd/Ctrl+↑/↓ → the loop/jump size, resizing an engaged beat loop
// (Shift+↑/↓ is the track table's extend-selection).
// Digits are read from e.code (layout-/Shift-independent) and a ref holds the // Digits are read from e.code (layout-/Shift-independent) and a ref holds the
// latest handlers so the listener attaches once and never goes stale. // latest handlers so the listener attaches once and never goes stale.
const shortcutsRef = useRef({ const shortcutsRef = useRef({
@@ -896,8 +940,8 @@ export function PrepStrip({
deleteHotcueSlot, deleteHotcueSlot,
onCuePress, onCuePress,
onCueRelease, onCueRelease,
beatJump, moveOrJump,
stepJumpSize, stepSize,
prevMarker, prevMarker,
nextMarker, nextMarker,
slotCount, slotCount,
@@ -909,8 +953,8 @@ export function PrepStrip({
deleteHotcueSlot, deleteHotcueSlot,
onCuePress, onCuePress,
onCueRelease, onCueRelease,
beatJump, moveOrJump,
stepJumpSize, stepSize,
prevMarker, prevMarker,
nextMarker, nextMarker,
slotCount, slotCount,
@@ -925,7 +969,7 @@ export function PrepStrip({
if ((e.metaKey || e.ctrlKey) && !e.altKey && !e.shiftKey && if ((e.metaKey || e.ctrlKey) && !e.altKey && !e.shiftKey &&
(e.code === 'ArrowUp' || e.code === 'ArrowDown')) { (e.code === 'ArrowUp' || e.code === 'ArrowDown')) {
e.preventDefault() e.preventDefault()
shortcutsRef.current.stepJumpSize(e.code === 'ArrowUp' ? 1 : -1) shortcutsRef.current.stepSize(e.code === 'ArrowUp' ? 1 : -1)
return return
} }
if (e.metaKey || e.ctrlKey || e.altKey) return if (e.metaKey || e.ctrlKey || e.altKey) return
@@ -943,13 +987,13 @@ export function PrepStrip({
if (e.code === 'ArrowLeft') { if (e.code === 'ArrowLeft') {
e.preventDefault() e.preventDefault()
if (e.shiftKey) shortcutsRef.current.prevMarker() if (e.shiftKey) shortcutsRef.current.prevMarker()
else shortcutsRef.current.beatJump(-1) else shortcutsRef.current.moveOrJump(-1)
return return
} }
if (e.code === 'ArrowRight') { if (e.code === 'ArrowRight') {
e.preventDefault() e.preventDefault()
if (e.shiftKey) shortcutsRef.current.nextMarker() if (e.shiftKey) shortcutsRef.current.nextMarker()
else shortcutsRef.current.beatJump(1) else shortcutsRef.current.moveOrJump(1)
return return
} }
const slot = slotForDigit(e.code, shortcutsRef.current.slotCount) const slot = slotForDigit(e.code, shortcutsRef.current.slotCount)
@@ -973,240 +1017,329 @@ export function PrepStrip({
} }
}, []) }, [])
const selectedCue = selectedSlot != null ? hotcueAt(selectedSlot) : null
const showWaves = track && cols && waveStatus === 'ready' const showWaves = track && cols && waveStatus === 'ready'
const activeLoop = loopActive && loopRegion ? loopRegion : null const activeLoop = loopActive && loopRegion ? loopRegion : null
const markerCount = grid?.count ?? 0
const subtitle = track
? [track.artist ?? 'Unknown artist', track.album, track.genre].filter(Boolean).join(' · ')
: ''
// The pad's right-click menu: its type (as one-click choices, the current one
// ticked), Rename, Delete. A cue the adapter will not edit gets the same menu
// disabled, so the reason is visible instead of the menu silently not opening.
const padMenuItems = (slot: number): MenuItem[] => {
const cue = hotcueAt(slot)
if (!cue) return []
const locked = !cue.editable
const items: MenuItem[] = []
if (cue.type === 'loop') {
items.push({ heading: `Hotcue ${slotLabel(slot)} · Loop` })
} else if (pointCueTypes.length > 1) {
items.push({ heading: `Hotcue ${slotLabel(slot)} · Type` })
for (const t of pointCueTypes) {
const color = cueTypeColor(t)
items.push({
label: CUE_TYPE_LABELS[t],
icon: (
<span
className="block h-2 w-2 rounded-full"
style={{ background: color, boxShadow: `0 0 6px ${color}` }}
/>
),
hint: t === cue.type ? '✓' : undefined,
disabled: locked,
onClick: () => t !== cue.type && void setSlotType(slot, t),
})
}
} else {
items.push({ heading: `Hotcue ${slotLabel(slot)}` })
}
if (locked) items.push({ heading: 'Managed by the DJ app — not editable here' })
items.push({ separator: true })
items.push({
label: 'Rename…',
disabled: locked,
onClick: () => !refuseCueEdit() && setRenamingSlot(slot),
})
items.push({
label: 'Delete',
danger: true,
disabled: locked,
onClick: () => void deleteHotcueSlot(slot),
})
return items
}
const DIVIDER = <span aria-hidden className="h-7 w-px shrink-0 bg-line" />
return ( return (
<div className="glass flex h-[25.5rem] shrink-0 items-stretch gap-3 p-3"> <div className="glass flex h-[19.75rem] shrink-0 flex-col gap-2 p-4">
{/* Controls */} {/* ---- Header: the track, its readouts, the analysis actions ---- */}
<div className="flex w-72 shrink-0 flex-col gap-3 px-1 py-1"> <div className="flex h-12 shrink-0 items-center gap-3">
<div className="flex min-w-0 items-center gap-3"> <CoverThumb trackId={track && !fromDevice ? track.id : null} />
<CoverThumb trackId={track && !fromDevice ? track.id : null} /> <div className="min-w-0 flex-1">
<div className="min-w-0 flex-1">
{track ? ( {track ? (
<> <>
<div className="truncate text-[15px] font-semibold tracking-tight text-text" title={track.title ?? ''}> <div className="flex min-w-0 items-center gap-2">
{track.title ?? 'Untitled'} <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>
<div className="truncate text-xs text-muted" title={track.artist ?? ''}> <div className="truncate text-[13px] text-muted" title={subtitle}>
{track.artist ?? 'Unknown artist'} {subtitle}
</div> </div>
{/* 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 themselves report the reason when pressed. */}
{readOnlyShort(caps) && (
<div
className="mt-1 inline-block rounded-md bg-ink-800 px-1.5 py-0.5 text-[10px] uppercase tracking-wider text-muted"
title={readOnlyNotice(caps) ?? ''}
>
{readOnlyShort(caps)}
</div>
)}
</> </>
) : ( ) : (
<div className="text-xs uppercase tracking-wider text-faint">No track loaded</div> <div className="text-xs uppercase tracking-wider text-faint">No track loaded</div>
)} )}
</div>
</div> </div>
{track && ( <div className="well flex h-11 shrink-0 items-stretch rounded-xl">
<GridControls <div className="flex flex-col justify-center gap-px px-4">
bpm={activeMarker?.bpm ?? null} <span className="text-[10px] tracking-[0.08em] text-faint">ELAPSED</span>
<span className="font-mono text-[17px] font-medium">{fmtTenths(current)}</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">−{fmtTenths(Math.max(0, duration - current))}</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={setBpm} />
</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="Detect BPM and first beat, then set the grid + hotcue 1 (fix the octave with ÷2 / ×2)"
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>
</div>
{/* ---- Waveforms ---- */}
{!track ? (
<div className="well flex min-h-0 flex-1 items-center justify-center rounded-2xl text-xs text-faint">
Load a track to prep it
</div>
) : waveStatus === 'error' ? (
<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>
) : (
<>
<div className="well relative min-h-0 flex-1 overflow-hidden rounded-2xl">
{showWaves ? (
<MainWaveform
cols={cols}
currentTime={current}
duration={duration}
cues={cueData?.cues ?? []}
cuePoint={cuePoint}
grid={grid}
activeMarker={activeMarkerIndex}
emphasizeGrid={gridMode}
loop={activeLoop}
secPerView={secPerView}
onZoomChange={setSecPerView}
onSeek={seekManual}
onScratchStart={onScratchStart}
onScratchMove={onScratchMove}
onScratchEnd={onScratchEnd}
/>
) : (
<div className="flex h-full items-center justify-center text-xs text-faint">
Analysing waveform…
</div>
)}
</div>
<div className="well h-7 shrink-0 overflow-hidden rounded-[9px]">
{showWaves && (
<OverviewWaveform
cols={cols}
currentTime={current}
duration={duration}
cues={cueData?.cues ?? []}
cuePoint={cuePoint}
loop={activeLoop}
onSeek={seekManual}
/>
)}
</div>
</>
)}
{/* ---- Controls: transport · loop/jump · pads or grid · tempo ---- */}
<div className="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}
className="flex h-10 w-14 shrink-0 items-center justify-center rounded-xl bg-gold/10 font-mono text-[13px] font-semibold tracking-wider text-gold shadow-[inset_0_1px_0_rgb(255_255_255/0.12),inset_0_0_0_1px_rgb(255_200_97/0.4)] transition-colors hover:bg-gold/15 disabled:cursor-not-allowed disabled:opacity-40"
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}
onLoopIn={loopIn}
onLoopOut={loopOut}
onToggleLoop={toggleLoop}
onMove={moveOrJump}
/>
{DIVIDER}
{gridMode ? (
<GridEditStrip
markerIndex={activeMarkerIndex} markerIndex={activeMarkerIndex}
markerCount={grid?.count ?? 0} markerCount={markerCount}
markerStart={activeMarker?.start ?? null} markerStart={activeMarker?.start ?? null}
atMarker={atMarker} atMarker={atMarker}
beforeFirst={beforeFirstMarker} beforeFirst={beforeFirstMarker}
locked={cueData?.grid_locked ?? false}
canReset={originalGridRef.current != null} canReset={originalGridRef.current != null}
onSetBpm={setBpm} onPrevMarker={prevMarker}
onNudgeBpm={nudgeBpm} onNextMarker={nextMarker}
onHalve={halveBpm}
onDouble={doubleBpm}
onNudgeMarker={nudgeGrid} onNudgeMarker={nudgeGrid}
onAddMarker={addMarkerHere} onAddMarker={addMarkerHere}
onDeleteMarker={deleteMarkerHere} onDeleteMarker={deleteMarkerHere}
onPrevMarker={prevMarker}
onNextMarker={nextMarker}
onReset={resetGrid}
onToggleLock={toggleLock}
onDeleteGrid={deleteGrid} onDeleteGrid={deleteGrid}
onAnalyze={runAnalyzeGrid} onReset={resetGrid}
analyzing={gridBusy} />
) : (
<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}
<div className="mt-auto flex items-center gap-2"> <TempoControls
<button bpm={activeMarker?.bpm ?? null}
onPointerDown={(e) => { locked={cueData?.grid_locked ?? false}
e.preventDefault() lockable={caps.grid.lockable}
e.currentTarget.setPointerCapture(e.pointerId) flexible={markerCount > 1}
onCuePress() markerIndex={activeMarkerIndex}
}} onSetBpm={setBpm}
onPointerUp={onCueRelease} onNudgeBpm={nudgeBpm}
onPointerCancel={onCueRelease} onHalve={halveBpm}
disabled={!ready} onDouble={doubleBpm}
className="flex h-11 items-center justify-center rounded-xl bg-gold/10 px-4 font-mono text-sm font-semibold tracking-wider text-gold shadow-[inset_0_1px_0_rgb(255_255_255/0.12),inset_0_0_0_1px_rgb(255_200_97/0.4)] transition-colors hover:bg-gold/15 disabled:cursor-not-allowed disabled:opacity-40" onToggleLock={toggleLock}
title="Cue — set the cue point (paused), hold to preview from it, or jump back to it (playing)"
>
CUE
</button>
<button
onClick={toggle}
disabled={!ready}
className={
'flex h-11 w-11 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' : 'Play'}
>
<Icon name={playing ? 'pause' : 'play'} size={18} />
</button>
<div className="font-mono text-[15px] font-medium text-muted">
{fmt(current)} / {fmt(duration)}
</div>
</div>
<BeatJumpControls
beats={jumpBeats}
onStep={stepJumpSize}
onJump={beatJump}
disabled={!canBeatJump}
/> />
<button
onClick={() => {
setGridMode((g) => !g)
setPadMenu(null)
setRenamingSlot(null)
}}
aria-pressed={gridMode}
disabled={!track}
title={gridMode ? 'Back to the hotcue pads' : 'Edit the beatgrid: markers, phase, reset'}
className={`flex h-10 shrink-0 items-center gap-1.5 rounded-xl px-3 text-xs font-semibold transition-colors disabled:opacity-40 ${
gridMode
? 'bg-gold/15 text-gold shadow-[inset_0_0_0_1px_rgb(255_200_97/0.5),0_0_16px_-4px_rgb(255_200_97/0.6)]'
: 'btn-glass text-text'
}`}
>
<Icon name="grid" size={14} />
Grid
</button>
</div> </div>
{/* Waveforms + loop/hotcue controls. */} {padMenu && (
<div className="relative flex min-w-0 flex-1 flex-col"> <ContextMenu
{!track ? ( key={`${padMenu.slot}:${padMenu.x}:${padMenu.y}`}
<div className="well flex flex-1 items-center justify-center rounded-2xl text-xs text-faint"> x={padMenu.x}
Load a track to prep it y={padMenu.y}
</div> items={padMenuItems(padMenu.slot)}
) : waveStatus === 'error' ? ( onClose={() => setPadMenu(null)}
<div className="well flex 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>
) : (
<>
<div className="well relative min-h-0 flex-1 overflow-hidden rounded-2xl">
{showWaves ? (
<MainWaveform
cols={cols}
currentTime={current}
duration={duration}
cues={cueData?.cues ?? []}
cuePoint={cuePoint}
grid={grid}
activeMarker={activeMarkerIndex}
loop={activeLoop}
secPerView={secPerView}
onZoomChange={setSecPerView}
onSeek={seekManual}
onScratchStart={onScratchStart}
onScratchMove={onScratchMove}
onScratchEnd={onScratchEnd}
/>
) : (
<div className="flex h-full items-center justify-center text-xs text-faint">
Analysing waveform…
</div>
)}
</div>
<div className="well mt-2 h-10 shrink-0 overflow-hidden rounded-xl">
{showWaves && (
<OverviewWaveform
cols={cols}
currentTime={current}
duration={duration}
cues={cueData?.cues ?? []}
cuePoint={cuePoint}
loop={activeLoop}
onSeek={seekManual}
/>
)}
</div>
<LoopControls
hasGrid={grid != null}
active={loopActive}
activeBeats={activeBeats}
canToggle={loopRegion != null}
snap={snap}
onToggleSnap={() => setSnap((s) => !s)}
onSetLoop={setBeatLoop}
onLoopIn={loopIn}
onLoopOut={loopOut}
onToggleActive={toggleLoop}
/>
{/* Hotcue row: label · 8 slots · type of selected cue · delete. */}
<div className="flex h-12 shrink-0 items-stretch gap-1.5 pt-2">
<span className="flex w-12 shrink-0 items-center text-[10px] font-semibold uppercase tracking-wider text-faint">
Cues
</span>
<HotcueBar
cues={cueData?.cues ?? []}
slotCount={slotCount}
slotLabel={slotLabel}
selectedSlot={selectedSlot}
onSlotPress={onSlotPress}
onSlotRelease={onSlotRelease}
/>
<div className="btn-glass flex w-28 shrink-0 items-center justify-center rounded-lg px-1">
{selectedCue && selectedCue.type === 'loop' ? (
<span className="text-sm font-semibold text-mint">Loop</span>
) : pointCueTypes.length < 2 ? (
// One point type means there is nothing to choose between —
// show it rather than a dropdown that cannot change anything.
<span className="text-sm font-semibold text-text">
{selectedCue ? CUE_TYPE_LABELS[selectedCue.type] : '—'}
</span>
) : (
<select
value={selectedCue ? selectedCue.type : ''}
disabled={!selectedCue}
onChange={(e) => changeSelectedType(e.target.value as CueType)}
className="w-full bg-transparent text-center text-sm font-semibold text-text outline-none disabled:opacity-40"
>
{!selectedCue && <option value="">—</option>}
{pointCueTypes.map((t) => (
<option key={t} value={t}>
{CUE_TYPE_LABELS[t]}
</option>
))}
</select>
)}
</div>
<button
onClick={openAutoHotcues}
disabled={!canAutoCue}
title={
canAutoCue
? 'Place hotcues on the track\'s drops, breakdowns and other sections'
: 'Set a beatgrid first'
}
className="btn-glass flex w-[4.5rem] shrink-0 items-center justify-center gap-1.5 rounded-lg text-[11px] font-semibold uppercase tracking-wider text-muted hover:text-accent disabled:opacity-30 disabled:hover:text-muted"
>
<Icon name="sparkle" size={14} />
Auto
</button>
<button
onClick={deleteSelected}
disabled={!selectedCue}
title="Delete selected hotcue"
aria-label="Delete selected hotcue"
className="btn-glass flex w-11 shrink-0 items-center justify-center rounded-lg text-muted hover:text-pink disabled:opacity-30 disabled:hover:text-muted"
>
<Icon name="trash" size={15} />
</button>
</div>
</>
)}
</div>
{autoOpen && track && ( {autoOpen && track && (
<AutoCueDialog <AutoCueDialog
track={track} track={track}
+4 -2
View File
@@ -31,12 +31,14 @@ function sections(slots: number): Section[] {
rows: [ rows: [
{ keys: [['Space']], action: 'Play / pause' }, { keys: [['Space']], action: 'Play / pause' },
{ keys: [['C']], action: 'CUE — jump back, set, or hold to preview' }, { keys: [['C']], action: 'CUE — jump back, set, or hold to preview' },
{ keys: [['←'], ['→']], action: 'Beat jump back / forward' }, { keys: [['←'], ['→']], action: 'Beat jump back / forward — or move the loop, while one plays' },
{ keys: [[MOD, '↓'], [MOD, '↑']], action: 'Smaller / larger beat jump' }, { keys: [[MOD, '↓'], [MOD, '↑']], action: 'Halve / double the loop and jump size' },
{ keys: [['Shift', '←'], ['Shift', '→']], action: 'Previous / next grid marker' }, { keys: [['Shift', '←'], ['Shift', '→']], action: 'Previous / next grid marker' },
{ keys: [[pads]], action: 'Hotcue — set if empty, else jump (hold to preview)' }, { keys: [[pads]], action: 'Hotcue — set if empty, else jump (hold to preview)' },
{ keys: [['Shift', pads]], action: 'Delete hotcue' }, { keys: [['Shift', pads]], action: 'Delete hotcue' },
{ keys: [['Drag waveform']], action: 'Scratch' }, { keys: [['Drag waveform']], action: 'Scratch' },
{ keys: [[MOD, 'Scroll']], action: 'Zoom the waveform' },
{ keys: [['Right-click', 'pad']], action: 'Hotcue type, rename, delete' },
], ],
}, },
{ {
+8
View File
@@ -104,6 +104,14 @@ textarea,
user-select: text; user-select: text;
} }
/* Keyboard focus: a soft accent ring instead of the browser's hard outline,
which reads as a white box on glass. :focus-visible only, so a mouse click
leaves no ring behind. */
:focus-visible {
outline: 2px solid color-mix(in oklab, var(--color-accent) 75%, transparent);
outline-offset: 2px;
}
input::placeholder, input::placeholder,
textarea::placeholder { textarea::placeholder {
color: var(--color-faint); color: var(--color-faint);
+5 -1
View File
@@ -255,6 +255,8 @@ export function drawBeatgrid(
h: number, h: number,
dpr: number, dpr: number,
activeMarker: number, activeMarker: number,
/** Grid mode: the grid is what is being edited, so it is drawn brighter. */
emphasize = false,
): void { ): void {
if (endSec <= startSec) return if (endSec <= startSec) return
const span = endSec - startSec const span = endSec - startSec
@@ -295,7 +297,9 @@ export function drawBeatgrid(
// Translucent white with no outline: the grid should read as a ruler laid // Translucent white with no outline: the grid should read as a ruler laid
// over the waveform, not bars cut through it. Downbeats are clearly // over the waveform, not bars cut through it. Downbeats are clearly
// brighter, which is what grid editing needs to see. // brighter, which is what grid editing needs to see.
ctx.fillStyle = downbeat ? 'rgba(255,255,255,0.62)' : 'rgba(255,255,255,0.26)' ctx.fillStyle = downbeat
? `rgba(255,255,255,${emphasize ? 0.9 : 0.62})`
: `rgba(255,255,255,${emphasize ? 0.5 : 0.26})`
ctx.fillRect(x - Math.floor(lw / 2), 0, lw, h) ctx.fillRect(x - Math.floor(lw / 2), 0, lw, h)
} }
} }
+1
View File
@@ -85,6 +85,7 @@ const PATHS = {
), ),
pencil: <path d="M4 20h4L19 9l-4-4L4 16zM13.5 6.5l4 4" strokeLinejoin="round" />, pencil: <path d="M4 20h4L19 9l-4-4L4 16zM13.5 6.5l4 4" strokeLinejoin="round" />,
plus: <path d="M12 5v14M5 12h14" />, plus: <path d="M12 5v14M5 12h14" />,
grid: <path d="M5 3v18M10 3v18M15 3v18M20 3v18" />,
} as const } as const
export type IconName = keyof typeof PATHS export type IconName = keyof typeof PATHS