import type { Params } from "../../core/params.ts"; import type { Layout } from "../../stream/layout.ts"; /** One stem: the six pendulums' own sound, rendered by the score. */ export function layout(): Layout { return { stems: [{ kind: "score", output: 0 }], outputs: [{ effects: "none", level: (Q) => Q.level as number }], }; } export const START_DELAY = 0.4; // s before the first step /** "36 25 1!4": one step per word, the pendulums pushed together; ! accents the digit before it. */ export function parseScore(text: string, add: number, accent: number): { i: number; add: number }[][] { return text .trim() .split(/\s+/) .filter(Boolean) .map((w) => { const step: { i: number; add: number }[] = []; for (let c = 0; c < w.length; c++) { if (!/[1-6]/.test(w[c])) continue; step.push({ i: Number(w[c]) - 1, add: add * (w[c + 1] === "!" ? accent : 1) }); } return step; }); } export const stepSec = (P: Params) => ((P.stepBeats as number) * 60) / Math.max(1, P.tempo as number); export const scoreEnd = (P: Params) => START_DELAY + parseScore(P.score as string, 0, 1).length * stepSec(P); export const estimateLength = (P: Params) => scoreEnd(P) + (P.tail as number);