75ca48aOverhaul playback: background-computed, buffered, one clockJeremy Magland 1import type { Params } from "../../core/params.ts";
2import { soundOf } from "../../instruments/sounds.ts";
3import type { Layout } from "../../stream/layout.ts";
5export const SLOTS = 6;
7export function orbitCount(P: Params): number {
8 return Math.max(1, Math.min(20, Math.round(P.orbitCount as number)));
9}
11/**
12 * Orbit n plays instrument slot n (cycling). One stem (synth worker) per distinct instrument, so
13 * the instruments render in parallel; orbits on the same instrument share it (it's polyphonic).
14 */
15export function orbitStems(P: Params): { names: string[]; stemOf: number[] } {
16 const names: string[] = [];
17 const stemOf: number[] = [];
18 for (let i = 0; i < orbitCount(P); i++) {
19 const name = P[`slot${(i % SLOTS) + 1}Instrument`] as string;
20 let s = names.indexOf(name);
21 if (s < 0) s = names.push(name) - 1;
22 stemOf.push(s);
23 }
24 return { names, stemOf };
25}
27export function layout(P: Params): Layout {
28 const { names } = orbitStems(P);
29 const sounds = names.map((n) => soundOf(n, P.modalCustom as string));
30 return {
1d9a68eRemove the hum; reliable stop; deeper render-ahead bufferJeremy Magland 31 stems: sounds.map((sound, i) => ({ kind: "synth" as const, sound, output: i })),
32 outputs: sounds.map((sound) => ({ effects: "shared" as const, sound, level: (Q: Params) => Q.notesLevel as number })),
75ca48aOverhaul playback: background-computed, buffered, one clockJeremy Magland 33 reverbTime: P.reverbTime as number,
34 };
35}
37export function estimateLength(P: Params): number {
38 return (P.duration as number) + 0.5 + (P.finalHold as number) + (P.finalFade as number) + 0.3;
39}