Fixed hot cue scaling

This commit is contained in:
patben8 committed 2026-09-26 18:13:03 +02:00
1 parent 84947bb0bb
commit 90beeef226
4 files changed
+138 -28

No files matched your search

+82 -3
View File
@@ -1,4 +1,5 @@
import { useEffect, useRef, useState } from 'react'
import { useEffect, useRef, useState, type ReactNode } from 'react'
import { createPortal } from 'react-dom'
import { askConfirm } from '../lib/confirm'
import { Icon } from '../lib/icons'
import { MIN_TAPS, RESET_MS, TapTempo } from '../lib/tapTempo'
@@ -8,7 +9,8 @@ import { MIN_TAPS, RESET_MS, TapTempo } from '../lib/tapTempo'
// BpmReadout — the header's BPM: shows the governing marker's tempo, and
// is where an exact BPM is typed (click it).
// TempoControls — the everyday tempo tools, always on the control row:
// nudge ±0.01 / ±0.25, ÷2 ×2, tap tempo, lock.
// nudge ±0.01 / ±0.25, ÷2 ×2, tap tempo, lock. On a
// narrow window they fold into TempoFold's popover.
// GridEditStrip — only in Grid mode, in place of the hotcue pads: step
// between markers, nudge the marker ±1 / ±10 ms, add or
// delete a marker, delete the grid, reset it.
@@ -129,6 +131,7 @@ export function TempoControls({
onHalve,
onDouble,
onToggleLock,
className = '',
}: {
bpm: number | null
locked: boolean
@@ -143,6 +146,7 @@ export function TempoControls({
onHalve: () => void
onDouble: () => void
onToggleLock: () => void
className?: string
}) {
// One run of taps; its reading is shown on the button, so a press that is
// not yet enough to commit still visibly counts.
@@ -169,7 +173,7 @@ export function TempoControls({
const off = bpm == null
const of = flexible ? ` of marker ${markerIndex + 1}` : ''
return (
<div role="group" aria-label="Tempo" className="glass-group flex h-10 shrink-0 items-center gap-0.5 rounded-xl px-1">
<div role="group" aria-label="Tempo" className={`glass-group flex h-10 shrink-0 items-center gap-0.5 rounded-xl px-1 ${className}`}>
<button className={`${T_BTN} w-7`} onClick={() => onNudgeBpm(-0.25)} disabled={off} title={`BPM −0.25${of}`}>−−</button>
<button className={`${T_BTN} w-[22px]`} onClick={() => onNudgeBpm(-0.01)} disabled={off} title={`BPM −0.01${of}`}>−</button>
<button className={`${T_BTN} w-[22px]`} onClick={() => onNudgeBpm(0.01)} disabled={off} title={`BPM +0.01${of}`}>+</button>
@@ -200,6 +204,81 @@ export function TempoControls({
)
}
/**
* TempoControls folded into one button, for a control row too narrow to hold
* them beside the pads. The popover holds the same controls rather than a
* reduced set, and stays open while you tap — only a click elsewhere, Esc, or
* a window resize (which can unfold the row under it) closes it. Portalled,
* like every overlay: the deck's panel is a stacking context.
*/
export function TempoFold({
locked,
className = '',
children,
}: {
locked: boolean
className?: string
children: ReactNode
}) {
const [pos, setPos] = useState<{ x: number; y: number } | null>(null)
const buttonRef = useRef<HTMLButtonElement>(null)
const popRef = useRef<HTMLDivElement>(null)
useEffect(() => {
if (!pos) return
const close = () => setPos(null)
const onDown = (e: MouseEvent) => {
const t = e.target as Node
if (!popRef.current?.contains(t) && !buttonRef.current?.contains(t)) close()
}
const onKey = (e: KeyboardEvent) => e.key === 'Escape' && close()
document.addEventListener('mousedown', onDown)
window.addEventListener('keydown', onKey)
window.addEventListener('resize', close)
return () => {
document.removeEventListener('mousedown', onDown)
window.removeEventListener('keydown', onKey)
window.removeEventListener('resize', close)
}
}, [pos])
const toggle = () => {
if (pos) return setPos(null)
const r = buttonRef.current!.getBoundingClientRect()
// Right-aligned under the button: it sits near the row's right end, so
// hanging left keeps the popover on screen.
setPos({ x: window.innerWidth - r.right, y: r.bottom + 6 })
}
return (
<>
<button
ref={buttonRef}
onClick={toggle}
aria-expanded={pos != null}
title="Tempo — nudge, halve/double, tap, lock"
className={`h-10 shrink-0 items-center gap-1.5 rounded-xl px-3 font-mono text-xs font-semibold ${
pos ? 'is-selected text-text' : 'btn-glass text-text'
} ${className}`}
>
{locked && <Icon name="lock" size={12} strokeWidth={2.2} />}
BPM
<Icon name="chevronDown" size={12} strokeWidth={2.4} />
</button>
{pos &&
createPortal(
<div
ref={popRef}
role="dialog"
aria-label="Tempo"
className="glass-overlay fixed z-[70] !rounded-2xl p-1.5"
style={{ right: pos.x, top: pos.y }}
>
{children}
</div>,
document.body,
)}
</>
)
}
/** Grid mode: everything that fixes a grid, in place of the pads. */
export function GridEditStrip({
markerIndex,
+19 -6
View File
@@ -20,6 +20,10 @@ interface Props {
onRenameCancel: () => void
}
// The narrowest a pad gets (a letter-only square) and the gap between pads.
const PAD_MIN = 40
const PAD_GAP = 6
const READONLY_LABELS: Record<string, string> = {
platform_managed: 'Managed by the DJ app — not editable here',
}
@@ -51,8 +55,13 @@ export function HotcueBar({
return (
// 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">
// rather than stretching them into bars. It never goes below a bank of
// PAD_MIN pads: squeezed further, the pads' padding spilled them out of
// the group and over the tempo controls.
<div
className="flex flex-1 items-center gap-1.5"
style={{ minWidth: slotCount * PAD_MIN + (slotCount - 1) * PAD_GAP }}
>
{Array.from({ length: slotCount }, (_, i) => i).map((slot) => {
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
@@ -91,7 +100,11 @@ export function HotcueBar({
}
style={color ? padStyle(color, selected) : undefined}
className={
'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] ' +
// Each pad is a container, so it decides for itself when it is
// too narrow for a name — under 4rem wide (2.75rem inside its
// padding, which is what a container query measures) it is a
// letter-only square, whatever the bank size or the rest of the row.
'@container 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
? 'hover:brightness-115'
: // An empty pad gets the same dark ground, so the row reads as
@@ -101,7 +114,7 @@ export function HotcueBar({
}
>
<span
className="font-mono text-[11px] font-bold leading-none"
className="font-mono text-[11px] font-bold leading-none @max-[2.75rem]:self-center"
style={color ? { color: lighten(color) } : undefined}
>
{locked ? <Icon name="lock" size={11} strokeWidth={2.2} /> : slotLabel(slot)}
@@ -116,7 +129,7 @@ export function HotcueBar({
// 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 ${
className={`w-full truncate text-[11px] leading-none @max-[2.75rem]:hidden ${
cue && cue.name && cue.name !== 'n.n.' ? 'text-text' : 'text-text/60'
}`}
>
@@ -126,7 +139,7 @@ export function HotcueBar({
{/* The type icon, top right on the number's line — the name below
is free to run the full width. */}
{icon && color && (
<span className="absolute right-2 top-[7px] flex" style={{ color: lighten(color) }}>
<span className="absolute right-2 top-[7px] flex @max-[2.75rem]:hidden" style={{ color: lighten(color) }}>
<Icon name={icon} size={14} strokeWidth={2} />
</span>
)}
+31 -18
View File
@@ -24,7 +24,7 @@ import { ScratchEngine } from '../lib/scratchEngine'
import { PlaybackEngine } from '../lib/playbackEngine'
import { AutoCueDialog, eventLabel } from './AutoCueDialog'
import { ContextMenu, type MenuItem } from './ContextMenu'
import { BpmReadout, GridEditStrip, TempoControls } from './GridControls'
import { BpmReadout, GridEditStrip, TempoControls, TempoFold } from './GridControls'
import { HotcueBar } from './HotcueBar'
import { LoopControls, LOOP_SIZES, type LoopMode } from './LoopControls'
import { MainWaveform, MIN_SEC, MAX_SEC, DEFAULT_SEC } from './MainWaveform'
@@ -1158,6 +1158,20 @@ export function PrepStrip({
}
const DIVIDER = <span aria-hidden className="h-7 w-px shrink-0 bg-line" />
// Rendered twice — inline on a wide row, inside TempoFold on a narrow one.
const tempoProps = {
bpm: activeMarker?.bpm ?? null,
locked: cueData?.grid_locked ?? false,
lockable: caps.grid.lockable,
flexible: markerCount > 1,
markerIndex: activeMarkerIndex,
onTapStart: tapStart,
onTapBpm: (bpm: number) => commitBpm(bpm, tapAnchorRef.current),
onNudgeBpm: nudgeBpm,
onHalve: halveBpm,
onDouble: doubleBpm,
onToggleLock: toggleLock,
}
return (
<div className="glass flex h-[19.75rem] shrink-0 flex-col gap-2 p-4">
@@ -1311,8 +1325,15 @@ export function PrepStrip({
</>
)}
{/* ---- Controls: transport · loop/jump · pads or grid · tempo ---- */}
<div className="flex h-11 shrink-0 items-center gap-3">
{/* ---- Controls: transport · loop/jump · pads or grid · tempo ----
A container, so the row gives way in stages as the window narrows
instead of the pads sliding under the tempo group: the pads drop
their names first (each pad queries its own width, see HotcueBar),
then below 74rem the tempo group folds into one BPM button, and below
60rem the Grid toggle keeps only its icon. Those are the row's
measured widths just before the pad bank would hit its minimum (with
a lockable grid's extra Lock button), so move them with the controls. */}
<div className="@container flex h-11 shrink-0 items-center gap-3">
<button
onClick={toggle}
disabled={!ready}
@@ -1405,19 +1426,10 @@ export function PrepStrip({
/>
)}
{DIVIDER}
<TempoControls
bpm={activeMarker?.bpm ?? null}
locked={cueData?.grid_locked ?? false}
lockable={caps.grid.lockable}
flexible={markerCount > 1}
markerIndex={activeMarkerIndex}
onTapStart={tapStart}
onTapBpm={(bpm) => commitBpm(bpm, tapAnchorRef.current)}
onNudgeBpm={nudgeBpm}
onHalve={halveBpm}
onDouble={doubleBpm}
onToggleLock={toggleLock}
/>
<TempoControls {...tempoProps} className="@max-[74rem]:hidden" />
<TempoFold locked={tempoProps.locked} className="hidden @max-[74rem]:flex">
<TempoControls {...tempoProps} />
</TempoFold>
<button
onClick={() => {
setGridMode((g) => !g)
@@ -1427,14 +1439,15 @@ export function PrepStrip({
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 ${
aria-label="Grid"
className={`flex h-10 shrink-0 items-center gap-1.5 rounded-xl px-3 text-xs font-semibold transition-colors disabled:opacity-40 @max-[60rem]:w-10 @max-[60rem]:justify-center @max-[60rem]:px-0 ${
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
<span className="@max-[60rem]:hidden">Grid</span>
</button>
</div>