// A gapped clip's picture decodes per kept piece, the next primed before its join (playCut.mjs pieceWants). import assert from "node:assert/strict"; import test from "node:test"; import { gapJoins, pieceWants, playPlan } from "./playCut.mjs"; // One clip, 10–40 s of its recording, 15–30 cut out: it plays 10–15 then 30–40 (15 s of cut). const entries = [{ id: "a", type: "clip", video: "v", start: 10, end: 40, gaps: [{ from: 15, to: 30 }] }]; const plan = playPlan([{ id: "a", start: 0, duration: 15 }], entries, { leadIn: 0 }); const it = plan.items[0]; test("pieceWants: the piece playing; the next one primed within `ahead` of its join", () => { const [join] = gapJoins(it); assert.ok(join, "the plan carries the gap"); // The cached window starts at source 5: media time is source − 5. const early = pieceWants(it, join.at - 3, 5, { ahead: 2 }); assert.deepEqual(early.map((w) => w.piece), [0], "3 s before the join: only the piece playing"); const near = pieceWants(it, join.at - 1, 5, { ahead: 2 }); assert.deepEqual(near.map((w) => w.piece), [0, 1]); assert.equal(near[1].mediaTime, 25, "the next piece from its first second: source 30"); const after = pieceWants(it, join.at + 0.5, 5, { ahead: 2 }); assert.deepEqual(after.map((w) => w.piece), [1], "past the join: the second piece, nothing after it"); assert.ok(Math.abs(after[0].mediaTime - 25.5) < 0.05); }); test("pieceWants: a clip with no gaps is one piece", () => { const p2 = playPlan([{ id: "b", start: 0, duration: 5 }], [{ id: "b", type: "clip", video: "v", start: 0, end: 5 }], { leadIn: 0 }); assert.deepEqual(pieceWants(p2.items[0], 1, 0).map((w) => w.piece), [0]); });