// A RENDERED FILE AS A BENCH'S MEDIA (lane/reel-bench, 2 Nov). // // The clip bench plays a clip's cached RAW window, on the source clock. A // reel's walk plays a take's rendered MASTER -- the final frames, the chrome // burned in -- and works on the same source seconds: a beat is written in its // clip's source seconds, the cues and words are the clip's. Between the two // clocks is the build record's map: the file second the clip's segment // starts at (`segStart`), the source second its picture starts at // (`recStart`), and the source seconds the render cut out of it (`gaps`, // gaps.mjs). Within a kept piece the map is a shift; across a gap the file // goes straight on while the source jumps. // // Plain ESM: the bench's media adapter (components/projects/bench/benchMedia.ts) // and the tests read it. import { inGap, offsetIn, sourceAtOffset } from "umtool-report-to-video/gaps"; /** * @typedef {{ segStart: number, recStart: number, gaps: Array<{ from: number, to: number }> }} FileMap */ /** * The file second a source second plays at (a second inside a gap the render * cut out: the join). * * @param {FileMap} map * @param {number} src */ export const fileAt = (map, src) => map.segStart + offsetIn(src, map.recStart, map.gaps ?? []); /** * The source second a file second shows; at a join, the material after the gap. * * @param {FileMap} map * @param {number} t */ export const sourceAt = (map, t) => sourceAtOffset(t - map.segStart, map.recStart, map.gaps ?? []); /** * Source-second spans as spans of the file's clock: what is left of each once * the render's own gaps are out (a span wholly inside one is nothing, and * dropped). * * @param {FileMap} map * @param {Array<{ from: number, to: number }>} spans * @param {number} [min] shorter than this on the file's clock is dropped */ export function fileSpans(map, spans, min = 1e-3) { const out = []; for (const s of spans ?? []) { const a = fileAt(map, s.from); const b = fileAt(map, s.to); if (b - a > min) out.push({ from: a, to: b }); } return out; } /** * A file's peaks (uniform over a span of the FILE's clock) as peaks over a * span of SOURCE seconds -- what the bench's waveform draws. A source second * inside a gap the render cut out is silence. * * @param {{ from: number, to: number, min: number[], max: number[] }} peaks on the file's clock * @param {{ from: number, to: number }} span source seconds * @param {FileMap} map * @param {number} [n] buckets out */ export function peaksOnSource(peaks, span, map, n = peaks.max.length) { const k = peaks.max.length; const pSpan = Math.max(1e-9, peaks.to - peaks.from); const width = Math.max(1e-9, span.to - span.from); const min = []; const max = []; for (let b = 0; b < n; b += 1) { const t = span.from + ((b + 0.5) / n) * width; const i = inGap(t, map.gaps) ? -1 : Math.floor(((fileAt(map, t) - peaks.from) / pSpan) * k); min.push(i >= 0 && i < k ? peaks.min[i] : 0); max.push(i >= 0 && i < k ? peaks.max[i] : 0); } return { from: span.from, to: span.to, min, max }; }