// A VIDEO entry in Play (report-to-video/video-entry.mjs; umtool/docs/knobs.md, // "Play the cut"): what the stage shows at cut second t. Pure, so the // arithmetic is unit-tested (playVideo.test.mjs) and PlayCut.tsx only applies it. // // - On a video item: its file at source second `src` (its `from` plus the // seconds since its lead's black), fading up over `enter.in` after the lead; // black before. The clips' sound is ducked to 0 (`duck`): the video's own // element plays its sound. // - On the item BEFORE a video that enters with a fade: the whole stage -- // its picture and every overlay -- darkens to black over its last // `enter.out` seconds (`dark`), its sound with it (`duck`), black at the // seam Play cuts on (the video item's `from`). // - Anything else: nothing (`null`), and the stage is what it always was. import { itemIndexAt } from "./playCut.mjs"; const fin = (v) => typeof v === "number" && Number.isFinite(v); const clamp01 = (v) => Math.max(0, Math.min(1, v)); const round = (v) => Math.round(v * 1000) / 1000; /** * @typedef {{ src: string, from: number, to: number, fit: "contain" | "cover", enter: { out: number, in: number } | null, * lead: number, hold: number, seconds: number, bass: number, gain: number, noChrome: boolean }} VideoEntryPlay */ /** * @param {{ items: Array<{ id: string, start: number, from: number, to: number, end: number }> }} plan * @param {Map} entries * @param {number} t * @returns {null | { id: string, video: VideoEntryPlay | null, src: number | null, opacity: number, dark: number, duck: number, playing: boolean }} */ export function videoStageAt(plan, entries, t) { const items = plan?.items ?? []; const i = itemIndexAt(plan, t); const it = items[i]; if (!it || !fin(t)) return null; const ve = entries.get(it.id)?.videoEntry; if (ve) { const local = t - it.start; const span = Math.max(0, ve.to - ve.from); const into = local - ve.lead; const src = round(ve.from + Math.min(span, Math.max(0, into))); const opacity = into < 0 ? 0 : ve.enter && ve.enter.in > 0 ? clamp01(into / ve.enter.in) : 1; return { id: it.id, video: ve, src, opacity: round(opacity), dark: 0, duck: 0, playing: into >= 0 && into < span }; } const next = items[i + 1]; const nv = next ? entries.get(next.id)?.videoEntry : null; if (nv?.enter && fin(next?.from)) { const end = /** @type {number} */ (next.from); const dark = clamp01((t - (end - nv.enter.out)) / nv.enter.out); if (dark <= 0) return null; return { id: it.id, video: null, src: null, opacity: 0, dark: round(dark), duck: round(1 - dark), playing: false }; } return null; }