UNPKG

mosfez-synth

Version:

A microtonal-aware synth engine library for web.

106 lines (101 loc) 2.55 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); 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 }; } } class DspNodePoly extends DspNode { input; polyphony; paramCacheSize; release; gate; dependencies; constructor(config) { super({ type: "poly" }); this.input = config.input; this.polyphony = config.polyphony; this.paramCacheSize = config.paramCacheSize; this.release = validateParamDefinition("release", config.release); this.gate = validateParamDefinition("gate", config.gate); this.dependencies = config.dependencies; } serialize() { const { polyphony, paramCacheSize, release, gate } = this; const input = this.input.serialize(); return { type: "poly", input, polyphony, paramCacheSize, release, gate }; } } exports.DspNode = DspNode; exports.DspNodeFaust = DspNodeFaust; exports.DspNodePoly = DspNodePoly; //# sourceMappingURL=dsp-node.js.map