virtual-audio-graph
Version:
Library for declaratively manipulating the Web Audio API
30 lines (29 loc) • 1.21 kB
JavaScript
import { OUTPUT } from "./constants";
import updateVirtualNodeGraph from "./updateVirtualNodeGraph";
var VirtualAudioGraph = /** @class */ (function () {
function VirtualAudioGraph(audioContext, output) {
this.audioContext = audioContext;
this.output = output;
this.virtualNodes = {};
}
VirtualAudioGraph.prototype.getAudioNodeById = function (id) {
var _a;
return (_a = this.virtualNodes[id]) === null || _a === void 0 ? void 0 : _a.audioNode;
};
VirtualAudioGraph.prototype.update = function (newGraph) {
var _this = this;
if (OUTPUT in newGraph)
throw new Error("\"".concat(OUTPUT, "\" is a virtual-audio-graph reserved string and therefore not a valid node ID"));
updateVirtualNodeGraph(this.virtualNodes, newGraph, this.audioContext, function (vNode) { return vNode.connect(_this.output); });
return this;
};
Object.defineProperty(VirtualAudioGraph.prototype, "currentTime", {
get: function () {
return this.audioContext.currentTime;
},
enumerable: false,
configurable: true
});
return VirtualAudioGraph;
}());
export default VirtualAudioGraph;