import { AutomationEventList } from 'automation-events'; import { IOscillatorNode, TContext, TEventHandler, TOscillatorType } from 'standardized-audio-context'; import { AudioNodeMock } from './audio-node-mock'; import { AudioParamMock } from './audio-param-mock'; import { createMockableFunction } from './mocking-implementation'; import { registrar } from './registrar'; export class OscillatorNodeMock extends AudioNodeMock implements IOscillatorNode { // tslint:disable-next-line no-empty public setPeriodicWave = createMockableFunction(() => {}); // tslint:disable-next-line no-empty public start = createMockableFunction(() => {}); // tslint:disable-next-line no-empty public stop = createMockableFunction(() => {}); public type: TOscillatorType; private _detune: AudioParamMock; private _frequency: AudioParamMock; private _onended: null | TEventHandler; constructor(context: T) { const deLorean = registrar.getDeLorean(context); super({ channelCount: 2, channelCountMode: 'max', channelInterpretation: 'speakers', context, numberOfInputs: 0, numberOfOutputs: 1 }); this._detune = new AudioParamMock({ automationEventList: new AutomationEventList(0), deLorean, maxValue: 153600, minValue: -153600 }); this._frequency = new AudioParamMock({ automationEventList: new AutomationEventList(440), deLorean, maxValue: context.sampleRate / 2, minValue: -(context.sampleRate / 2) }); // @todo Implement the ended event. this._onended = null; this.type = 'sine'; registrar.addAudioNode(context, 'OscillatorNode', this); } get detune(): AudioParamMock { return this._detune; } set detune(value) { value; // tslint:disable-line:no-unused-expression } get frequency(): AudioParamMock { return this._frequency; } set frequency(value) { value; // tslint:disable-line:no-unused-expression } get onended(): null | TEventHandler { return this._onended; } set onended(value) { this._onended = typeof value === 'function' ? value : null; } }