/ music / double-pendulum
Sign in
music / double-pendulum
double-pendulum / src / compositions / c05-ensemble / layout.ts
32 lines · 1.2 KBBlameHistoryRaw
1import type { Params } from "../../core/params.ts";
2import type { Layout } from "../../stream/layout.ts";
4/** One stem: the six pendulums' own sound, rendered by the score. */
5export function layout(): Layout {
6 return {
7 stems: [{ kind: "score", output: 0 }],
8 outputs: [{ effects: "none", level: (Q) => Q.level as number }],
9 };
12export const START_DELAY = 0.4; // s before the first step
14/** "36 25 1!4": one step per word, the pendulums pushed together; ! accents the digit before it. */
15export function parseScore(text: string, add: number, accent: number): { i: number; add: number }[][] {
16 return text
17 .trim()
18 .split(/\s+/)
19 .filter(Boolean)
20 .map((w) => {
21 const step: { i: number; add: number }[] = [];
22 for (let c = 0; c < w.length; c++) {
23 if (!/[1-6]/.test(w[c])) continue;
24 step.push({ i: Number(w[c]) - 1, add: add * (w[c + 1] === "!" ? accent : 1) });
25 }
26 return step;
27 });
30export const stepSec = (P: Params) => ((P.stepBeats as number) * 60) / Math.max(1, P.tempo as number);
31export const scoreEnd = (P: Params) => START_DELAY + parseScore(P.score as string, 0, 1).length * stepSec(P);
32export const estimateLength = (P: Params) => scoreEnd(P) + (P.tail as number);
↑↓ move↵openescclose