// Tests for the effects region's pure half (fx.mjs, release 35 O2): the // validators, the schedule's times (each to the frame), the cue compiler, and // the promise that a cut without `render.chrome.fx` schedules, joins and // crossfades exactly as it did. // // Run with: pnpm test:scripts import assert from "node:assert/strict"; import test from "node:test"; import { FX_KEYS, compileCues, fxClipDate, fxKeysOn, fxOn, fxQuoteFallback, fxRandom, fxSchedule, fxWipeJoins, fxWordsOf, punchMask, quotePages, resolveFx, validateFx, validateFxEntries, } from "./fx.mjs"; import { deckSchedule, estimateSchedule, fxGeometry, deckGeometry, feedGeometry, validateChrome, hidesDeck, resolveDeck, playWindow } from "./deck.mjs"; import { segmentJoins, xfadeBatchJoins, xfadeGraph, chromeOverlayChain, fxRegion } from "./build-video.mjs"; const PALETTE = { bg: "#12100c", fg: "#f6f1e6", muted: "#a2957f", accent: "#c8752a", amber: "#ffc860" }; const FPS = 30; const FRAME = 1 / FPS; const render = (fx, extra = {}) => ({ width: 1920, height: 1080, fps: FPS, transition: 0.5, palette: PALETTE, chrome: { engine: "hyperframes", layout: "deck", deck: { qr: { show: false } }, ...(fx === undefined ? {} : { fx }) }, ...extra, }); const clip = (id, date, extra = {}) => ({ type: "clip", id, channel: "ch", video: `v${id}`, start: 10, end: 18, cutStart: 11, cutEnd: 17, date, quote: "it must be an exceedingly slow news week as we have what appears to be collusion", montage: { match: "slow news week", n: Number(id.slice(1)) * 9 }, ...extra, }); const TIMELINE = [ clip("c1", "2019-05-02"), clip("c2", "2020-06-11", { fx: { receipts: [{ shot: "shots/b.png", mark: [0.04, 0.3, 0.9, 0.5] }, { shot: "shots/a.png" }] } }), clip("c3", "2021-01-01"), clip("c4", "2026-01-01", { fx: { zoom: { shot: "shots/a.png", focus: [0.1, 0.2, 0.6, 0.4] } } }), ]; const ALL = { kineticQuote: { clips: ["c1", "c3", "c4"] }, redact: { clips: ["c2"] }, odometer: {}, scrubber: {}, glitch: {}, thenNow: { pairs: [{ then: "c3", now: "c4" }] }, receipts: {}, zoom: {}, }; const near = (a, b, tol, msg) => assert.ok(Math.abs(a - b) <= tol + 1e-9, `${msg}: ${a} vs ${b} (±${tol})`); /** The schedule as the build would write it, from fixed durations and the words given. */ function sched(fx, { words = null, timeline = TIMELINE, durs = [6.4, 6.4, 6.4, 6.4], D = 0.5 } = {}) { const r = render(fx, { transition: D }); return deckSchedule({ entries: timeline, durs, D, render: r, fxWords: words }); } // --------------------------------------------------------------------------- test("validateFx: every effect accepts {} and null; unknown keys and bad values are sentences", () => { assert.deepEqual(validateFx(undefined), []); assert.deepEqual(validateFx(null), []); assert.deepEqual(validateFx({}), []); for (const k of FX_KEYS) { const v = k === "thenNow" ? { pairs: [{ then: "a", now: "b" }] } : {}; assert.deepEqual(validateFx({ [k]: v }), [], k); assert.deepEqual(validateFx({ [k]: null }), [], `${k}: null`); } assert.match(validateFx({ sparkle: {} }).join(), /sparkle is not an effect/); assert.match(validateFx({ odometer: { positon: "top-left" } }).join(), /positon is not a odometer setting/); assert.match(validateFx({ odometer: { position: "middle" } }).join(), /position must be/); assert.match(validateFx({ kineticQuote: { maxWords: 2 } }).join(), /maxWords must be a whole number from 3 to 30/); assert.match(validateFx({ glitch: { seconds: 3 } }).join(), /seconds must be from 0.2 to 1.5/); assert.match(validateFx({ thenNow: {} }).join(), /pairs is needed/); assert.match(validateFx({ thenNow: { pairs: [{ then: "a" }] } }).join(), /pairs\[0\] must be/); assert.match(validateFx({ receipts: { width: 0.9 } }).join(), /width must be from 0.2 to 0.6/); assert.match(validateFx({ zoom: [] }).join(), /must be an object/); // The two treatments of a clip's line are one or the other. assert.match(validateFx({ kineticQuote: {}, redact: {} }).join(), /give one of them clips/); assert.match(validateFx({ kineticQuote: { clips: ["c1", "c2"] }, redact: { clips: ["c2"] } }).join(), /both name c2/); assert.deepEqual(validateFx({ kineticQuote: {}, redact: { clips: ["c2"] } }), []); }); test("validateChrome knows fx, and refuses through it", () => { assert.deepEqual(validateChrome(render(ALL).chrome, render(ALL)), []); assert.match(validateChrome(render({ wobble: {} }).chrome, render({})).join(), /wobble is not an effect/); }); test("validateFxEntries: entry fields, clip lists, the pair's adjacency, and the posts' shift", () => { const m = (fx, timeline = TIMELINE, extra = {}) => ({ render: render(fx), timeline, ...extra }); assert.deepEqual(validateFxEntries(m(ALL)), []); // An entry's fx is inert without the effect, but still checked. const bad = [clip("c1", "2019-05-02", { fx: { recipts: [], receipts: [{ shot: "https://x/y.png" }], zoom: { shot: "a.gif", focus: [0.5, 0.5, 0.4, 0.6] } } })]; const errs = validateFxEntries(m(undefined, bad)).join("\n"); assert.match(errs, /recipts is not an effect field/); assert.match(errs, /not a URL/); assert.match(errs, /\.png, \.jpg, \.jpeg, \.webp/); assert.match(errs, /focus must be \[left, top, right, bottom\]/); assert.match(validateFxEntries(m({ kineticQuote: { clips: ["c9"] } })).join(), /names c9, which is not a clip/); assert.match(validateFxEntries(m({ thenNow: { pairs: [{ then: "c1", now: "c3" }] } })).join(), /c3 must be the entry right after c1/); assert.match(validateFxEntries(m({ thenNow: { pairs: [{ then: "c1", now: "c2" }, { then: "c2", now: "c3" }] } })).join(), /c2 is in another pair's cut/); const posts = [{ id: "p1", platform: "x", text: "t", date: "2020-01-01" }]; assert.match(validateFxEntries(m(ALL, TIMELINE, { posts })).join(), /popup posts move aside/); const noShift = render(ALL); noShift.chrome.deck.posts = { shift: false }; assert.deepEqual(validateFxEntries({ render: noShift, timeline: TIMELINE, posts }), []); }); test("fxOn / fxKeysOn / resolveFx: an effect is on when it is an object", () => { assert.equal(fxOn(render(undefined)), false); assert.equal(fxOn(render(null)), false); assert.equal(fxOn(render({})), false); assert.equal(fxOn(render({ glitch: null })), false); assert.deepEqual(fxKeysOn(render({ glitch: {}, odometer: null, scrubber: {} })), ["scrubber", "glitch"]); assert.deepEqual(resolveFx(render({ glitch: { seconds: 0.8 } }), "glitch"), { on: "year", seconds: 0.8, stamp: true, year: true, clips: null }); assert.equal(resolveFx(render({}), "glitch"), null); }); test("byte for byte: without an effect on, the schedule is the one it always was", () => { const base = sched(undefined); assert.equal("fx" in base, false); for (const off of [null, {}, { glitch: null, odometer: null }]) { assert.deepEqual(sched(off), base, JSON.stringify(off)); assert.equal(JSON.stringify(sched(off)), JSON.stringify(base)); } // An entry's fx alone changes nothing either. const bare = TIMELINE.map(({ fx: _f, ...e }) => e); assert.equal(JSON.stringify(sched(undefined, { timeline: bare })), JSON.stringify(base)); // And the estimate. const est = (fx) => estimateSchedule({ render: render(fx), timeline: TIMELINE }); assert.equal(JSON.stringify(est({})), JSON.stringify(est(undefined))); }); test("byte for byte: without a wipe the joins, the crossfade graph and the overlay chain are unchanged", () => { const s = sched(undefined); assert.equal(segmentJoins(s), null); const durs = [6.4, 6.4, 6.4, 6.4]; const plain = xfadeGraph(durs, 0.5, null); assert.ok(plain.parts.every((p) => !/wipeleft/.test(p))); assert.equal(JSON.stringify(xfadeGraph(durs, 0.5, [null, null, null, null])), JSON.stringify(plain)); assert.equal(xfadeBatchJoins(null, [{ from: 0, to: 2 }, { from: 2, to: 4 }]), null); const dip = { seconds: 1, lastFrame: 10, black: 0 }; assert.deepEqual(xfadeBatchJoins([null, { dip }, null, null], [{ from: 0, to: 2 }, { from: 2, to: 4 }]), [{ dip }, null]); const r = render(undefined); const regions = [{ name: "deck", frames: "/o/chrome/deck-frames", x: 0, y: 890, width: 1920, height: 190 }]; assert.deepEqual(chromeOverlayChain(r, regions, "[v3]", 4), chromeOverlayChain(r, regions, "[v3]", 4)); }); test("thenNow: the pair's cut is a wipe on the THEN join; the crossfade wipes left there and only there", () => { const s = sched({ thenNow: { pairs: [{ then: "c3", now: "c4" }] } }); assert.deepEqual([...fxWipeJoins(s)], [2]); const joins = segmentJoins(s); assert.deepEqual(joins, [null, null, { hold: 0, move: null, wipe: true }, null]); const g = xfadeGraph([6.4, 6.4, 6.4, 6.4], 0.5, joins); const xf = g.parts.filter((p) => /xfade=/.test(p)); assert.equal(xf.length, 3); assert.match(xf[0], /transition=fade/); assert.match(xf[1], /transition=fade/); assert.match(xf[2], /transition=wipeleft:duration=0\.5:offset=17\.700/); // The batched join pass carries it across a batch boundary too. assert.deepEqual(xfadeBatchJoins(joins, [{ from: 0, to: 3 }, { from: 3, to: 4 }]), [{ wipe: true }, null]); // A hard cut has no wipe to make: the divider sweeps alone. const hard = sched({ thenNow: { pairs: [{ then: "c3", now: "c4" }], seconds: 0.8 } }, { D: 0 }); assert.equal(hard.fx.thenNow.wipes[0].real, false); assert.equal(segmentJoins(hard), null); }); test("thenNow: the divider's sweep is the crossfade's own span, to the frame", () => { const s = sched(ALL); const w = s.fx.thenNow.wipes[0]; const now = s.segments.find((x) => x.id === "c4"); near(w.at, now.start, FRAME, "the wipe starts where the NOW segment starts (the xfade's offset)"); near(w.seconds, 0.5, 0, "it lasts the transition"); assert.deepEqual([w.thenDate, w.nowDate], ["1 Jan 2021", "1 Jan 2026"]); const hard = sched({ thenNow: { pairs: [{ then: "c3", now: "c4" }], seconds: 0.8 } }, { D: 0 }); const h = hard.fx.thenNow.wipes[0]; const s4 = hard.segments.find((x) => x.id === "c4").start; near(h.at + h.seconds / 2, s4, FRAME, "a hard cut's sweep is centred on the cut"); }); test("kinetic and redacted lines: each word lands on its own time, to the frame; the punch is the phrase", () => { // Timed words in each clip's SEGMENT seconds, as the build reads them. const words = new Map(["c1", "c2", "c3", "c4"].map((id) => [id, [ { text: "it", start: 1.0, end: 1.2 }, { text: "was", start: 1.2, end: 1.5 }, { text: "a", start: 1.5, end: 1.6 }, { text: "slow", start: 1.7, end: 2.0 }, { text: "news", start: 2.0, end: 2.3 }, { text: "week.", start: 2.3, end: 2.7 }, { text: "really", start: 3.1, end: 3.6 }, ]])); const s = sched(ALL, { words }); assert.deepEqual(s.fx.quotes.map((q) => [q.segment, q.style]), [["c1", "kinetic"], ["c2", "redact"], ["c3", "kinetic"], ["c4", "kinetic"]]); for (const q of s.fx.quotes) { const seg = s.segments.find((x) => x.id === q.segment); const flat = q.pages.flatMap((p) => p.words); assert.deepEqual(flat.map((w) => w.text), ["it", "was", "a", "slow", "news", "week.", "really"]); flat.forEach((w, j) => near(w.at, seg.start + words.get(q.segment)[j].start, FRAME, `${q.segment} word ${j}`)); assert.deepEqual(flat.map((w) => w.punch), [false, false, false, true, true, true, false]); } // An entry's own punch wins over the montage's match. const t2 = TIMELINE.map((e) => (e.id === "c1" ? { ...e, fx: { punch: "it was" } } : e)); const s2 = sched(ALL, { words, timeline: t2 }); assert.deepEqual(s2.fx.quotes[0].pages.flatMap((p) => p.words).map((w) => w.punch), [true, true, false, false, false, false, false]); // A clip that opts out draws no line. const t3 = TIMELINE.map((e) => (e.id === "c3" ? { ...e, fx: { quote: false } } : e)); assert.deepEqual(sched(ALL, { words, timeline: t3 }).fx.quotes.map((q) => q.segment), ["c1", "c2", "c4"]); }); test("without timed words a clip's quote is spread over its cited span (the estimate, and a build's fallback)", () => { const s = sched({ kineticQuote: {} }); const q = s.fx.quotes[0]; const flat = q.pages.flatMap((p) => p.words); assert.equal(flat.length, 16); const pw = playWindow(TIMELINE[0], render({})); // The first word starts at cutStart, in the cut's clock. near(flat[0].at, s.segments[0].start + (TIMELINE[0].cutStart - pw.from), FRAME, "first word"); assert.ok(flat.every((w, j) => j === 0 || w.at >= flat[j - 1].at), "in order"); assert.deepEqual(fxQuoteFallback({ quote: " ", start: 1, end: 2 }), []); }); test("quotePages: at most maxWords, a break after a clause once half full, no orphan", () => { const w = (t) => ({ text: t }); const pages = quotePages("one two three, four five six seven eight nine ten eleven twelve thirteen".split(" ").map(w), 6); assert.deepEqual(pages.map((p) => p.map((x) => x.text).join(" ")), ["one two three,", "four five six seven eight nine", "ten eleven twelve thirteen"]); assert.deepEqual(quotePages(["a", "b", "c", "d", "e", "f", "g"].map(w), 6).map((p) => p.length), [7]); }); test("punchMask: every time the phrase is said; the last word may run on", () => { const ws = "slow news days and a slow news week".split(" ").map((text) => ({ text })); assert.deepEqual(punchMask(ws, "slow news day"), [true, true, true, false, false, false, false, false]); assert.deepEqual(punchMask(ws, "slow news"), [true, true, false, false, false, true, true, false]); assert.deepEqual(punchMask(ws, ""), ws.map(() => false)); }); test("fxWordsOf: a span's words share it by their characters; furniture goes", () => { const ws = fxWordsOf([{ start: 0, end: 2, text: ">> ab [Music] abcd" }]); assert.deepEqual(ws.map((w) => w.text), ["ab", "abcd"]); near(ws[0].start, 0, 1e-9, "first"); near(ws[1].start, (2 * 3) / 8, 1e-9, "second starts after ab and a space"); assert.deepEqual(fxWordsOf([{ start: 0, end: 2, text: "a b" }], 1, 2).map((w) => w.text), ["b"]); }); test("the odometer rolls on each clip's punch, to the frame, from the count before", () => { const words = new Map([["c1", [{ text: "slow", start: 1.7, end: 2 }, { text: "news", start: 2, end: 2.3 }, { text: "week", start: 2.3, end: 2.6 }]]]); const s = sched({ odometer: {} }, { words }); const o = s.fx.odometer; assert.deepEqual(o.counts.map((c) => [c.segment, c.prev, c.value]), [["c1", 0, 9], ["c2", 9, 18], ["c3", 18, 27], ["c4", 27, 36]]); near(o.counts[0].at, s.segments[0].start + 1.7, FRAME, "c1 rolls on 'slow'"); assert.equal(o.digits, 2); // `at: "start"`: a quarter second after the clip is clean on screen. const st = sched({ odometer: { at: "start" } }, { words }); near(st.fx.odometer.counts[1].at, s.segments[1].start + 0.25 + 0.25, FRAME, "c2 at its in + 0.25"); // No montage numbers: places. const bare = TIMELINE.map(({ montage: _m, ...e }) => e); assert.deepEqual(sched({ odometer: {} }, { timeline: bare }).fx.odometer.counts.map((c) => c.value), [1, 2, 3, 4]); // The panel's span runs across consecutive clips. assert.deepEqual(o.spans, [{ in: 0, out: s.total }]); }); test("the glitch tears at each cut between years, centred on the mid-dissolve", () => { const timeline = [clip("c1", "2019-05-02"), clip("c2", "2019-08-02"), clip("c3", "2021-01-01"), clip("c4", "2026-01-01")]; const s = sched({ glitch: {} }, { timeline }); assert.deepEqual(s.fx.glitch.bursts.map((b) => [b.segment, b.year]), [["c3", 2021], ["c4", 2026]]); for (const b of s.fx.glitch.bursts) { const seg = s.segments.find((x) => x.id === b.segment); near(b.at, seg.start + 0.25, FRAME, `${b.segment} burst at the mid-dissolve`); } assert.equal(sched({ glitch: { on: "every" } }, { timeline }).fx.glitch.bursts.length, 3); }); test("the glitch on \"clips\": a tear only at the cut INTO each named clip, the rest as on \"every\"", () => { const timeline = [clip("c1", "2019-05-02"), clip("c2", "2019-08-02"), clip("c3", "2021-01-01"), clip("c4", "2026-01-01")]; const every = sched({ glitch: { on: "every", stamp: false } }, { timeline }).fx.glitch; const named = sched({ glitch: { on: "clips", clips: ["c4", "c2"], stamp: false } }, { timeline }).fx.glitch; // The list's order is not the cut's: the bursts are in the cut's order, each // exactly the burst "every" makes at that cut (its time, seed, year and date). assert.deepEqual(named.bursts.map((b) => b.segment), ["c2", "c4"]); assert.deepEqual(named.bursts, every.bursts.filter((b) => b.segment !== "c3")); assert.equal(named.stamp, false); // Into c2 is a cut within one year: "clips" tears there all the same. assert.deepEqual(sched({ glitch: { on: "clips", clips: ["c2"] } }, { timeline }).fx.glitch.bursts.map((b) => [b.segment, b.year]), [["c2", 2019]]); // The first clip has no cut into it; a card between two clips is its own break. assert.deepEqual(sched({ glitch: { on: "clips", clips: ["c1"] } }, { timeline }).fx.glitch.bursts, []); const carded = [clip("c1", "2019-05-02"), { type: "card", id: "k1", seconds: 4, heading: "x" }, clip("c2", "2021-01-01"), clip("c3", "2022-01-01")]; assert.deepEqual(sched({ glitch: { on: "clips", clips: ["c2", "c3"] } }, { timeline: carded, durs: [6.4, 4, 6.4, 6.4] }).fx.glitch.bursts.map((b) => b.segment), ["c3"]); }); test("the glitch on \"year\" and \"every\" schedule as they did before \"clips\"", () => { const timeline = [clip("c1", "2019-05-02"), clip("c2", "2019-08-02"), clip("c3", "2021-01-01"), clip("c4", "2026-01-01")]; // Pinned from the schedule before the "clips" mode was added. assert.deepEqual(sched({ glitch: {} }, { timeline }).fx.glitch, { stamp: true, bursts: [ { segment: "c3", at: 12.05, seconds: 0.5, year: 2021, date: "1 Jan 2021", seed: 2 }, { segment: "c4", at: 17.95, seconds: 0.5, year: 2026, date: "1 Jan 2026", seed: 3 }, ], }); assert.deepEqual(sched({ glitch: { on: "every", stamp: false, seconds: 0.8 } }, { timeline }).fx.glitch, { stamp: false, bursts: [ { segment: "c2", at: 6.15, seconds: 0.8, year: 2019, date: "2 Aug 2019", seed: 1 }, { segment: "c3", at: 12.05, seconds: 0.8, year: 2021, date: "1 Jan 2021", seed: 2 }, { segment: "c4", at: 17.95, seconds: 0.8, year: 2026, date: "1 Jan 2026", seed: 3 }, ], }); }); test("the glitch's clips: a list for on \"clips\" alone, 1 to 60 ids, each a clip of the cut with a clip before it", () => { assert.deepEqual(validateFx({ glitch: { on: "clips", clips: ["c2"], stamp: false } }), []); assert.match(validateFx({ glitch: { on: "clips" } }).join(), /glitch\.clips is needed with on "clips"/); assert.match(validateFx({ glitch: { on: "clips", clips: null } }).join(), /glitch\.clips is needed/); assert.match(validateFx({ glitch: { on: "clips", clips: [] } }).join(), /clips must be a list of 1 to 60 clip ids/); assert.match(validateFx({ glitch: { on: "clips", clips: ["c2", 3] } }).join(), /clips must be a list of 1 to 60 clip ids/); assert.match(validateFx({ glitch: { on: "clips", clips: "c2" } }).join(), /clips must be a list of 1 to 60 clip ids/); assert.match(validateFx({ glitch: { on: "clips", clips: Array.from({ length: 61 }, (_, i) => `c${i}`) } }).join(), /clips must be a list of 1 to 60/); assert.deepEqual(validateFx({ glitch: { on: "clips", clips: Array.from({ length: 60 }, (_, i) => `c${i}`) } }), []); assert.match(validateFx({ glitch: { on: "every", clips: ["c2"] } }).join(), /glitch\.clips is only for on "clips" \(on is "every"\)/); assert.match(validateFx({ glitch: { clips: ["c2"] } }).join(), /glitch\.clips is only for on "clips" \(on is "year"\)/); assert.match(validateFx({ glitch: { on: "never" } }).join(), /on must be "year", "every", "clips"/); // Against the cut: every id a clip, each with a clip right before it. const m = (glitch, timeline = TIMELINE) => validateFxEntries({ render: render({ glitch }), timeline }); assert.deepEqual(m({ on: "clips", clips: ["c2", "c4"] }), []); assert.deepEqual(m({ on: "clips", clips: ["c2", "c9", "c8"] }), ["render.chrome.fx.glitch.clips names c9, c8, which are not clips of the cut"]); assert.deepEqual(m({ on: "clips", clips: ["c9"] }), ["render.chrome.fx.glitch.clips names c9, which is not a clip of the cut"]); assert.match(m({ on: "clips", clips: ["c1"] }).join(), /names c1, with no clip right before/); const carded = [clip("c1", "2019-05-02"), { type: "card", id: "k1", seconds: 4, heading: "x" }, clip("c2", "2021-01-01")]; assert.match(m({ on: "clips", clips: ["k1"] }, carded).join(), /names k1, which is not a clip/); assert.match(m({ on: "clips", clips: ["c2"] }, carded).join(), /names c2, with no clip right before/); // The other modes never look at the list's ids (validateFx refuses the list there). assert.deepEqual(m({ on: "every" }), []); }); test("the glitch's year: true or false; false is written to the schedule, true (the default) leaves it as it was", () => { assert.deepEqual(validateFx({ glitch: { year: false, stamp: false } }), []); assert.deepEqual(validateFx({ glitch: { year: true } }), []); assert.match(validateFx({ glitch: { year: "no" } }).join(), /glitch\.year must be true or false/); const timeline = [clip("c1", "2019-05-02"), clip("c2", "2021-01-01"), clip("c3", "2021-06-01"), clip("c4", "2026-01-01")]; const dflt = sched({ glitch: { on: "every" } }, { timeline }).fx.glitch; assert.ok(!("year" in dflt), "no year key unless it is off"); assert.deepEqual(sched({ glitch: { on: "every", year: true } }, { timeline }).fx.glitch, dflt); const bare = sched({ glitch: { on: "every", year: false, stamp: false } }, { timeline }).fx.glitch; assert.equal(bare.year, false); // The bursts are the same tears: only the page leaves the year out. assert.deepEqual(bare.bursts, dflt.bursts); }); test("the scrubber: a tick per dated clip, the rail padded, a year mark per new year", () => { const s = sched({ scrubber: {} }); const sc = s.fx.scrubber; assert.deepEqual(sc.ticks.map((t) => t.label), ["2 May 2019", "11 Jun 2020", "1 Jan 2021", "1 Jan 2026"]); assert.ok(sc.from < sc.ticks[0].day && sc.to > sc.ticks[3].day); assert.deepEqual(sc.years.map((y) => y.year), [2020, 2021, 2022, 2023, 2024, 2025, 2026]); // A clip's date: montage.date first, then its date, then the record's. assert.deepEqual(fxClipDate({ montage: { date: "20190502" }, date: "2020-01-01" }, { uploadDate: "20210101" }), { y: 2019, m: 5, d: 2 }); assert.deepEqual(fxClipDate({}, { uploadDate: "20210101" }), { y: 2021, m: 1, d: 1 }); }); test("receipts and the zoom: placed inside the clip, the marker after the cards land", () => { const s = sched(ALL); const r = s.fx.receipts.clips[0]; const seg = s.segments.find((x) => x.id === "c2"); assert.equal(r.segment, "c2"); near(r.in, seg.start + 0.25 + 0.3, 1e-9, "after the clip is clean on screen"); assert.deepEqual(r.cards.map((c) => c.shot), ["shots/b.png", "shots/a.png"]); assert.ok(r.markAt >= r.cards[1].at + 0.4, "the marker waits for the last card"); const z = s.fx.zoom.clips[0]; assert.equal(z.segment, "c4"); assert.ok(z.in < z.outline && z.outline < z.push && z.push + 1 < z.out); }); test("receipts: `at` flies one in at its source second (past a gap), `hold` sends it off that long after", () => { const timeline = [ clip("c1", "2019-05-02"), clip("c2", "2020-06-11", { gaps: [{ from: 12, to: 13 }], fx: { receipts: [{ shot: "shots/b.png", mark: [0.04, 0.3, 0.9, 0.5], at: 15, hold: 1.5 }] } }), clip("c3", "2021-01-01"), ]; const s = sched({ receipts: {} }, { timeline, durs: [6.4, 7.4, 6.4] }); const r = s.fx.receipts.clips[0]; const seg = s.segments.find((x) => x.id === "c2"); // Source 15, the picture from 10.6 with 1 s cut out at 12-13: 3.4 s into the segment. near(r.cards[0].at, seg.start + 3.4, 1e-9, "the card flies in at its word"); near(r.in, r.cards[0].at, 1e-9, "nothing on screen before it"); near(r.out, r.cards[0].at + 0.42 + 1.5 + 0.38, 1e-9, "it leaves after its hold"); assert.ok(r.markAt >= r.cards[0].at + 0.42 && r.markAt + 0.55 <= r.out, "the marker swipes while it is up"); // Without at/hold the schedule is what it was. const plain = sched(ALL).fx.receipts.clips[0]; near(plain.cards[1].at - plain.cards[0].at, 0.18, 1e-9, "fanned in from the clip's start"); assert.deepEqual(validateFxEntries({ render: render({}), timeline: [clip("c9", "2020-01-01", { fx: { receipts: [{ shot: "shots/a.png", at: 30, hold: 20, when: 1 }] } })] }).map((x) => x.replace(/^.*receipts\[0\]\./, "")).sort(), ["at is outside the clip (10–18)", "hold must be from 0.5 to 10 seconds (up after it lands), or absent for the rest of the clip", "when is not a receipt field"]); }); test("no effect is drawn over a segment the deck hides (a card)", () => { const timeline = [clip("c1", "2019-05-02"), { type: "card", id: "k1", seconds: 4, heading: "x" }, clip("c2", "2021-01-01")]; const s = sched({ glitch: { on: "every" }, odometer: {}, kineticQuote: {} }, { timeline, durs: [6.4, 4, 6.4] }); assert.deepEqual(s.fx.quotes.map((q) => q.segment), ["c1", "c2"]); assert.equal(s.fx.glitch.bursts.length, 0, "a card between two clips is its own break"); assert.equal(s.fx.odometer.spans.length, 2, "the counter steps aside over the card"); assert.ok(hidesDeck(timeline[1], resolveDeck(render({})))); }); test("compileCues: ordered, clamped per element, every from stated", () => { const cues = compileCues({ a: { x: 0, autoAlpha: 0 } }, [ { k: "a", at: 2, dur: 1, to: { x: 10 } }, { k: "a", at: 1, dur: 0.5, to: { autoAlpha: 1 } }, { k: "a", at: 2.5, dur: 1, to: { x: 20 } }, ]); assert.deepEqual(cues.map((c) => [c.at, c.dur, c.from, c.to]), [ [1, 0.5, { autoAlpha: 0 }, { autoAlpha: 1 }], [2, 1, { x: 0 }, { x: 10 }], [3, 0.5, { x: 10 }, { x: 20 }], ]); }); test("fxRandom: the same seed, the same numbers", () => { const a = fxRandom(7), b = fxRandom(7), c = fxRandom(8); const xs = [a(), a(), a()]; assert.deepEqual(xs, [b(), b(), b()]); assert.notDeepEqual(xs, [c(), c(), c()]); assert.ok(xs.every((x) => x >= 0 && x < 1)); }); test("fxGeometry is the footage box: the deck's, the feed's, beside the rail", () => { assert.deepEqual(fxGeometry(render({})), deckGeometry(render({})).footage); assert.deepEqual(fxGeometry(render({}), { feed: true }), feedGeometry(render({})).footage); assert.deepEqual(fxRegion(render({}), "/o/chrome/fx-frames", { layout: undefined }), { name: "fx", frames: "/o/chrome/fx-frames", x: 173, y: 2, width: 1574, height: 886 }); }); test("the overlay lays the effects like the deck: whole cut, reinit off, rgba, shortest", () => { const r = render(ALL); const regions = [ { name: "deck", frames: "/o/chrome/deck-frames", x: 0, y: 890, width: 1920, height: 190 }, fxRegion(r, "/o/chrome/fx-frames", {}), ]; const c = chromeOverlayChain(r, regions, "[v3]", 4); assert.ok(c.inputs.join(" ").includes("-reinit_filter 0 -framerate 30 -start_number 1 -i /o/chrome/fx-frames/frame_%06d.png")); assert.match(c.chain, /\[5:v\]format=rgba\[hfa1\];\[hf0\]\[hfa1\]overlay=x=173:y=2:format=yuv444:shortest=1/); }); test("fxSuggestPairs: neighbouring clips years apart, widest gaps first, none twice, in cut order", async () => { const { fxSuggestPairs } = await import("./fx.mjs"); const tl = [clip("a", "2019-01-01"), clip("b", "2019-06-01"), clip("c", "2024-01-01"), clip("d", "2025-01-01"), { type: "card", id: "k", seconds: 3 }, clip("e", "2010-01-01")]; // b→c (4.6 years) is the widest; c→d (1 year) would reuse c; a→b is the same year; the card breaks d→e. assert.deepEqual(fxSuggestPairs({ timeline: tl }), [{ then: "b", now: "c" }]); assert.deepEqual(fxSuggestPairs({ timeline: tl }, 1), [{ then: "b", now: "c" }]); assert.deepEqual(fxSuggestPairs({ timeline: [clip("a", "2019-01-01"), clip("b", "2019-02-01")] }), []); }); test("fxPresetsFor: one preset per effect the cut can show, each a patch the validators accept", async () => { const { fxPresetsFor } = await import("./fx.mjs"); const m = { render: render(undefined, { transition: 0 }), timeline: TIMELINE }; const presets = fxPresetsFor(m); assert.deepEqual(presets.map((p) => p.name), ["kinetic-quote", "redaction", "odometer", "scrubber", "glitch", "punch-in", "whip", "reaction", "then-now", "receipts", "zoom", "everything"]); for (const p of presets) { assert.equal(p.patch.render.transition, 0.4, `${p.name}: a hard-cut project gets a crossfade to wipe on`); const chrome = { ...m.render.chrome, ...p.patch.render.chrome }; assert.deepEqual(validateChrome(chrome, { ...m.render, transition: 0.4 }), [], p.name); assert.deepEqual(validateFxEntries({ render: { ...m.render, chrome }, timeline: TIMELINE }), [], p.name); } // Without screenshots on any clip there is no receipts or zoom preset. const bare = TIMELINE.map(({ fx: _f, ...e }) => e); assert.deepEqual(fxPresetsFor({ render: render(undefined), timeline: bare }).map((p) => p.name).filter((n) => n === "receipts" || n === "zoom"), []); // The cut's own transition is kept. assert.equal(fxPresetsFor({ render: render(undefined, { transition: 0.25 }), timeline: TIMELINE })[0].patch.render.transition, 0.25); }); // ---- reaction highlights: two voices, the punch-in, the whip ---------------------- test("fxWordsOf marks a speaker's turn at '>>' and a dash; the kinetic line gives each voice its own pages", () => { const ws = fxWordsOf([{ start: 0, end: 4, text: "- Oh god, it is. - Sometimes it's a slow news day. >> Yeah" }]); assert.deepEqual(ws.filter((w) => w.turn).map((w) => w.text), ["Oh", "Sometimes", "Yeah"]); const words = new Map([["c1", ws.map((w) => ({ ...w, start: w.start + 1, end: w.end + 1 }))]]); const s = sched({ kineticQuote: {} }, { words, timeline: [clip("c1", "2024-05-22")], durs: [6.4] }); const q = s.fx.quotes[0]; assert.deepEqual(q.pages.map((p) => [p.speaker, p.words.map((w) => w.text).join(" ")]), [ [0, "Oh god, it is."], [1, "Sometimes it's a slow news day."], [0, "Yeah"], ]); assert.deepEqual(s.fx.quoteStyle.voices, [{ label: "", color: null }, { label: "", color: "#6fa8dc" }]); // speakers: false keeps one voice and no voices block. const off = sched({ kineticQuote: { speakers: false } }, { words, timeline: [clip("c1", "2024-05-22")], durs: [6.4] }); assert.ok(off.fx.quotes[0].pages.every((p) => !("speaker" in p))); assert.equal(off.fx.quoteStyle.voices, undefined); // A line with one voice has no speaker marks at all (the schedule it was). const one = sched({ kineticQuote: {} }, { words: new Map([["c1", [{ text: "solo", start: 1, end: 1.4 }]]]), timeline: [clip("c1", "2024-05-22")], durs: [6.4] }); assert.ok(one.fx.quotes[0].pages.every((p) => !("speaker" in p))); }); test("a clip's fx.speakers (source seconds) name the voices over the captions' turns; labels are the manifest's", () => { const words = new Map([["c1", [{ text: "a", start: 1, end: 1.2 }, { text: "b", start: 2, end: 2.2 }, { text: "c", start: 3, end: 3.2 }]]]); const c1 = clip("c1", "2024-05-22", { fx: { speakers: [{ at: 11.5, who: 1 }, { at: 12.5, who: 0 }] } }); const r = { kineticQuote: { voices: [{ label: "Host" }, { label: "Video", color: "#22ab83" }] } }; // The clip's segment starts at its play window's from (cutStart − lead-in = 10.6). const s = sched(r, { words, timeline: [c1], durs: [6.4] }); assert.deepEqual(s.fx.quotes[0].pages.map((p) => [p.speaker, p.words.map((w) => w.text).join(" ")]), [[1, "a"], [0, "b c"]]); const who = s.fx.quotes[0].pages.flatMap((p) => p.words.map(() => p.speaker)); // a at source 11.6 (≥ 11.5 → 1), b at 12.6 (≥ 12.5 → 0), c 13.6 → 0. assert.deepEqual(who, [1, 0, 0]); assert.deepEqual(s.fx.quoteStyle.voices, [{ label: "Host", color: null }, { label: "Video", color: "#22ab83" }]); assert.match(validateFxEntries({ render: render({}), timeline: [clip("c1", "2024-05-22", { fx: { speakers: [{ at: 1, who: 2 }] } })] }).join(), /speakers must be a list/); assert.match(validateFx({ kineticQuote: { voices: [{ color: "red" }] } }).join(), /#rrggbb/); }); test("the punch-in: on a clip's marked seconds and its captions' laughs, inside the clip, in the segment's clock", async () => { const words = new Map([["c1", [{ text: "that's", start: 1, end: 1.3 }, { text: "hahaha", start: 2.5, end: 3 }, { text: "lol", start: 2.9, end: 3.1 }]]]); const c1 = clip("c1", "2024-05-22", { fx: { punchIn: [14.6] } }); const s = sched({ punchIn: {} }, { words, timeline: [c1, clip("c2", "2024-05-23")], durs: [6.4, 6.4] }); const p = s.fx.punchIn.punches; // 2.5 (the laugh) and 14.6 − 10.6 = 4.0 (the mark); "lol" is inside the first's hold. assert.deepEqual(p.map((x) => [x.segment, x.segmentAt, x.segmentUntil]), [["c1", 2.5, 3.9], ["c1", 4, 5.4]]); near(p[0].at, s.segments[0].start + 2.5, FRAME, "cut time"); const { fxZoomJoins } = await import("./fx.mjs"); const zj = fxZoomJoins(s); assert.deepEqual([...zj.keys()], [0]); const joins = segmentJoins(s); assert.equal(joins[0].zoom.length, 2); assert.deepEqual(joins[0].zoom[0].box, { x: 173, y: 2, width: 1574, height: 886 }); assert.equal(joins[1], null); // auto: false keeps only the marks. assert.deepEqual(sched({ punchIn: { auto: false } }, { words, timeline: [c1], durs: [6.4] }).fx.punchIn.punches.map((x) => x.segmentAt), [4]); assert.match(validateFxEntries({ render: render({}), timeline: [clip("c1", "2024-05-22", { fx: { punchIn: [99] } })] }).join(), /outside the clip/); }); test("the punch-in's graph crops the box and lays it back over itself between its seconds; the record names it", async () => { const { joinInputChain, concatRecordText, punchInParts } = await import("./build-video.mjs"); const r = render({}); const c = joinInputChain(0, { hold: 0, move: null, zoom: [{ at: 2.5, until: 3.9, scale: 1.2, anchor: "upper" }] }, r); assert.deepEqual(c.parts, [ "[0:v]split=2[j0z0a][j0z0b]", "[j0z0b]crop=1312:738:304:39,scale=1574:886:flags=lanczos,setsar=1[j0z0c]", "[j0z0a][j0z0c]overlay=173:2:enable='between(t,2.5,3.9)'[j0z0]", ]); assert.equal(c.v, "[j0z0]"); // With a hold too, the hold clones the zoomed stream. const h = joinInputChain(0, { hold: 1, move: null, zoom: [{ at: 1, until: 2, scale: 1.2, anchor: "center" }] }, r); assert.match(h.parts.at(-2) ?? "", /^\[j0z0\]tpad=/); assert.equal(punchInParts(3, [], r, "[3:v]").v, "[3:v]"); const rec = concatRecordText(["a.mp4"], [{ hold: 0, move: null, zoom: [{ at: 1, until: 2, scale: 1.2, anchor: "upper" }] }]); assert.match(rec, /# join 0 \{"hold":0,"move":null,"zoom":\[/); assert.equal(concatRecordText(["a.mp4"], [{ hold: 1, move: null }]).includes("zoom"), false); }); test("the whip: every cut between clips slides (slideleft), but never one that wipes; a hard cut only streaks", () => { const tn = { thenNow: { pairs: [{ then: "c3", now: "c4" }] }, whip: {} }; const s = sched(tn); assert.deepEqual(s.fx.whip.cuts.map((c) => c.segment), ["c2", "c3"]); const joins = segmentJoins(s); assert.deepEqual(joins.map((j) => (j?.wipe ? "wipe" : j?.whip ? "whip" : null)), ["whip", "whip", "wipe", null]); const xf = xfadeGraph([6.4, 6.4, 6.4, 6.4], 0.5, joins).parts.filter((p) => /xfade=/.test(p)); assert.deepEqual(xf.map((p) => /transition=(\w+)/.exec(p)[1]), ["slideleft", "slideleft", "wipeleft"]); assert.deepEqual(xfadeBatchJoins(joins, [{ from: 0, to: 1 }, { from: 1, to: 4 }]), [{ whip: true }, null]); const hard = sched({ whip: {} }, { D: 0 }); assert.ok(hard.fx.whip.cuts.every((c) => !c.real && c.seconds === 0.24)); assert.equal(segmentJoins(hard), null); assert.deepEqual(sched({ whip: { on: "year" } }, { timeline: [clip("c1", "2019-01-01"), clip("c2", "2019-02-01"), clip("c3", "2020-01-01")], durs: [6.4, 6.4, 6.4] }).fx.whip.cuts.map((c) => c.segment), ["c3"]); });