import type { Params } from "../../core/params.ts"; import { soundOf } from "../../instruments/sounds.ts"; import type { Layout } from "../../stream/layout.ts"; export const SLOTS = 6; export function orbitCount(P: Params): number { return Math.max(1, Math.min(20, Math.round(P.orbitCount as number))); } /** * Orbit n plays instrument slot n (cycling). One stem (synth worker) per distinct instrument, so * the instruments render in parallel; orbits on the same instrument share it (it's polyphonic). */ export function orbitStems(P: Params): { names: string[]; stemOf: number[] } { const names: string[] = []; const stemOf: number[] = []; for (let i = 0; i < orbitCount(P); i++) { const name = P[`slot${(i % SLOTS) + 1}Instrument`] as string; let s = names.indexOf(name); if (s < 0) s = names.push(name) - 1; stemOf.push(s); } return { names, stemOf }; } export function layout(P: Params): Layout { const { names } = orbitStems(P); const sounds = names.map((n) => soundOf(n, P.modalCustom as string)); return { stems: sounds.map((sound, i) => ({ kind: "synth" as const, sound, output: i })), outputs: sounds.map((sound) => ({ effects: "shared" as const, sound, level: (Q: Params) => Q.notesLevel as number })), reverbTime: P.reverbTime as number, }; } export function estimateLength(P: Params): number { return (P.duration as number) + 0.5 + (P.finalHold as number) + (P.finalFade as number) + 0.3; }