"use client"; import { useRef } from "react"; import Waveform, { type Peaks } from "@/components/Waveform"; import { buttonVariants } from "@/components/ui/button"; import { GAP_LIMITS, gappedLength } from "umtool-report-to-video/gaps"; import { GapLayer, type GapWallsView, type WaveZoom } from "./GapsZoom"; import type { Span } from "./benchMedia"; import type { GapEditor, SavedGap } from "./useGapEditor"; // --------------------------------------------------------------------------- // THE BENCH'S WAVEFORM AND ITS GAPS (lifted out of ClipBench.tsx; shared with // the reel's walk, lane/reel-bench): the zoomed waveform with its handles, // Alt + drag selecting a span for a gap (the waveform's own drag held off), // the gaps' bands and close-in pauses and words (GapLayer), any marks the // bench draws over it (`children`), and the gaps' row of tools under it. // Source seconds throughout; what plays is the bench's media's business. // --------------------------------------------------------------------------- type Cue = { start: number; end: number; text: string }; /** The waveform box: Waveform, GapLayer and the bench's own overlays, with Alt + drag for a gap. */ export function BenchWaveBox({ zoom, sel, cand, cues, peaks, playhead, onSel, gap, gaps, silences, words, busy, held = false, walls = null, children, }: { zoom: WaveZoom; sel: Span; /** The saved extent, drawn behind the selection. */ cand: Span; cues: Cue[]; peaks: Peaks | null; playhead: number | null; onSel: (next: Span, dragging: boolean, edge?: "start" | "end" | null) => void; gap: GapEditor; gaps: SavedGap[]; silences: Span[] | null; words: { start: number; end?: number; w?: string }[] | null; busy: boolean; /** Another pick is armed (the mute mark's): Alt + drag and the gap pick stand down. */ held?: boolean; /** Where a gap cannot go, and why (gaps.mjs gapWalls), drawn on the waveform. */ walls?: GapWallsView | null; children?: React.ReactNode; }) { const altDrag = useRef<{ id: number; at: number } | null>(null); const zspan = Math.max(1e-6, zoom.vis.to - zoom.vis.from); const tAt = (e: React.PointerEvent) => { const r = e.currentTarget.getBoundingClientRect(); return zoom.vis.from + Math.min(1, Math.max(0, (e.clientX - r.left) / Math.max(1, r.width))) * zspan; }; return (
{ if (!e.altKey || gap.pick || held) return; e.preventDefault(); e.stopPropagation(); e.currentTarget.setPointerCapture(e.pointerId); const at = tAt(e); altDrag.current = { id: e.pointerId, at }; gap.select({ from: at, to: at }, false); }} onPointerMoveCapture={(e) => { const d = altDrag.current; if (!d || d.id !== e.pointerId) return; e.stopPropagation(); const t = tAt(e); gap.select({ from: Math.min(d.at, t), to: Math.max(d.at, t) }, false); }} onPointerUpCapture={(e) => { const d = altDrag.current; if (!d || d.id !== e.pointerId) return; e.stopPropagation(); altDrag.current = null; const t = tAt(e); gap.select({ from: Math.min(d.at, t), to: Math.max(d.at, t) }, true); }} > ({ start: c.start, end: c.end, w: c.text.slice(0, 24) }))} peaks={peaks} playhead={playhead} height={104} onSel={onSel} onReachEdge={() => { /* widening is the bench's own button, never a redraw */ }} /> {/* The gaps, the span being selected for one, and close in the silences and the pauses between words. */} {children}
); } /** * The gaps' tools under the waveform: what they leave, Select a gap, Cut gap, * Hear it, Play the span, Undo. `span` is what the gaps are inside (the * clip's cut, a beat), `noun` what plays as one ("the cut", "the beat"). */ export function GapTools({ gap, gaps, span, sel, busy, fmt, play, noun = "the cut", of = "the clip", }: { gap: GapEditor; gaps: Span[]; span: Span; sel: Span; busy: boolean; fmt: (t: number) => string; play: (from: number, to: number, o?: { through?: boolean; extra?: Span | null }) => unknown; noun?: string; of?: string; }) { const g = gap.sel; return ( // Seconds cut out of its middle: it plays as one run of jump cuts. Written // at once (not drafted like the edges), and every playback here skips them. `${x.from}-${x.to}`).join(",")} className="flex flex-wrap items-center gap-1.5"> {gaps.length ? ( {gaps.length} gap{gaps.length === 1 ? "" : "s"}{" "} ({noun} plays {gappedLength(span.from, span.to, gaps).toFixed(2)} s of {(span.to - span.from).toFixed(2)} s, one segment) ) : ( no gaps — {noun} plays whole )} {g && ( <> )} {gap.undo && ( )} ); }