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
+41 -73

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