// THE DIAL'S CLAIM GHOSTS (`render.chrome.deck.measure.ghosts`, 6 Nov 2026): // every weight the cut has shown him claim leaves a faint residual tick on the // dial's rim at its value, so after a few minutes the face carries the history // of everything he has said; a value claimed again changes that tick's colour // along a short ramp (1x faint neutral, 2x warm, 3x+ hot) and thickens it, and // the tick pulses once as the repeat lands. // // Not the dial's own `deck.dial.ghosts` (his REMEMBERED weights as long grey // ticks with their as-of words, the latest a long ghost needle): those stay as // they are, drawn over these. // // A claim is a measure event the cut shows (`measure.events`, t finite) of his // own (no `speaker`) that puts a number on his weight: a STATED weight (each // one the needle goes to) or a REMEMBERED one. Two claims are the same tick // when their values are within `tolerance` lb of the tick's first value; an // "≈" value counts as its rounded number; a ">300" or "<300" is a claim at // 300 (its bound is where it stands on the face). // // PURE and SEEK-SAFE: ghostTicks is a function of the schedule's measure alone, // in cut order -- no state from playback -- so Play, the live preview and the // render draw the same tick at the same second from either side of it. // // A LEAF: measure-slice.mjs (the setting's validator) and chrome-instruments.mjs // (the dial's page) import it; it imports nothing. /** The setting's knobs and their defaults (`ghosts: true`). */ export const GHOST_DEFAULTS = Object.freeze({ // The 1x tick's opacity; each step of the ramp adds GHOST_OPACITY_STEP, to at most 0.95. opacity: 0.5, // Pounds: a claim within this of a tick's value is a repeat of it. tolerance: 0.5, // The ramp's colours, 1x first, the last for every count from there up (2 to 4 #hex), or // null: the palette's -- its muted, its amber, and amber half way to the needle's red. ramp: null, // The tick pulses once as a repeat lands. pulse: true, }); export const GHOST_OPACITY = Object.freeze([0.15, 0.9]); export const GHOST_OPACITY_STEP = 0.2; export const GHOST_TOLERANCE = Object.freeze([0, 5]); export const GHOST_RAMP = Object.freeze([2, 4]); const isObj = (v) => v !== null && typeof v === "object" && !Array.isArray(v); const HEX_RE = /^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/; const inRange = (v, [lo, hi]) => typeof v === "number" && Number.isFinite(v) && v >= lo && v <= hi; /** `render.chrome.deck.measure.ghosts`, as sentences. */ export function validateGhosts(v, where = "render.chrome.deck.measure.ghosts") { if (v === undefined || typeof v === "boolean") return []; if (!isObj(v)) return [`${where} must be true, false or { ${Object.keys(GHOST_DEFAULTS).join(", ")} }`]; const errors = []; for (const k of Object.keys(v)) { if (!Object.hasOwn(GHOST_DEFAULTS, k)) errors.push(`${where}.${k} is not a setting of it (${Object.keys(GHOST_DEFAULTS).join(", ")})`); } if (v.opacity !== undefined && !inRange(v.opacity, GHOST_OPACITY)) errors.push(`${where}.opacity must be a number from ${GHOST_OPACITY[0]} to ${GHOST_OPACITY[1]}`); if (v.tolerance !== undefined && !inRange(v.tolerance, GHOST_TOLERANCE)) errors.push(`${where}.tolerance must be pounds from ${GHOST_TOLERANCE[0]} to ${GHOST_TOLERANCE[1]}`); if (v.ramp !== undefined && v.ramp !== null) { if (!Array.isArray(v.ramp) || v.ramp.length < GHOST_RAMP[0] || v.ramp.length > GHOST_RAMP[1] || v.ramp.some((c) => typeof c !== "string" || !HEX_RE.test(c))) { errors.push(`${where}.ramp must be ${GHOST_RAMP[0]} to ${GHOST_RAMP[1]} #hex colours (1x first), or null for the palette's`); } } if (v.pulse !== undefined && typeof v.pulse !== "boolean") errors.push(`${where}.pulse must be true or false`); return errors; } /** The ghosts' settings, defaults filled, or null when off (absent, `false`). */ export function resolveGhosts(render) { const v = render?.chrome?.deck?.measure?.ghosts; if (v === true) return { ...GHOST_DEFAULTS }; if (!isObj(v)) return null; return { ...GHOST_DEFAULTS, ...v }; } /** The ramp's colours: the setting's, else from the palette roles (`muted`, `amber`, `needle`, and a `mix`). */ export function ghostRamp(cfg, { muted, amber, needle }, mix) { if (Array.isArray(cfg?.ramp) && cfg.ramp.length >= GHOST_RAMP[0]) return [...cfg.ramp]; return [muted, amber, mix(amber, needle, 0.5)]; } /** Step `k` (0 = 1x) of a ramp of `n`: its opacity from the 1x opacity. */ export const ghostOpacity = (base, k) => Math.min(0.95, Math.round((base + k * GHOST_OPACITY_STEP) * 100) / 100); /** The claim's value as its tick counts it: an "≈" value is its rounded number. */ export const claimValue = (e) => (e?.qualifier === "≈" ? Math.round(Number(e.value)) : Number(e.value)); /** Is this event a weight claim of his the cut shows: stated or remembered, a number, a time, no other speaker. */ export const isClaim = (e) => !!e && (e.kind === "stated" || e.kind === "remembered") && Number.isFinite(Number(e.value)) && e.value !== null && Number.isFinite(e.t) && !(typeof e.speaker === "string" && e.speaker.trim()); /** * The ghost ticks of a measure: one per value claimed, in the order first * claimed -- `{ value, claims: [{ t, row, kind, n }] }`, `value` the first * claim's (as its tick counts it), each claim with its count `n` (1 the * first). In cut order: a claim joins the first tick whose value is within * `tolerance` of it, else starts a tick. * * @param {{ events?: object[] }} measure the schedule's measure slice * @param {{ tolerance?: number }} [cfg] */ export function ghostTicks(measure, cfg = {}) { const tol = Number.isFinite(cfg.tolerance) ? cfg.tolerance : GHOST_DEFAULTS.tolerance; const claims = (Array.isArray(measure?.events) ? measure.events : []) .map((e, i) => ({ e, i })) .filter(({ e }) => isClaim(e)) .sort((a, b) => a.e.t - b.e.t || a.i - b.i); const ticks = []; for (const { e } of claims) { const v = claimValue(e); let tick = ticks.find((x) => Math.abs(x.value - v) <= tol + 1e-9); if (!tick) ticks.push((tick = { value: v, claims: [] })); tick.claims.push({ t: e.t, row: e.row ?? null, kind: e.kind, n: tick.claims.length + 1 }); } return ticks; } /** * The ticks as they stand at cut second `t`: each tick claimed by then with * its count so far (`count`), the ramp step it is on (`step`, 0 = 1x, held at * the ramp's last), and whether a repeat landed within `pulse` s before `t`. * A pure function of the ticks and `t` -- what a frame at `t` shows. */ export function ghostsAt(ticks, t, { steps = 3, pulse = 0 } = {}) { const out = []; for (const x of ticks) { const by = x.claims.filter((c) => c.t <= t + 1e-9); if (!by.length) continue; const last = by[by.length - 1]; out.push({ value: x.value, count: by.length, step: Math.min(steps - 1, by.length - 1), pulsing: pulse > 0 && last.n > 1 && t - last.t < pulse }); } return out; }