{"size": 1990, "ext": "js", "max_stars_repo_path": "Calla/audio/sources/AudioBufferSpawningSource.js", "max_stars_repo_name": "TommyTeaVee/Calla", "max_stars_repo_stars_event_min_datetime": "2020-04-19T21:56:10.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T09:04:30.000Z", "max_issues_repo_path": "Calla/audio/sources/AudioBufferSpawningSource.js", "max_issues_repo_name": "TommyTeaVee/Calla", "max_issues_repo_issues_event_min_datetime": "2020-04-21T13:13:26.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-25T18:43:46.000Z", "max_forks_repo_path": "Calla/audio/sources/AudioBufferSpawningSource.js", "max_forks_repo_name": "TommyTeaVee/Calla", "max_forks_repo_forks_event_min_datetime": "2020-04-19T21:57:44.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-25T22:18:55.000Z"}
{"max_stars_count": 938, "max_issues_count": 88, "max_forks_count": 70, "avg_line_length": 34.9122807018, "max_line_length": 119, "alphanum_fraction": 0.6050251256}
import { arrayClear } from "kudzu/arrays/arrayClear";
import { arrayRemove } from "kudzu/arrays/arrayRemove";
import { buffer, BufferSource, loop } from "kudzu/audio";
import { once } from "kudzu/events/once";
import { AudioBufferSource } from "./AudioBufferSource";
import { BaseAudioBufferSource } from "./BaseAudioBufferSource";
export class AudioBufferSpawningSource extends BaseAudioBufferSource {
    counter = 0;
    playingSources = new Array();
    constructor(id, source, spatializer) {
        super(id, source, spatializer);
    }
    connectSpatializer() {
        // do nothing, this node doesn't play on its own
    }
    disconnectSpatializer() {
        // do nothing, this node doesn't play on its own
    }
    get isPlaying() {
        for (const source of this.playingSources) {
            if (source.isPlaying) {
                return true;
            }
        }
        return false;
    }
    async play() {
        const newBuffer = BufferSource("buffer-source-" + this.id, buffer(this.source.buffer), loop(this.source.loop));
        const newSpatializer = this.spatializer.clone();
        const newSource = new AudioBufferSource(`${this.id}-${this.counter++}`, newBuffer, newSpatializer);
        newSource.spatializer = newSpatializer;
        this.playingSources.push(newSource);
        newSource.play();
        if (!this.source.loop) {
            await once(newBuffer, "ended");
            if (this.playingSources.indexOf(newSource) >= 0) {
                newSource.dispose();
                arrayRemove(this.playingSources, newSource);
            }
        }
    }
    stop() {
        for (const source of this.playingSources) {
            source.dispose();
        }
        arrayClear(this.playingSources);
    }
    disposed3 = false;
    dispose() {
        if (!this.disposed3) {
            this.stop();
            super.dispose();
            this.disposed3 = true;
        }
    }
}
//# sourceMappingURL=AudioBufferSpawningSource.js.map