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
+130 -17

No files matched your search

+36 -3
View File
@@ -26,6 +26,10 @@ interface Props {
onToggleSize: () => void
// manual mode
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
onLoopOut: () => void
onToggleLoop: () => void
@@ -35,7 +39,16 @@ interface Props {
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)]'
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
// 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]'
@@ -59,6 +72,8 @@ export function LoopControls({
sizeLit,
onToggleSize,
canToggle,
inArmed,
manualSet,
onLoopIn,
onLoopOut,
onToggleLoop,
@@ -121,10 +136,28 @@ export function LoopControls({
</div>
) : (
<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
</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
</button>
<button
+11 -1
View File
@@ -1,7 +1,7 @@
import { useEffect, useRef } from 'react'
import type { CuePoint } from '../api'
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'
interface Props {
@@ -16,6 +16,10 @@ interface Props {
/** Grid mode is on: draw the beat lines brighter. */
emphasizeGrid?: boolean
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
survives track switches and persists to prefs. */
secPerView: number
@@ -48,6 +52,8 @@ export function MainWaveform({
activeMarker,
emphasizeGrid = false,
loop,
idleLoop = null,
loopIn = null,
secPerView,
onZoomChange,
onSeek,
@@ -93,7 +99,11 @@ export function MainWaveform({
// Loop band (under the grid/cues), then beatgrid, then cue markers.
if (loop) {
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) {
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 [loopActive, setLoopActive] = useState(false)
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 audioCtxRef = useRef<AudioContext | null>(null) // playback
@@ -239,7 +241,7 @@ export function PrepStrip({
setLoopActive(false)
setActiveBeats(null)
setCuePoint(0)
loopInRef.current = null
setLoopInPoint(null)
previewRef.current = null
setPreviewing(false)
setCueHeld(false)
@@ -590,7 +592,7 @@ export function PrepStrip({
setLoopRegion({ start, end })
setLoopActive(true)
setActiveBeats(beats)
loopInRef.current = null
setLoopInPoint(null)
setCurrent(eng.getPosition())
}
@@ -615,15 +617,18 @@ export function PrepStrip({
const loopIn = () => {
const eng = playbackRef.current
if (!eng || !eng.ready) return
loopInRef.current = snapTime(eng.getPosition())
setLoopInPoint(snapTime(eng.getPosition()))
}
const loopOut = () => {
const eng = playbackRef.current
if (!eng || !eng.ready || loopInRef.current == null) return
if (!eng || !eng.ready) return
const end = snapTime(eng.getPosition())
if (end <= loopInRef.current) return
engagLoop(loopInRef.current, end, null)
// OUT closes an armed IN — or, with a manual loop already set, moves that
// 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 = () => {
@@ -1202,6 +1207,8 @@ export function PrepStrip({
activeMarker={activeMarkerIndex}
emphasizeGrid={gridMode}
loop={activeLoop}
idleLoop={!loopActive ? loopRegion : null}
loopIn={loopInPoint}
secPerView={secPerView}
onZoomChange={setSecPerView}
onSeek={seekManual}
@@ -1283,6 +1290,8 @@ export function PrepStrip({
sizeLit={loopActive && activeBeats === beatSize}
onToggleSize={toggleSizeLoop}
canToggle={loopRegion != null}
inArmed={loopInPoint != null}
manualSet={loopRegion != null && activeBeats == null}
onLoopIn={loopIn}
onLoopOut={loopOut}
onToggleLoop={toggleLoop}