"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Functional_1 = require("../../../../../../Class/Functional");
const AudioNode_1 = require("../../../../../../wrap/AudioNode");
const _ids_1 = require("../../../../../_ids");
class GainNode_ extends Functional_1.Functional {
    constructor(system) {
        super({
            i: ['node', 'gain'],
            o: ['node'],
        }, {
            input: {
                node: {
                    ref: true,
                },
            },
            output: {
                node: {
                    ref: true,
                },
            },
        }, system, _ids_1.ID_GAIN_NODE);
        this._disconnect = (sourceNode) => {
            if (sourceNode) {
                sourceNode.disconnect();
                this._node = undefined;
            }
        };
        this.addListener('destroy', () => {
            if (this._node) {
                this._disconnect(this._i.node);
            }
        });
    }
    f({ node: sourceNode, gain }, done) {
        let _node;
        sourceNode = sourceNode;
        const context = sourceNode.getContext();
        _node = context.createGain();
        _node.gain.value = gain;
        this._node = _node;
        sourceNode.connect(_node);
        const node = (0, AudioNode_1.wrapAudioNode)(_node, this.__system);
        done({
            node,
        });
    }
    i() {
        this._disconnect(this._i.node);
    }
    d(name, data) {
        if (name === 'node') {
            this._disconnect(this._i.node);
        }
    }
}
exports.default = GainNode_;
//# sourceMappingURL=index.js.map