Archilyzer · Source

archilyzer

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

commit fd8358a3f883cf0d3aea182f43c800986a4bcfaa
parent 28a4abf85d63e599e4f56b4d01f9eec3ea1ea495
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Sat, 24 Oct 2026 03:24:54 -0400

Play the cut: the engine's self-measure per clock run; specs read the render's clock exactly

The engine's measured nodes carry their clock run (a restart schedules
again), and an element's drift is measured against the frame it presented,
in its own frame length. play-cut.spec.ts: a note's source second is stored
to the hundredth and seeks back by it; c04's first shown second is
mid-dissolve from c03's ground.

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

Diffstat:
Mumtool/components/projects/review/playEngine/elementPicture.ts | 18+++++++++++++++++-
Mumtool/components/projects/review/playEngine/engine.ts | 8+++++---
Mumtool/e2e/play-cut.spec.ts | 14++++++++------
Mumtool/e2e/play-engine.spec.ts | 5+++--
4 files changed, 33 insertions(+), 12 deletions(-)

diff --git a/umtool/components/projects/review/playEngine/elementPicture.ts b/umtool/components/projects/review/playEngine/elementPicture.ts @@ -23,11 +23,13 @@ type Slot = { /** The media time of the frame last presented (rVFC), or null when the element cannot say. */ presented: number | null; presentedAt: number; + /** The picture's frame length, as the presented frames step (the shortest step seen; 0 until they have). */ + frame: number; rvfc: number; }; export class ElementPicture { - private slots: Slot[] = [0, 1].map(() => ({ el: null, index: -1, url: "", presented: null, presentedAt: 0, rvfc: 0 })); + private slots: Slot[] = [0, 1].map(() => ({ el: null, index: -1, url: "", presented: null, presentedAt: 0, rvfc: 0, frame: 0 })); /** The element's sound is the fallback's (no Web Audio): unmuted on the clip the clock follows. */ soundFromElement = false; @@ -51,6 +53,17 @@ export class ElementPicture { return v && v.readyState >= 2 && v.videoWidth > 0 ? v : null; } + /** The media time of the frame item `index`'s element last presented (requestVideoFrameCallback), when it is fresh. */ + presentedFor(index: number): number | null { + const s = this.slots.find((x) => x.index === index && x.el); + return s && s.presented !== null && performance.now() - s.presentedAt < 250 ? s.presented : null; + } + + /** The frame length of item `index`'s picture (1/30 until its frames have stepped). */ + frameFor(index: number): number { + return this.slots.find((x) => x.index === index && x.el)?.frame || 1 / 30; + } + /** Which slot holds item `index` (-1: none). */ slotOf(index: number) { return this.slots.findIndex((x) => x.index === index); @@ -108,6 +121,7 @@ export class ElementPicture { s.index = w.index; s.url = w.url; s.presented = null; + s.frame = 0; if (v.getAttribute("src") !== w.url) { v.setAttribute("src", w.url); v.dataset.playSlotItem = w.id; @@ -154,6 +168,8 @@ export class ElementPicture { if (!v?.requestVideoFrameCallback) return; const on = (_now: number, m: { mediaTime: number }) => { if (s.el !== v) return; + const step = s.presented !== null ? m.mediaTime - s.presented : 0; + if (step > 1 / 121 && step < 0.11) s.frame = s.frame ? Math.min(s.frame, step) : step; s.presented = m.mediaTime; s.presentedAt = performance.now(); s.rvfc = v.requestVideoFrameCallback!(on); diff --git a/umtool/components/projects/review/playEngine/engine.ts b/umtool/components/projects/review/playEngine/engine.ts @@ -127,7 +127,8 @@ 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 }[], + nodes: [] as { id: string; at: number; stop: number; late: number; run: number }[], + run: 0, drawn: 0, off: 0, worst: 0, late: [] as { id: string; want: number; at: number }[], }; @@ -303,6 +304,7 @@ export class PlayEngine { this.started.clear(); this.lastDraw = ""; this.restartedAt = performance.now(); + this.measured.run += 1; // The first nodes now, inside the lead, not at the next frame. if (this.playing) this.schedule(); } @@ -428,7 +430,7 @@ 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 }].slice(-40); + this.measured.nodes = [...this.measured.nodes, { id: p.id, at: this.c0 + p.atWall, stop, late, run: this.measured.run }].slice(-40); const node: Node = { key: p.id, src, gain }; src.onended = () => { src.disconnect(); @@ -552,7 +554,7 @@ export class PlayEngine { layers.push({ ...v, source: f, w: f?.displayWidth ?? 0, h: f?.displayHeight ?? 0 }); } else { const el = this.elements.sourceFor(v.i); - if (el && runs && inFootage(v.i)) this.measure(items[v.i].id, el.currentTime, this.mediaTimeOf(v.i, t), 1 / 30); + if (el && runs && inFootage(v.i)) this.measure(items[v.i].id, this.elements.presentedFor(v.i) ?? el.currentTime, this.mediaTimeOf(v.i, t), this.elements.frameFor(v.i)); layers.push({ ...v, source: el, w: el?.videoWidth ?? 0, h: el?.videoHeight ?? 0 }); } } diff --git a/umtool/e2e/play-cut.spec.ts b/umtool/e2e/play-cut.spec.ts @@ -133,13 +133,14 @@ test("a note at the playhead: its kind, the cut second, the clip and its source await page.keyboard.press("n"); // 7.972: 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"); - // Paused, the clip's frame is in the picture (the fixture's window is dark green), not a black box. + // 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 .poll( () => page.locator("[data-play-footage]").evaluate((c: HTMLCanvasElement) => { const [r, g, b] = c.getContext("2d")!.getImageData(Math.floor(c.width / 2), Math.floor(c.height / 2), 1, 1).data; - return g > 60 && r < 40 && b < 40; + return g > 35 && g > r + 20 && g > b + 20; }), { timeout: 15_000 }, ) @@ -161,22 +162,23 @@ test("a note at the playhead: its kind, the cut second, the clip and its source 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), the kind. + // source 6.007, so 7.972 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.107, ask: "trim" }); + expect(n.anchor).toEqual({ kind: "cut", t: 7.97, 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.) await page.keyboard.press("]"); await expect(root(page)).toHaveAttribute("data-play-item", "c04"); - expect(await tNow(page)).toBeCloseTo(7.972, 2); + expect(Math.abs((await tNow(page)) - 7.975)).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(await tNow(page)).toBeCloseTo(7.972, 2); + expect(Math.abs((await tNow(page)) - 7.975)).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 }); diff --git a/umtool/e2e/play-engine.spec.ts b/umtool/e2e/play-engine.spec.ts @@ -31,7 +31,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 }[]; + scheduled: { id: string; at: number; stop: number; late: number; run: number }[]; framesDrawn: number; framesOff: number; worstFrames: number; @@ -82,8 +82,9 @@ test("the clock is the sound's: one AudioContext, nodes started ahead of their t 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. - const c01 = s.scheduled.find((n) => n.id === "c01")!; + // (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);