import type { Instrument } from './types.ts'; import { builtinInstruments } from './builtins.ts'; // The instrument registry. Custom instruments (a GPU physical model, a // sampler, anything implementing Instrument) are added with // registerInstrument, typically at startup; tracks refer to instruments by // id, so an unknown id falls back to the first builtin rather than // failing. const instruments = new Map(); for (const ins of builtinInstruments) instruments.set(ins.id, ins); export function registerInstrument(ins: Instrument): void { instruments.set(ins.id, ins); } export function unregisterInstrument(id: string): void { instruments.delete(id); } export function getInstrument(id: string): Instrument { return instruments.get(id) ?? builtinInstruments[0]; } export function listInstruments(): Instrument[] { return [...instruments.values()]; }