UNPKG

mosfez-synth

Version:

A microtonal-aware synth engine library for web.

83 lines (78 loc) 1.91 kB
import { compile } from 'mosfez-faust/faust'; function validateParamDefinition(name, paramDef) { if (!isConstant(paramDef) && !isVariable(paramDef)) { throw new Error(`param "${name}" must be a constant number or a string referring to a param name, but got ${paramDef}`); } return paramDef; } function validateParamDefinitionObject(paramDefs) { for (const name in paramDefs) { validateParamDefinition(name, paramDefs[name]); } return paramDefs; } function isConstant(paramDef) { return typeof paramDef === "number"; } function isVariable(paramDef) { return typeof paramDef === "string"; } class DspNode { type; constructor(config) { this.type = config.type; } static isFaustDspNode(DspNode2) { return DspNode2.type === "faust"; } static isPolyDspNode(DspNode2) { return DspNode2.type === "poly"; } static isFaustDspNodeSerialized(serialized) { return serialized.type === "faust"; } static isPolyDspNodeSerialized(serialized) { return serialized.type === "poly"; } serialize() { throw new Error(".serialize() can only be called on subclasses"); } } class DspNodeFaust extends DspNode { dsp; inputs; paramDefs; dependencies; constructor(config) { super({ type: "faust" }); this.dsp = config.dsp; this.inputs = config.inputs ?? []; this.paramDefs = validateParamDefinitionObject(config.paramDefs); this.dependencies = config.dependencies; } serialize() { const { dsp, paramDefs } = this; const inputs = this.inputs.map((input) => input.serialize()); return { type: "faust", dsp, inputs, paramDefs }; } } function faust(dsp, paramDefs) { const { inputs, ...rest } = paramDefs; return new DspNodeFaust({ dsp, inputs, paramDefs: rest, dependencies: { compile } }); } export { faust }; //# sourceMappingURL=faust.mjs.map