Improved prep control UI

This commit is contained in:
Ben committed 2026-07-04 20:14:03 +02:00
1 parent fdcae5e0f5
commit 14f5bf3774
3 files changed
+60 -92

No files matched your search

+8 -7
View File
@@ -10,13 +10,14 @@ interface Props {
const SLOTS = [0, 1, 2, 3, 4, 5, 6, 7] // Traktor hotcue slots → labelled 1–8 const SLOTS = [0, 1, 2, 3, 4, 5, 6, 7] // Traktor hotcue slots → labelled 1–8
/** /**
* Traktor-style hotcue bar: all 8 hotcue slots, colour-coded by cue type when * The 8 hotcue slots, colour-coded by cue type when assigned (gray when empty).
* assigned (gray when empty). Clicking a slot selects it — the parent decides * Rendered as a flex-1 group inside the hotcue row; the parent supplies the row
* whether that creates a cue (empty slot) or jumps to it (assigned slot). * chrome and the trailing edit controls. Clicking a slot delegates to the parent
* (create when empty, jump/trigger when assigned).
*/ */
export function HotcueBar({ cues, selectedSlot, onSlotClick }: Props) { export function HotcueBar({ cues, selectedSlot, onSlotClick }: Props) {
return ( return (
<div className="flex h-8 shrink-0 items-stretch gap-px border-t border-line bg-ink-950"> <div className="flex flex-1 items-stretch gap-px">
{SLOTS.map((slot) => { {SLOTS.map((slot) => {
const cue = cues.find((c) => c.hotcue === slot) ?? null const cue = cues.find((c) => c.hotcue === slot) ?? null
const selected = selectedSlot === slot const selected = selectedSlot === slot
@@ -34,9 +35,9 @@ export function HotcueBar({ cues, selectedSlot, onSlotClick }: Props) {
} }
style={color ? { backgroundColor: color, color: contrastText(color) } : undefined} style={color ? { backgroundColor: color, color: contrastText(color) } : undefined}
className={ className={
'flex flex-1 items-center justify-center text-xs font-semibold transition-[filter] hover:brightness-110 ' + 'relative flex flex-1 items-center justify-center text-sm font-semibold transition-colors ' +
(color ? '' : 'text-faint hover:bg-ink-900 ') + (color ? 'hover:brightness-110' : 'bg-ink-900 text-faint hover:bg-ink-800') +
(selected ? 'ring-2 ring-inset ring-white/80' : '') (selected ? ' ring-2 ring-inset ring-white/80' : '')
} }
> >
{slot + 1} {slot + 1}
+23 -56
View File
@@ -1,5 +1,3 @@
import { useState } from 'react'
interface Props { interface Props {
bpm: number | null // beat-loops need a grid; buttons disable without one bpm: number | null // beat-loops need a grid; buttons disable without one
active: boolean // a loop is currently engaged active: boolean // a loop is currently engaged
@@ -13,15 +11,17 @@ interface Props {
onToggleActive: () => void onToggleActive: () => void
} }
// Fixed beat-loop sizes, 1/32 → 32 beats. // All fixed beat-loop sizes, 1/32 → 32 beats, shown at once.
const SIZES = [1 / 32, 1 / 16, 1 / 8, 1 / 4, 1 / 2, 1, 2, 4, 8, 16, 32] const SIZES = [1 / 32, 1 / 16, 1 / 8, 1 / 4, 1 / 2, 1, 2, 4, 8, 16, 32]
const WINDOW = 6 // sizes shown at once (Traktor-style), shifted with the arrows
const DEFAULT_START = 3 // start on 1/4 … 8
function label(size: number): string { 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 = 'flex items-center justify-center text-sm font-semibold transition-colors select-none'
const IDLE = 'bg-ink-900 text-text hover:bg-ink-800'
const OFF = 'disabled:opacity-30 disabled:hover:bg-ink-900'
export function LoopControls({ export function LoopControls({
bpm, bpm,
active, active,
@@ -34,37 +34,15 @@ export function LoopControls({
onLoopOut, onLoopOut,
onToggleActive, onToggleActive,
}: Props) { }: Props) {
const [start, setStart] = useState(DEFAULT_START)
const maxStart = SIZES.length - WINDOW
const visible = SIZES.slice(start, start + WINDOW)
const hasGrid = !!bpm && bpm > 0 const hasGrid = !!bpm && bpm > 0
const btn =
'flex h-6 min-w-8 items-center justify-center rounded px-1.5 text-xs font-semibold ' +
'border border-line text-muted hover:text-text disabled:opacity-30'
return ( return (
<div className="flex h-9 shrink-0 items-center gap-1.5 border-t border-line bg-ink-900 px-3"> <div className="flex h-10 shrink-0 items-stretch gap-px border-t border-line bg-ink-950">
<button <span className="flex w-16 items-center justify-center bg-ink-900 text-[10px] font-semibold uppercase tracking-wider text-faint">
onClick={onToggleSnap} Loop
title="Snap to the nearest beat" </span>
className={
'mr-1 rounded px-2 py-0.5 text-xs font-semibold uppercase tracking-wider ' +
(snap ? 'bg-accent text-ink-950' : 'border border-line text-muted hover:text-text')
}
>
Snap
</button>
<button {SIZES.map((size) => {
onClick={() => setStart((s) => Math.max(0, s - 1))}
disabled={start === 0}
className={btn}
title="Smaller sizes"
>
‹
</button>
{visible.map((size) => {
const isActive = active && activeBeats === size const isActive = active && activeBeats === size
return ( return (
<button <button
@@ -72,47 +50,36 @@ export function LoopControls({
onClick={() => onSetLoop(size)} onClick={() => onSetLoop(size)}
disabled={!hasGrid} disabled={!hasGrid}
title={hasGrid ? `${label(size)}-beat loop` : 'No beatgrid'} title={hasGrid ? `${label(size)}-beat loop` : 'No beatgrid'}
className={ className={`${CELL} ${OFF} flex-1 ${isActive ? 'bg-mint text-ink-950' : IDLE}`}
'flex h-6 min-w-9 items-center justify-center rounded px-1.5 text-xs font-semibold ' +
(isActive
? 'bg-mint text-ink-950'
: 'border border-line text-text hover:border-accent disabled:opacity-30')
}
> >
{label(size)} {label(size)}
</button> </button>
) )
})} })}
<button
onClick={() => setStart((s) => Math.min(maxStart, s + 1))}
disabled={start === maxStart}
className={btn}
title="Larger sizes"
>
›
</button>
<div className="mx-1 h-5 w-px bg-line" /> <button onClick={onLoopIn} className={`${CELL} ${IDLE} w-12`} title="Loop in at playhead">
<button onClick={onLoopIn} className={btn} title="Set loop in point at playhead">
IN IN
</button> </button>
<button onClick={onLoopOut} className={btn} title="Set loop out point at playhead"> <button onClick={onLoopOut} className={`${CELL} ${IDLE} w-12`} title="Loop out at playhead">
OUT OUT
</button> </button>
<button <button
onClick={onToggleActive} onClick={onToggleActive}
disabled={!canToggle} disabled={!canToggle}
title={active ? 'Disable loop' : 'Enable loop'} title={active ? 'Disable loop' : 'Enable loop'}
className={ className={`${CELL} ${OFF} w-12 text-base ${active ? 'bg-mint text-ink-950' : IDLE}`}
'flex h-6 min-w-9 items-center justify-center rounded px-2 text-sm ' +
(active
? 'bg-mint text-ink-950'
: 'border border-line text-muted hover:text-text disabled:opacity-30')
}
> >
⟳ ⟳
</button> </button>
<button
onClick={onToggleSnap}
title="Snap to the nearest beat"
className={`${CELL} w-16 text-[11px] uppercase tracking-wider ${
snap ? 'bg-accent text-ink-950' : `${IDLE} text-muted`
}`}
>
Snap
</button>
</div> </div>
) )
} }
+29 -29
View File
@@ -490,40 +490,40 @@ export function PrepStrip({ track, onError }: Props) {
onToggleActive={toggleLoop} onToggleActive={toggleLoop}
/> />
<HotcueBar {/* Hotcue row: label · 8 slots · type of selected cue · delete. */}
cues={cueData?.cues ?? []} <div className="flex h-10 shrink-0 items-stretch gap-px border-t border-line bg-ink-950">
selectedSlot={selectedSlot} <span className="flex w-16 items-center justify-center bg-ink-900 text-[10px] font-semibold uppercase tracking-wider text-faint">
onSlotClick={onSlotClick} Cues
/>
{/* Selected-hotcue editing: type + delete. */}
<div className="flex h-8 shrink-0 items-center gap-2 border-t border-line bg-ink-900 px-3 text-xs">
<span className="text-faint">
{selectedCue ? `Hotcue ${(selectedSlot ?? 0) + 1}` : 'No hotcue selected'}
</span> </span>
<div className="flex-1" /> <HotcueBar
{selectedCue && selectedCue.type === LOOP_TYPE ? ( cues={cueData?.cues ?? []}
<span className="rounded border border-line px-2 py-0.5 text-mint">Loop</span> selectedSlot={selectedSlot}
) : ( onSlotClick={onSlotClick}
<select />
value={selectedCue ? selectedCue.type : ''} <div className="flex w-28 items-center justify-center bg-ink-900 px-1">
disabled={!selectedCue} {selectedCue && selectedCue.type === LOOP_TYPE ? (
onChange={(e) => changeSelectedType(Number(e.target.value))} <span className="text-sm font-semibold text-mint">Loop</span>
className="rounded border border-line bg-ink-850 px-2 py-0.5 text-text outline-none focus:border-accent disabled:opacity-40" ) : (
> <select
{!selectedCue && <option value="">—</option>} value={selectedCue ? selectedCue.type : ''}
{CUE_TYPES.map((t) => ( disabled={!selectedCue}
<option key={t.value} value={t.value}> onChange={(e) => changeSelectedType(Number(e.target.value))}
{t.label} className="w-full bg-transparent text-center text-sm font-semibold text-text outline-none disabled:opacity-40"
</option> >
))} {!selectedCue && <option value="">—</option>}
</select> {CUE_TYPES.map((t) => (
)} <option key={t.value} value={t.value}>
{t.label}
</option>
))}
</select>
)}
</div>
<button <button
onClick={deleteSelected} onClick={deleteSelected}
disabled={!selectedCue} disabled={!selectedCue}
title="Delete selected hotcue" title="Delete selected hotcue"
className="rounded border border-line px-2 py-0.5 text-muted hover:border-pink hover:text-pink disabled:opacity-40 disabled:hover:border-line disabled:hover:text-muted" className="flex w-12 items-center justify-center bg-ink-900 text-muted transition-colors hover:bg-ink-800 hover:text-pink disabled:opacity-30 disabled:hover:bg-ink-900 disabled:hover:text-muted"
> >
🗑 🗑
</button> </button>