Archilyzer · Source

archilyzer

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

commit 4bc8926a7a5c66172ddaa1102720e874fbe9b599
parent 9249a96dd5bda74a7b14169f2ac91713b18d0461
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Fri, 13 Nov 2026 09:16:35 -0500

um song, reuse pass after review: a passed plan is refused, a kept-word clip is left as it was, swap-clip drops the raw mark, the renderer processes a raw note it measures more than RAW_GUARD off, and among equally-used ums the one longest quiet wins

Co-Authored-By: Claude <noreply@anthropic.com>

Diffstat:
Mumtool/song/render-poly.mjs | 13++++++++++---
Mumtool/song/reuse-pass.mjs | 37++++++++++++++++++++++++++++---------
Mumtool/song/swap-clip.mjs | 4+++-
3 files changed, 41 insertions(+), 13 deletions(-)

diff --git a/umtool/song/render-poly.mjs b/umtool/song/render-poly.mjs @@ -197,7 +197,8 @@ const master = new Float32Array(Math.ceil((Math.max(TOTAL, overlayEnd) + 1.0) * // the actual audio once the mix exists (see below). let END = TOTAL; -let rawNotes = 0; +let rawNotes = 0, rawRefused = 0; +const RAW_GUARD = Number(process.env.RAW_GUARD ?? 0.5); const rawOff = []; for (const v of (SKIP_AUDIO ? [] : voices)) { let n = 0; @@ -256,10 +257,15 @@ for (const v of (SKIP_AUDIO ? [] : voices)) { // below. reuse-pass.mjs sets it, after measuring this same clip against this // same note with the two functions above; what is measured here is printed at // the end, so a plan marked by other means cannot claim more than it plays. - const asSaid = p.raw === true; + // A raw note measured more than RAW_GUARD semitones off is not played untouched: + // something changed the clip or the note after the pass (a swap, a retune), and an + // um a semitone out is worse than a shifted one. It is processed, and counted. + const off0 = head.f0 > 0 ? Math.abs(p.targetMidi - midiOf(head.f0)) : 0; + const asSaid = p.raw === true && off0 <= RAW_GUARD; + if (p.raw === true && !asSaid) rawRefused += 1; if (asSaid) { rawNotes += 1; - if (head.f0 > 0) rawOff.push(Math.abs(p.targetMidi - midiOf(head.f0))); + if (head.f0 > 0) rawOff.push(off0); } // Preferred path: if a straight speed change lands BOTH the pitch and a // length that fits the note, take it -- it is the only transformation here @@ -325,6 +331,7 @@ for (const v of (SKIP_AUDIO ? [] : voices)) { } console.log(` voice ${v.name}: ${n}/${v.plan.length} notes mixed`); } +if (rawRefused) console.log(` ${rawRefused} notes marked raw measured more than ${RAW_GUARD} semitones off and were processed instead`); if (rawNotes) { const o = [...rawOff].sort((x, y) => x - y); const q = (f) => (o.length ? o[Math.floor(f * (o.length - 1))] : 0).toFixed(2); diff --git a/umtool/song/reuse-pass.mjs b/umtool/song/reuse-pass.mjs @@ -23,7 +23,10 @@ // (default 0.85; it cannot be stretched to fit) // MAX_USES=<n> cap on soundings of one um (default: none; the gap already caps it) // REUSE=0 step 1 only: no um repeats -// DRY=1 report, write nothing +// DRY=1 report, write no plan (measurements are still cached) +// PRE=<st> measure a clip against a note only when its whole-window pitch is +// within this of the note (default 1.0; wider finds a few more fits and +// measures for longer) // // The pool is the clips the plan already plays, voice by voice: each has been heard // in this song and has its word guards, and a voice keeps its own sources (one timbre, @@ -51,9 +54,18 @@ const REUSE = process.env.REUSE !== "0", DRY = process.env.DRY === "1"; const SR = 48000; // how far a clip's whole-window pitch may sit from a note before it is not worth // measuring against that note's own length -const PRE = 1.0; +const PRE = num("PRE", 1.0); +// past this an um counts as simply "not recently heard" +const FAR = 30; const plan = JSON.parse(readFileSync(IN, "utf8")); +// A plan this pass has already been over cannot be passed again: the clips its notes +// gave up are gone from it, so a second pass with other settings would keep the repeats +// and could not give the ums back. Start from the plan that had every note's own clip. +if (plan.voices.some((v) => v.plan.some((p) => "raw" in p))) { + console.error(`${IN} has already been through reuse-pass (it has raw notes). Run the pass on the plan it was made from.`); + process.exit(2); +} const CACHE_FILE = process.env.MEASURE_CACHE ?? `${OUT}.measure.json`; let cache = {}; try { cache = JSON.parse(readFileSync(CACHE_FILE, "utf8")); } catch {} @@ -168,8 +180,7 @@ const offBy = (c, fill, p) => { // every sounding of every um, by song time const uses = new Map(); // um -> [slotStart] const addUse = (um, t) => { if (!uses.has(um)) uses.set(um, []); uses.get(um).push(t); }; -const dropUse = (um, t) => { const a = uses.get(um); a.splice(a.indexOf(t), 1); }; -const clear = (um, t) => (uses.get(um) ?? []).every((u) => Math.abs(u - t) >= GAP); +const dropUse = (um, t) => { const a = uses.get(um), i = a.indexOf(t); if (i < 0) throw new Error(`um ${um} has no sounding at ${t}`); a.splice(i, 1); }; const clipOf = new Map(voices.flatMap((x) => x.clips.map((c) => [c.key, c]))); for (const { v } of voices) for (const p of v.plan) if (p.video) addUse(clipOf.get(clipKey(p)).um, p.slotStart); @@ -181,9 +192,10 @@ for (const [vi, { v, fill, clips }] of voices.entries()) { // step 1: its own clip, untouched const rest = []; for (const p of notes) { - delete p.raw; const c = clipOf.get(clipKey(p)); - const d = offBy(c, fill, p); + // A clip kept for its stray word stays as it was: the renderer starts it early or + // chops it from the front, and neither is what was measured here. + const d = p.keepSide ? null : offBy(c, fill, p); if (d !== null) { p.raw = true; p.shift = +d.toFixed(3); own += 1; } else rest.push(p); } // step 2: another um of this voice, if it has been quiet long enough @@ -202,10 +214,17 @@ for (const [vi, { v, fill, clips }] of voices.entries()) { let best = null; for (const { c, d } of fits.get(p)) { // its own um does not count against itself: the note is leaving it - const n = (uses.get(c.um) ?? []).length - (c.um === mine ? 1 : 0); + const others = [...(uses.get(c.um) ?? [])]; + if (c.um === mine) others.splice(others.indexOf(p.slotStart), 1); + const n = others.length; if (n >= MAX_USES) continue; - if (c.um === mine ? !(uses.get(mine).filter((u) => u !== p.slotStart).every((u) => Math.abs(u - p.slotStart) >= GAP)) : !clear(c.um, p.slotStart)) continue; - if (!best || n < best.n || (n === best.n && Math.abs(d) < Math.abs(best.d))) best = { c, d, n }; + // how long this um has been quiet around this note; every candidate is already + // on the pitch, so among equally-used ums the one furthest from its other + // soundings wins, and then the one whose length is nearest the note's + const far = Math.min(FAR, ...others.map((u) => Math.abs(u - p.slotStart))); + if (far < GAP) continue; + const fit = Math.abs(Math.log(cache[c.key].len / noteMaxLen(fill, p, SR))); + if (!best || n < best.n || (n === best.n && (far > best.far || (far === best.far && fit < best.fit)))) best = { c, d, n, far, fit }; } if (!best) continue; dropUse(mine, p.slotStart); diff --git a/umtool/song/swap-clip.mjs b/umtool/song/swap-clip.mjs @@ -274,7 +274,9 @@ const dates = JSON.parse(readFileSync(path.join(DIR, "dates.json"), "utf8")); const date = dates[c.video]; if (!date) console.log(` WARNING: ${c.video} has no entry in dates.json; the note keeps no date`); else if (note.date && date !== note.date) console.log(` date ${note.date} -> ${date} (the slot's place in the chronology moves)`); -const { date: _oldDate, ...rest } = note; +// `raw` goes too: reuse-pass.mjs marked the OLD clip as playing untouched on this note, +// and the new one was chosen within 3 semitones, not on the pitch. +const { date: _oldDate, raw: _oldRaw, ...rest } = note; v.plan[idx] = { ...rest, ...(date ? { date } : {}), video: c.video, srcStart: c.start, srcEnd: c.end, srcDur: +dur.toFixed(3), srcF0: best.f0 ?? c.f0, srcMidi: +midi.toFixed(2), shift: +(note.targetMidi - midi).toFixed(3),