node-web-audio-api
Version:
Web Audio API implementation for Node.js
140 lines (115 loc) • 5.63 kB
JavaScript
// -------------------------------------------------------------------------- //
// -------------------------------------------------------------------------- //
// //
// //
// //
// ██╗ ██╗ █████╗ ██████╗ ███╗ ██╗██╗███╗ ██╗ ██████╗ //
// ██║ ██║██╔══██╗██╔══██╗████╗ ██║██║████╗ ██║██╔════╝ //
// ██║ █╗ ██║███████║██████╔╝██╔██╗ ██║██║██╔██╗ ██║██║ ███╗ //
// ██║███╗██║██╔══██║██╔══██╗██║╚██╗██║██║██║╚██╗██║██║ ██║ //
// ╚███╔███╔╝██║ ██║██║ ██║██║ ╚████║██║██║ ╚████║╚██████╔╝ //
// ╚══╝╚══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═══╝╚═╝╚═╝ ╚═══╝ ╚═════╝ //
// //
// //
// - This file has been generated --------------------------- //
// //
// //
// -------------------------------------------------------------------------- //
// -------------------------------------------------------------------------- //
/* eslint-disable no-unused-vars */
const conversions = require('webidl-conversions');
const {
toSanitizedSequence,
} = require('./lib/cast.js');
const {
isFunction,
kEnumerableProperty,
} = require('./lib/utils.js');
const {
throwSanitizedError,
} = require('./lib/errors.js');
const {
kNapiObj,
kAudioBuffer,
} = require('./lib/symbols.js');
/* eslint-enable no-unused-vars */
const AudioNode = require('./AudioNode.js');
module.exports = (jsExport, nativeBinding) => {
class GainNode extends AudioNode {
#gain = null;
constructor(context, options) {
if (arguments.length < 1) {
throw new TypeError(`Failed to construct 'GainNode': 1 argument required, but only ${arguments.length} present`);
}
if (!(context instanceof jsExport.BaseAudioContext)) {
throw new TypeError(`Failed to construct 'GainNode': argument 1 is not of type BaseAudioContext`);
}
// parsed version of the option to be passed to NAPI
const parsedOptions = {};
if (options && typeof options !== 'object') {
throw new TypeError('Failed to construct \'GainNode\': argument 2 is not of type \'GainOptions\'');
}
if (options && options.gain !== undefined) {
parsedOptions.gain = conversions['float'](options.gain, {
context: `Failed to construct 'GainNode': Failed to read the 'gain' property from GainOptions: The provided value (${options.gain}})`,
});
} else {
parsedOptions.gain = 1.0;
}
if (options && options.channelCount !== undefined) {
parsedOptions.channelCount = conversions['unsigned long'](options.channelCount, {
enforceRange: true,
context: `Failed to construct 'GainNode': Failed to read the 'channelCount' property from GainOptions: The provided value '${options.channelCount}'`,
});
}
if (options && options.channelCountMode !== undefined) {
parsedOptions.channelCountMode = conversions['DOMString'](options.channelCountMode, {
context: `Failed to construct 'GainNode': Failed to read the 'channelCount' property from GainOptions: The provided value '${options.channelCountMode}'`,
});
}
if (options && options.channelInterpretation !== undefined) {
parsedOptions.channelInterpretation = conversions['DOMString'](options.channelInterpretation, {
context: `Failed to construct 'GainNode': Failed to read the 'channelInterpretation' property from GainOptions: The provided value '${options.channelInterpretation}'`,
});
}
let napiObj;
try {
napiObj = new nativeBinding.GainNode(context[kNapiObj], parsedOptions);
} catch (err) {
throwSanitizedError(err);
}
super(context, {
[kNapiObj]: napiObj,
});
this.#gain = new jsExport.AudioParam({
[kNapiObj]: this[kNapiObj].gain,
});
}
get gain() {
if (!(this instanceof GainNode)) {
throw new TypeError('Invalid Invocation: Value of \'this\' must be of type \'GainNode\'');
}
return this.#gain;
}
}
Object.defineProperties(GainNode, {
length: {
__proto__: null,
writable: false,
enumerable: false,
configurable: true,
value: 1,
},
});
Object.defineProperties(GainNode.prototype, {
[Symbol.toStringTag]: {
__proto__: null,
writable: false,
enumerable: false,
configurable: true,
value: 'GainNode',
},
gain: kEnumerableProperty,
});
return GainNode;
};