const echoPlugin = id: "echo-delay", name: "Echo Tunnel", category: "audio", exclusiveGroup: "delay", apply: (ctx) => // apply echo effect to ctx.audioBuffer ctx.userParams.delayTime = ctx.userParams.delayTime , ui: knob: ["delayTime (0–1)"] ; Part 3: Selection Manager Logic The core engine that enables/disables plugins and resolves conflicts. 3.1. Basic Manager class PluginSelectionManager constructor() this.activePlugins = new Map(); // id -> plugin instance this.groups = new Map(); // exclusiveGroup -> active id enable(plugin) // 1. check exclusive group if (plugin.exclusiveGroup) const existing = this.groups.get(plugin.exclusiveGroup); if (existing) this.disable(existing); this.groups.set(plugin.exclusiveGroup, plugin.id);
getPipeline() return Array.from(this.activePlugins.values()); plugin selection toys
interface ToyPlugin id: string; // unique, e.g., "echo-delay" name: string; // "Crazy Echo" category: "audio" interface ToyContext // shared state across plugins audioBuffer?: AudioBuffer; canvas?: HTMLCanvasElement; physicsWorld?: Matter.World; userParams: Record<string, any>; const echoPlugin = id: "echo-delay", name: "Echo Tunnel",
reorder() // sort: visual → physics → audio (example) this.activePlugins = new Map([...this.activePlugins.entries()] .sort((a,b) => orderMap[a[1].category] - orderMap[b[1].category])); check exclusive group if (plugin