Improved manual loop visuals

This commit is contained in:
patben8 committed 2026-09-25 16:56:15 +02:00
1 parent 9f299051fa
commit 642977e9bc
5 files changed
+128 -15

No files matched your search

+6
View File
@@ -404,6 +404,12 @@ Two independent apps that talk over HTTP:
`LoopControls` has a BEAT / MAN switch: BEAT shows `− size +` (the size `LoopControls` has a BEAT / MAN switch: BEAT shows `− size +` (the size
key sets or clears a loop of that length; −/+ halve/double, resizing an key sets or clears a loop of that length; −/+ halve/double, resizing an
engaged beat loop from its locked start), MAN shows IN / OUT / toggle. engaged beat loop from its locked start), MAN shows IN / OUT / toggle.
The armed IN point is React STATE (`loopInPoint`), not a ref, because the
IN button (lit "armed") and the waveform (`drawLoopIn`: a green IN line
plus a dashed band to the playhead — the loop OUT would make now) both
show it. OUT closes an armed IN, or with a manual loop already set moves
its end to the playhead. A loop that is switched off stays drawn as a dim
outline (`drawLoop(…, idle)`), so the toggle shows what it would restore.
**‹ › (and ←/→) MOVE an engaged loop by its own length**, Traktor-style, **‹ › (and ←/→) MOVE an engaged loop by its own length**, Traktor-style,
and only jump the playhead when no loop is engaged. The move sets the new and only jump the playhead when no loop is engaged. The move sets the new
loop BEFORE seeking: `PlaybackEngine.seek` honours the loop in force, so loop BEFORE seeking: `PlaybackEngine.seek` honours the loop in force, so
+36 -3
View File
@@ -26,6 +26,10 @@ interface Props {
onToggleSize: () => void onToggleSize: () => void
// manual mode // manual mode
canToggle: boolean // a loop region exists to switch on/off canToggle: boolean // a loop region exists to switch on/off
/** IN was pressed and is waiting for OUT. */
inArmed: boolean
/** A manual (IN/OUT) loop exists, engaged or not. */
manualSet: boolean
onLoopIn: () => void onLoopIn: () => void
onLoopOut: () => void onLoopOut: () => void
onToggleLoop: () => void onToggleLoop: () => void
@@ -35,7 +39,16 @@ interface Props {
const LIT = const LIT =
'bg-gradient-to-b from-[#7bf0ad] to-mint text-ink-950 shadow-[inset_0_1px_0_rgb(255_255_255/0.6),0_0_14px_rgb(61_220_132/0.55)]' 'bg-gradient-to-b from-[#7bf0ad] to-mint text-ink-950 shadow-[inset_0_1px_0_rgb(255_255_255/0.6),0_0_14px_rgb(61_220_132/0.55)]'
const KEY = 'flex items-center justify-center rounded-[9px] transition-colors disabled:opacity-30' // Every key presses in when clicked, so a press is felt even when what it did
// (a loop moved, an in-point set) is somewhere else on screen.
const KEY =
'flex items-center justify-center rounded-[9px] transition-[color,background-color,box-shadow,transform,filter] duration-75 ' +
'active:scale-[0.93] active:brightness-125 disabled:opacity-30 disabled:active:scale-100'
// An armed IN: a green rim and glow — "waiting for OUT".
const ARMED =
'bg-mint/15 text-mint shadow-[inset_0_0_0_1px_rgb(61_220_132/0.75),0_0_12px_-3px_rgb(61_220_132/0.7)]'
// A set point (the loop exists): green text on a faint green tint.
const SET = 'bg-mint/10 text-mint shadow-[inset_0_0_0_1px_rgb(61_220_132/0.35)]'
// BOTH modes' clusters are this wide, so switching BEAT ⇄ MAN never shifts // BOTH modes' clusters are this wide, so switching BEAT ⇄ MAN never shifts
// the pads and tempo controls to their right. // the pads and tempo controls to their right.
const CLUSTER = 'well flex h-10 w-[8.5rem] shrink-0 items-center gap-0.5 rounded-xl p-[3px]' const CLUSTER = 'well flex h-10 w-[8.5rem] shrink-0 items-center gap-0.5 rounded-xl p-[3px]'
@@ -59,6 +72,8 @@ export function LoopControls({
sizeLit, sizeLit,
onToggleSize, onToggleSize,
canToggle, canToggle,
inArmed,
manualSet,
onLoopIn, onLoopIn,
onLoopOut, onLoopOut,
onToggleLoop, onToggleLoop,
@@ -121,10 +136,28 @@ export function LoopControls({
</div> </div>
) : ( ) : (
<div role="group" aria-label="Manual loop" className={`${CLUSTER} text-xs font-semibold`}> <div role="group" aria-label="Manual loop" className={`${CLUSTER} text-xs font-semibold`}>
<button onClick={onLoopIn} disabled={!ready} title="Loop in at the playhead" className={`${KEY} btn-glass h-[34px] min-w-0 flex-1 text-text`}> <button
onClick={onLoopIn}
disabled={!ready}
aria-pressed={inArmed || manualSet}
title={inArmed ? 'Loop in is set — now press OUT (or IN again to move it)' : 'Loop in at the playhead'}
className={`${KEY} h-[34px] min-w-0 flex-1 ${inArmed ? ARMED : manualSet ? SET : 'btn-glass text-text'}`}
>
IN IN
</button> </button>
<button onClick={onLoopOut} disabled={!ready} title="Loop out at the playhead" className={`${KEY} btn-glass h-[34px] min-w-0 flex-1 text-text`}> <button
onClick={onLoopOut}
disabled={!ready || (!inArmed && !manualSet)}
aria-pressed={manualSet && !inArmed}
title={
inArmed
? 'Loop out at the playhead'
: manualSet
? "Move the loop's end to the playhead"
: 'Set IN first'
}
className={`${KEY} h-[34px] min-w-0 flex-1 ${manualSet && !inArmed ? SET : 'btn-glass text-text'}`}
>
OUT OUT
</button> </button>
<button <button
+11 -1
View File
@@ -1,7 +1,7 @@
import { useEffect, useRef } from 'react' import { useEffect, useRef } from 'react'
import type { CuePoint } from '../api' import type { CuePoint } from '../api'
import type { BeatGrid } from '../lib/beatgrid' import type { BeatGrid } from '../lib/beatgrid'
import { drawBeatgrid, drawCuePoint, drawCues, drawLoop, drawPlayhead } from '../lib/cues' import { drawBeatgrid, drawCuePoint, drawCues, drawLoop, drawLoopIn, drawPlayhead } from '../lib/cues'
import { paintWave, type WaveColumn } from '../lib/waveform' import { paintWave, type WaveColumn } from '../lib/waveform'
interface Props { interface Props {
@@ -16,6 +16,10 @@ interface Props {
/** Grid mode is on: draw the beat lines brighter. */ /** Grid mode is on: draw the beat lines brighter. */
emphasizeGrid?: boolean emphasizeGrid?: boolean
loop: { start: number; end: number } | null loop: { start: number; end: number } | null
/** A loop that exists but is switched off — drawn as a dim outline. */
idleLoop?: { start: number; end: number } | null
/** An armed manual loop-in point, waiting for OUT. */
loopIn?: number | null
/** Seconds across the view — the zoom level, owned by the parent so it /** Seconds across the view — the zoom level, owned by the parent so it
survives track switches and persists to prefs. */ survives track switches and persists to prefs. */
secPerView: number secPerView: number
@@ -48,6 +52,8 @@ export function MainWaveform({
activeMarker, activeMarker,
emphasizeGrid = false, emphasizeGrid = false,
loop, loop,
idleLoop = null,
loopIn = null,
secPerView, secPerView,
onZoomChange, onZoomChange,
onSeek, onSeek,
@@ -93,7 +99,11 @@ export function MainWaveform({
// Loop band (under the grid/cues), then beatgrid, then cue markers. // Loop band (under the grid/cues), then beatgrid, then cue markers.
if (loop) { if (loop) {
drawLoop(ctx, timeToX(loop.start), timeToX(loop.end), h, dpr) drawLoop(ctx, timeToX(loop.start), timeToX(loop.end), h, dpr)
} else if (idleLoop) {
drawLoop(ctx, timeToX(idleLoop.start), timeToX(idleLoop.end), h, dpr, true)
} }
// An armed IN, and the loop OUT would make right now: IN → playhead.
if (loopIn != null) drawLoopIn(ctx, timeToX(loopIn), w / 2, h, dpr)
if (grid) { if (grid) {
drawBeatgrid(ctx, grid, startSec, endSec, w, h, dpr, activeMarker, emphasizeGrid) drawBeatgrid(ctx, grid, startSec, endSec, w, h, dpr, activeMarker, emphasizeGrid)
} }
+16 -7
View File
@@ -119,7 +119,9 @@ export function PrepStrip({
const [loopRegion, setLoopRegion] = useState<{ start: number; end: number } | null>(null) const [loopRegion, setLoopRegion] = useState<{ start: number; end: number } | null>(null)
const [loopActive, setLoopActive] = useState(false) const [loopActive, setLoopActive] = useState(false)
const [activeBeats, setActiveBeats] = useState<number | null>(null) const [activeBeats, setActiveBeats] = useState<number | null>(null)
const loopInRef = useRef<number | null>(null) // armed manual loop-in point // The armed manual loop-in point: IN was pressed, OUT not yet. STATE, not a
// ref, because the IN button and the waveform both show it while it waits.
const [loopInPoint, setLoopInPoint] = useState<number | null>(null)
const originalGridRef = useRef<GridMarker[] | null>(null) const originalGridRef = useRef<GridMarker[] | null>(null)
const audioCtxRef = useRef<AudioContext | null>(null) // playback const audioCtxRef = useRef<AudioContext | null>(null) // playback
@@ -239,7 +241,7 @@ export function PrepStrip({
setLoopActive(false) setLoopActive(false)
setActiveBeats(null) setActiveBeats(null)
setCuePoint(0) setCuePoint(0)
loopInRef.current = null setLoopInPoint(null)
previewRef.current = null previewRef.current = null
setPreviewing(false) setPreviewing(false)
setCueHeld(false) setCueHeld(false)
@@ -590,7 +592,7 @@ export function PrepStrip({
setLoopRegion({ start, end }) setLoopRegion({ start, end })
setLoopActive(true) setLoopActive(true)
setActiveBeats(beats) setActiveBeats(beats)
loopInRef.current = null setLoopInPoint(null)
setCurrent(eng.getPosition()) setCurrent(eng.getPosition())
} }
@@ -615,15 +617,18 @@ export function PrepStrip({
const loopIn = () => { const loopIn = () => {
const eng = playbackRef.current const eng = playbackRef.current
if (!eng || !eng.ready) return if (!eng || !eng.ready) return
loopInRef.current = snapTime(eng.getPosition()) setLoopInPoint(snapTime(eng.getPosition()))
} }
const loopOut = () => { const loopOut = () => {
const eng = playbackRef.current const eng = playbackRef.current
if (!eng || !eng.ready || loopInRef.current == null) return if (!eng || !eng.ready) return
const end = snapTime(eng.getPosition()) const end = snapTime(eng.getPosition())
if (end <= loopInRef.current) return // OUT closes an armed IN — or, with a manual loop already set, moves that
engagLoop(loopInRef.current, end, null) // loop's end to the playhead (Traktor's loop-out adjust).
const start = loopInPoint ?? (loopRegion && activeBeats == null ? loopRegion.start : null)
if (start == null || end <= start) return
engagLoop(start, end, null)
} }
const toggleLoop = () => { const toggleLoop = () => {
@@ -1202,6 +1207,8 @@ export function PrepStrip({
activeMarker={activeMarkerIndex} activeMarker={activeMarkerIndex}
emphasizeGrid={gridMode} emphasizeGrid={gridMode}
loop={activeLoop} loop={activeLoop}
idleLoop={!loopActive ? loopRegion : null}
loopIn={loopInPoint}
secPerView={secPerView} secPerView={secPerView}
onZoomChange={setSecPerView} onZoomChange={setSecPerView}
onSeek={seekManual} onSeek={seekManual}
@@ -1283,6 +1290,8 @@ export function PrepStrip({
sizeLit={loopActive && activeBeats === beatSize} sizeLit={loopActive && activeBeats === beatSize}
onToggleSize={toggleSizeLoop} onToggleSize={toggleSizeLoop}
canToggle={loopRegion != null} canToggle={loopRegion != null}
inArmed={loopInPoint != null}
manualSet={loopRegion != null && activeBeats == null}
onLoopIn={loopIn} onLoopIn={loopIn}
onLoopOut={loopOut} onLoopOut={loopOut}
onToggleLoop={toggleLoop} onToggleLoop={toggleLoop}
+59 -4
View File
@@ -173,29 +173,84 @@ export function drawCuePoint(
ctx.restore() ctx.restore()
} }
/** Draw the active loop region: a green band, brightest at the top, with lit edges. */ /**
* Draw a loop region: a green band, brightest at the top, with lit edges.
* `idle` draws a loop that exists but is switched off — the same region as a
* faint outline with no glow, so it reads as "available", not "playing".
*/
export function drawLoop( export function drawLoop(
ctx: CanvasRenderingContext2D, ctx: CanvasRenderingContext2D,
startX: number, startX: number,
endX: number, endX: number,
h: number, h: number,
dpr: number, dpr: number,
idle = false,
): void { ): void {
const edge = Math.max(1, Math.round(1.5 * dpr)) const edge = Math.max(1, Math.round(1.5 * dpr))
const band = ctx.createLinearGradient(0, 0, 0, h) const band = ctx.createLinearGradient(0, 0, 0, h)
band.addColorStop(0, 'rgba(61,220,132,0.22)') band.addColorStop(0, `rgba(61,220,132,${idle ? 0.07 : 0.22})`)
band.addColorStop(1, 'rgba(61,220,132,0.08)') band.addColorStop(1, `rgba(61,220,132,${idle ? 0.02 : 0.08})`)
ctx.fillStyle = band ctx.fillStyle = band
ctx.fillRect(startX, 0, Math.max(1, endX - startX), h) ctx.fillRect(startX, 0, Math.max(1, endX - startX), h)
ctx.save() ctx.save()
if (!idle) {
ctx.shadowColor = '#3ddc84' ctx.shadowColor = '#3ddc84'
ctx.shadowBlur = 8 * dpr ctx.shadowBlur = 8 * dpr
ctx.fillStyle = 'rgba(61,220,132,0.9)' }
ctx.fillStyle = idle ? 'rgba(61,220,132,0.4)' : 'rgba(61,220,132,0.9)'
ctx.fillRect(startX, 0, edge, h) ctx.fillRect(startX, 0, edge, h)
ctx.fillRect(endX - edge, 0, edge, h) ctx.fillRect(endX - edge, 0, edge, h)
ctx.restore() ctx.restore()
} }
/**
* An armed manual loop-in, before OUT: a lit green line with an "IN" flag at
* the bottom (the top belongs to hotcue flags), and — when the playhead is past
* it — a dashed-edged band from IN to the playhead: the loop OUT would make now.
*/
export function drawLoopIn(
ctx: CanvasRenderingContext2D,
x: number,
playheadX: number,
h: number,
dpr: number,
): void {
if (playheadX > x) {
ctx.fillStyle = 'rgba(61,220,132,0.10)'
ctx.fillRect(x, 0, playheadX - x, h)
ctx.save()
ctx.strokeStyle = 'rgba(61,220,132,0.55)'
ctx.lineWidth = Math.max(1, dpr)
ctx.setLineDash([4 * dpr, 4 * dpr])
ctx.beginPath()
ctx.moveTo(x, 0.5 * dpr)
ctx.lineTo(playheadX, 0.5 * dpr)
ctx.moveTo(x, h - 0.5 * dpr)
ctx.lineTo(playheadX, h - 0.5 * dpr)
ctx.stroke()
ctx.restore()
}
const lw = Math.max(2, Math.round(2 * dpr))
ctx.save()
ctx.shadowColor = '#3ddc84'
ctx.shadowBlur = 10 * dpr
ctx.fillStyle = '#3ddc84'
ctx.fillRect(Math.round(x) - Math.floor(lw / 2), 0, lw, h)
ctx.restore()
const pad = Math.round(6 * dpr)
const fh = Math.round(17 * dpr)
const inset = Math.round(5 * dpr)
ctx.font = `600 ${Math.round(11 * dpr)}px 'Geist Variable', system-ui, sans-serif`
const fw = Math.ceil(ctx.measureText('IN').width) + pad * 2
ctx.fillStyle = 'rgba(61,220,132,0.9)'
ctx.beginPath()
ctx.roundRect(Math.round(x) - Math.floor(lw / 2), h - inset - fh, fw, fh, [0, 8 * dpr, 8 * dpr, 0])
ctx.fill()
ctx.fillStyle = '#03210f'
ctx.textBaseline = 'middle'
ctx.fillText('IN', Math.round(x) - Math.floor(lw / 2) + pad, h - inset - fh / 2 + dpr * 0.5)
}
/** /**
* The main waveform's fixed centre playhead: a red line with a soft red glow * The main waveform's fixed centre playhead: a red line with a soft red glow
* and inward-pointing caps top and bottom that anchor the eye in the quiet * and inward-pointing caps top and bottom that anchor the eye in the quiet