// THE LAYERS ONE READ ASKS, read from a project's folder (cast.mjs, post-say.mjs voiceSourceOf; knobs.md, "A // character is a preset"): the project's own characters (`narration/characters.json`) over its voice map // (`narration/voices.json`), the CAST it reads (castStore.mjs castForProject), and the character a post item names // for itself (`narration.character`). Every reader -- a single post's take (readVoice.mjs), a thread read // (postThreadRead.mjs), a recording made a read (postNarrationCli.mjs importRecording), the bench's routes, `umtool // cast project` -- loads them here, so they ask the same files. // // A broken characters.json or cast.json reads as none (its `error` kept: `umtool cast project` says it); a broken // voice map reads as none too unless `strictMap` (a thread read refuses one, as before). // // Plain ESM. import { castPresetMap, characterForRead, itemCharacterOf, itemPresetOf, projectPresetMap, recordedPresetOf } from "umtool-report-to-video/cast"; import { castForProject, readProjectCharacters } from "./castStore.mjs"; /** * The trim a recording of post item `e` is kept with (postRecord.mjs keepRecording's `trim`): its character's recorded * preset's (cast.mjs characterForRead, recordedPresetOf) -- `{ on, padMs }` -- or null: no character, the recorder's own. */ export async function recordedTrimFor(dir, e) { const who = (await readLayers(dir).catch(() => null))?.characterForRead(e) ?? null; return who?.character ? recordedPresetOf(who.character).trim : null; } /** * @param {string} dir the project's folder * @param {{ reportsRoot?: string, strictMap?: boolean }} [o] * @returns {Promise<{ castRead: any, projectRead: any, voiceMap: Record, cast: any, project: any, * map: Record, castMap: Record, itemOf: (e: any) => any, itemCharacterOf: (e: any) => any, * characterForRead: (e: any, as?: string | null) => any }>} */ export async function readLayers(dir, { reportsRoot = undefined, strictMap = false } = {}) { const { readVoiceMap } = await import("./postSay.mjs"); const castRead = await castForProject(dir, ...(reportsRoot ? [reportsRoot] : [])); const projectRead = await readProjectCharacters(dir); const voiceMap = strictMap ? await readVoiceMap(dir) : await readVoiceMap(dir).catch(() => ({})); const layers = { project: projectRead.doc, cast: castRead.cast }; return { castRead, projectRead, voiceMap, ...layers, /** voiceSourceOf's `map`: the project's characters over its voice map. */ map: projectPresetMap(projectRead.doc, voiceMap), /** voiceSourceOf's `cast`. */ castMap: castPresetMap(castRead.cast), /** voiceSourceOf's `item` for post item `e`. */ itemOf: (e) => itemPresetOf(e, layers), itemCharacterOf: (e) => itemCharacterOf(e, layers), /** The character a recording of `e` is made into (cast.mjs characterForRead). */ characterForRead: (e, as = null) => characterForRead(e, { ...layers, as }), }; }