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

+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>
)
}