// gapCueView.mjs (lane gap-cue, slice 1b): the mark as umtool's pages draw it -- // the bench on its source clock, Play on the cut's -- is the build's mark: the // same joins, the same seconds up, the same text, the same fade. // // Run with: pnpm test:scripts import assert from "node:assert/strict"; import test from "node:test"; import { GAP_CUE_LIFE, GAP_CUE_MOTION, clipGapCueOf } from "yt-dlp-transcript-common/lib/report/gapCue.mjs"; import { segmentGapJoins, segmentGapMarks } from "../../report-to-video/gap-mark.mjs"; import { clipGapMarks, clipPlayClock, gapMarkAt, gapMarkCorner, playGapMarks } from "./gapCueView.mjs"; import { gapJoins } from "./playCut.mjs"; const near = (a, b, what, tol = 1e-3) => assert.ok(Math.abs(a - b) <= tol, `${what}: ${a} vs ${b}`); test("clipGapMarks: the build's marks for the same clip (segmentGapJoins + segmentGapMarks), at the same seconds with the same text", () => { // A clip played 100–160 with gaps 110–137 (27 s, marked by the project), 150–151 (under min) and 154–157 (its own off). const render = { gapCue: { mark: true, label: "{s} later" } }; const entry = { type: "clip", gaps: [{ from: 110, to: 137 }, { from: 150, to: 151 }, { from: 154, to: 157, mark: false }] }; const page = clipGapMarks({ cue: clipGapCueOf(render, entry), gaps: entry.gaps, from: 100, to: 160 }); const segGaps = entry.gaps.map((g) => ({ from: g.from - 100, to: g.to - 100 })); const seconds = 60 - 27 - 1 - 3; const build = segmentGapMarks({ render, entry, seconds, joins: segmentGapJoins({ segGaps, clipGaps: entry.gaps, segStart: 100, cue: clipGapCueOf(render, entry) }) }); assert.deepEqual(page, build); assert.deepEqual(page.map((m) => [m.at, m.text]), [[10, "27 s later"]]); near(page[0].until - page[0].at, GAP_CUE_LIFE, "a mark's life"); }); test("clipGapMarks: nothing marked is no mark; a gap's own on over the clip's off; joins inside a life are one mark", () => { const gaps = [{ from: 3.5, to: 5.5 }, { from: 6, to: 9, mark: true }]; assert.deepEqual(clipGapMarks({ cue: clipGapCueOf({}, { gaps }), gaps: [{ from: 3.5, to: 5.5 }], from: 0.5, to: 12 }), [], "off by default"); const own = clipGapMarks({ cue: clipGapCueOf({}, { gaps }), gaps, from: 0.5, to: 12 }); assert.deepEqual(own.map((m) => [m.at, m.text]), [[3.5, "» 3 s"]], "only the gap that says so"); // Both marked: 3.5–5.5 joins at 3, 6–9 at 3.5 (0.5 s later): one mark, both gaps' seconds. const both = clipGapMarks({ cue: clipGapCueOf({ gapCue: { mark: true } }, { gaps }), gaps, from: 0.5, to: 12 }); assert.equal(both.length, 1); assert.deepEqual([both[0].at, both[0].count, both[0].text], [3, 2, "» 5 s"]); near(both[0].until, 3.5 + GAP_CUE_LIFE, "a life after the last join"); // A gap outside what plays draws nothing. assert.deepEqual(clipGapMarks({ cue: clipGapCueOf({ gapCue: { mark: true } }, {}), gaps: [{ from: 20, to: 30 }], from: 0, to: 12 }), []); }); test("clipPlayClock: a source second on the marks' clock; inside a gap its join; outside what plays null", () => { const o = { gaps: [{ from: 3.5, to: 5.5 }], from: 0.5, to: 8.5 }; assert.equal(clipPlayClock(o, 2), 1.5); assert.equal(clipPlayClock(o, 4.2), 3, "inside the gap: its join"); assert.equal(clipPlayClock(o, 6), 3.5); assert.equal(clipPlayClock(o, 0.2), null); assert.equal(clipPlayClock(o, null), null); }); test("gapMarkAt: up over `in`, held at the peak, down over `out`; none before the join or after the life", () => { const marks = [{ at: 3, until: 3 + GAP_CUE_LIFE, seconds: 2, count: 1, text: "» 2 s" }]; assert.equal(gapMarkAt(marks, 2.9), null); assert.equal(gapMarkAt(marks, 3), null, "at the join itself it is still 0"); near(gapMarkAt(marks, 3 + GAP_CUE_MOTION.in / 2).alpha, GAP_CUE_MOTION.peak / 2, "half way up"); near(gapMarkAt(marks, 3.5).alpha, GAP_CUE_MOTION.peak, "held"); assert.equal(gapMarkAt(marks, 3.5).text, "» 2 s"); assert.equal(gapMarkAt(marks, 3 + GAP_CUE_LIFE + 0.01), null); }); test("playGapMarks: on the cut's clock at Play's joins, each marked as the clip's own gap says, never past the footage", () => { // g01 0.5–8.5 with 3.5–5.5 out, starting at cut second 10: the join at 13, the footage to 16. const item = { id: "g01", start: 10, clip: { sourceFrom: 0.5, sourceTo: 8.5, playEnd: 16, hold: 0, gaps: [{ from: 3.5, to: 5.5 }] } }; const joins = gapJoins(item); assert.deepEqual(joins, [{ at: 13, from: 3.5, to: 5.5 }]); const on = playGapMarks(joins, { cue: clipGapCueOf({ gapCue: { mark: true } }, {}), entryGaps: [{ from: 3.5, to: 5.5 }], playEnd: 16 }); assert.deepEqual(on.map((m) => [m.at, m.text]), [[13, "» 2 s"]]); near(on[0].until, 13 + GAP_CUE_LIFE, "a mark's life"); // The clip's own gap off (the render's gap a frame off the manifest's: still it). assert.deepEqual(playGapMarks(joins, { cue: clipGapCueOf({ gapCue: { mark: true } }, {}), entryGaps: [{ from: 3.53, to: 5.47, mark: false }], playEnd: 16 }), []); // A join near the footage's end: clamped to it. const late = playGapMarks([{ at: 15.5, from: 3.5, to: 5.5 }], { cue: clipGapCueOf({ gapCue: { mark: true } }, {}), playEnd: 16 }); assert.equal(late[0].until, 16); }); test("gapMarkCorner: a clip's corner as it says; auto the layout's (the deck's footage bottom left, a plain cut's top left)", () => { assert.equal(gapMarkCorner("br", { deck: true }), "br"); assert.equal(gapMarkCorner("auto", { deck: true }), "bl"); assert.equal(gapMarkCorner("auto", { deck: false }), "tl"); assert.equal(gapMarkCorner(undefined, { deck: false }), "tl"); }); test("the reason and the gap's own corner reach the page's mark as the build's (operator rulings, 20 Nov)", () => { const gaps = [{ from: 3.5, to: 5.5, why: "dead-air", corner: "tr" }, { from: 7, to: 7.6 }]; const cue = clipGapCueOf({ gapCue: { mark: true, min: 0.5 } }, { gaps }); const page = clipGapMarks({ cue, gaps, from: 0.5, to: 12 }); assert.deepEqual(page.map((m) => [m.text, m.corner ?? null]), [["» 2 s · dead air", "tr"], ["» 1 s", null]]); const segGaps = gaps.map((g) => ({ from: g.from - 0.5, to: g.to - 0.5 })); const build = segmentGapMarks({ render: { gapCue: { mark: true, min: 0.5 } }, entry: { type: "clip", gaps }, seconds: 11.5 - 2.6, joins: segmentGapJoins({ segGaps, clipGaps: gaps, segStart: 0.5, cue }) }); assert.deepEqual(page, build); assert.equal(gapMarkAt(page, 3.5).corner, "tr"); // Play: the gap's own words over its why. const play = playGapMarks([{ at: 13, from: 3.5, to: 5.5 }], { cue, entryGaps: [{ from: 3.5, to: 5.5, why: "other", reason: "ad break" }], playEnd: 20 }); assert.equal(play[0].text, "» 2 s · ad break"); });