Fixed some UI issues

This commit is contained in:
Ben committed 2026-07-05 10:14:11 +02:00
1 parent 14f93bedc0
commit c3768f816a
5 files changed
+168 -44

No files matched your search

+45 -3
View File
@@ -5,6 +5,7 @@ interface Props {
locked: boolean
hasGrid: boolean
onSetBpm: (bpm: number) => void
onNudgeBpm: (delta: number) => void
onHalve: () => void
onDouble: () => void
onNudge: (deltaMs: number) => void
@@ -20,15 +21,17 @@ const BTN =
'disabled:hover:border-line'
/**
* Beatgrid / tempo panel (Traktor grid-control equivalent): editable BPM, half/
* double, tap tempo, grid-phase nudge (±1/±10 ms), set beat 1 at the playhead,
* reset to the loaded values, lock, and delete grid.
* 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), set beat 1 at the playhead, reset to the loaded values, lock,
* and delete grid.
*/
export function GridControls({
bpm,
locked,
hasGrid,
onSetBpm,
onNudgeBpm,
onHalve,
onDouble,
onNudge,
@@ -91,6 +94,45 @@ export function GridControls({
<div className="text-[10px] font-semibold uppercase tracking-wider text-faint">BPM</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="Halve BPM">
+12 -7
View File
@@ -1,4 +1,4 @@
import { useEffect, useRef, useState } from 'react'
import { useEffect, useRef } from 'react'
import type { CuePoint } from '../api'
import { drawBeatgrid, drawCuePoint, drawCues, drawLoop } from '../lib/cues'
import { paintWave, type WaveColumn } from '../lib/waveform'
@@ -12,6 +12,10 @@ interface Props {
bpm: number | null
gridAnchor: number | null
loop: { start: number; end: number } | null
/** Seconds across the view — the zoom level, owned by the parent so it
survives track switches and persists to prefs. */
secPerView: number
onZoomChange: (secPerView: number) => void
onSeek: (t: number) => void
onScratchStart: () => void
onScratchMove: (t: number) => void
@@ -20,9 +24,9 @@ interface Props {
const DRAG_THRESHOLD = 3 // px before a press becomes a scratch (vs a click-seek)
const MIN_SEC = 2 // most zoomed-in (seconds across the view)
const MAX_SEC = 64 // most zoomed-out
const DEFAULT_SEC = 16
export const MIN_SEC = 2 // most zoomed-in (seconds across the view)
export const MAX_SEC = 64 // most zoomed-out
export const DEFAULT_SEC = 16
/**
* Traktor-style scrolling main waveform: the playhead is fixed at the centre and
@@ -39,6 +43,8 @@ export function MainWaveform({
bpm,
gridAnchor,
loop,
secPerView,
onZoomChange,
onSeek,
onScratchStart,
onScratchMove,
@@ -46,7 +52,6 @@ export function MainWaveform({
}: Props) {
const wrapRef = useRef<HTMLDivElement>(null)
const canvasRef = useRef<HTMLCanvasElement>(null)
const [secPerView, setSecPerView] = useState(DEFAULT_SEC)
// Drag state for scratching. startTime is the playhead position at press;
// dragging maps horizontal movement to a time offset (right = earlier, so the
// waveform follows the cursor like grabbing a record).
@@ -172,8 +177,8 @@ export function MainWaveform({
else onSeek(timeAtClientX(e.clientX, e.currentTarget.getBoundingClientRect()))
}
const zoomIn = () => setSecPerView((s) => Math.max(MIN_SEC, s / 2))
const zoomOut = () => setSecPerView((s) => Math.min(MAX_SEC, s * 2))
const zoomIn = () => onZoomChange(Math.max(MIN_SEC, secPerView / 2))
const zoomOut = () => onZoomChange(Math.min(MAX_SEC, secPerView * 2))
return (
<div
+35 -3
View File
@@ -1,5 +1,5 @@
import { useEffect, useRef, useState } from 'react'
import { useQueryClient } from '@tanstack/react-query'
import { useQuery, useQueryClient } from '@tanstack/react-query'
import { api, type Track, type TrackCues } from '../api'
import { analyzeWaveform, type WaveColumn } from '../lib/waveform'
import { ScratchEngine } from '../lib/scratchEngine'
@@ -7,7 +7,7 @@ import { PlaybackEngine } from '../lib/playbackEngine'
import { GridControls } from './GridControls'
import { HotcueBar } from './HotcueBar'
import { LoopControls } from './LoopControls'
import { MainWaveform } from './MainWaveform'
import { MainWaveform, MIN_SEC, MAX_SEC, DEFAULT_SEC } from './MainWaveform'
import { OverviewWaveform } from './OverviewWaveform'
interface Props {
@@ -53,6 +53,7 @@ export function PrepStrip({ track, playRequest = 0, onError }: Props) {
const [snap, setSnap] = useState(true)
const [selectedSlot, setSelectedSlot] = useState<number | null>(null)
const [cuePoint, setCuePoint] = useState(0) // floating "CUE" point (frontend-only)
const [secPerView, setSecPerView] = useState(DEFAULT_SEC) // main-waveform zoom (persisted)
// Loop state (transient — persisted only when saved as a hotcue later).
const [loopRegion, setLoopRegion] = useState<{ start: number; end: number } | null>(null)
@@ -73,6 +74,32 @@ export function PrepStrip({ track, playRequest = 0, onError }: Props) {
const trackId = track?.id ?? null
// Main-waveform zoom persists to userprefs.json so it survives track switches
// (MainWaveform unmounts during each load) and app restarts. Hydrate once from
// the shared ['prefs'] query, then persist changes debounced (mirrors the
// column-layout prefs flow in App).
const prefsQuery = useQuery({ queryKey: ['prefs'], queryFn: api.getPrefs })
const zoomHydratedRef = useRef(false)
const zoomSaveTimer = useRef<number | null>(null)
useEffect(() => {
if (zoomHydratedRef.current || !prefsQuery.data) return
zoomHydratedRef.current = true
const z = (prefsQuery.data as { mainZoomSec?: unknown }).mainZoomSec
if (typeof z === 'number' && isFinite(z)) {
setSecPerView(Math.min(MAX_SEC, Math.max(MIN_SEC, z)))
}
}, [prefsQuery.data])
useEffect(() => {
if (!zoomHydratedRef.current) return // don't clobber saved prefs pre-hydration
if (zoomSaveTimer.current) window.clearTimeout(zoomSaveTimer.current)
zoomSaveTimer.current = window.setTimeout(() => {
api.patchPrefs({ mainZoomSec: secPerView }).catch(() => {})
}, 500)
return () => {
if (zoomSaveTimer.current) window.clearTimeout(zoomSaveTimer.current)
}
}, [secPerView])
const getCtx = (): AudioContext => {
if (!audioCtxRef.current) {
audioCtxRef.current = new (window.AudioContext ??
@@ -531,6 +558,8 @@ export function PrepStrip({ track, playRequest = 0, onError }: Props) {
}
}
const setBpm = (bpm: number) => editGrid({ bpm })
const nudgeBpm = (delta: number) =>
gridBpm && editGrid({ bpm: Math.round((gridBpm + delta) * 1000) / 1000 })
const halveBpm = () => gridBpm && editGrid({ bpm: gridBpm / 2 })
const doubleBpm = () => gridBpm && editGrid({ bpm: gridBpm * 2 })
const nudgeGrid = (deltaMs: number) => {
@@ -565,7 +594,7 @@ export function PrepStrip({ track, playRequest = 0, onError }: Props) {
const activeLoop = loopActive && loopRegion ? loopRegion : null
return (
<div className="flex h-72 shrink-0 items-stretch gap-px border-b border-line bg-ink-950">
<div className="flex h-[21rem] shrink-0 items-stretch gap-px border-b border-line bg-ink-950">
{/* Controls */}
<div className="flex w-72 shrink-0 flex-col gap-3 bg-ink-900 px-4 py-3">
<div className="min-w-0">
@@ -589,6 +618,7 @@ export function PrepStrip({ track, playRequest = 0, onError }: Props) {
locked={cueData?.locked ?? false}
hasGrid={gridAnchor != null}
onSetBpm={setBpm}
onNudgeBpm={nudgeBpm}
onHalve={halveBpm}
onDouble={doubleBpm}
onNudge={nudgeGrid}
@@ -659,6 +689,8 @@ export function PrepStrip({ track, playRequest = 0, onError }: Props) {
bpm={cueData?.bpm ?? null}
gridAnchor={cueData?.grid_anchor ?? null}
loop={activeLoop}
secPerView={secPerView}
onZoomChange={setSecPerView}
onSeek={seekManual}
onScratchStart={onScratchStart}
onScratchMove={onScratchMove}