import _ from 'lodash';
import '../../../globals.js';
// Copyright 2020-2023, University of Colorado Boulder
/**
 * A sound generator that is composed of multiple SoundClips that are all started and stopped at the same time.
 * Basically, this is a container to create and control multiple SoundClip instances as one.
 *
 * @author Michael Kauzmann (PhET Interactive Simulations)
 */
import tambo from '../tambo.js';
import SoundClip from './SoundClip.js';
import SoundGenerator from './SoundGenerator.js';
class CompositeSoundClip extends SoundGenerator {
    constructor(soundsAndOptionsTuples, options) {
        super(options);
        this.soundClips = [];
        for (let i = 0; i < soundsAndOptionsTuples.length; i++) {
            const soundAndOptions = soundsAndOptionsTuples[i];
            const soundClip = new SoundClip(soundAndOptions.sound, soundAndOptions.options);
            soundClip.connect(this.soundSourceDestination);
            this.soundClips.push(soundClip);
        }
    }
    play() {
        this.soundClips.forEach(soundClip => soundClip.play());
    }
    stop() {
        this.soundClips.forEach(soundClip => soundClip.stop());
    }
    connect(destination) {
        this.soundClips.forEach(soundClip => soundClip.connect(destination));
    }
    dispose() {
        this.soundClips.forEach(soundClip => soundClip.dispose());
        super.dispose();
    }
    get isPlaying() {
        return _.some(this.soundClips, soundClip => soundClip.isPlaying);
    }
    setOutputLevel(outputLevel, timeConstant) {
        this.soundClips.forEach(soundClip => soundClip.setOutputLevel(outputLevel, timeConstant));
    }
}
tambo.register('CompositeSoundClip', CompositeSoundClip);
export default CompositeSoundClip;
//# sourceMappingURL=CompositeSoundClip.js.map