import { useMemo } from 'react'; import { store, useApp, usePlayerVersion } from '../state/store.ts'; import { player } from '../audio/player.ts'; import { TempoMap } from '../midi/time.ts'; const SNAP_OPTIONS: { label: string; beats: number }[] = [ { label: 'snap off', beats: 0 }, { label: '1 bar', beats: 4 }, { label: '1/2', beats: 2 }, { label: '1/4', beats: 1 }, { label: '1/8', beats: 0.5 }, { label: '1/16', beats: 0.25 }, { label: '1/32', beats: 0.125 }, ]; export function Transport() { const app = useApp(); usePlayerVersion(); const song = app.rec?.song ?? null; const tm = useMemo(() => (song ? new TempoMap(song.ppq, song.tempo, song.timeSig) : null), [song]); if (!song || !tm) return
; const pos = Math.max(0, player.getPositionSec()); const tick = tm.secToTick(pos); const { bar, beat } = tm.barBeatAt(tick); const mm = Math.floor(pos / 60); const ss = (pos % 60).toFixed(1).padStart(4, '0'); const singleTempo = song.tempo.length === 1; const bpm = Math.round(tm.bpmAt(tick)); const state = player.state; return (
{bar}.{beat} {mm}:{ss} {player.preparing && rendering…}
); }