// Play the cut with gaps inside a clip (gaps.mjs): the plan plays the kept // seconds as one item -- its footage the cut less its gaps, the cut ↔ source // mapping jumping at each join (on the estimate's clock and on the render's, // from the cut-points route's `gaps`), the chrome seeked by source second // through them; the sound is one span per kept piece, abutting on the cut's // clock, with the build's join fades; the clip editor's live clock agrees. // Without gaps every number is the one it was. // // Run with: pnpm test:scripts import assert from "node:assert/strict"; import test from "node:test"; import { estimateSchedule } from "umtool-report-to-video/deck"; import { GAP_FADE } from "umtool-report-to-video/gaps"; import { chromeTime, cutAtSource, gapJoins, playPlan, playTimeOfChrome, skipEntries, sourceAt } from "./playCut.mjs"; import { audioSpans, levelAt, scheduleFrom } from "./playSchedule.mjs"; import { cutTimeAt, liveClock, sourceTimeAt } from "./liveClock.mjs"; const GAPS = [{ from: 12, to: 13 }, { from: 15, to: 15.5 }]; const manifest = (gaps) => ({ slug: "t", render: { width: 1920, height: 1080, fps: 30, transition: 0 }, timeline: [ { type: "clip", id: "a", video: "v1", start: 10, end: 18, ...(gaps ? { gaps } : {}) }, { type: "clip", id: "b", video: "v2", start: 100, end: 103 }, ], }); const planOf = (gaps, cuts = null) => { const m = manifest(gaps); return playPlan(estimateSchedule(m).segments, m.timeline, { cuts }); }; const near = (a, b, what, tol = 1e-6) => assert.ok(Math.abs(a - b) <= tol, `${what}: ${a} vs ${b}`); test("the estimate: a gapped clip is one item, its footage the kept seconds; b moves up by the gaps", () => { const plain = planOf(null); const p = planOf(GAPS); assert.equal(plain.items[0].clip.playEnd, 8); assert.equal(p.items[0].clip.playEnd, 6.5); assert.deepEqual(p.items[0].clip.gaps, GAPS); assert.equal("gaps" in plain.items[0].clip, false, "no key without gaps"); assert.equal(p.items[1].start, 6.5); assert.equal(p.total, 9.5); }); test("sourceAt / cutAtSource jump at each join; a second inside a gap plays at its join", () => { const it = planOf(GAPS).items[0]; assert.equal(sourceAt(it, 1.9), 11.9); assert.equal(sourceAt(it, 2), 13, "the join shows the material after the gap"); assert.equal(sourceAt(it, 3.5), 14.5); assert.equal(sourceAt(it, 4.2), 15.7); assert.equal(sourceAt(it, 6.5), 18); assert.equal(cutAtSource(it, 12.5), 2, "inside the first gap: its join"); assert.equal(cutAtSource(it, 14), 3); assert.equal(cutAtSource(it, 16), 4.5); assert.deepEqual(gapJoins(it), [{ at: 2, from: 12, to: 13 }, { at: 4, from: 15, to: 15.5 }]); // Without gaps: the subtraction it always was. const plain = planOf(null).items[0]; assert.equal(sourceAt(plain, 2.5), 12.5); assert.equal(cutAtSource(plain, 12.5), 2.5); assert.deepEqual(gapJoins(plain), []); }); test("the render's edges: the route's gaps and footage; the chrome (on the estimate's clock) is seeked by source second", () => { const cuts = { a: { cutStart: 9.9, cutEnd: 18.1, footage: 6.7, gaps: [{ from: 12, to: 13 }, { from: 15, to: 15.5 }] }, b: { cutStart: 100, cutEnd: 103 } }; const p = planOf(GAPS, cuts); const it = p.items[0]; assert.equal(it.clip.sourceFrom, 9.9); assert.equal(it.clip.playEnd, 6.7); assert.equal(sourceAt(it, 2.1), 13, "9.9 + 2.1 is the first gap's start: the join"); // Source 14 plays at Play 3.1 (render) and at estimate 3 -- the chrome is seeked there. near(chromeTime(p, cutAtSource(it, 14)), 3, "chromeTime"); near(playTimeOfChrome(p, 3), 3.1, "and back"); // Skipping b keeps a's gaps on its estimate. const s = skipEntries(p, ["b"]); assert.deepEqual(s.items[0].est.gaps, GAPS); }); test("the sound: one span per kept piece, abutting; the join fades; a seek into a later piece reads its own source", () => { const spans = audioSpans(planOf(GAPS)).filter((s) => s.id === "a"); assert.deepEqual(spans.map((s) => [s.from, s.to, s.src, s.srcTo]), [[0, 2, 10, 12], [2, 4, 13, 15], [4, 6.5, 15.5, 18]]); // The fades: out over the last GAP_FADE of a piece before a join, in over the first after it; full level between. near(levelAt(spans[0].env, 2 - GAP_FADE / 2), 0.5, "fading out into the first join", 1e-3); near(levelAt(spans[1].env, 2 + GAP_FADE / 2), 0.5, "fading in out of it", 1e-3); assert.equal(levelAt(spans[1].env, 3), 1); assert.equal(levelAt(spans[0].env, 0), 1, "the clip's own first sample is not faded"); const sch = scheduleFrom(audioSpans(planOf(GAPS)), 3); assert.deepEqual(sch.slice(0, 2).map((x) => [x.atWall, x.src]), [[0, 14], [1, 15.5]]); // Without gaps: one span, as ever. assert.deepEqual(audioSpans(planOf(null)).filter((s) => s.id === "a").map((s) => [s.from, s.to, s.src]), [[0, 8, 10]]); }); test("the clip editor's live clock: the footage less the gaps, the jump at each join", () => { const sched = estimateSchedule(manifest(GAPS)); const clock = liveClock(sched, { id: "a", start: 10, end: 18, gaps: GAPS }); assert.equal(clock.playEnd, 6.5); assert.deepEqual(cutTimeAt(clock, 14), { t: 3, where: "inside" }); assert.deepEqual(cutTimeAt(clock, 12.4), { t: 2, where: "inside" }); assert.equal(sourceTimeAt(clock, 4.5), 16); const plain = liveClock(estimateSchedule(manifest(null)), { id: "a", start: 10, end: 18 }); assert.equal(plain.playEnd, 8); assert.equal("gaps" in plain, false); });