import { useEffect, useRef } from 'react'
import { bendFor, PITCH_RANGES } from '../../lib/sync'
import { Fader } from '../mixer/Controls'
import type { Deck } from './useDeck'
interface Props {
deck: Deck
/** This deck is the tempo master (the one SYNC follows). */
master: boolean
synced: boolean
/** Why SYNC cannot engage (no grid on a deck), else null. */
syncBlocked: string | null
onSync: () => void
onMaster: () => void
/** Moving the pitch fader — or bending — by hand takes the deck out of SYNC. */
onManualPitch: () => void
/** This deck's beats against the other deck's, in beats (-0.5..0.5); null
* when either has no grid or is not playing. Read every frame. */
phase: () => number | null
}
const lit = 'is-selected text-text'
const unlit = 'btn-glass text-muted'
/**
* A deck's tempo row in performance mode (decided 2026-11-02): keylock, SYNC,
* MASTER, the phase meter, the pitch fader with its range, and the tempo as
* heard. The pitch fader is the deck's SPEED — the grid's BPM is still edited
* in the header and Grid mode.
*/
export function DeckTempo({ deck, master, synced, syncBlocked, onSync, onMaster, onManualPitch, phase }: Props) {
const { pitch, setPitch, pitchRange, changeRange, rate, setBend, keylock, setKeylock, keylockAvailable, activeMarker, track } = deck
const bpm = activeMarker ? activeMarker.bpm * rate : null
const pct = pitch * pitchRange * 100
const nextRange = PITCH_RANGES[(PITCH_RANGES.indexOf(pitchRange) + 1) % PITCH_RANGES.length]
return (