Archilyzer · Source

archilyzer

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

commit d1c5cbbee6da498b61b5b93f28f20445c1b04882
parent fd8358a3f883cf0d3aea182f43c800986a4bcfaa
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Sat, 24 Oct 2026 04:21:59 -0400

Play the cut: each clip as long as its encode makes it, in whole frames

The build's segment is its cut in whole frames (cutOffsets sums the probed
frames), so the cut-points route gives each clip its `footage` (the span
rounded up to a frame) and the plan times it by that; the part-frame past
the source's end is silent, as the encode pads it. On the Huck walked take
(51 clips, 25:48) Play's segment starts now land within 0.60 s of the
render's schedule at the very end (the estimate's were 19.1 s off).

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

Diffstat:
Mumtool/components/projects/review/playEngine/engine.ts | 8++++++--
Mumtool/e2e/play-cut.spec.ts | 51++++++++++++++++++++++++++-------------------------
Mumtool/e2e/play-engine.spec.ts | 17+++++++++++------
Mumtool/lib/report/cutPoints.mjs | 7+++++++
Mumtool/lib/report/playCut.mjs | 5+++--
Mumtool/lib/report/playSchedule.mjs | 8+++++---
Mumtool/lib/report/playSchedule.test.mjs | 6++++++
7 files changed, 64 insertions(+), 38 deletions(-)

diff --git a/umtool/components/projects/review/playEngine/engine.ts b/umtool/components/projects/review/playEngine/engine.ts @@ -127,7 +127,7 @@ export class PlayEngine { * playing was from the second the clock wanted (in frames of 1/30 s). */ private measured = { - nodes: [] as { id: string; at: number; stop: number; late: number; run: number }[], + nodes: [] as { id: string; at: number; stop: number; late: number; run: number; from: number; to: number }[], run: 0, drawn: 0, off: 0, worst: 0, late: [] as { id: string; want: number; at: number }[], @@ -430,7 +430,11 @@ export class PlayEngine { } src.start(at, offset); src.stop(stop); - this.measured.nodes = [...this.measured.nodes, { id: p.id, at: this.c0 + p.atWall, stop, late, run: this.measured.run }].slice(-40); + const cut = (wall: number) => Math.round((this.t0 + wall * this.rate) * 1e6) / 1e6; + this.measured.nodes = [ + ...this.measured.nodes, + { id: p.id, at: this.c0 + p.atWall, stop, late, run: this.measured.run, from: cut(p.atWall), to: cut(p.atWall + p.durWall) }, + ].slice(-40); const node: Node = { key: p.id, src, gain }; src.onended = () => { src.disconnect(); diff --git a/umtool/e2e/play-cut.spec.ts b/umtool/e2e/play-cut.spec.ts @@ -13,11 +13,12 @@ import * as urls from "./urls"; // kind) lists, pins and seeks, and a take plays its own timeline. // // The clock is the RENDER'S: each clip at its snapped edges (the cut-points -// route). On vid1's window (silences 2.90-3.11 and 5.92-6.11) c01 plays -// 1.000-3.082, c02 3.011-6.101, c04 6.007-8.000, so with the 0.2 s -// crossfades: c01 0-2.082 (shown to 1.982), c02 1.882-4.972 (shown 1.982- -// 4.872), k01 4.772-6.272 (shown to 6.172), c03 6.072-8.072 (shown to -// 7.972), c04 7.872-9.865. play-engine.spec.ts covers the engine itself. +// route), in the encode's whole frames (15 fps here). On vid1's window +// (silences 2.90-3.11 and 5.92-6.11) c01 plays 1.000-3.082 (2.133 s), c02 +// 3.011-6.101 (3.133 s), c04 6.007-8.000 (2 s), so with the 0.2 s +// crossfades: c01 0-2.133 (shown to 2.033), c02 1.933-5.067 (shown 2.033- +// 4.967), k01 4.867-6.367 (shown to 6.267), c03 6.167-8.167 (shown to +// 8.067), c04 7.967-9.967. play-engine.spec.ts covers the engine itself. // Screenshots at 1280 and 390 px land in test-results. Fixture: // e2e/fixtures/play-cut-fixture.mjs. // --------------------------------------------------------------------------- @@ -65,12 +66,12 @@ test("the cut plays clip after clip on one clock; prev / next / keys; the strip await page.locator("[data-play-toggle]").click(); await expect(root(page)).toHaveAttribute("data-play-item", "c01"); await expect.poll(() => tNow(page), { timeout: 20_000 }).toBeGreaterThan(0.5); - // ...and carries on into clip 2 (c01 is shown to 1.982 s on the render's clock). + // ...and carries on into clip 2 (c01 is shown to 2.033 s on the render's clock). await expect(root(page)).toHaveAttribute("data-play-item", "c02", { timeout: 20_000 }); await expect(page.locator('[data-play-row="c02"]')).toHaveAttribute("aria-current", "true"); // c02's picture is drawn (whichever path the browser plays it on). await expect(page.locator("[data-play-footage]")).toHaveAttribute("data-play-layers", /^[12]$/, { timeout: 15_000 }); - await expect.poll(() => tNow(page)).toBeGreaterThan(1.982); + await expect.poll(() => tNow(page)).toBeGreaterThan(2.033); // NOW: c02 on the reader, the next entry named. await expect(page.locator('[data-play-now="c02"]')).toBeVisible(); await expect(page.locator("[data-play-next-up]")).toHaveAttribute("data-play-next-up", "k01"); @@ -81,7 +82,7 @@ test("the cut plays clip after clip on one clock; prev / next / keys; the strip await page.locator("[data-play-next]").click(); await expect(root(page)).toHaveAttribute("data-play-item", "k01"); await expect(page.locator('[data-play-placeholder="card"]')).toContainText("Between the clips"); - expect(await tNow(page)).toBeCloseTo(4.872, 2); + expect(await tNow(page)).toBeCloseTo(4.967, 2); // The stamp on c02 (k1 at source 4.5) has landed by now: the counter at the playhead says so. await expect(page.locator("[data-play-strip-at]")).toContainText("Seizures 1"); // n: the clip whose source was never fetched -- named, not waited on. @@ -98,23 +99,23 @@ test("the cut plays clip after clip on one clock; prev / next / keys; the strip await expect(root(page)).toHaveAttribute("data-play-item", "c03"); await page.locator("[data-play-prev]").click(); await expect(root(page)).toHaveAttribute("data-play-item", "k01"); - // ← is 5 s back: from 4.872, the cut's first second. + // ← is 5 s back: from 4.967, the cut's first second. await page.keyboard.press("ArrowLeft"); await expect(root(page)).toHaveAttribute("data-play-item", "c01"); expect(await tNow(page)).toBe(0); - // → is 5 s on: the card's second (it is shown 4.872-6.172). + // → is 5 s on: the card's second (it is shown 4.967-6.267). await page.keyboard.press("ArrowRight"); await expect(root(page)).toHaveAttribute("data-play-item", "k01"); expect(await tNow(page)).toBeCloseTo(5, 1); // A cell's Enter jumps to its start; a click on the strip scrubs to that second. await page.locator('[data-play-row="c02"]').press("Enter"); await expect(root(page)).toHaveAttribute("data-play-item", "c02"); - expect(await tNow(page)).toBeCloseTo(1.982, 2); + expect(await tNow(page)).toBeCloseTo(2.033, 2); const cells = page.locator("[data-play-cells]"); const box = (await cells.boundingBox())!; await page.mouse.click(box.x + box.width * 0.9, box.y + box.height / 2); await expect(root(page)).toHaveAttribute("data-play-item", "c04"); - expect(Math.abs((await tNow(page)) - 0.9 * 9.865)).toBeLessThan(0.15); + expect(Math.abs((await tNow(page)) - 0.9 * 9.967)).toBeLessThan(0.15); // ? lists the keys; Esc closes it. await page.keyboard.press("?"); @@ -129,10 +130,10 @@ test("a note at the playhead: its kind, the cut second, the clip and its source await ready(page); await expect(page.locator("[data-play-note-list]")).toContainText("Press M while it plays to note this moment."); await page.locator('[data-play-row="c02"]').press("Enter"); - await page.keyboard.press("ArrowRight"); // 1.982 + 5 = 6.982: c03 (shown to 7.972) - await page.keyboard.press("n"); // 7.972: c04's first shown second + await page.keyboard.press("ArrowRight"); // 2.033 + 5 = 7.033: c03 (shown to 8.067) + await page.keyboard.press("n"); // 8.067: c04's first shown second await expect(root(page)).toHaveAttribute("data-play-item", "c04"); - await expect(page.locator("[data-play-note-add]")).toHaveText("Note at 00:07.9"); + await expect(page.locator("[data-play-note-add]")).toHaveText("Note at 00:08.0"); // Paused, the clip's frame is in the picture (the fixture's window is dark green), not a black box -- // half of it: c04's first shown second is the middle of its crossfade from c03 (no media: the ground). await expect @@ -148,7 +149,7 @@ test("a note at the playhead: its kind, the cut second, the clip and its source await page.keyboard.press("m"); const input = page.getByTestId("play-note-input"); await expect(input).toBeFocused(); - await expect(page.locator("[data-play-note-at]")).toHaveAttribute("data-play-note-at", "7.97"); + await expect(page.locator("[data-play-note-at]")).toHaveAttribute("data-play-note-at", "8.07"); await input.fill("start this one later"); await input.press("Alt+t"); await expect(page.locator('[data-play-ask="trim"]')).toHaveAttribute("aria-pressed", "true"); @@ -156,29 +157,29 @@ test("a note at the playhead: its kind, the cut second, the clip and its source const note = page.locator("[data-play-note]"); await expect(note).toHaveCount(1); await expect(note).toContainText("start this one later"); - await expect(note.locator("[data-play-note-seek]")).toHaveText("00:07.9"); + await expect(note.locator("[data-play-note-seek]")).toHaveText("00:08.0"); await expect(note.locator("[data-play-note-ask]")).toHaveText("trim"); await expect(page.locator("[data-play-pin]")).toHaveCount(1); await expect(page.locator("[data-play-send-all]")).toHaveText("Send 1 open note to the assistant"); - // Written through the notes store: the cut anchor, the clip, its source second (c04's segment starts at 7.872 at - // source 6.007, so 7.972 is 6.107, stored to the hundredth), the kind. + // Written through the notes store: the cut anchor, the clip, its source second (c04's segment starts at 7.967 at + // source 6.007, so 8.067 is 6.107, stored to the hundredth), the kind. const doc = JSON.parse(readFileSync(path.join(DIR, "notes.json"), "utf8")); const n = doc.notes.find((x: { text: string }) => x.text === "start this one later"); - expect(n.anchor).toEqual({ kind: "cut", t: 7.97, entry: "c04", sourceT: 6.11, ask: "trim" }); + expect(n.anchor).toEqual({ kind: "cut", t: 8.07, entry: "c04", sourceT: 6.11, ask: "trim" }); expect(n.author).toBe("operator"); // Elsewhere, then ] (the next note) and the note's timecode: back where it was taken. await page.locator('[data-play-row="c01"]').press("Enter"); await expect(root(page)).toHaveAttribute("data-play-item", "c01"); - // (A note seeks by its clip and source second: 6.11 in c04 is 7.975 on this clock.) + // (A note seeks by its clip and source second: 6.11 in c04 is 8.070 on this clock.) await page.keyboard.press("]"); await expect(root(page)).toHaveAttribute("data-play-item", "c04"); - expect(Math.abs((await tNow(page)) - 7.975)).toBeLessThan(0.011); + expect(Math.abs((await tNow(page)) - 8.07)).toBeLessThan(0.011); await page.locator('[data-play-row="c01"]').press("Enter"); await note.locator("[data-play-note-seek]").click(); await expect(root(page)).toHaveAttribute("data-play-item", "c04"); - expect(Math.abs((await tNow(page)) - 7.975)).toBeLessThan(0.011); + expect(Math.abs((await tNow(page)) - 8.07)).toBeLessThan(0.011); // How it looks: the desk at 1280, the stack at a phone's 390 (no sideways scroll). await page.setViewportSize({ width: 1280, height: 860 }); @@ -225,7 +226,7 @@ test("a take plays its own timeline (its patch over the project's manifest); a r await expect(page.locator('[data-play-take="quick-joins"]')).toContainText("not rendered yet"); await expect(root(page)).toHaveAttribute("data-play-edges", "render", { timeout: 30_000 }); await expect(rows(page)).toHaveCount(5); - // A hard-cut look: each entry is its segment, so c02 starts where c01's render cut ends (2.082 s), not mid-fade. + // A hard-cut look: each entry is its segment, so c02 starts where c01's render segment ends (2.133 s), not mid-fade. await page.locator('[data-play-row="c02"]').press("Enter"); - expect(await tNow(page)).toBeCloseTo(2.082, 2); + expect(await tNow(page)).toBeCloseTo(2.133, 2); }); diff --git a/umtool/e2e/play-engine.spec.ts b/umtool/e2e/play-engine.spec.ts @@ -21,7 +21,8 @@ import * as urls from "./urls"; // Fixture: e2e/fixtures/play-cut-fixture.mjs's play-engine-fixture (the // play-cut cut, which this spec WRITES). On vid1's window (silences // 2.90-3.11, 5.92-6.11) the render cuts c01 at 1.000-3.082, c02 3.011-6.101, -// c04 6.007-8.000. +// c04 6.007-8.000; in whole frames at 15 fps c01 lasts 2.133 s, so c02's +// segment starts at 1.933 (the 0.2 s crossfade before c01's end). // --------------------------------------------------------------------------- const HERE = path.dirname(fileURLToPath(import.meta.url)); @@ -31,7 +32,7 @@ const MANIFEST = path.join(HERE, "..", ".e2e-song", "reports", "play-engine-fixt const root = (page: Page) => page.locator("[data-play-cut]"); const tNow = async (page: Page) => Number(await root(page).getAttribute("data-play-t")); type Stats = { - scheduled: { id: string; at: number; stop: number; late: number; run: number }[]; + scheduled: { id: string; at: number; stop: number; late: number; run: number; from: number; to: number }[]; framesDrawn: number; framesOff: number; worstFrames: number; @@ -68,7 +69,7 @@ test("the clock is the sound's: one AudioContext, nodes started ahead of their t await page.locator("[data-play-toggle]").click(); await expect(root(page)).toHaveAttribute("data-play-sound", "webaudio", { timeout: 15_000 }); await expect.poll(() => tNow(page), { timeout: 20_000 }).toBeGreaterThan(0.4); - // Through the c01 → c02 join (shown to 1.982, crossfading 1.882-2.082). + // Through the c01 → c02 join (shown to 2.033, crossfading 1.933-2.133). await expect(root(page)).toHaveAttribute("data-play-item", "c02", { timeout: 20_000 }); await expect.poll(() => tNow(page), { timeout: 10_000 }).toBeGreaterThan(2.4); // The context stops: so does the clock, and everything that reads it. @@ -81,13 +82,17 @@ test("the clock is the sound's: one AudioContext, nodes started ahead of their t await expect.poll(() => tNow(page), { timeout: 5_000 }).toBeGreaterThan(held + 0.2); const s = await stats(page); // Every node was started AHEAD of its time (Web Audio then starts it on the sample), and the two - // clips meet as the build joins them: c02 starts 0.2 s (the crossfade) before c01 stops. + // clips meet as the build joins them, on one clock: c02 sounds from its segment's first second + // (1.933), c01 to its source's last (2.082: the rest of its last frame is the encode's silence). // (One run of the clock: a restart -- the chrome composing, a seek -- schedules again.) const c02 = s.scheduled.find((n) => n.id === "c02")!; const c01 = s.scheduled.find((n) => n.id === "c01" && n.run === c02?.run)!; expect(c01 && c02).toBeTruthy(); expect(Math.max(...s.scheduled.map((n) => n.late))).toBeLessThanOrEqual(0); - expect(Math.abs(c01.stop - c02.at - 0.2)).toBeLessThan(1e-6); + expect(c02.from).toBeCloseTo(1.933, 3); + expect(c01.to).toBeCloseTo(2.082, 3); + expect(Math.abs(c02.at - c01.at - (c02.from - c01.from))).toBeLessThan(1e-6); + expect(Math.abs(c01.stop - c01.at - (c01.to - c01.from))).toBeLessThan(1e-6); console.log(`play-engine: joins ${JSON.stringify(s.scheduled)}; frames drawn ${s.framesDrawn}, more than 1.5 frames off ${s.framesOff}, worst ${s.worstFrames.toFixed(2)} frames`); await page.keyboard.press("k"); }); @@ -99,7 +104,7 @@ test("the picture: WebCodecs in this browser, a dissolve is two layers; the <vid await page.locator('[data-play-row="c02"]').press("Enter"); await expect(root(page)).toHaveAttribute("data-play-picture", want, { timeout: 15_000 }); await expect(page.locator("[data-play-approximate]")).toContainText(want === "webcodecs" ? "picture: WebCodecs" : "picture: <video>"); - // c02's first shown second (1.982) is inside the crossfade from c01 (1.882-2.082): both clips are drawn. + // c02's first shown second (2.033) is inside the crossfade from c01 (1.933-2.133): both clips are drawn. await expect(page.locator("[data-play-footage]")).toHaveAttribute("data-play-layers", "2", { timeout: 15_000 }); // Played on past it: one layer, and the frames drawn are the clock's. await page.locator("[data-play-toggle]").click(); diff --git a/umtool/lib/report/cutPoints.mjs b/umtool/lib/report/cutPoints.mjs @@ -124,6 +124,8 @@ async function cutContext(project, take) { * * cutStart / cutEnd where its segment starts and ends (`<id>.cut.json`'s * `start`/`end`): the picture's span, room included + * footage the segment's length in the cut: that span in whole + * frames, as the encode makes it * snapped { start, end }: which edge moved to a silence * sound [from, to] the sound is heard over, when room mutes * an edge (else the whole segment) @@ -220,9 +222,14 @@ async function clipCutPoints(entry, ctx) { sound = room.record.sound; } } + // The segment's length as its encode makes it: whole frames, the last one + // begun counted (the build's cutOffsets sums the probed frames; measured on + // the Huck walk, 34 of 51 segments exactly this, the rest one frame more). + const fps = fin(render.fps) && render.fps > 0 ? render.fps : 30; const row = { id: entry.id, window: path.basename(src.path), + footage: Number((Math.ceil((segB - segA) * fps - 1e-6) / fps).toFixed(6)), fetchStart: r3(fetchStart), silences: sil, playFrom: pw.from, diff --git a/umtool/lib/report/playCut.mjs b/umtool/lib/report/playCut.mjs @@ -44,7 +44,7 @@ const fin = (v) => typeof v === "number" && Number.isFinite(v); const round = (v) => Math.round(v * 1000) / 1000; /** - * @typedef {{ cutStart: number, cutEnd: number, snapped?: { start: boolean, end: boolean }, + * @typedef {{ cutStart: number, cutEnd: number, footage?: number, snapped?: { start: boolean, end: boolean }, * sound?: [number, number], gainDb?: number, audio?: Record<string, number>, muteFrom?: number }} RenderCut */ @@ -77,7 +77,8 @@ export function playPlan(segments, entries, { leadIn = 0.4, cuts = null } = {}) return { ...it, start: round(it.start + before), end: round(it.end + before), from: round(it.from + before), to: round(it.to + before), clip: it.clip ? { ...it.clip, playEnd: round(it.clip.playEnd + before) } : null, est: estAt }; } - const foot = c.cutEnd - c.cutStart; + // Its length in the cut: the encode's whole frames when the route said (`footage`), else the span. + const foot = fin(c.footage) && /** @type {number} */ (c.footage) > 0 ? /** @type {number} */ (c.footage) : c.cutEnd - c.cutStart; // The estimate's segment is its footage (at least a second) and its hold; the render's, its cut and the same hold. const delta = foot + it.clip.hold - (it.end - it.start); shift += delta; diff --git a/umtool/lib/report/playSchedule.mjs b/umtool/lib/report/playSchedule.mjs @@ -63,8 +63,8 @@ const ramp = (a, b, down = false) => (b > a ? [[a, down ? 1 : 0], [b, down ? 0 : * Where each clip's sound sits on the cut's clock and what its level does. * * from / to the cut seconds it sounds over: its segment's start to its - * footage's end (a carrying clip's hold is silent, as the - * build pads it) + * source's end (the encode's last part-frame and a carrying + * clip's hold are silent, as the build pads them) * src the source second at `from` (an `audio.offset` reads the * sound that much earlier: later against the picture) * env its level: the crossfades (a linear ramp over each @@ -85,7 +85,9 @@ export function audioSpans(plan) { const c = it.clip; if (!c || !(c.playEnd > it.start)) return; const from = it.start; - const to = c.playEnd; + // Its source's length: the encode pads a segment to whole frames with SILENCE (apad), and a hold is silent too. + const to = Math.min(c.playEnd, it.start + Math.max(0, c.sourceTo - c.sourceFrom)); + if (!(to > from)) return; const prev = items[i - 1]; const next = items[i + 1]; const dIn = prev ? Math.max(0, prev.end - it.start) : 0; diff --git a/umtool/lib/report/playSchedule.test.mjs b/umtool/lib/report/playSchedule.test.mjs @@ -102,6 +102,12 @@ test("the render's edges, room, loudness, the clip's knobs and the mute mark sha near(levelAt(b.env, b.from + 2 - 0.04), 1, "b full until the mute fade"); }); +test("a segment longer than its source (whole frames) is silent past the source's end", () => { + const spans = audioSpans(planOf(0, { a: { cutStart: 10, cutEnd: 13.99, footage: 4 } })); + assert.equal(spans[0].to, 3.99); + assert.equal(spans[1].from, 4); +}); + test("envelopes multiply on the union of their points; a decode span is the sound and a pad", () => { assert.deepEqual(multiply([[[0, 0], [1, 1]], [[0.5, 1], [1.5, 0]]], 0, 2), [[0, 0], [0.5, 0.5], [1, 0.5], [1.5, 0], [2, 0]]); assert.deepEqual(decodeSpanOf({ src: 10, srcTo: 14 }), { from: 9.75, to: 14.25 });