Tone.js/Tone/core/context/BaseContext.ts

163 lines
3.9 KiB
TypeScript
Raw Normal View History

import { Seconds } from "../type/Units";
import { Emitter } from "../util/Emitter";
import { AnyAudioContext } from "./AudioContext";
type Draw = import("../util/Draw").Draw;
type Destination = import("./Destination").Destination;
type Transport = import("../clock/Transport").Transport;
type Listener = import("./Listener").Listener;
// these are either not used in Tone.js or deprecated and not implemented.
2021-01-01 01:53:38 +00:00
export type ExcludedFromBaseAudioContext =
| "onstatechange"
| "addEventListener"
| "removeEventListener"
| "listener"
| "dispatchEvent"
| "audioWorklet"
| "destination"
| "createScriptProcessor";
// the subset of the BaseAudioContext which Tone.Context implements.
2021-01-01 01:53:38 +00:00
export type BaseAudioContextSubset = Omit<
BaseAudioContext,
ExcludedFromBaseAudioContext
2021-01-01 01:53:38 +00:00
>;
export type ContextLatencyHint = AudioContextLatencyCategory;
2019-11-13 19:16:20 +00:00
2021-01-01 01:53:38 +00:00
export abstract class BaseContext
extends Emitter<"statechange" | "tick">
implements BaseAudioContextSubset {
//---------------------------
// BASE AUDIO CONTEXT METHODS
//---------------------------
2021-01-01 01:53:38 +00:00
abstract createAnalyser(): AnalyserNode;
2021-01-01 01:53:38 +00:00
abstract createOscillator(): OscillatorNode;
2021-01-01 01:53:38 +00:00
abstract createBufferSource(): AudioBufferSourceNode;
2021-01-01 01:53:38 +00:00
abstract createBiquadFilter(): BiquadFilterNode;
2021-01-01 01:53:38 +00:00
abstract createBuffer(
_numberOfChannels: number,
_length: number,
_sampleRate: number
): AudioBuffer;
2021-01-01 01:53:38 +00:00
abstract createChannelMerger(
_numberOfInputs?: number | undefined
): ChannelMergerNode;
2021-01-01 01:53:38 +00:00
abstract createChannelSplitter(
_numberOfOutputs?: number | undefined
): ChannelSplitterNode;
2021-01-01 01:53:38 +00:00
abstract createConstantSource(): ConstantSourceNode;
2021-01-01 01:53:38 +00:00
abstract createConvolver(): ConvolverNode;
2021-01-01 01:53:38 +00:00
abstract createDelay(_maxDelayTime?: number | undefined): DelayNode;
2021-01-01 01:53:38 +00:00
abstract createDynamicsCompressor(): DynamicsCompressorNode;
2021-01-01 01:53:38 +00:00
abstract createGain(): GainNode;
2021-01-01 01:53:38 +00:00
abstract createIIRFilter(
_feedForward: number[] | Float32Array,
_feedback: number[] | Float32Array
): IIRFilterNode;
2021-01-01 01:53:38 +00:00
abstract createPanner(): PannerNode;
abstract createPeriodicWave(
_real: number[] | Float32Array,
_imag: number[] | Float32Array,
2021-01-01 01:53:38 +00:00
_constraints?: PeriodicWaveConstraints | undefined
): PeriodicWave;
abstract createStereoPanner(): StereoPannerNode;
2021-01-01 01:53:38 +00:00
abstract createWaveShaper(): WaveShaperNode;
2021-01-01 01:53:38 +00:00
abstract createMediaStreamSource(
_stream: MediaStream
): MediaStreamAudioSourceNode;
2021-01-01 01:53:38 +00:00
abstract createMediaElementSource(
_element: HTMLMediaElement
): MediaElementAudioSourceNode;
2020-04-15 01:06:21 +00:00
2021-01-01 01:53:38 +00:00
abstract createMediaStreamDestination(): MediaStreamAudioDestinationNode;
abstract decodeAudioData(_audioData: ArrayBuffer): Promise<AudioBuffer>;
//---------------------------
// TONE AUDIO CONTEXT METHODS
//---------------------------
abstract createAudioWorkletNode(
2020-04-15 01:06:21 +00:00
_name: string,
_options?: Partial<AudioWorkletNodeOptions>
2021-01-01 01:53:38 +00:00
): AudioWorkletNode;
2021-01-01 01:53:38 +00:00
abstract get rawContext(): AnyAudioContext;
2021-01-01 01:53:38 +00:00
abstract async addAudioWorkletModule(
_url: string,
_name: string
): Promise<void>;
abstract lookAhead: number;
2019-11-13 19:16:20 +00:00
abstract latencyHint: ContextLatencyHint | Seconds;
2021-01-01 01:53:38 +00:00
abstract resume(): Promise<void>;
abstract setTimeout(
_fn: (...args: any[]) => void,
_timeout: Seconds
): number;
2021-01-01 01:53:38 +00:00
abstract clearTimeout(_id: number): this;
2021-01-01 01:53:38 +00:00
abstract setInterval(
_fn: (...args: any[]) => void,
_interval: Seconds
): number;
2021-01-01 01:53:38 +00:00
abstract clearInterval(_id: number): this;
2021-01-01 01:53:38 +00:00
abstract getConstant(_val: number): AudioBufferSourceNode;
2021-01-01 01:53:38 +00:00
abstract get currentTime(): Seconds;
2021-01-01 01:53:38 +00:00
abstract get state(): AudioContextState;
2021-01-01 01:53:38 +00:00
abstract get sampleRate(): number;
2021-01-01 01:53:38 +00:00
abstract get listener(): Listener;
2021-01-01 01:53:38 +00:00
abstract get transport(): Transport;
2021-01-01 01:53:38 +00:00
abstract get draw(): Draw;
2021-01-01 01:53:38 +00:00
abstract get destination(): Destination;
2021-01-01 01:53:38 +00:00
abstract now(): Seconds;
2021-01-01 01:53:38 +00:00
abstract immediate(): Seconds;
/*
* This is a placeholder so that JSON.stringify does not throw an error
* This matches what JSON.stringify(audioContext) returns on a native
* audioContext instance.
*/
toJSON(): Record<string, any> {
return {};
}
readonly isOffline: boolean = false;
}