commit 70d4cf09619f79c61c09eeb44b770772dec6de1c
parent 989776f7e1e4485dcdc4d7e210b9a88070960caa
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Tue, 17 Nov 2026 09:38:39 -0500
umtool: a script edited for reading never moves the card (narration.forReading), the next reading of a text, a recorded takes always asked again
- post-item.mjs: shownDraftOf / saysShownDraft / scriptEditOf (null, "reading", "legacy").
- manifest.mjs postNarrationIn: the single-item writer marks a script that differs from the shown draft
(paragraph-aware) as forReading and clears it when it says the draft; undo restores it with the script;
a spoken edit that says what the screens mask or redact is refused at write (post-thread.mjs
spokenSaysHiddenErrors).
- read-follow.mjs followParts (Rule A): with the marker, his post's blocks come from the shown draft, timed one
for one by the read's parts or shared by words over the span they were read in.
- post-thread.mjs partRoles (Rule B): with the marker, a read with no stored roles is his post's.
- post-narration.mjs nextReadingOf; readTuning.mjs tuningArgvOf passes a recorded takes always (cast test updated).
- The reading pin: edited variants (respelled, merged, shortened, unrelated) draw the golden hashes.
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat:
9 files changed, 209 insertions(+), 18 deletions(-)
diff --git a/umtool/lib/report/cast.test.mjs b/umtool/lib/report/cast.test.mjs
@@ -243,7 +243,7 @@ test("rereadPlan: a thread read's own options kept, the changed author's overrid
assert.equal(plan.skipped[0].id, "p-8");
});
-test("rereadPlan: a single take's own tuning and reading are asked again (lane orpheus-tuning); defaults and thread reads add nothing", () => {
+test("rereadPlan: a single take's own tuning and reading are asked again (lane orpheus-tuning) -- its recorded takes always (lane line-rerun: the settings' default may not be 3); thread reads add nothing", () => {
const made = (o) => ({ temperature: 0.55, top_p: 0.85, top_k: 50, min_p: 0, repeat_penalty: 1.2, takes: 3, ...o });
const m = { timeline: [
{ type: "post", id: "p-1", handle: "x", narration: { takes: [{ file: "a.wav", engine: "orpheus", voice: "zac", tuning: made({ temperature: 0.7 }), reading: 2 }], pick: 0 } },
@@ -254,8 +254,8 @@ test("rereadPlan: a single take's own tuning and reading are asked again (lane o
const drift = (id, thread = false) => ({ id, handle: "x", role: "post", reads: "orpheus:zac", want: "orpheus:leah", kind: "tts", thread });
const plan = rereadPlan("p", m, [drift("p-1"), drift("p-2"), drift("p-3"), drift("p-4", true)], ["x"]);
assert.deepEqual(plan.items.map((x) => x.argv.slice(4)), [
- ["--take", "--reading", "2", "--temperature", "0.7"],
- ["--take"],
+ ["--take", "--reading", "2", "--temperature", "0.7", "--chunk-takes", "3"],
+ ["--take", "--chunk-takes", "3"],
["--take", "--speed", "1.2", "--top-k", "40", "--chunk-takes", "5"],
["--take", "--thread"],
]);
diff --git a/umtool/lib/report/manifest.mjs b/umtool/lib/report/manifest.mjs
@@ -67,8 +67,8 @@ import {
variantsProblems, verdictOfInput,
} from "./knobs.mjs";
import { validateNarration } from "umtool-report-to-video/narration";
-import { postReadText, validatePostItem, validatePostItems } from "umtool-report-to-video/post-item";
-import { threadReadErrors } from "umtool-report-to-video/post-thread";
+import { postReadText, saysShownDraft, shownDraftOf, validatePostItem, validatePostItems } from "umtool-report-to-video/post-item";
+import { spokenSaysHiddenErrors, threadReadErrors } from "umtool-report-to-video/post-thread";
import { planContext } from "umtool-report-to-video/post-conversation";
import { followKnobs } from "umtool-report-to-video/read-follow";
import { AVATARS_DIR, avatarEntryOf, handleKey, validatePostAvatars } from "umtool-report-to-video/post-avatars";
@@ -3410,7 +3410,7 @@ export const POST_NARRATION_KNOBS = Object.freeze(["script", "excerpt", "engine"
* what was approved was that take on those words. Refused in the build's
* words (validatePostItem).
*/
-export function postNarrationIn(m, id, patch) {
+export function postNarrationIn(m, id, patch, { forReading = false } = {}) {
const i = entryIndex(m.timeline, id);
const e = m.timeline[i];
if (e?.type !== "post") throw new Error(`${id} is a ${e?.type ?? "?"} entry, not a post item`);
@@ -3426,6 +3426,19 @@ export function postNarrationIn(m, id, patch) {
if (v === null || v === undefined || v === false && (k === "excerpt" || k === "approved" || k === "off")) delete n[k];
else n[k] = typeof v === "number" && k !== "pick" ? round2(v) : typeof v === "string" && k === "script" ? v.trim() : v;
}
+ // THE SCRIPT AS A SPOKEN EDIT (lane line-rerun; ruling 3): saved by the one writer (`forReading`: a single item's
+ // script -- the bench's Save, `posts narrate --script`, a take that carries one), it is marked for reading when it
+ // differs from his words as drafted, so the card's layout follows the shown text; undo restores it with the script.
+ // A spoken edit saying what the item's screens hide is refused here, never kept to be refused at the build.
+ if (forReading && "script" in patch) {
+ const s = typeof n.script === "string" ? n.script.trim() : "";
+ if (s && String(shownDraftOf(e) ?? "").trim() && !saysShownDraft(e, s)) n.forReading = true;
+ else delete n.forReading;
+ if (s && (before?.script ?? "") !== n.script) {
+ const hid = spokenSaysHiddenErrors(e, n.script, "the script");
+ if (hid.length) throw new StructureRefused(hid);
+ }
+ }
if (isObj(patch.addTake)) {
n.takes.push(patch.addTake);
if (patch.keepPick !== true) n.pick = n.takes.length - 1;
@@ -3542,7 +3555,7 @@ export async function updatePostFx(dir, id, op, { token = null } = {}) {
*/
export async function updatePostNarration(dir, id, patch, { token = null } = {}) {
if (!isObj(patch) || !Object.keys(patch).length) throw new Error("a narration patch is an object of knobs");
- return structural(dir, "post-narration", token, (m) => postNarrationIn(m, id, patch));
+ return structural(dir, "post-narration", token, (m) => postNarrationIn(m, id, patch, { forReading: true }));
}
/**
diff --git a/umtool/lib/report/readTuning.mjs b/umtool/lib/report/readTuning.mjs
@@ -3,7 +3,7 @@
// take's own --speed. The ranges and the defaults are the editor's (yt-dlp-transcript-common/lib/ttsTuning.mjs).
//
// Plain ESM, pure.
-import { ORPHEUS_DEFAULT_TAKES, normalizeTtsTuning } from "yt-dlp-transcript-common/lib/ttsTuning.mjs";
+import { normalizeTtsTuning } from "yt-dlp-transcript-common/lib/ttsTuning.mjs";
/** The flags that make a read's tuning, and the tuning field each sets. */
export const TUNING_FLAGS = Object.freeze({
@@ -11,14 +11,15 @@ export const TUNING_FLAGS = Object.freeze({
});
/**
- * The flags that ask a take's tuning and reading again: `--reading N` when it was not the first reading, and a flag
- * for each tuning value that is not Orpheus's default (the take records every value; `takes` against the settings'
- * default). `[]` for a take made with the defaults, or one that records neither (another engine, an older take).
+ * The flags that ask a take's tuning and reading again: `--reading N` when it was not the first reading, a flag for
+ * each sampler value that is not Orpheus's default, and the takes it recorded ALWAYS (`--chunk-takes`: the settings'
+ * default may differ from the code's 3, and the editor drops a value equal to its settings' own -- the same key).
+ * `[]` for a take that records neither (another engine, an older take).
*/
export function tuningArgvOf(take) {
const a = [];
if (Number.isInteger(take?.reading) && take.reading > 0) a.push("--reading", String(take.reading));
- const off = normalizeTtsTuning(take?.tuning, { takes: ORPHEUS_DEFAULT_TAKES });
+ const off = normalizeTtsTuning(take?.tuning);
for (const [flag, field] of Object.entries(TUNING_FLAGS)) if (off[field] !== undefined) a.push(flag, String(off[field]));
return a;
}
diff --git a/umtool/lib/report/readTuning.test.mjs b/umtool/lib/report/readTuning.test.mjs
@@ -0,0 +1,28 @@
+// readTuning.mjs: the flags that ask a take's tuning and reading again (lane line-rerun: its recorded takes always).
+import assert from "node:assert/strict";
+import { test } from "node:test";
+import { tuningArgvOf } from "./readTuning.mjs";
+import { nextReadingOf } from "umtool-report-to-video/post-narration";
+
+const made = (o) => ({ temperature: 0.55, top_p: 0.85, top_k: 50, min_p: 0, repeat_penalty: 1.2, takes: 3, ...o });
+
+test("tuningArgvOf: the takes a take recorded are asked again even when they are the code's 3 (the settings' default may differ); a sampler default is not", () => {
+ assert.deepEqual(tuningArgvOf({ tuning: made({}), reading: 0 }), ["--chunk-takes", "3"]);
+ assert.deepEqual(tuningArgvOf({ tuning: made({ takes: 4, top_p: 0.9 }), reading: 2 }), ["--reading", "2", "--top-p", "0.9", "--chunk-takes", "4"]);
+ assert.deepEqual(tuningArgvOf({ engine: "kokoro" }), []);
+});
+
+test("nextReadingOf: one past the highest reading of THESE words among the synthesized takes; new words read first (0)", () => {
+ const takes = [
+ { file: "a", script: "One line.", reading: 0 },
+ { file: "b", script: "One line.", reading: 2 },
+ { file: "c", script: "One line." },
+ { file: "d", script: "Other words.", reading: 7 },
+ { file: "e", engine: "recorded", script: "One line." },
+ { file: "f", script: "One line.", reading: 9, read: { kind: "thread" } },
+ ];
+ assert.equal(nextReadingOf(takes, "One line."), 3);
+ assert.equal(nextReadingOf(takes, "Other words."), 8);
+ assert.equal(nextReadingOf(takes, "Never read."), 0);
+ assert.equal(nextReadingOf([], "x"), 0);
+});
diff --git a/umtool/report-to-video/post-item.mjs b/umtool/report-to-video/post-item.mjs
@@ -30,7 +30,7 @@
// and the card's HTML.
import {
- isNarrated, narrationSchedule, postNarrationFiles, postNarrationKnobs, validatePostNarration,
+ draftScript, isNarrated, narrationSchedule, postNarrationFiles, postNarrationKnobs, validatePostNarration,
} from "./post-narration.mjs";
import { BAR_CSS, barsHtml, hasMarks, projectRedactOf, redactEntry, redactSceneRef, redactionOn, validatePostsRender } from "./post-redact.mjs";
import { blurErrors, blurOn, censorEntry } from "./post-censor.mjs";
@@ -170,6 +170,31 @@ export function postReadText(entry) {
return spans && excerptRanges(cardText(entry), spans) ? spans.map((x) => x.trim()).join(POST_EXCERPT_JOIN) : cardText(entry);
}
+/** What a script says when nobody edited it: what is read of the post, drafted to be spoken (draftScript). */
+export const shownDraftOf = (entry) => draftScript(postReadText(entry)).script;
+
+/** A script's words as compared: each paragraph's spacing collapsed, the paragraphs kept (a merge is an edit). */
+const spacing = (t) => str(t).split(/\n\s*\n/).map((x) => x.replace(/\s+/g, " ").trim()).filter(Boolean).join("\n\n");
+
+/** Whether `script` says his words as drafted (shownDraftOf), paragraph for paragraph: not an edit for reading. */
+export const saysShownDraft = (entry, script) => spacing(script) === spacing(shownDraftOf(entry));
+
+/**
+ * Whether a script is the post's words EDITED FOR READING (lane line-rerun; operator ruling 3, 15 Nov 2026: an edit
+ * changes only what is spoken) -- `script` the one to judge (default: the item's own):
+ * null no script, no words on the card, or the script says the shown text as drafted
+ * "reading" edited, and `narration.forReading` set by the writer: the card's layout follows the SHOWN text
+ * (read-follow.mjs followParts, post-thread.mjs partRoles), never the edited words
+ * "legacy" edited before reads were kept apart from the card (no marker): its layout follows the script, as it
+ * always did -- saving the script again moves it to the new rule
+ */
+export function scriptEditOf(entry, script = entry?.narration?.script) {
+ const own = spacing(script);
+ const shown = spacing(shownDraftOf(entry));
+ if (!own || !shown || own === shown) return null;
+ return entry?.narration?.forReading === true ? "reading" : "legacy";
+}
+
/** The card's word indices (cardTokens') that the excerpt does NOT read (drawn dimmed), or null with no excerpt. */
export function excerptCutWords(entry) {
const spans = excerptSpansOf(entry);
diff --git a/umtool/report-to-video/post-narration.mjs b/umtool/report-to-video/post-narration.mjs
@@ -192,7 +192,9 @@ const MIX_KEYS = ["lead", "tail", "ramp", "linger", "clip", "wet", "lowpassHz",
// `thread`: the cut's thread reads (post-thread.mjs) -- what each context post is on screen, the shrink and dim.
const RENDER_KEYS = new Set([...MIX_KEYS.filter((k) => k !== "attach"), "engine", "voice", "follow", "thread"]);
// `character`: the character THIS item's own read is made with (cast.mjs: the project's own, else the cast's) -- absent: by its author's handle.
-const ITEM_KEYS = new Set([...MIX_KEYS, "script", "excerpt", "engine", "voice", "speed", "character", "takes", "pick", "approved", "off", "window"]);
+// `forReading` (lane line-rerun): the script is his words EDITED FOR READING -- the card follows the shown text
+// (post-item.mjs scriptEditOf). Set and cleared by the one writer that saves the script, never by hand.
+const ITEM_KEYS = new Set([...MIX_KEYS, "script", "excerpt", "engine", "voice", "speed", "character", "takes", "pick", "approved", "off", "window", "forReading"]);
// `said`: what a synthesized read SAID when an anonymous handle made it differ from its script (post-anon.mjs; the
// lint reads it); `speedAsked`: where its speed came from -- true (the command's --speed: kept as asked), "item" (the
// item's own), "preset" (its character's: drift when that changes). Absent: unknown -- never speed drift.
@@ -242,6 +244,24 @@ export function pickedTake(entry) {
return isObj(t) && typeof t.file === "string" && fin(t.seconds) && t.seconds > 0 ? { ...t, index: i } : null;
}
+/** Whitespace collapsed: two texts that differ only in their spacing are the same text to a read. */
+const sameText = (t) => String(t ?? "").replace(/\s+/g, " ").trim();
+
+/**
+ * THE NEXT READING of `text` (lane line-rerun, "Read again"): one past the highest `reading` among the takes that
+ * SYNTHESIZED those words (a missing reading is 0, the first), or 0 when none did -- the first reading of new words.
+ * Pure: the bench, its route and `--reading next` share it.
+ */
+export function nextReadingOf(takes, text) {
+ const want = sameText(text);
+ let hi = -1;
+ for (const t of Array.isArray(takes) ? takes : []) {
+ if (!isObj(t) || takeSourceOf(t).kind !== "tts" || t.read?.kind === "thread" || sameText(t.script) !== want) continue;
+ hi = Math.max(hi, Number.isInteger(t.reading) && t.reading >= 0 ? t.reading : 0);
+ }
+ return hi + 1;
+}
+
/** The read's speed for a post (its `rate`, else the cut's, else 1), held to its limits. */
export function narrationRateOf(entry, render) {
const r = Number(postNarrationKnobs(entry, render).rate);
@@ -615,6 +635,7 @@ export function validatePostNarration(e) {
for (const k of Object.keys(n)) if (!ITEM_KEYS.has(k)) errors.push(`${w}.${k} is not a narration key`);
if (n.script !== undefined) errors.push(...scriptErrors(n.script, `${w}.script`));
for (const k of ["excerpt", "approved", "off"]) if (n[k] !== undefined && typeof n[k] !== "boolean") errors.push(`${w}.${k} must be true or false`);
+ if (n.forReading !== undefined && n.forReading !== true) errors.push(`${w}.forReading must be true (or absent)`);
if (n.speed !== undefined && !numIn(n.speed, POST_NARRATION_LIMITS.speed)) errors.push(`${w}.speed must be ${POST_NARRATION_LIMITS.speed.join("–")}`);
if (n.character !== undefined && !(typeof n.character === "string" && /^[a-z0-9][a-z0-9_-]{0,47}$/.test(n.character))) errors.push(`${w}.character must be a character's id (umtool posts character)`);
if (n.window !== undefined) {
diff --git a/umtool/report-to-video/post-reading-pin.test.mjs b/umtool/report-to-video/post-reading-pin.test.mjs
@@ -117,3 +117,56 @@ test("THE READING PIN: an item whose read says its shown text as drafted draws a
}
assert.deepEqual(got, PINNED);
});
+
+// ---------------------------------------------------------------------------
+// EDITED FOR READING (lane line-rerun): the read's words edited -- an acronym spelled out, a tag, paragraphs merged,
+// a sentence left out, words that match nothing on the card -- and a new take of them picked. The card draws exactly
+// what it drew before the edit: the same hashes as the pin above.
+// ---------------------------------------------------------------------------
+
+const EDITS = {
+ respelled: "The council met on Tuesday about the new bridge, the B R I D G E.\n\nNobody from the ministry <sigh> came to explain the delay.",
+ merged: "The council met on Tuesday about the new bridge. Nobody from the ministry came to explain the delay.",
+ shortened: "The council met on Tuesday about the new bridge.",
+ unrelated: "Completely different words that the card never shows.\n\nAnd a second paragraph of them.\n\nAnd a third.",
+};
+
+/** A single item whose script is `script`, saved for reading, and a take of it picked. */
+function editedSingle(script) {
+ const e = singleItem();
+ return { ...e, narration: { ...e.narration, script, forReading: true, pick: 1, takes: [...e.narration.takes, { file: "narration/posts/7003/take-2.orpheus-zac.wav", engine: "orpheus", voice: "zac", seconds: 5.1, script, reading: 1 }] } };
+}
+
+/** A thread item whose post piece reads `script` (its paragraphs its parts), saved for reading, picked. */
+function editedThread(script) {
+ const e = threadItem();
+ const t = e.narration.takes[0];
+ const own = draftScript(script).script.split("\n\n");
+ const before = t.parts.filter((p) => p.role !== "post");
+ const at = t.parts.findIndex((p) => p.role === "post");
+ let start = t.parts[at].start;
+ const post = own.map((text, i) => {
+ const sec = Math.round((text.split(/\s+/).length / 3) * 100) / 100;
+ const p = { n: 0, para: 200 + i, text, voice: "zac", role: "post", start: Math.round(start * 1000) / 1000, seconds: sec };
+ start += sec + 0.6;
+ return p;
+ });
+ const parts = [...before.slice(0, at), ...post, ...before.slice(at)].map((p, i) => ({ ...p, n: i + 1 }));
+ const take = { ...t, file: "narration/posts/7003/take-2.orpheus-thread.wav", parts, script: parts.map((p) => p.text).join("\n\n"), reading: 1 };
+ return { ...e, narration: { ...e.narration, script, forReading: true, pick: 1, takes: [t, take] } };
+}
+
+for (const [name, script] of Object.entries(EDITS)) {
+ test(`EDITED FOR READING (${name}): a single read's card draws as before the edit`, () => {
+ assert.deepEqual(drawn(editedSingle(script)), PINNED.single);
+ });
+ test(`EDITED FOR READING (${name}): a thread read's card draws as before the edit -- the excerpt tile hides what it hid, the tiles keep their modes`, () => {
+ assert.deepEqual(drawn(editedThread(script)), PINNED.thread);
+ });
+}
+
+test("EDITED BEFORE (no marker): the card follows the script, as it always did", () => {
+ const e = editedSingle(EDITS.unrelated);
+ delete e.narration.forReading;
+ assert.notDeepEqual(drawn(e), PINNED.single);
+});
diff --git a/umtool/report-to-video/post-thread.mjs b/umtool/report-to-video/post-thread.mjs
@@ -48,7 +48,7 @@
// PURE and dependency-free (but its siblings): the plan, the build, Play, the
// bench, the writers and the lint all read the same rules from here.
-import { POST_PARENTS_MAX, cardText, contextText, linksOf, parentsOf, refMediaOf, refShown } from "./post-item.mjs";
+import { POST_PARENTS_MAX, cardText, contextText, linksOf, parentsOf, refMediaOf, refShown, scriptEditOf } from "./post-item.mjs";
import { draftScript, isNarrated, isOnlyUrls, joinSplitLinks, pickedTake, postNarrationKnobs, scriptParts, spokenUrls } from "./post-narration.mjs";
import { normWord, scriptWordsOf } from "./word-zoom.mjs";
import { followKnobs } from "./read-follow.mjs";
@@ -223,6 +223,9 @@ export function partRoles(entry, take = undefined) {
parts = scriptParts(script).map((p) => ({ text: p.text, para: p.para * 100 }));
}
if (!parts.length) return [];
+ // HIS WORDS EDITED FOR READING (post-item.mjs scriptEditOf; ruling 3): a read of them that stores no roles is his
+ // post's, part by part -- never inferred from the edited words as a parent, the quoted post or a picture.
+ if (scriptEditOf(entry) === "reading" && !parts.some((p) => typeof p?.role === "string")) return parts.map(() => ({ role: "post", source: "inferred" }));
const texts = readTexts(entry);
const orderOf = roleOrderOf(entry);
const images = (Array.isArray(entry?.media) ? entry.media : []).map((m, i) => ({ m, i })).filter((x) => x.m?.kind === "image");
@@ -659,6 +662,17 @@ export function readSaysHiddenErrors(e) {
return out;
}
+/**
+ * WHAT A SPOKEN EDIT WOULD SAY THAT ITS SCREENS HIDE, pure (lane line-rerun): readSaysHiddenErrors over `text` as the
+ * read's words -- the script saved for reading, a screen line's "said as" -- so a spoken edit the build would refuse is
+ * refused when it is WRITTEN, and never reaches a take (whose refusal would drop the read from the preview).
+ */
+export function spokenSaysHiddenErrors(e, text, where = "the read") {
+ if (!str(text).trim() || !screensOfEntry(e).length) return [];
+ const probe = { ...e, narration: { pick: 0, takes: [{ file: "narration/probe.wav", seconds: 1, script: str(text) }] } };
+ return readSaysHiddenErrors(probe).map((m) => m.replace("its picked take", where).replace(/: make the read again \(umtool posts screen <p> [^)]*\)$/, ": say it another way"));
+}
+
// ---------------------------------------------------------------------------
// WHAT A PREVIEW PLAYS (Play, Present, the post bench's player, the card page): never a read the build refuses.
// ---------------------------------------------------------------------------
diff --git a/umtool/report-to-video/read-follow.mjs b/umtool/report-to-video/read-follow.mjs
@@ -43,7 +43,7 @@
// sets it on the page -- in the build per frame before a screenshot
// (post-render.mjs), in Play per tick (PostItemPlayer).
-import { cardText, contextReadSeconds, contextText, linksOf, parentsOf, readSeconds } from "./post-item.mjs";
+import { cardText, contextReadSeconds, contextText, linksOf, parentsOf, readSeconds, scriptEditOf, shownDraftOf } from "./post-item.mjs";
import { isNarrated, narrationSchedule, partStartOnItem, pickedTake, scriptParts } from "./post-narration.mjs";
import { cardTokens, easeOf, normWord, scriptWordsOf } from "./word-zoom.mjs";
import { partRoles, threadGeoAt, threadKnobs, threadLayout, threadSchedule, threadStateAt } from "./post-thread.mjs";
@@ -203,11 +203,17 @@ function fitMatch(a, b, lo, hi) {
export function followParts(entry) {
if (isNarrated(entry)) {
const t = pickedTake(entry);
+ // HIS WORDS EDITED FOR READING (post-item.mjs scriptEditOf; ruling 3): the card follows the SHOWN text -- his
+ // post's blocks are made from his words as drafted, never from the edited ones, so no edit to what is said moves,
+ // dims for good or hides a drawn word. The edited read only times them.
+ const forReading = scriptEditOf(entry) === "reading";
if (Array.isArray(t?.parts) && t.parts.length) {
// Each part's ROLE (post-thread.mjs): the text it reads -- a context post, his words, an attachment's.
const roles = partRoles(entry);
- return { source: "take", parts: t.parts.map((p, k) => ({ text: str(p.text), start: fin(p.start) ? p.start : null, ...(roles[k]?.role ? { scope: roles[k].role } : {}) })) };
+ const parts = t.parts.map((p, k) => ({ text: str(p.text), start: fin(p.start) ? p.start : null, ...(roles[k]?.role ? { scope: roles[k].role } : {}) }));
+ return { source: "take", parts: forReading ? shownPostParts(entry, parts, t.parts) : parts };
}
+ if (forReading) return { source: "script", parts: scriptParts(shownDraftOf(entry)).map((p) => ({ text: p.text, scope: "post" })) };
const script = str(t?.script).trim() ? t.script : str(entry?.narration?.script);
const roles = partRoles(entry);
return { source: "script", parts: scriptParts(script).map((p, k) => ({ text: p.text, ...(roles[k]?.role ? { scope: roles[k].role } : {}) })) };
@@ -218,6 +224,35 @@ export function followParts(entry) {
}
/**
+ * His post's parts of a take (scope "post", one run of them) REPLACED by his words as drafted (the shown text's
+ * paragraphs), each `shown: true` and timed from the read: one for one when the read kept as many parts, else shared
+ * by words over the span his parts were read in -- every block read in turn, none left unread by an edit.
+ */
+function shownPostParts(entry, parts, takeParts) {
+ const at = parts.map((p, i) => (p.scope === "post" ? i : -1)).filter((i) => i >= 0);
+ if (!at.length || at.some((i, j) => j && i !== at[j - 1] + 1)) return parts;
+ const shown = scriptParts(shownDraftOf(entry)).map((q) => ({ text: q.text, scope: "post", shown: true }));
+ if (!shown.length) return parts;
+ const own = at.map((i) => parts[i]);
+ let timed;
+ if (shown.length === own.length) timed = shown.map((q, j) => ({ ...q, start: own[j].start }));
+ else {
+ const last = takeParts[at[at.length - 1]];
+ const t0 = own[0].start;
+ const t1 = fin(t0) && fin(last?.start) && fin(last?.seconds) ? last.start + last.seconds : null;
+ const total = shown.reduce((n, q) => n + Math.max(1, wordsIn(q.text)), 0);
+ let w = 0;
+ timed = shown.map((q) => {
+ const start = fin(t0) && fin(t1) ? Math.round((t0 + ((t1 - t0) * w) / total) * 1000) / 1000 : null;
+ w += Math.max(1, wordsIn(q.text));
+ return { ...q, start };
+ });
+ }
+ // The parts after his keep the take's part they are (`at`): the schedule times them by it.
+ return [...parts.slice(0, at[0]), ...timed, ...parts.slice(at[at.length - 1] + 1).map((p, j) => ({ ...p, at: at[at.length - 1] + 1 + j }))];
+}
+
+/**
* THE BLOCK MAP, pure, from the entry alone: `{ source, blocks: [{ k, scope,
* from, to, part }], parts }` -- each block a run of one card text's words
* (card word indices, inclusive), `part` the index of the part that reads it
@@ -362,7 +397,8 @@ export function followSchedule(entry, render = undefined, { hold = null, narrati
readEnd = r3(sch.at + sch.seconds);
const take = pickedTake(entry);
const timed = map.source === "take" && parts.every((p) => fin(p.start));
- if (timed) take.parts.forEach((p, i) => (starts[i] = partStartOnItem(sch, p)));
+ // A part of his words as drafted (shownPostParts) is timed by its own start; every other by the take's part.
+ if (timed) parts.forEach((p, i) => (starts[i] = partStartOnItem(sch, p.shown ? p : take.parts[p.at ?? i])));
else {
// No parts: the read's seconds shared by words.
const total = parts.reduce((n, p) => n + wordsIn(p.text), 0) || 1;