// this is the mixer that takes all the different outputs and mixes them into the 2 busses:
// WorldBus: The directional audio
// SecondaryBus: All the UI and things that are non directional
import EffectChain from './effect-chain';
export default class AudioGraph {
    constructor(scene, context, swapChannels = false) {
        this.scene = scene;
        this.context = context;
        this.swapChannels = swapChannels;
        this.init();
    }
    init() {
        this.effectsBus = this.context.createGain();
        this.worldBus = this.context.createGain();
        this.secondaryBus = this.context.createGain();
        this.master = this.context.createGain();
        this.scene.getOutput().connect(this.worldBus);
        // this.worldBus.connect(this.master);
        this.worldBus.connect(this.effectsBus);
        this.effects = new EffectChain(this.context, this, this.effectsBus, this.master);
        this.secondaryBus.connect(this.master);
        if (this.swapChannels) {
            this.channelSplitter = this.context.getContext().createChannelSplitter(2);
            this.channelMerger = this.context.getContext().createChannelMerger(2);
            this.master.connect(this.channelSplitter);
            this.channelSplitter.connect(this.channelMerger, 0, 1);
            this.channelSplitter.connect(this.channelMerger, 1, 0);
            this.channelMerger.connect(this.context.getOutputDestination());
        }
        else {
            this.master.connect(this.context.getOutputDestination());
        }
    }
    connectToMaster(input) {
        input.connect(this.master);
    }
    connectToUI(input) {
        input.connect(this.secondaryBus);
    }
    applyEffect(effect) {
        this.effects.applyEffect(effect);
    }
    removeEffect(effect) {
        this.effects.removeEffect(effect);
    }
}
