Archilyzer · Source

archilyzer

Archilyzer
git clone https://archilyzer.pages.dev/source/archilyzer.git
Log | Files | Refs | README | LICENSE

commit 71676766ad7bf0947c69797942b489244ec826b6
parent 2484d0c04b03c3f8d947d42328f93bb53767aa90
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Fri, 30 Oct 2026 15:43:14 -0400

Merge lane/posts-persist-fx: popup posts can persist across clips without freezing the footage (deck.posts.persist), and a clip's fx gets a writer (umtool set fx.zoom=…, fx.zoom.hold)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

# Conflicts:
#	umtool/report-to-video/deck.mjs

Diffstat:
Mumtool/app/api/report/window/route.ts | 10++++++++++
Mumtool/docs/cli.md | 2+-
Mumtool/docs/knobs.md | 5+++++
Aumtool/lib/report/clip-fx.test.mjs | 132+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mumtool/lib/report/footage-move.mjs | 19+++++++++++++++++--
Mumtool/lib/report/knobsCli.mjs | 20+++++++++++++++++++-
Mumtool/lib/report/manifest.mjs | 121++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
Mumtool/lib/report/takeEdit.mjs | 2+-
Mumtool/report-to-video/build-video.mjs | 13++++++++++++-
Mumtool/report-to-video/chrome-posts.mjs | 22++++++++++++++++------
Mumtool/report-to-video/deck.mjs | 125++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
Mumtool/report-to-video/flips.mjs | 6+++---
Mumtool/report-to-video/fx.mjs | 21+++++++++++++++++----
Mumtool/report-to-video/modules/fx.mjs | 2++
Mumtool/report-to-video/modules/popup-posts.mjs | 8+++++++-
Mumtool/report-to-video/modules/settings.mjs | 25++++++++++++++++++++++++-
Aumtool/report-to-video/posts-persist.test.mjs | 260+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mumtool/report-to-video/threads.mjs | 29+++++++++++++++++++++++++++--
18 files changed, 788 insertions(+), 34 deletions(-)

diff --git a/umtool/app/api/report/window/route.ts b/umtool/app/api/report/window/route.ts @@ -68,6 +68,16 @@ export async function PUT(request: Request) { // What the deck says over this clip: { title?, subtitle? }, or null to // clear it. Normalised and checked by the writer, like the date. "onscreen", + // The clip's effects (report-to-video fx.mjs): `fx` whole, or one field + // (`fx.zoom`, …); null clears. Checked by the writer in the build's + // words, a screenshot against the project's files. + "fx", + "fx.punch", + "fx.quote", + "fx.punchIn", + "fx.speakers", + "fx.receipts", + "fx.zoom", ]) { if (body[k] !== undefined) patch[k] = body[k]; } diff --git a/umtool/docs/cli.md b/umtool/docs/cli.md @@ -26,7 +26,7 @@ Inbox cannot disagree about what is wrong with one. | `window <project> <clip> --take <take> …` | a **take's** clip (walk a take): the same fields, written into the take's patch (`takes/<take>/take.json`) with an undo point first; the project's manifest is untouched ([clip-bench.md](clip-bench.md#walking-a-take)) | | `walk <project> [--take <take>] [--all] [--json]` | the clip bench's **walk**: every clip in walk order with its window, verdict and whether a fetched file holds it, and (→) the ones the walk visits — fetched and needing a verdict; `--all` every fetched one; `--take` walks a take (a draft too); the bench's address to start at | | `link <project> <site>/<report>` · `link <project> --clear` | the manifest names the article it is the video of (settles `link-ambiguous`) | -| `set <project> <clip> key=value …` | a clip's **knobs**: `claim.at` `claim.hold` `claim.stamp` `claim.count` `claim.label` (the first mark's, or `--mark <id>`'s), its **marks** `mark.add=<verdict>[@<sec>]` `mark.remove=<id>` `mark.verdict=<verdict>` `marks=<json>`, `audio.offset` `audio.gain` `audio.fadeIn` `audio.fadeOut`, its picture's **blur** `blur.on=true` `blur.caption=…` `blur.strength` `blur.from` `blur.to` (`blur.on=` clears it; [knobs.md](knobs.md#a-clips-picture-blurred)); `key=` clears one ([knobs.md](knobs.md#marks)) | +| `set <project> <clip> key=value …` | a clip's **knobs**: `claim.at` `claim.hold` `claim.stamp` `claim.count` `claim.label` (the first mark's, or `--mark <id>`'s), its **marks** `mark.add=<verdict>[@<sec>]` `mark.remove=<id>` `mark.verdict=<verdict>` `marks=<json>`, `audio.offset` `audio.gain` `audio.fadeIn` `audio.fadeOut`, its picture's **blur** `blur.on=true` `blur.caption=…` `blur.strength` `blur.from` `blur.to` (`blur.on=` clears it; [knobs.md](knobs.md#a-clips-picture-blurred)), its **effects** `fx.zoom=<json>` `fx.receipts=<json>` `fx.punch=…` `fx.quote` `fx.punchIn=<json>` `fx.speakers=<json>` (`fx=<json>` all of them, `fx=` clears them; a shot is a file in the project; [knobs.md](knobs.md#effects)); `key=` clears one ([knobs.md](knobs.md#marks)) | | `look <project> key=value …` | the cut's **knobs**: `factcheck.stamp.*`, `factcheck.verdicts.<V>.stampLabel\|label\|color`, `deck.markers=<json>`, `deck.markerLayout`, `variants=<json>`, and the look's keys ([knobs.md](knobs.md)) | | `variants <project> [--take <t>] [--list] [--json]` | **Make variants**: the encode ladder of the build (or of a take's); `--list` what was made and the build's sync report, each clip's lag (past a frame flagged) ([knobs.md](knobs.md)) | | `build <project> [--preset preview\|fast\|final] [--only ID]` | **prints** the chain | diff --git a/umtool/docs/knobs.md b/umtool/docs/knobs.md @@ -31,6 +31,8 @@ that generates it ([notes.md](notes.md)). | `blur.strength` — the blur's radius, % of the picture's height as it plays (2–15; default 5) | Blur, **strength** | `blur.strength=8` | same | | `blur.from`, `blur.to` — source seconds inside the clip's window: blur only that span (either alone runs to the clip's edge; default the whole clip) | Blur, **From playhead** / **To playhead**, **Whole clip** | `blur.from=231.5 blur.to=262` | same | | `layout` — `finale`: the deck's finale layout for this clip (`render.chrome.deck.finale`); `clip` is the default | — | `umtool set <p> <clip> layout=finale` | — | +| `fx.zoom` — `{shot, focus, at?, hold?}`: a screenshot (a file in the project; a bare name under its `shots/` is written as `shots/<name>`) that comes up over the footage and pushes in on `focus` (`[left, top, right, bottom]`, fractions of the shot) — drawn once `render.chrome.fx.zoom` is on ([Effects](#effects)). **How long it stays**: up 0.2 s into the clip's clean span (rising in over 0.38 s), its focus box drawn 0.55 s later, the push at `at` (seconds into the clip; default as soon as the box has drawn) over 1 s, then a slow drift on the detail; it leaves with a 0.3 s fade 0.3 s before the clip's clean span ends — or, with `hold` (0.5–10 s), that long after the push lands (never past the clip's own leave) | — | `umtool set <p> <clip> fx.zoom='{"shot":"shots/x.png","focus":[0.1,0.2,0.9,0.4],"at":5.9,"hold":4}'` (`fx.zoom=` clears it) | `PUT /api/report/window {project, clip, "fx.zoom": {…} \| null}` | +| `fx.receipts`, `fx.punch`, `fx.quote`, `fx.punchIn`, `fx.speakers` — the clip's other effect fields (`[{shot, mark?}]` 1–4; the words to punch; `false`: no line; 1–8 source seconds inside the clip; `[{at, who: 0\|1}]`), each inert until its effect is on; `fx` is all of them at once. Checked by the build's own `validateFxEntries` | — | `fx.punch="the words"` `fx.punchIn='[231.4]'` · `fx='{…}'` sets them all, `fx=` clears every one | `PUT /api/report/window {project, clip, fx}` (or one `"fx.<field>"`) | `key=` (nothing after the `=`) clears a knob; in umtool, **Clear** beside a field (Audio: **Clear all**). A claim's knobs are read from the clip that **stamps** it — the last clip carrying the claim id; the box on any other @@ -545,6 +547,7 @@ A clip's posts as cards over the footage (`deck.posts`, the `popup` layout), eac | `deck.posts.position` | `top-right` · `top-left` · default `top-right` | same | | `deck.posts.shift` | `false` · `{scale 0.5–1, seconds 0–3}` · default 0.86, 0.6 (the footage moves aside while they are up) | same | | `deck.posts.shotMaxHeight` | null · 120–1080 px · default null (a full card of words) | same | +| `deck.posts.persist` | `true` · `{seconds 8–60, gap 0–30}` · `false`/absent (off: each clip's posts its own short window, as above) · default seconds 12, gap 6. On: the footage NEVER freezes (`hold` is ignored). A card comes up at its moment (`at`, as above) and stays up on its own clock for `seconds`, over clip joins and dissolves. A post whose moment comes while the bar is up, or within `gap` after it would go, keeps it up: a later clip's cards SWAP in (the cards up slide up and out as the new one lands — the bar holds one clip's posts at a time, so stale cards never pile up over the footage), a clip's own still stack. With no post soon it leaves (0.45 s fade). The bar never runs into a card, a teaser, an image or the finale: it is gone by the transition into one. `shift` spans it too: the footage stays aside across the joins the bar spans, every segment moving on the cut's clock, and glides back as the bar leaves (a segment that starts as it leaves comes in at its normal box). Absent, every render is byte for byte what it was | `umtool look <p> deck.posts.persist='{"seconds":12,"gap":6}'` (`deck.posts.persist=` off) | ### Stamps @@ -595,6 +598,8 @@ Overlays on the picture -- receipts, a zoom, the scrubber, a kinetic quote, punc |---|---|---| | `render.chrome.fx.<effect>` | scrubber · receipts · zoom · kineticQuote · redact · odometer · punchIn · thenNow · whip · glitch | a take: `umtool take <p> --effect <name>` | | `render.chrome.fx.glitch.on`, `.clips` | `year` (a tear at each cut between years) · `every` (each cut between clips) · `clips` (only the cut INTO each clip `clips` names: 1–60 ids, each with a clip right before it) · default `year`; `clips` only with `on: "clips"`. `.seconds` 0.2–1.5 · 0.5, `.stamp` (the `PLAY ▶` date) · `true`, `.year` (the new year big over the tear; `false` with `stamp: false` is a bare tear, no text) · `true` | manifest | +| a clip's `fx` — what an effect draws on it, inert until that effect is on: `zoom` `{shot, focus, at?, hold?}`, `receipts` `[{shot, mark?}]` (1–4), `punch` (the words), `quote` (false: no line), `punchIn` `[source s…]` (1–8, inside the clip), `speakers` `[{at, who: 0|1}]`. A `shot` is a file in the project (a bare name under its `shots/` is written as `shots/<name>`); `focus`/`mark` are `[left, top, right, bottom]` fractions of it | `fx.<field>=<json>` sets one and keeps the rest · `fx=<json>` all · `fx=` none; checked by the build's own `validateFxEntries` | `umtool set <p> <clip> fx.zoom='{"shot":"shots/x.png","focus":[0.1,0.2,0.9,0.4],"at":5.9}'` · `PUT /api/report/window {project, clip, fx}` (or `"fx.zoom"`, …) | +| the zoom's timing (`fx.zoom.at`, `.hold`) | up 0.2 s into the clip's clean span (the card rises in over 0.38 s, `back.out`); its focus box draws 0.55 s later (0.45 s); it pushes in on the box at `at` — seconds into the clip, default as soon as the box has drawn — over 1 s (`power2.inOut`), then drifts slowly on the detail. It leaves with a 0.3 s fade 0.3 s before the clip's clean span ends, or with `hold` (0.5–10 s) that long after the push lands (never past the clip's own leave) | `fx.zoom='{…,"hold":4}'` | ### Thread rail diff --git a/umtool/lib/report/clip-fx.test.mjs b/umtool/lib/report/clip-fx.test.mjs @@ -0,0 +1,132 @@ +// A clip's `fx` through the one writer (updateClip / patchClipEntry): whole, +// per field, cleared; refused in validateFxEntries's words; a screenshot is a +// file in the project (or under its shots/); a take's walk writes it too; and +// `umtool set fx.*` is the same writer from a terminal. +// +// Run with: pnpm test:scripts +import assert from "node:assert/strict"; +import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises"; +import { tmpdir } from "node:os"; +import path from "node:path"; +import test from "node:test"; + +import { fxSchedule, validateFxEntries, FX_MOTION } from "umtool-report-to-video/fx"; + +const ROOT = await mkdtemp(path.join(tmpdir(), "umtool-clip-fx-")); +process.env.REPORTS_DIR = ROOT; +const { MANIFEST_NAME, manifestToken, patchClipEntry, updateClip } = await import("./manifest.mjs"); +const { setCommand } = await import("./knobsCli.mjs"); + +const base = () => ({ + slug: "t", + provenance: { siteOrigin: "https://example.test", channelSlug: "chan" }, + render: { width: 1920, height: 1080, fps: 30, transition: 0.5 }, + timeline: [ + { type: "card", id: "k1", heading: "Opening" }, + { type: "clip", id: "c01", video: "v1", start: 10, end: 20 }, + { type: "clip", id: "c02", video: "v2", start: 30, end: 41, fx: { punch: "kept" } }, + ], +}); + +async function project(name, manifest = base()) { + const dir = path.join(ROOT, name); + await mkdir(path.join(dir, "shots"), { recursive: true }); + await writeFile(path.join(dir, MANIFEST_NAME), JSON.stringify(manifest, null, 2) + "\n"); + await writeFile(path.join(dir, "shots", "doc.png"), "png"); + await writeFile(path.join(dir, "top.png"), "png"); + return dir; +} +const readRaw = (dir) => readFile(path.join(dir, MANIFEST_NAME), "utf8"); +const read = async (dir) => JSON.parse(await readRaw(dir)); +const clip = (m, id) => m.timeline.find((e) => e.id === id); + +test.after(() => rm(ROOT, { recursive: true, force: true })); + +test("updateClip fx.zoom: written, rounded, its shot checked in the project; a bare name found under shots/", async () => { + const dir = await project("zoom"); + const res = await updateClip(dir, "c01", { "fx.zoom": { shot: "shots/doc.png", focus: [0.1, 0.20001, 0.9, 0.4], at: 5.904, hold: 4 } }, { token: await manifestToken(dir) }); + assert.deepEqual(res.entry.fx, { zoom: { shot: "shots/doc.png", focus: [0.1, 0.2, 0.9, 0.4], at: 5.9, hold: 4 } }); + assert.deepEqual(clip(await read(dir), "c01").fx, res.entry.fx); + // A bare name only under shots/ is written as that path; one beside the manifest as itself. + await updateClip(dir, "c01", { "fx.zoom": { shot: "doc.png", focus: [0, 0, 1, 1] } }); + assert.equal(clip(await read(dir), "c01").fx.zoom.shot, "shots/doc.png"); + await updateClip(dir, "c01", { "fx.zoom": { shot: "top.png", focus: [0, 0, 1, 1] } }); + assert.equal(clip(await read(dir), "c01").fx.zoom.shot, "top.png"); + // The manifest still validates as the build reads it. + assert.deepEqual(validateFxEntries(await read(dir)), []); +}); + +test("updateClip fx: a missing or escaping shot, or a shape the build refuses, is refused in its words and nothing is written", async () => { + const dir = await project("refuse"); + const before = await readRaw(dir); + await assert.rejects(updateClip(dir, "c01", { "fx.zoom": { shot: "shots/nope.png", focus: [0, 0, 1, 1] } }), /fx\.zoom\.shot shots\/nope\.png is not a file in the project/); + await assert.rejects(updateClip(dir, "c01", { "fx.zoom": { shot: "../x.png", focus: [0, 0, 1, 1] } }), /not outside it/); + await assert.rejects(updateClip(dir, "c01", { "fx.zoom": { shot: "shots/doc.png", focus: [0.5, 0, 0.4, 1] } }), /timeline entry c01: fx\.zoom\.focus must be \[left, top, right, bottom\]/); + await assert.rejects(updateClip(dir, "c01", { "fx.zoom": { shot: "shots/doc.png", focus: [0, 0, 1, 1], hold: 30 } }), /fx\.zoom\.hold must be from 0\.5 to 10 seconds/); + await assert.rejects(updateClip(dir, "c01", { "fx.zoom": { shot: "shots/doc.png", focus: [0, 0, 1, 1], spin: 1 } }), /fx\.zoom\.spin is not a zoom field/); + await assert.rejects(updateClip(dir, "c01", { "fx.punchIn": [5] }), /fx\.punchIn has a second outside the clip \(10–20\)/); + await assert.rejects(updateClip(dir, "c01", { "fx.quote": "yes" }), /fx\.quote must be true or false/); + await assert.rejects(updateClip(dir, "c01", { fx: [1] }), /^Error: fx must be \{/); + await assert.rejects(updateClip(dir, "c01", { "fx.receipts": [{ shot: "shots/nope.png" }] }), /fx\.receipts\[0\]\.shot shots\/nope\.png is not a file/); + assert.equal(await readRaw(dir), before); +}); + +test("updateClip fx: a field patch keeps the rest; null removes a field; fx whole replaces; fx null (or \"\") clears", async () => { + const dir = await project("fields"); + await updateClip(dir, "c02", { "fx.punchIn": [31.234], "fx.quote": false, "fx.receipts": [{ shot: "doc.png", mark: [0, 0.4, 1, 0.5] }] }); + assert.deepEqual(clip(await read(dir), "c02").fx, { + punch: "kept", punchIn: [31.23], quote: false, receipts: [{ shot: "shots/doc.png", mark: [0, 0.4, 1, 0.5] }], + }); + await updateClip(dir, "c02", { "fx.punch": null, "fx.quote": "" }); + assert.deepEqual(clip(await read(dir), "c02").fx, { punchIn: [31.23], receipts: [{ shot: "shots/doc.png", mark: [0, 0.4, 1, 0.5] }] }); + await updateClip(dir, "c02", { fx: { punch: " the words ", speakers: [{ at: 32, who: 1 }] } }); + assert.deepEqual(clip(await read(dir), "c02").fx, { punch: "the words", speakers: [{ at: 32, who: 1 }] }); + await updateClip(dir, "c02", { fx: null }); + assert.equal("fx" in clip(await read(dir), "c02"), false); + // The last field removed removes fx. + await updateClip(dir, "c02", { "fx.punch": "x" }); + await updateClip(dir, "c02", { "fx.punch": null }); + assert.equal("fx" in clip(await read(dir), "c02"), false); +}); + +test("patchClipEntry: a window save that strands a punch-in is refused; one under an fx already bad is not blamed for it", () => { + const m = base(); + clip(m, "c01").fx = { punchIn: [12] }; + assert.throws(() => patchClipEntry(m, "c01", { start: 13 }), /punchIn has a second outside the clip \(13–20\)/); + const bad = base(); + clip(bad, "c01").fx = { quote: "nope" }; + const { entry } = patchClipEntry(bad, "c01", { end: 19 }); + assert.equal(entry.end, 19); +}); + +test("fx.zoom.hold: absent, the zoom stays to its clip's end (as it was); set, it leaves that long after the push lands", () => { + const render = { width: 1920, height: 1080, fps: 30, chrome: { engine: "hyperframes", layout: "deck", fx: { zoom: {} } } }; + const segments = [{ id: "c01", start: 0, duration: 20 }]; + const sched = (zoom) => fxSchedule({ + segments, entries: [{ type: "clip", id: "c01", start: 0, end: 20, fx: { zoom } }], render, D: 0.5, total: 20, + sourceFrom: () => 0, hidden: () => false, + }).zoom.clips[0]; + const plain = sched({ shot: "s.png", focus: [0, 0, 1, 1], at: 3 }); + assert.equal(plain.out, 19.7); // the clip's clean span less 0.3 + const held = sched({ shot: "s.png", focus: [0, 0, 1, 1], at: 3, hold: 4 }); + assert.equal(held.push, plain.push); + assert.equal(held.out, Math.round((plain.push + FX_MOTION.push + 4 + 0.3) * 1000) / 1000); + // Never past the clip's own leave. + assert.equal(sched({ shot: "s.png", focus: [0, 0, 1, 1], at: 12, hold: 10 }).out, 19.7); +}); + +test("umtool set fx.*: the zoom as JSON, the punch as words, fx= clears every field; a bad one refused", async () => { + const dir = await project("cli"); + const lines = []; + const run = (...args) => setCommand(args, { root: ROOT, out: (s) => lines.push(s), err: (s) => lines.push(`ERR ${s}`) }); + assert.equal(await run("cli", "c01", 'fx.zoom={"shot":"shots/doc.png","focus":[0.1,0.2,0.9,0.4],"at":5.9}', "fx.punch=2020"), 0, lines.join("\n")); + assert.deepEqual(clip(await read(dir), "c01").fx, { zoom: { shot: "shots/doc.png", focus: [0.1, 0.2, 0.9, 0.4], at: 5.9 }, punch: "2020" }); + assert.match(lines.at(-1), /^c01: fx \{.*"zoom":\{"shot":"shots\/doc.png"/); + assert.equal(await run("cli", "c01", "fx.zoom.hold=4"), 2); + assert.match(lines.at(-1), /not a clip knob/); + assert.equal(await run("cli", "c01", 'fx.zoom={"shot":"shots/gone.png","focus":[0,0,1,1]}'), 1); + assert.match(lines.at(-1), /is not a file in the project/); + assert.equal(await run("cli", "c01", "fx="), 0); + assert.equal("fx" in clip(await read(dir), "c01"), false); + assert.match(lines.at(-1), /^c01: fx none/); +}); diff --git a/umtool/lib/report/footage-move.mjs b/umtool/lib/report/footage-move.mjs @@ -13,11 +13,14 @@ // the scrubber is in the next segment there is no move; // - before `at` the footage is in its box; over `seconds` it eases to `to`; // after that it stays at `to` to the end of the segment (the hold included). +// - under PERSISTING popups (`posts.persist`) every segment a bar spans has +// a move with `phases` on the cut's clock: aside at `at`, back at `until`. // // The easing is smoothstep, p²(3 − 2p): the curve the build's move uses. /** @typedef {{ x: number, y: number, width: number, height: number }} Rect */ -/** @typedef {{ segment: string, at: number, segmentAt: number, seconds: number, from: Rect, to: Rect }} Move */ +/** @typedef {{ at: number, segmentAt: number, until: number, segmentUntil: number }} Phase */ +/** @typedef {{ segment: string, at: number, segmentAt: number, seconds: number, from: Rect, to: Rect, phases?: Phase[] }} Move */ /** smoothstep on [0, 1], clamped: 0 and 1 outside it. */ export function ease(p) { @@ -43,6 +46,18 @@ export function segmentIdAt(schedule, t) { const lerp = (a, b, p) => a + (b - a) * p; /** + * A persisting popup's move (`posts.persist`, deck.mjs persistMoves): aside + * at each phase's `at`, back at its `until` (cut clock), each over `seconds` + * -- min(1, Σ in·(1 − back)), the build's own sum. + */ +function phasesProgress(m, t) { + const step = (from) => (m.seconds > 0 ? ease((t - from) / m.seconds) : t >= from ? 1 : 0); + let e = 0; + for (const ph of m.phases) e += step(ph.at) * (1 - step(ph.until)); + return Math.min(1, e); +} + +/** * The footage's box at `t`, when the segment on screen has a move: its * eased progress (0 before the move, 1 after it) and the rect between `from` * and `to`. null when the segment on screen has no move -- the footage is in @@ -58,7 +73,7 @@ export function footageAt(schedule, t) { const id = segmentIdAt(schedule, t); const m = moves.find((x) => x.segment === id); if (!m) return null; - const progress = m.seconds > 0 ? ease((t - m.at) / m.seconds) : t >= m.at ? 1 : 0; + const progress = Array.isArray(m.phases) && m.phases.length ? phasesProgress(m, t) : m.seconds > 0 ? ease((t - m.at) / m.seconds) : t >= m.at ? 1 : 0; const rect = { x: lerp(m.from.x, m.to.x, progress), y: lerp(m.from.y, m.to.y, progress), diff --git a/umtool/lib/report/knobsCli.mjs b/umtool/lib/report/knobsCli.mjs @@ -11,6 +11,8 @@ // audio.offset audio.gain audio.fadeIn audio.fadeOut // blur.on blur.caption blur.strength blur.from blur.to // (`blur.on=` clears the whole blur; report-to-video clip-blur.mjs) +// fx=<json> fx.zoom fx.receipts fx.punch fx.quote fx.punchIn fx.speakers +// (the clip's effects; `fx=` clears them all; report-to-video fx.mjs) // umtool look <project> key=value … factcheck.stamp.<k>, factcheck.verdicts.<V>.<k>, factcheck.tally.<k>, // deck.markers=<json>, deck.markerLayout=…, deck.claims=<json>, variants=<json>, // and the look's keys (transition=0.3, …) @@ -25,6 +27,7 @@ import { REPORTS_ROOT, resolveProject } from "../projects/core.mjs"; import { readManifest } from "../projects/report.mjs"; import { withEditNotes } from "./edit-guard.mjs"; import { + FX_ENTRY_FIELDS, LOOK_KEYS, manifestToken, updateClaimKnobs, @@ -45,7 +48,9 @@ export const BLUR_KNOBS = Object.freeze(["on", "caption", "strength", "from", "t const MARK_KEYS = ["marks", "mark.add", "mark.remove", "mark.verdict"]; /** The walk's verdict, set like a knob: verdict=confirmed|incorrect|wrong-speaker, reason=wrong-speaker, correction=… (`key=` clears). */ const REVIEW_KEYS = ["verdict", "reason", "correction"]; -const SET_KEYS = [...CLAIM_KNOBS.map((k) => `claim.${k}`), ...MARK_KEYS, ...AUDIO_KNOBS.map((k) => `audio.${k}`), ...BLUR_KNOBS.map((k) => `blur.${k}`), "layout", ...REVIEW_KEYS]; +/** The clip's effects (report-to-video fx.mjs): `fx=<json>` whole (`fx=` clears it), `fx.<field>=<json>` one field. */ +const FX_KEYS = ["fx", ...FX_ENTRY_FIELDS.map((k) => `fx.${k}`)]; +const SET_KEYS = [...CLAIM_KNOBS.map((k) => `claim.${k}`), ...MARK_KEYS, ...AUDIO_KNOBS.map((k) => `audio.${k}`), ...BLUR_KNOBS.map((k) => `blur.${k}`), "layout", ...REVIEW_KEYS, ...FX_KEYS]; export const SET_USAGE = [ "usage: umtool set <project> <clip> key=value … [--mark <id>] [--json]", @@ -69,6 +74,12 @@ export const SET_USAGE = [ " seconds inside the clip's window, to blur only that span. render.blur=off (umtool look, or a take's", " --set) renders every clip unblurred: the uncensored variant. layout=finale|clip (the deck's finale", " layout for this clip; clip is the default). `key=` clears it (the default).", + " The clip's effects (drawn once render.chrome.fx turns the effect on; docs/knobs.md \"Effects\"):", + " fx.zoom='{\"shot\":\"shots/x.png\",\"focus\":[0.1,0.2,0.9,0.4],\"at\":5.9,\"hold\":4}' (shot: a file in the project;", + " focus: left, top, right, bottom fractions of it; at: seconds into the clip it pushes in; hold 0.5–10 s on the", + " detail, absent: to the clip's end); fx.receipts='[{\"shot\":\"shots/a.png\",\"mark\":[0,0.4,1,0.5]}]' (1–4);", + " fx.punch=\"the words\"; fx.quote=false; fx.punchIn='[231.4]' (source seconds);", + " fx.speakers='[{\"at\":231,\"who\":1}]'; fx='{…}' sets them all, `fx=` clears every one, `fx.<field>=` that one.", ].join("\n"); export const LOOK_USAGE = [ @@ -170,6 +181,11 @@ export async function setCommand(args, { root = REPORTS_ROOT, out = (s) => conso entryPatch.layout = value; continue; } + if (FX_KEYS.includes(key)) { + // The punch is words whatever they parse as (`fx.punch=2020`). + entryPatch[key] = key === "fx.punch" && value !== null ? String(value) : value; + continue; + } if (REVIEW_KEYS.includes(key)) { entryPatch[key] = value === null || value === undefined ? "" : String(value); continue; @@ -209,6 +225,7 @@ export async function setCommand(args, { root = REPORTS_ROOT, out = (s) => conso if ("audio" in entryPatch) results.audio = result.entry.audio ?? null; if ("blur" in entryPatch) results.blur = result.entry.blur ?? null; if ("layout" in entryPatch) results.layout = result.entry.layout ?? "clip"; + if (FX_KEYS.some((k) => k in entryPatch)) results.fx = result.entry.fx ?? null; if (REVIEW_KEYS.some((k) => k in entryPatch)) { results.review = { verdict: result.entry.verdict ?? null, reason: result.entry.reason ?? null, correction: result.entry.correction ?? null }; } @@ -229,6 +246,7 @@ export async function setCommand(args, { root = REPORTS_ROOT, out = (s) => conso if ("audio" in results) out(`${clipId}: audio ${results.audio ? JSON.stringify(results.audio) : "as recorded"}`); if ("blur" in results) out(`${clipId}: blur ${results.blur ? JSON.stringify(results.blur) : "none (the picture as recorded)"}`); if ("layout" in results) out(`${clipId}: layout ${results.layout}`); + if ("fx" in results) out(`${clipId}: fx ${results.fx ? JSON.stringify(results.fx) : "none"}`); if (results.review) { const r = results.review; out(`${clipId}: ${r.verdict ?? "not reviewed"}${r.reason ? ` (${r.reason})` : ""}${r.correction ? ` — ${r.correction}` : ""}`); diff --git a/umtool/lib/report/manifest.mjs b/umtool/lib/report/manifest.mjs @@ -20,6 +20,7 @@ // 4. GUARD ON THE FILE'S OWN MTIME. A PUT carrying a stale token is a 409, not // a silent overwrite -- somebody may have run `resolve-windows --write` in // between, and losing that is losing human judgement. +import { statSync } from "node:fs"; import { copyFile, readFile, rename, stat, writeFile } from "node:fs/promises"; import path from "node:path"; import { @@ -46,6 +47,7 @@ import { loadPreset, resolvePresetLayers } from "umtool-report-to-video/presets" import { storyClipErrors } from "umtool-report-to-video/modules/story-settings"; import { counterOrder } from "umtool-report-to-video/counter"; import { validateFinaleEntries } from "umtool-report-to-video/finale"; +import { validateFxEntries } from "umtool-report-to-video/fx"; import { validateClipAudio } from "umtool-report-to-video/clip-audio"; import { BLUR_CAPTION_DEFAULT, BLUR_STRENGTH, validateClipBlur, validateClipBlurEntries } from "umtool-report-to-video/clip-blur"; import { @@ -199,7 +201,7 @@ export async function updateClip(dir, clipId, patch, { token = null, edit = "tri // Re-read INSIDE the lock, every time. Nothing is held across requests. const raw = await readFile(manifestFile(dir), "utf8"); const manifest = JSON.parse(raw); - const { entry, before } = patchClipEntry(manifest, clipId, patch, { edit, now, raw }); + const { entry, before } = patchClipEntry(manifest, clipId, patch, { edit, now, raw, dir }); const nextToken = await writeManifestAtomic(dir, manifest); // A moved extent may need a new bench excerpt: queued, never waited for. if (entry.start !== before.start || entry.end !== before.end) benchPrepAfterWrite(dir, [clipId]); @@ -217,12 +219,13 @@ export async function updateClip(dir, clipId, patch, { token = null, edit = "tri * @param {Record<string, any>} manifest * @param {string} clipId * @param {Record<string, unknown>} patch - * @param {{ edit?: string, now?: string | null, raw?: string | null }} [opts] + * @param {{ edit?: string, now?: string | null, raw?: string | null, dir?: string | null }} [opts] * `raw`: the manifest's text before the patch, when the caller has it (the - * finale check compares against it); else it is taken here. + * finale check compares against it); else it is taken here. `dir`: the + * project's directory, where an `fx` screenshot written here must be. * @returns {{ entry: Record<string, any>, before: { start: number, end: number } }} */ -export function patchClipEntry(manifest, clipId, patch, { edit = "trim", now = null, raw = null } = {}) { +export function patchClipEntry(manifest, clipId, patch, { edit = "trim", now = null, raw = null, dir = null } = {}) { const original = patch.layout !== undefined ? (raw ?? JSON.stringify(manifest)) : null; const entry = (manifest.timeline ?? []).find((e) => e.id === clipId); if (!entry) throw new Error(`no timeline entry with id ${clipId}`); @@ -238,6 +241,13 @@ export function patchClipEntry(manifest, clipId, patch, { edit = "trim", now = n const before = { start: entry.start, end: entry.end }; const cutBefore = cutOf(entry); + // The effects' fields as they were, for a check that refuses only what a + // write ADDS: a window save, or an fx write, under an fx that already had + // a problem is not blamed for it. + const fxWrite = patch.fx !== undefined || FX_ENTRY_FIELDS.some((k) => patch[`fx.${k}`] !== undefined); + const fxWas = fxWrite || ((patch.start !== undefined || patch.end !== undefined) && entry.fx !== undefined) + ? new Set(entryFxErrors(structuredClone(entry))) + : null; for (const k of WINDOW_FIELDS) { if (patch[k] === undefined) continue; const v = Number(patch[k]); @@ -607,6 +617,38 @@ export function patchClipEntry(manifest, clipId, patch, { edit = "trim", now = n } } + // ---- the clip's effects (video knobs) ------------------------------------ + // + // `fx: { punch, quote, punchIn, speakers, receipts, zoom }` -- read by the + // effects page (report-to-video fx.mjs, whose validateFxEntries is the + // check) and inert until its effect is on (`render.chrome.fx`). `fx` whole + // replaces them all (null or "" removes `fx`); `fx.<field>` sets that one + // and keeps the rest (null or "" removes it); nothing left removes `fx`. A + // screenshot (`fx.zoom.shot`, `fx.receipts[].shot`) is a file in the + // project, as the build reads it (relative to the manifest); a bare name + // that is only under the project's `shots/` is written as `shots/<name>`. + if (fxWrite) { + let next = {}; + if (patch.fx !== undefined && patch.fx !== null && patch.fx !== "") { + if (!isObj(patch.fx)) throw new Error(`fx must be { ${FX_ENTRY_FIELDS.join(", ")} } (each optional), or null to clear it`); + next = { ...patch.fx }; + } else if (patch.fx === undefined && isObj(entry.fx)) next = { ...entry.fx }; + for (const k of FX_ENTRY_FIELDS) { + const v = patch[`fx.${k}`]; + if (v === undefined) continue; + if (v === null || v === "") delete next[k]; + else next[k] = v; + } + for (const k of Object.keys(next)) if (next[k] === null || next[k] === "") delete next[k]; + next = normalizeFx(next, dir, patch); + if (Object.keys(next).length) entry.fx = next; + else delete entry.fx; + } + if (fxWas) { + const bad = entryFxErrors(entry).filter((e) => !fxWas.has(e)); + if (bad.length) throw new Error(bad.join("; ")); + } + // ---- an assistant's clip, edited by a person (release 35 C2) ------------- // // A clip the clip finder proposed carries `assist`. The first human edit @@ -630,6 +672,77 @@ export function patchClipEntry(manifest, clipId, patch, { edit = "trim", now = n // --------------------------------------------------------------------------- const isObj = (v) => !!v && typeof v === "object" && !Array.isArray(v); + +/** A clip's effect fields (`fx.<field>`): fx.mjs validateFxEntries's list. */ +export const FX_ENTRY_FIELDS = Object.freeze(["punch", "quote", "punchIn", "speakers", "receipts", "zoom"]); + +/** validateFxEntries's sentences about ONE entry's own `fx` (not the cut's effects). */ +function entryFxErrors(entry) { + return validateFxEntries({ timeline: [entry], render: {} }); +} + +/** + * An `fx` as it is stored: the words trimmed, seconds to 2 dp, a box's + * fractions to 4, and each screenshot the patch names checked against the + * project's files (`dir`) -- the shape is validateFxEntries's to judge. + */ +function normalizeFx(fx, dir, patch) { + const r2 = (v) => (typeof v === "number" && Number.isFinite(v) ? round2(v) : v); + const r4 = (v) => (typeof v === "number" && Number.isFinite(v) ? Number(v.toFixed(4)) : v); + const box = (b) => (Array.isArray(b) ? b.map(r4) : b); + const out = { ...fx }; + if (typeof out.punch === "string") out.punch = out.punch.trim(); + if (Array.isArray(out.punchIn)) out.punchIn = out.punchIn.map(r2); + if (Array.isArray(out.speakers)) out.speakers = out.speakers.map((x) => (isObj(x) ? { ...x, at: r2(x.at) } : x)); + const named = (k) => (patch.fx !== undefined && patch.fx !== null && patch.fx !== "") || patch[`fx.${k}`] !== undefined; + if (isObj(out.zoom)) { + const z = { ...out.zoom }; + if (z.focus !== undefined) z.focus = box(z.focus); + if (z.at !== undefined) z.at = r2(z.at); + if (z.hold !== undefined) z.hold = r2(z.hold); + if (named("zoom")) z.shot = projectShot(z.shot, dir, "fx.zoom.shot"); + out.zoom = z; + } + if (Array.isArray(out.receipts)) { + out.receipts = out.receipts.map((c, i) => { + if (!isObj(c)) return c; + const r = { ...c }; + if (r.mark !== undefined) r.mark = box(r.mark); + if (named("receipts")) r.shot = projectShot(r.shot, dir, `fx.receipts[${i}].shot`); + return r; + }); + } + return out; +} + +/** + * A screenshot path as the build reads it -- relative to the manifest, so a + * file in the project -- or a refusal naming where it was looked. A bare + * name found only under the project's `shots/` is that path. Without `dir` + * (no project to look in) the path is left to the shape check. + */ +function projectShot(shot, dir, what) { + if (!dir || typeof shot !== "string" || !shot.trim() || /^[a-z]+:\/\//i.test(shot)) return shot; + const rel = shot.trim().replace(/\\/g, "/"); + const root = path.resolve(dir); + const inside = (p) => { + const r = path.relative(root, p); + return !!r && !r.startsWith("..") && !path.isAbsolute(r); + }; + const isFile = (p) => { + try { + return statSync(p).isFile(); + } catch { + return false; + } + }; + const file = path.resolve(root, rel); + if (!inside(file)) throw new Error(`${what} ${rel} must be a file in the project (a path relative to it), not outside it`); + if (isFile(file)) return rel; + if (!rel.includes("/") && isFile(path.join(root, "shots", rel))) return `shots/${rel}`; + throw new Error(`${what} ${rel} is not a file in the project (looked for ${rel}${rel.includes("/") ? "" : ` and shots/${rel}`} in ${root})`); +} + /** How many edits a clip keeps; the oldest go first. */ export const ASSIST_EDITS_MAX = 200; /** What updateClip restores from (a sentinel: the edges are read inside the lock). */ diff --git a/umtool/lib/report/takeEdit.mjs b/umtool/lib/report/takeEdit.mjs @@ -193,7 +193,7 @@ export async function updateTakeClip(projectDir, id, clipId, patch, { token = nu id, edit === "trim" ? "clip" : edit, token, - (m) => patchClipEntry(m, clipId, patch, { edit, now: now.toISOString() }), + (m) => patchClipEntry(m, clipId, patch, { edit, now: now.toISOString(), dir: projectDir }), { now }, ); } diff --git a/umtool/report-to-video/build-video.mjs b/umtool/report-to-video/build-video.mjs @@ -3773,7 +3773,18 @@ export function moveFilter(move, render) { const a = exprNum(move.segmentAt); const p = move.seconds > 0 ? `clip((${t}-${a})/${exprNum(move.seconds)},0,1)` : `gte(${t},${a})`; // smoothstep, 3p² − 2p³: flat at both ends, so the glide starts and lands without a jolt. - const e = (base, d) => `'st(0,${p});${base}+(${exprNum(d)})*ld(0)*ld(0)*(3-2*ld(0))'`; + let e = (base, d) => `'st(0,${p});${base}+(${exprNum(d)})*ld(0)*ld(0)*(3-2*ld(0))'`; + if (Array.isArray(move.phases) && move.phases.length) { + // Persisting popups (deck.mjs persistMoves): aside at each phase's + // `segmentAt`, back at its `segmentUntil`, either possibly outside the + // segment -- e = min(1, Σ S(in)·(1 − S(back))), S the same smoothstep. + const at = (x) => (move.seconds > 0 ? `clip((${t}-(${exprNum(x)}))/${exprNum(move.seconds)},0,1)` : `gte(${t},${exprNum(x)})`); + const S = (k) => `ld(${k})*ld(${k})*(3-2*ld(${k}))`; + const sum = move.phases + .map((ph) => `st(0,${at(ph.segmentAt)});st(1,${at(ph.segmentUntil)});st(2,ld(2)+${S(0)}*(1-${S(1)}))`) + .join(";"); + e = (base, d) => `'st(2,0);${sum};${base}+(${exprNum(d)})*min(1,ld(2))'`; + } const corners = [ ["x0", e("0", dx(0))], ["y0", e("0", dy(0))], ["x1", e("W", dx(W))], ["y1", e("0", dy(0))], diff --git a/umtool/report-to-video/chrome-posts.mjs b/umtool/report-to-video/chrome-posts.mjs @@ -61,9 +61,15 @@ export const POSTS_MOTION = Object.freeze({ enter: 0.55, slide: 0.35, gap: 14, glowAt: 0.3, glowUp: 0.18, glowDown: 1.1, glowRest: 0.3, }); -/** The schedule's posts for one window's segment, in slot order. */ +/** + * The schedule's posts for one window's segment, in slot order -- or, for a + * persisting span (`posts.persist`, keyed by its first clip), every post of + * the span in the order they come up. + */ export function windowPosts(schedule, segment) { - return (schedule.posts ?? []).filter((p) => p.segment === segment).sort((a, b) => a.slot - b.slot); + return (schedule.posts ?? []) + .filter((p) => (p.span ?? p.segment) === segment) + .sort((a, b) => (a.span !== undefined ? a.appear - b.appear : 0) || a.slot - b.slot); } /** @@ -129,9 +135,10 @@ export function postsCues({ for (let j = 0; j < posts.length; j += 1) { const p = posts[j]; const t = p.appear; - // The oldest go until card j fits below what is left. + // The oldest go until card j fits below what is left -- or, a `fresh` + // card (a later clip's, on a persisting bar), every card up goes. const gone = []; - while (visible.length && tops[j] + (heights[j] || 0) - shift > column) { + while (visible.length && (p.fresh || tops[j] + (heights[j] || 0) - shift > column)) { gone.push(visible.shift()); shift = visible.length ? tops[visible[0]] : tops[j]; } @@ -145,7 +152,9 @@ export function postsCues({ add(`g${j}`, t + glowAt + glowUp, glowDown, { opacity: glowRest }, "power2.inOut", `settle ${p.id}`); if (pans[j] > 0) { const landed = t + enter; - const leave = p.out[0]; + // Its leave: the bar's, or a later clip's cards swapping it out first. + const swap = posts.find((q, n) => n > j && q.fresh); + const leave = swap ? Math.min(p.out[0], swap.appear) : p.out[0]; let a = landed + panHold; let b = leave - panHold; if (b - a < 1) { a = landed; b = Math.max(landed + MIN, leave); } @@ -312,7 +321,8 @@ export function postsHtml(schedule, render, window, opts = {}) { glowDown: POSTS_MOTION.glowDown, glowRest: POSTS_MOTION.glowRest, ids: posts.map((p) => p.id), - posts: posts.map((p) => ({ id: p.id, appear: p.appear, out: p.out })), + // `fresh` only on a persisting bar's swap, so every other page is as it was. + posts: posts.map((p) => ({ id: p.id, appear: p.appear, out: p.out, ...(p.fresh ? { fresh: true } : {}) })), }; // `</script>` inside a JSON string would close the tag; nothing in here is // trusted text, but a segment id is the manifest's and costs nothing to guard. diff --git a/umtool/report-to-video/deck.mjs b/umtool/report-to-video/deck.mjs @@ -27,7 +27,7 @@ import { resolveCounter } from "./counter.mjs"; import { DECK_PAD_X, COUNTER_CELL } from "./modules/design.mjs"; import { DECK_DEFAULTS, MARKER_ALIGNS, MARKER_DEFAULT_COLOR, MARKER_LAYOUTS, MARKER_LIMITS, MARKER_PALETTE_KEYS, markerShapeErrors, - PIP_COLORS, PIP_PITCH_DEFAULT, PIP_SPACINGS, POST_AT, POST_LAYOUTS, POST_LINKS, QR_LINKS, SECTION_TITLE_DEFAULTS, SETTINGS, settingValue, + PIP_COLORS, PIP_PITCH_DEFAULT, PIP_SPACINGS, POST_AT, POST_LAYOUTS, POST_LINKS, POST_PERSIST, QR_LINKS, SECTION_TITLE_DEFAULTS, SETTINGS, settingValue, SUBTITLE_TOKENS, } from "./modules/settings.mjs"; @@ -36,7 +36,7 @@ import { // they always had. export { DECK_DEFAULTS, MARKER_ALIGNS, MARKER_DEFAULT_COLOR, MARKER_LAYOUTS, MARKER_LIMITS, MARKER_PALETTE_KEYS, PIP_COLORS, PIP_PITCH_DEFAULT, - PIP_SPACINGS, POST_AT, POST_LAYOUTS, POST_LINKS, QR_LINKS, SUBTITLE_TOKENS, + PIP_SPACINGS, POST_AT, POST_LAYOUTS, POST_LINKS, POST_PERSIST, QR_LINKS, SUBTITLE_TOKENS, }; export { SECTION_TITLE_DEFAULTS, SUBTITLE_LINES } from "./modules/settings.mjs"; import { threadOf, threadSchedule, threadsOn, validateThreads } from "./threads.mjs"; @@ -2026,7 +2026,80 @@ export function postSchedule({ posts = [], entries, metas = [], segments, D, tot }); }); }); - return out; + // `posts.persist`: each card stays up on its own clock, across the joins. + const persist = feed ? null : postsPersist(render); + return persist ? persistPosts(out, { segments, entries, D, total, persist }) : out; +} + +/** + * `posts.persist` resolved: `{ seconds, gap }` when the popup posts persist + * across clips, else null (absent, false, or the feed -- which keeps every + * post up anyway). + */ +export function postsPersist(render) { + const p = resolveDeck(render).posts; + if (p.layout === "feed" || !p.persist) return null; + const v = isObj(p.persist) ? p.persist : {}; + return { seconds: v.seconds ?? POST_PERSIST.seconds.default, gap: v.gap ?? POST_PERSIST.gap.default }; +} + +/** How long a persisting bar takes to leave (its cards' fade), in seconds. */ +export const POSTS_PERSIST_LEAVE = 0.45; + +/** + * The popup posts that PERSIST (`posts.persist`): placed as ever (their + * `appear`), then each stays up on its own clock for `seconds` instead of + * leaving with its clip -- over the joins, the footage playing on (no hold). + * Posts whose moments come while the bar is up, or within `gap` after it + * would go, share one SPAN: one page (`span`, its first clip's id, keys the + * window -- postWindows), up from the first post's appear until `seconds` + * after the last's, then out over POSTS_PERSIST_LEAVE (every card of the span + * leaves together, `out`). A clip's own posts are always one span. + * + * A later clip's posts come in as `fresh`: the cards up before them slide up + * and out as they land (chrome-posts.mjs postsCues), so the bar holds one + * clip's posts at a time -- a SWAP between clips, a stack within one. + * + * The bar is drawn over clips only: a span is gone by the transition into the + * first entry after its clip that is not a clip (a card, a teaser, an image) + * or is the finale's, and by the end of the cut. + * + * @returns {Array<object>} the posts, each with `out`, `span` and (a swap) `fresh` + */ +export function persistPosts(placed, { segments, entries = [], D, total, persist }) { + if (!placed.length) return placed; + const idx = new Map(segments.map((s, i) => [s.id, i])); + const run = finaleRunOf(entries) && !finaleRunProblems(entries).length ? finaleRunOf(entries) : null; + const leaveInto = (k) => (D > 0 ? [segments[k].start, segments[k].start + D] : [segments[k].start - 0.3, segments[k].start]); + const limitOf = (i) => { + for (let k = i + 1; k < segments.length; k += 1) { + const type = entries[k]?.type ?? segments[k].type; + if (type !== "clip" || (run && k >= run.first && k <= run.last)) return leaveInto(k); + } + return [total - 0.3, total]; + }; + const order = [...placed].sort((a, b) => a.appear - b.appear || idx.get(a.segment) - idx.get(b.segment) || a.slot - b.slot); + const spanOf = new Map(); + const fresh = new Set(); + const spans = []; + let cur = null; + for (const p of order) { + const joins = cur && (cur.segments.has(p.segment) || (p.appear <= cur.hide + persist.gap && p.appear < cur.limit[0])); + if (!joins) { + cur = { key: p.segment, hide: -Infinity, limit: limitOf(idx.get(p.segment)), segments: new Set() }; + spans.push(cur); + } else if (!cur.segments.has(p.segment)) fresh.add(p.id); + cur.segments.add(p.segment); + cur.hide = Math.max(cur.hide, p.appear + persist.seconds); + spanOf.set(p.id, cur); + } + for (const s of spans) { + s.out = s.hide >= s.limit[0] ? s.limit : [s.hide, Math.min(s.hide + POSTS_PERSIST_LEAVE, s.limit[1])]; + } + return placed.map((p) => { + const s = spanOf.get(p.id); + return { ...p, out: s.out, span: s.key, ...(fresh.has(p.id) ? { fresh: true } : {}) }; + }); } /** What a placed post carries for the page that draws it. */ @@ -2112,10 +2185,12 @@ export function postWindows(schedule) { if (schedule.layout === "feed") return []; const by = new Map(); for (const p of schedule.posts ?? []) { - const w = by.get(p.segment) ?? { segment: p.segment, from: Infinity, to: -Infinity }; + // A persisting span (`posts.persist`) is one window, keyed by its first clip. + const key = p.span ?? p.segment; + const w = by.get(key) ?? { segment: key, from: Infinity, to: -Infinity }; w.from = Math.min(w.from, p.appear); w.to = Math.max(w.to, p.out[1]); - by.set(p.segment, w); + by.set(key, w); } return [...by.values()].sort((a, b) => a.from - b.from); } @@ -2302,8 +2377,10 @@ export function postHolds({ posts = [], entries = [], metas = [], render }) { const settings = resolveDeck(render).posts; const hold = Math.round(settings.hold * fps) / fps; const out = new Map(); - // The feed never pauses the cut: a post is in its column while the clip plays on. - if (!(hold > 0) || settings.layout === "feed") return out; + // The feed never pauses the cut: a post is in its column while the clip + // plays on. Nor do persisting popups (`posts.persist`): the card stays up + // on its own clock instead. + if (!(hold > 0) || settings.layout === "feed" || postsPersist(render)) return out; for (const a of attachPosts({ posts, entries, metas })) out.set(a.entryId, hold); return out; } @@ -2324,6 +2401,7 @@ export function footageMoves({ posts, segments, render }) { if (!to) return []; const from = deckGeometry(render).footage; const seconds = resolveDeck(render).posts.shift.seconds; + if (posts.some((p) => p.span !== undefined)) return persistMoves({ posts, segments, from, to, seconds }); const first = new Map(); for (const p of posts) first.set(p.segment, Math.min(first.get(p.segment) ?? Infinity, p.appear)); return segments @@ -2331,6 +2409,39 @@ export function footageMoves({ posts, segments, render }) { .map((s) => ({ segment: s.id, at: first.get(s.id), segmentAt: first.get(s.id) - s.start, seconds, from, to })); } +/** + * The footage moves under PERSISTING popups (`posts.persist`): the footage is + * aside for as long as a span's bar is up, across the joins it spans -- every + * segment the span overlaps moves on the CUT's clock, so the two sides of a + * dissolve stand at the same place -- and it glides back as the bar leaves. + * Each move carries its `phases`: `{ at, segmentAt, until, segmentUntil }`, + * aside over `seconds` from `at`, back over `seconds` from `until` (cut + * clock; `segment…` in the segment's own, which may be negative or past its + * end). `at`/`segmentAt` are the first phase's, for the readers that take one. + * A segment that starts once the bar is leaving comes in at its normal box. + * + * @returns {Array<{ segment, at, segmentAt, seconds, from, to, phases }>} + */ +function persistMoves({ posts, segments, from, to, seconds }) { + const R = (v) => Math.round(v * 1000) / 1000; + const spans = new Map(); + for (const p of posts) { + const s = spans.get(p.span) ?? { at: Infinity, until: p.out[0] }; + s.at = Math.min(s.at, p.appear); + spans.set(p.span, s); + } + const out = []; + for (const seg of segments) { + const end = seg.start + seg.duration; + const phases = [...spans.values()] + .filter((s) => seg.start < s.until && end > s.at) + .sort((a, b) => a.at - b.at) + .map((s) => ({ at: R(s.at), segmentAt: R(s.at - seg.start), until: R(s.until), segmentUntil: R(s.until - seg.start) })); + if (phases.length) out.push({ segment: seg.id, at: phases[0].at, segmentAt: phases[0].segmentAt, seconds, from, to, phases }); + } + return out; +} + // --------------------------------------------------------------------------- // Cut edits made where the cut is joined, like the hold: a clip's `muteFrom` // and the cut's `render.endFade`. Neither touches a segment file, so diff --git a/umtool/report-to-video/flips.mjs b/umtool/report-to-video/flips.mjs @@ -18,7 +18,7 @@ // The limits and the validators are common's (lib/report/panels.mjs, release // 28): the flips draft task checks exactly what the build refuses. import { FLIPS_LIMITS, flipsOn, validateFlipEntries, validateFlips } from "yt-dlp-transcript-common/lib/report/panels.mjs"; -import { planCues } from "./threads.mjs"; +import { asidesOf, planCues } from "./threads.mjs"; export { FLIPS_LIMITS, flipsOn, validateFlipEntries, validateFlips }; @@ -69,9 +69,9 @@ export function flipSchedule({ segments, total, render, moves = [] }) { .filter((p) => p.then && p.now) .sort((a, b) => a.then.from - b.then.from) .map((p, i, all) => ({ ...p, index: i + 1, of: all.length })); - const asides = moves.map((m) => { + const asides = asidesOf(moves, (m) => { const i = idx.get(m.segment); - return { from: R(m.at), to: R(i === undefined ? total : endOf(i)) }; + return R(i === undefined ? total : endOf(i)); }); return { pairs, asides }; } diff --git a/umtool/report-to-video/fx.mjs b/umtool/report-to-video/fx.mjs @@ -19,7 +19,12 @@ // timeline entry: "fx": { "punch": "…", "quote": false, "punchIn": [<source s>, …], // "speakers": [{ "at": <source s>, "who": 0 | 1 }], // "receipts": [{ "shot": "shots/a.png", "mark": [x0, y0, x1, y1] }], -// "zoom": { "shot": "shots/b.png", "focus": [x0, y0, x1, y1], "at": 1.2 } } +// "zoom": { "shot": "shots/b.png", "focus": [x0, y0, x1, y1], "at": 1.2, "hold": 4 } } +// (a zoom is up from 0.2 s into its clip's clean span -- the card rising in +// over 0.38 s, its focus box drawing at +0.55 s -- pushes in at `at` (seconds +// into the clip; default as soon as the box has drawn) over FX_MOTION.push, +// then drifts on the detail; it leaves (a 0.3 s fade) 0.3 s before the clip's +// clean span ends -- or, with `hold`, that many seconds after the push lands.) // // Every key is opt-in; `render.chrome.fx` absent (or null, or {}) draws nothing // and every schedule, graph and file is byte for byte what it was. An entry's @@ -41,6 +46,8 @@ export const FX_QUOTE_POSITIONS = Object.freeze(["bottom", "top"]); export const FX_RAIL_POSITIONS = Object.freeze(["top", "bottom"]); export const FX_SIDES = Object.freeze(["right", "left"]); export const FX_GLITCH_ON = Object.freeze(["year", "every", "clips"]); +/** A zoom's `hold` (seconds on the detail after the push lands): its bounds. Absent: until its clip's end. */ +export const FX_ZOOM_HOLD = Object.freeze({ min: 0.5, max: 10 }); /** The most clips a glitch on "clips" may name. */ export const FX_GLITCH_CLIPS_MAX = 60; export const FX_DATES = Object.freeze(["date", "year"]); @@ -323,13 +330,16 @@ export function validateFxEntries(manifest) { } if (e.fx.zoom !== undefined) { const z = e.fx.zoom; - if (!isObj(z)) errors.push(`${w}.zoom must be { shot, focus, at? }`); + if (!isObj(z)) errors.push(`${w}.zoom must be { shot, focus, at?, hold? }`); else { - for (const k of Object.keys(z)) if (!["shot", "focus", "at"].includes(k)) errors.push(`${w}.zoom.${k} is not a zoom field`); + for (const k of Object.keys(z)) if (!["shot", "focus", "at", "hold"].includes(k)) errors.push(`${w}.zoom.${k} is not a zoom field`); const se = shotError(z.shot, `${w}.zoom.shot`); if (se) errors.push(se); if (!rect01(z.focus)) errors.push(`${w}.zoom.focus must be [left, top, right, bottom], fractions of the shot`); if (z.at !== undefined && !numIn(z.at, 0, 600)) errors.push(`${w}.zoom.at must be seconds into the clip`); + if (z.hold !== undefined && !numIn(z.hold, FX_ZOOM_HOLD.min, FX_ZOOM_HOLD.max)) { + errors.push(`${w}.zoom.hold must be from ${FX_ZOOM_HOLD.min} to ${FX_ZOOM_HOLD.max} seconds (on the detail after the push), or absent for the whole clip`); + } } } } @@ -798,7 +808,10 @@ export function fxSchedule({ segments, entries, metas = [], render, D, total, wo if (outT - inn < 2) continue; const outline = inn + 0.55; const push = Math.min(outT - FX_MOTION.push - 0.3, Math.max(outline + FX_MOTION.outline + 0.2, Number.isFinite(z.at) ? c.start + z.at : 0)); - rows.push({ segment: c.id, in: r3(inn), out: r3(outT), shot: z.shot, focus: z.focus, outline: r3(outline), push: r3(push) }); + // `hold`: that long on the detail once the push lands, then it leaves + // (its 0.3 s fade ends `out`); never past the clip's own leave. + const out = Number.isFinite(z.hold) ? Math.min(outT, push + FX_MOTION.push + z.hold + 0.3) : outT; + rows.push({ segment: c.id, in: r3(inn), out: r3(out), shot: z.shot, focus: z.focus, outline: r3(outline), push: r3(push) }); } out.zoom = { width: zm.width, clips: rows }; } diff --git a/umtool/report-to-video/modules/fx.mjs b/umtool/report-to-video/modules/fx.mjs @@ -22,6 +22,8 @@ export default defineModule({ rows: [ ["`render.chrome.fx.<effect>`", "scrubber · receipts · zoom · kineticQuote · redact · odometer · punchIn · thenNow · whip · glitch", "a take: `umtool take <p> --effect <name>`"], ["`render.chrome.fx.glitch.on`, `.clips`", "`year` (a tear at each cut between years) · `every` (each cut between clips) · `clips` (only the cut INTO each clip `clips` names: 1–60 ids, each with a clip right before it) · default `year`; `clips` only with `on: \"clips\"`. `.seconds` 0.2–1.5 · 0.5, `.stamp` (the `PLAY ▶` date) · `true`, `.year` (the new year big over the tear; `false` with `stamp: false` is a bare tear, no text) · `true`", "manifest"], + ["a clip's `fx` — what an effect draws on it, inert until that effect is on: `zoom` `{shot, focus, at?, hold?}`, `receipts` `[{shot, mark?}]` (1–4), `punch` (the words), `quote` (false: no line), `punchIn` `[source s…]` (1–8, inside the clip), `speakers` `[{at, who: 0|1}]`. A `shot` is a file in the project (a bare name under its `shots/` is written as `shots/<name>`); `focus`/`mark` are `[left, top, right, bottom]` fractions of it", "`fx.<field>=<json>` sets one and keeps the rest · `fx=<json>` all · `fx=` none; checked by the build's own `validateFxEntries`", "`umtool set <p> <clip> fx.zoom='{\"shot\":\"shots/x.png\",\"focus\":[0.1,0.2,0.9,0.4],\"at\":5.9}'` · `PUT /api/report/window {project, clip, fx}` (or `\"fx.zoom\"`, …)"], + ["the zoom's timing (`fx.zoom.at`, `.hold`)", "up 0.2 s into the clip's clean span (the card rises in over 0.38 s, `back.out`); its focus box draws 0.55 s later (0.45 s); it pushes in on the box at `at` — seconds into the clip, default as soon as the box has drawn — over 1 s (`power2.inOut`), then drifts slowly on the detail. It leaves with a 0.3 s fade 0.3 s before the clip's clean span ends, or with `hold` (0.5–10 s) that long after the push lands (never past the clip's own leave)", "`fx.zoom='{…,\"hold\":4}'`"], ], }, region: "fx", diff --git a/umtool/report-to-video/modules/popup-posts.mjs b/umtool/report-to-video/modules/popup-posts.mjs @@ -8,7 +8,7 @@ import path from "node:path"; import { postsGeometry, postWindows, resolveDeck, snapWindow } from "../deck.mjs"; import { postsHtml, windowPosts } from "../chrome-posts.mjs"; import { assertRegion, defineModule } from "./contract.mjs"; -import { DECK_DEFAULTS, POST_AT, POST_LAYOUTS, POST_LINKS, settingsOf } from "./settings.mjs"; +import { DECK_DEFAULTS, POST_AT, POST_LAYOUTS, POST_LINKS, POST_PERSIST, settingsOf } from "./settings.mjs"; const SEGMENT_RE = /^[A-Za-z0-9_-]+$/; @@ -37,6 +37,11 @@ export default defineModule({ { key: "hold", type: "number", min: 0, max: 10, step: 0.5, label: "Hold (s)", default: DECK_DEFAULTS.posts.hold }, { key: "position", type: "enum", options: ["top-right", "top-left"], label: "Side", default: "top-right" }, { key: "shotMaxHeight", type: "number", min: 120, max: 1080, label: "Screenshot height cap", default: null }, + // `persist` (opt-in): the cards stay up on their own clock across clips; no hold. + { key: "persist.seconds", type: "number", min: POST_PERSIST.seconds.min, max: POST_PERSIST.seconds.max, step: 1, + label: "Persist across clips: seconds up", default: null }, + { key: "persist.gap", type: "number", min: POST_PERSIST.gap.min, max: POST_PERSIST.gap.max, step: 1, + label: "Persist: stay up for a post within (s)", default: null }, ], docs: { heading: "Popup posts", @@ -47,6 +52,7 @@ export default defineModule({ ["`deck.posts.position`", "`top-right` · `top-left` · default `top-right`", "same"], ["`deck.posts.shift`", "`false` · `{scale 0.5–1, seconds 0–3}` · default 0.86, 0.6 (the footage moves aside while they are up)", "same"], ["`deck.posts.shotMaxHeight`", "null · 120–1080 px · default null (a full card of words)", "same"], + ["`deck.posts.persist`", "`true` · `{seconds 8–60, gap 0–30}` · `false`/absent (off: each clip's posts its own short window, as above) · default seconds 12, gap 6. On: the footage NEVER freezes (`hold` is ignored). A card comes up at its moment (`at`, as above) and stays up on its own clock for `seconds`, over clip joins and dissolves. A post whose moment comes while the bar is up, or within `gap` after it would go, keeps it up: a later clip's cards SWAP in (the cards up slide up and out as the new one lands — the bar holds one clip's posts at a time, so stale cards never pile up over the footage), a clip's own still stack. With no post soon it leaves (0.45 s fade). The bar never runs into a card, a teaser, an image or the finale: it is gone by the transition into one. `shift` spans it too: the footage stays aside across the joins the bar spans, every segment moving on the cut's clock, and glides back as the bar leaves (a segment that starts as it leaves comes in at its normal box). Absent, every render is byte for byte what it was", "`umtool look <p> deck.posts.persist='{\"seconds\":12,\"gap\":6}'` (`deck.posts.persist=` off)"], ], }, region: "posts", diff --git a/umtool/report-to-video/modules/settings.mjs b/umtool/report-to-video/modules/settings.mjs @@ -153,6 +153,16 @@ export const POST_AT = Object.freeze(["end", "start"]); export const POST_LAYOUTS = Object.freeze(["popup", "feed"]); /** Where a post's QR links (`posts.links`): its page on the archive, or the platform's own link. */ export const POST_LINKS = Object.freeze(["archive", "original"]); +/** + * Popup posts that PERSIST (`posts.persist`, opt-in): a card stays up on its + * own clock for `seconds` after it comes up, across clip joins, while the + * footage plays on (no hold); a post coming up within that, or within `gap` + * after it, keeps the bar up. Each with its bounds and default. + */ +export const POST_PERSIST = Object.freeze({ + seconds: Object.freeze({ min: 8, max: 60, default: 12 }), + gap: Object.freeze({ min: 0, max: 30, default: 6 }), +}); const isObj = (v) => v !== null && typeof v === "object" && !Array.isArray(v); const numIn = (v, lo, hi) => typeof v === "number" && Number.isFinite(v) && v >= lo && v <= hi; @@ -373,8 +383,21 @@ export function validateQrSettings(d, { where: w }) { /** The posts (the popup cards and the feed): every `deck.posts` setting. */ export function validatePostsSettings(d, { where: w }) { const errors = []; - sub(d, "posts", ["show", "layout", "seconds", "hold", "position", "width", "qrSize", "maxLines", "inset", "shift", "links", "at", "shotMaxHeight", "qr"], w, errors, (p) => { + sub(d, "posts", ["show", "layout", "seconds", "hold", "position", "width", "qrSize", "maxLines", "inset", "shift", "links", "at", "shotMaxHeight", "qr", "persist"], w, errors, (p) => { if (p.qr !== undefined && typeof p.qr !== "boolean") errors.push(`${w}.posts.qr must be true or false`); + // `persist`: true (the defaults), { seconds?, gap? }, or false/null (off). + if (p.persist !== undefined && p.persist !== null && typeof p.persist !== "boolean") { + if (!isObj(p.persist)) errors.push(`${w}.posts.persist must be true, false or { seconds, gap }`); + else { + unknownKeys(p.persist, ["seconds", "gap"], `${w}.posts.persist`, errors); + for (const k of ["seconds", "gap"]) { + const b = POST_PERSIST[k]; + if (p.persist[k] !== undefined && !numIn(p.persist[k], b.min, b.max)) { + errors.push(`${w}.posts.persist.${k} must be from ${b.min} to ${b.max} seconds`); + } + } + } + } if (p.at !== undefined && !POST_AT.includes(p.at)) { errors.push(`${w}.posts.at must be ${POST_AT.map((a) => `"${a}"`).join(" or ")}`); } diff --git a/umtool/report-to-video/posts-persist.test.mjs b/umtool/report-to-video/posts-persist.test.mjs @@ -0,0 +1,260 @@ +// Popup posts that PERSIST (`render.chrome.deck.posts.persist`): a card stays +// up on its own clock across clip joins, the footage playing on; close posts +// share one bar (a later clip's swap in), and the bar leaves when none follows +// soon. Absent, every schedule and page is what it was. +// +// Run with: pnpm test:scripts +import assert from "node:assert/strict"; +import { spawnSync } from "node:child_process"; +import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs"; +import { tmpdir } from "node:os"; +import path from "node:path"; +import test from "node:test"; +import { fileURLToPath } from "node:url"; + +import { postsCues, postsHtml, snapWindow, windowPosts } from "./chrome-posts.mjs"; +import { + POSTS_PERSIST_LEAVE, deckSchedule, footageMoves, postHolds, postSchedule, postWindows, postsPersist, shiftedFootage, + deckGeometry, validateChrome, +} from "./deck.mjs"; +import { asidesOf } from "./threads.mjs"; +import { footageAt } from "../lib/report/footage-move.mjs"; + +const HERE = path.dirname(fileURLToPath(import.meta.url)); +const PALETTE = { bg: "#12101a", fg: "#f4f1ea", muted: "#9a93ad", accent: "#a97bff", amber: "#ffc860" }; +const renderOf = (posts = {}) => ({ + width: 1920, height: 1080, fps: 30, transition: 0.5, palette: PALETTE, + chrome: { engine: "hyperframes", layout: "deck", deck: { posts } }, +}); +const POST = (id, attachTo, extra = {}) => ({ + id, platform: "bluesky", author: "A", handle: "a.example", date: "2024-10-01", attachTo, + text: `words of ${id}`, url: `https://bsky.app/profile/a.example/post/${id}`, ...extra, +}); + +// Four 20 s clips under 0.5 s dissolves: starts 0, 19.5, 39, 58.5; the cut is 78.5 s. +const CLIPS = ["c1", "c2", "c3", "c4"].map((id) => ({ id, type: "clip", date: "2024-09-01" })); +const SEGS = CLIPS.map((c, i) => ({ id: c.id, start: i * 19.5, duration: 20 })); +const TOTAL = 78.5; +const place = (posts, persist, { entries = CLIPS, segments = SEGS, total = TOTAL } = {}) => + postSchedule({ posts, entries, segments, D: 0.5, total, render: renderOf(persist === undefined ? {} : { persist }) }); +const byId = (placed) => Object.fromEntries(placed.map((p) => [p.id, p])); + +test("validation: persist is true, false/null, or { seconds 8–60, gap 0–30 }", () => { + const ok = (persist) => validateChrome(renderOf({ persist }).chrome, renderOf({ persist })); + for (const v of [true, false, null, {}, { seconds: 8 }, { seconds: 60, gap: 0 }, { gap: 30 }]) assert.deepEqual(ok(v), [], JSON.stringify(v)); + assert.match(ok({ seconds: 5 }).join(), /posts\.persist\.seconds must be from 8 to 60 seconds/); + assert.match(ok({ gap: 31 }).join(), /posts\.persist\.gap must be from 0 to 30 seconds/); + assert.match(ok({ hold: 2 }).join(), /posts\.persist\.hold is not a deck setting/); + assert.match(ok("yes").join(), /posts\.persist must be true, false or \{ seconds, gap \}/); + assert.deepEqual(postsPersist(renderOf({ persist: true })), { seconds: 12, gap: 6 }); + assert.deepEqual(postsPersist(renderOf({ persist: { seconds: 20 } })), { seconds: 20, gap: 6 }); + assert.equal(postsPersist(renderOf({ persist: false })), null); + assert.equal(postsPersist(renderOf({})), null); + // The feed keeps every post up anyway: persist is not its. + assert.equal(postsPersist(renderOf({ persist: true, layout: "feed" })), null); +}); + +test("absent persist: the schedule, the windows, the holds and the page are what they were (false and null alike)", () => { + const posts = [POST("a", "c1"), POST("b", "c2"), POST("b2", "c2")]; + const plain = place(posts); + for (const v of [false, null]) assert.deepEqual(place(posts, v), plain); + for (const p of plain) assert.ok(!("span" in p) && !("fresh" in p), "no persist keys"); + assert.deepEqual(postWindows({ posts: plain }).map((w) => w.segment), ["c1", "c2"]); + const entries = CLIPS; + assert.equal(postHolds({ posts, entries, render: renderOf({}) }).get("c1"), 2.5); + const sched = { fps: 30, total: TOTAL, posts: plain }; + const win = snapWindow(postWindows(sched)[1], { fps: 30, total: TOTAL }); + const html = postsHtml(sched, renderOf({}), win, {}); + assert.equal(postsHtml({ ...sched, posts: place(posts, false) }, renderOf({ persist: false }), win, {}), html); + assert.doesNotMatch(html, /"fresh"/); +}); + +test("persist: a card stays up across the join, the bar runs to `seconds` after the last post, and nothing is held", () => { + const posts = [POST("a", "c1")]; + const p = byId(place(posts, { seconds: 12, gap: 6 })).a; + // At its clip's end as ever (A = c2's start, 19.5, less posts.seconds 4)... + assert.equal(p.appear, 15.5); + // ...and up for 12 s on its own clock: past the join at 19.5–20, out over POSTS_PERSIST_LEAVE. + assert.deepEqual(p.out, [27.5, 27.5 + POSTS_PERSIST_LEAVE]); + assert.equal(p.span, "c1"); + const w = postWindows({ posts: [p] }); + assert.deepEqual(w, [{ segment: "c1", from: 15.5, to: 27.95 }]); + assert.ok(w[0].to > SEGS[1].start + 0.5, "the window runs over the join into c2"); + // The footage never freezes. + assert.equal(postHolds({ posts, entries: CLIPS, render: renderOf({ persist: true }) }).size, 0); + const s = deckSchedule({ entries: CLIPS, durs: SEGS.map((x) => x.duration), D: 0.5, render: renderOf({ persist: true }), posts }); + assert.ok(s.segments.every((x) => !("hold" in x))); + assert.equal(s.total, TOTAL); +}); + +test("persist: a later clip's post within the bar (or the gap after it) joins it and swaps in; one past the gap opens a new bar", () => { + const posts = [POST("a", "c1"), POST("b", "c2"), POST("b2", "c2"), POST("d", "c4")]; + const near = byId(place(posts, { seconds: 12, gap: 8 })); + // c2's two posts come up a posts.seconds apart before its dissolve out (39): 31, 35. + assert.equal(near.b.appear, 31); + assert.equal(near.b2.appear, 35); + // a's bar would go at 27.5; b's moment, 31, is within its gap of 8: one bar. + assert.equal(near.b.span, "c1"); + assert.equal(near.b2.span, "c1"); + assert.equal(near.b.fresh, true, "the first of a later clip's posts swaps the bar's cards out"); + assert.ok(!("fresh" in near.b2), "the clip's own next one stacks"); + assert.ok(!("fresh" in near.a)); + // The bar runs to 12 s after the last post on it, every card out together. + for (const id of ["a", "b", "b2"]) assert.deepEqual(near[id].out, [47, 47 + POSTS_PERSIST_LEAVE]); + // d (c4: appear 74.2) is past 47 + 8: a bar of its own, ending with the cut. + assert.equal(near.d.span, "c4"); + assert.deepEqual(near.d.out, [TOTAL - 0.3, TOTAL]); + assert.deepEqual(postWindows({ posts: Object.values(near) }).map((w) => [w.segment, w.from, w.to]), [["c1", 15.5, 47.45], ["c4", 74.2, 78.5]]); + // The page for the span: every post of it, in the order they come up. + assert.deepEqual(windowPosts({ posts: Object.values(near) }, "c1").map((p) => p.id), ["a", "b", "b2"]); + + // A gap too short: a's bar goes at 27.5 and b's opens at 31. + const far = byId(place(posts, { seconds: 12, gap: 2 })); + assert.equal(far.a.span, "c1"); + assert.deepEqual(far.a.out, [27.5, 27.95]); + assert.equal(far.b.span, "c2"); + assert.ok(!("fresh" in far.b), "the first post of a bar is not a swap"); +}); + +test("persist: the bar is over clips only -- gone by the dissolve into a card (or the finale), and a post after it starts anew", () => { + const entries = [CLIPS[0], { id: "k1", type: "card" }, CLIPS[1], CLIPS[2]]; + const segments = entries.map((e, i) => ({ id: e.id, start: i * 19.5, duration: 20 })); + const posts = [POST("a", "c1"), POST("b", "c2")]; + const p = byId(place(posts, { seconds: 30, gap: 30 }, { entries, segments })); + assert.deepEqual(p.a.out, [19.5, 20], "out with the dissolve into the card, as a clip's posts always left"); + assert.equal(p.b.span, "c2"); + // The finale: its clips are the end of any bar. + const fin = [CLIPS[0], CLIPS[1], { ...CLIPS[2], layout: "finale" }]; + const segs3 = fin.map((e, i) => ({ id: e.id, start: i * 19.5, duration: 20 })); + const q = byId(place([POST("a", "c1")], { seconds: 60, gap: 0 }, { entries: fin, segments: segs3, total: 59 })); + assert.deepEqual(q.a.out, [39, 39.5]); +}); + +test("persist + shift: the footage is aside across the joins the bar spans, on the cut's clock, and glides back as it leaves", () => { + const render = renderOf({ persist: { seconds: 12, gap: 8 } }); + const posts = [POST("a", "c1"), POST("b", "c2")]; + const placed = postSchedule({ posts, entries: CLIPS, segments: SEGS, D: 0.5, total: TOTAL, render }); + const moves = footageMoves({ posts: placed, segments: SEGS, render }); + // a: 15.5; b: 35 (its clip's end); the bar leaves at 47 -- inside c3. + assert.deepEqual(moves.map((m) => m.segment), ["c1", "c2", "c3"]); + const phase = { at: 15.5, until: 47 }; + for (const m of moves) { + const s = SEGS.find((x) => x.id === m.segment); + assert.deepEqual(m.phases, [{ ...phase, segmentAt: Math.round((15.5 - s.start) * 1000) / 1000, segmentUntil: Math.round((47 - s.start) * 1000) / 1000 }]); + assert.equal(m.at, 15.5); + assert.deepEqual(m.to, shiftedFootage(render)); + assert.deepEqual(m.from, deckGeometry(render).footage); + } + // The preview's box: aside after the glide, on both sides of the join and through it; back after the bar. + const sched = { segments: SEGS, moves }; + assert.equal(footageAt(sched, 15.4).progress, 0); + for (const t of [16.2, 19.4, 19.6, 20.2, 30, 46.9]) assert.equal(footageAt(sched, t).progress, 1, `aside at ${t}`); + assert.ok(footageAt(sched, 47.3).progress > 0 && footageAt(sched, 47.3).progress < 1, "gliding back"); + assert.equal(footageAt(sched, 47.7).progress, 0); + assert.equal(footageAt(sched, 60), null, "c4 never moves"); + // The left panel steps aside once for the whole bar. + assert.deepEqual(asidesOf(moves, () => 0), [{ from: 15.5, to: 47 }]); +}); + +test("postsCues: a fresh card swaps the bar -- every card up slides up and out as it lands; without fresh, as before", () => { + const posts = [ + { id: "a", appear: 1, out: [20, 20.45] }, + { id: "a2", appear: 3, out: [20, 20.45] }, + { id: "b", appear: 9, out: [20, 20.45], fresh: true }, + ]; + const plan = postsCues({ posts, heights: [200, 200, 200], column: 900 }); + const at9 = plan.cues.filter((c) => c.at === 9); + assert.deepEqual(at9.filter((c) => c.k === "stack").map((c) => c.to), [{ y: -428 }], "the stack moves the new card to the top"); + assert.deepEqual(at9.filter((c) => c.why === "slide for b").map((c) => c.k).sort(), ["c0", "c1", "stack"]); + assert.ok(plan.cues.some((c) => c.k === "c2" && c.why === "enter b" && c.at === 9)); + assert.ok(!plan.cues.some((c) => c.why === "leave a"), "a swapped card does not leave again"); + assert.ok(plan.cues.some((c) => c.why === "leave b" && c.at === 20)); + // The same posts without the flag stack as they always did: nobody slides out. + const stacked = postsCues({ posts: posts.map(({ fresh: _f, ...p }) => p), heights: [200, 200, 200], column: 900 }); + assert.ok(!stacked.cues.some((c) => c.k === "stack")); +}); + +test("ffmpeg: a persisting move's phases -- aside before the segment starts, back inside it -- parse and move the picture", { skip: !have("ffmpeg", ["-version"]) }, async () => { + const { joinInputChain } = await import("./build-video.mjs"); + const dir = mkdtempSync(path.join(tmpdir(), "persist-ff-")); + try { + const render = renderOf({ persist: true }); + const move = { + segment: "c2", at: 15.5, segmentAt: -4, seconds: 0.6, from: deckGeometry(render).footage, to: shiftedFootage(render), + phases: [{ at: 15.5, segmentAt: -4, until: 21, segmentUntil: 1.5 }], + }; + const runChain = (m, name) => { + const c = joinInputChain(0, { hold: 0, move: m }, render); + const out = path.join(dir, name); + const res = spawnSync("ffmpeg", ["-nostdin", "-v", "error", "-y", "-f", "lavfi", "-i", "testsrc2=s=1920x1080:r=30:d=3", + "-filter_complex", `${c.parts.join(";")};${c.v}format=rgb24[o]`, "-map", "[o]", "-f", "rawvideo", out], { maxBuffer: 1 << 28 }); + assert.equal(res.status, 0, String(res.stderr)); + return readFileSync(out); + }; + const a = runChain(move, "o.rgb"); + // The same chain with the bar never up: the picture in its box (the + // move's edge pinning included), what "back" must equal. + const b = runChain({ ...move, phases: [{ at: 99, segmentAt: 99, until: 100, segmentUntil: 100 }] }, "p.rgb"); + const F = 1920 * 1080 * 3; + const frame = (buf, n) => buf.subarray(n * F, (n + 1) * F); + assert.ok(!frame(a, 0).equals(frame(b, 0)), "aside from its first frame (the bar came up before it)"); + assert.ok(!frame(a, 30).equals(frame(b, 30)), "still aside at 1 s"); + assert.ok(frame(a, 75).equals(frame(b, 75)), "back in its box once the bar has gone (2.5 s)"); + } finally { + rmSync(dir, { recursive: true, force: true }); + } +}); + +// --------------------------------------------------------------------------- +// The pixels: the page a persisting bar is drawn by, seeked as the renderer seeks. +// --------------------------------------------------------------------------- + +function have(b, a) { + return spawnSync(b, a, { stdio: "ignore" }).status === 0; +} +const haveChromium = have("qrencode", ["-V"]) && have("magick", ["-version"]) && have(process.env.CHROME ?? "/usr/bin/chromium", ["--version"]); + +function inked(png, x, y, w, h) { + const r = spawnSync("magick", [png, "-crop", `${w}x${h}+${x}+${y}`, "+repage", "-depth", "8", "rgba:-"], { maxBuffer: 1 << 26 }); + let n = 0; + for (let i = 3; i < r.stdout.length; i += 4) if (r.stdout[i] > 128) n += 1; + return n / (r.stdout.length / 4); +} + +test("pixels: the card is up across the join and after it, swapped for the next clip's, and gone when no post follows", { skip: !haveChromium }, async () => { + const { composeChrome } = await import("./compose-chrome.mjs"); + const dir = mkdtempSync(path.join(tmpdir(), "persist-px-")); + try { + const render = { + ...renderOf({ persist: { seconds: 12, gap: 8 } }), + fontRegular: path.join(HERE, "fonts", "IBMPlexMono-Regular.ttf"), + fontBold: path.join(HERE, "fonts", "IBMPlexMono-Bold.ttf"), + }; + const manifestPath = path.join(dir, "video.manifest.json"); + writeFileSync(manifestPath, JSON.stringify({ slug: "t", title: "t", provenance: {}, render, timeline: [] })); + const posts = postSchedule({ posts: [POST("a", "c1"), POST("b", "c2")], entries: CLIPS, segments: SEGS, D: 0.5, total: TOTAL, render }); + const sched = { + version: 1, kind: "deck", estimated: false, fps: 30, transition: 0.5, total: TOTAL, multiChannel: false, + segments: SEGS.map((s) => ({ ...s, type: "clip", end: s.start + s.duration, title: "", subtitle: "", qrUrl: null, hideDeck: false })), + posts, + }; + const [window] = postWindows(sched); + assert.deepEqual([window.segment, window.from, window.to], ["c1", 15.5, 47.45]); + const still = async (t) => { + const png = path.join(dir, `still-${t}.png`); + await composeChrome({ manifestPath, region: "posts", schedule: sched, window, still: t, png }); + return png; + }; + // The top card's band of the column (the region is the posts column). + const band = [40, 20, 500, 120]; + assert.ok(inked(await still(15.3), ...band) < 0.01, "nothing before the first post"); + for (const t of [17, 19.75, 21, 29]) assert.ok(inked(await still(t), ...band) > 0.3, `the card is up at ${t} (the join is 19.5–20)`); + // b swaps in at 35 and stays to 47; the bar leaves by 47.45. + const html = readFileSync(path.join(dir, "out", "sourced", "chrome", "posts-c1", "index.html"), "utf8"); + assert.match(html, /"id":"b","appear":35,"out":\[47,47\.45\],"fresh":true/); + assert.ok(inked(await still(40), ...band) > 0.3, "the next clip's card is up"); + assert.ok(inked(await still(47.44), ...band) < 0.05, "gone as the bar leaves"); + } finally { + rmSync(dir, { recursive: true, force: true }); + } +}); diff --git a/umtool/report-to-video/threads.mjs b/umtool/report-to-video/threads.mjs @@ -39,6 +39,31 @@ export const THREAD_MOTION = Object.freeze({ /** How long before its thread's last clip ends the outcome lands, at most. */ export const OUTCOME_LEAD = 1.8; +/** + * When the left panel steps aside for the popup posts' footage moves: one + * `{from, to}` per move, `to` its segment's end (`endOf(m)`) -- or, under + * PERSISTING popups (a move's `phases`, deck.mjs persistMoves), each phase's + * own span, from `at` to `until`, once however many segments it crosses. + */ +export function asidesOf(moves, endOf) { + const R = (v) => Math.round(v * 1000) / 1000; + const out = []; + const seen = new Set(); + for (const m of moves) { + if (!Array.isArray(m.phases)) { + out.push({ from: R(m.at), to: endOf(m) }); + continue; + } + for (const ph of m.phases) { + const key = `${ph.at}|${ph.until}`; + if (seen.has(key)) continue; + seen.add(key); + out.push({ from: R(ph.at), to: R(ph.until) }); + } + } + return out; +} + const isObj = (v) => v !== null && typeof v === "object" && !Array.isArray(v); /** @@ -92,9 +117,9 @@ export function threadSchedule({ segments, D, total, render, moves = [] }) { t.clips.push({ segment: s.id, at: R(i === 0 ? s.start : s.start + D / 2) }); last.set(t.id, i); }); - const asides = moves.map((m) => { + const asides = asidesOf(moves, (m) => { const i = segments.findIndex((s) => s.id === m.segment); - return { from: R(m.at), to: R(i < 0 ? total : endOf(i)) }; + return R(i < 0 ? total : endOf(i)); }); for (const t of threads) { if (!t.outcome || !last.has(t.id)) continue;