UNPKG

mosfez-synth

Version:

A microtonal-aware synth engine library for web.

150 lines (144 loc) 4.86 kB
import { compile } from 'mosfez-faust/faust'; declare type ParamValue = number | string; declare type ParamValueObject = Record<string, ParamValue>; declare type ResolveGate<P extends ParamValueObject> = (p: Partial<P>) => number | undefined; declare type VoiceControllerConfig<P extends ParamValueObject> = { polyphony: number; resolveGate: ResolveGate<P>; paramCacheSize: number; }; declare type VoiceParam<P extends ParamValueObject> = { index: number; params: Partial<P>; }; declare class VoiceController<P extends ParamValueObject> { private _polyphony; private _resolveGate; private _release; private _paramCacheSize; private _allocator; private _allParams; private _perVoiceParamsStore; private _recentlyAccessedIds; constructor(config: VoiceControllerConfig<P>); private _accessId; private _getParamsForVoice; private _addParamForVoice; private _addParamsForVoice; private _deleteParamsForId; setRelease(release: number): void; set({ voice, ...params }: Partial<P>): VoiceParam<P>[]; private setWithId; private setAll; } declare type ParamDefinition = number | string; declare type ParamDefinitionObject = Record<string, ParamDefinition>; declare type DspNodeType = "faust" | "poly"; declare type DspNodeSerialized = DspNodeFaustSerialized | DspNodePolySerialized; declare type DspNodeConfig = { type: DspNodeType; }; declare class DspNode { type: DspNodeType; constructor(config: DspNodeConfig); static isFaustDspNode(DspNode: DspNode): DspNode is DspNodeFaust; static isPolyDspNode(DspNode: DspNode): DspNode is DspNodePoly; static isFaustDspNodeSerialized(serialized: DspNodeSerialized): serialized is DspNodeFaustSerialized; static isPolyDspNodeSerialized(serialized: DspNodeSerialized): serialized is DspNodePolySerialized; serialize(): DspNodeSerialized; } declare type DspNodeFaustDependencies = { compile: typeof compile; }; declare type DspNodeFaustConfig = { dsp: string; inputs?: DspNode[]; paramDefs: ParamDefinitionObject; dependencies: DspNodeFaustDependencies; }; declare type DspNodeFaustSerialized = { type: "faust"; dsp: string; inputs: DspNodeSerialized[]; paramDefs: ParamDefinitionObject; }; declare class DspNodeFaust extends DspNode { dsp: string; inputs: DspNode[]; paramDefs: ParamDefinitionObject; dependencies: DspNodeFaustDependencies; constructor(config: DspNodeFaustConfig); serialize(): DspNodeFaustSerialized; } declare type DspNodePolyDependencies = { VoiceController: typeof VoiceController; }; declare type DspNodePolyConfig = { input: DspNode; polyphony: number; paramCacheSize?: number; release: ParamDefinition; gate: ParamDefinition; dependencies: DspNodePolyDependencies; }; declare type DspNodePolySerialized = { type: "poly"; input: DspNodeSerialized; polyphony: number; paramCacheSize?: number; release: ParamDefinition; gate: ParamDefinition; }; declare class DspNodePoly extends DspNode { input: DspNode; polyphony: number; paramCacheSize?: number; release: ParamDefinition; gate: ParamDefinition; dependencies: DspNodePolyDependencies; constructor(config: DspNodePolyConfig); serialize(): DspNodePolySerialized; } declare type InputSetEvent = { type: "set"; time: number; params: Partial<ParamValueObject>; }; declare type InputStopEvent = { type: "stop"; time: number; }; declare type InputEvent = InputSetEvent | InputStopEvent; declare function isInputSetEvent(e: InputEvent): e is InputSetEvent; declare function isInputStopEvent(e: InputEvent): e is InputStopEvent; declare class InputEventRecorder<P extends ParamValueObject> { recording: boolean; private recordingStartTime; private events; record(): void; stop(): InputEvent[]; addSetEvent(params: Partial<P>): void; } declare type SynthConfig<P> = { audioContext: AudioContext | OfflineAudioContext; params?: Partial<P>; }; declare class Synth<P extends ParamValueObject> { private audioContext; private initialParams?; private node?; private connection?; constructor(config: SynthConfig<P>); build(dspNode: DspNode): Promise<void>; connect(audio: AudioNode, output?: number, input?: number): AudioNode; private tryConnectNode; disconnect(): void; disconnect(output: number): void; disconnect(destinationNode: AudioNode): void; disconnect(destinationNode: AudioNode, output: number): void; disconnect(destinationNode: AudioNode, output: number, input: number): void; set(params: Partial<P>): void; destroy(): void; inputEvents: InputEventRecorder<P>; } export { InputEvent, InputSetEvent, InputStopEvent, Synth, SynthConfig, isInputSetEvent, isInputStopEvent };