WickSoundController - An Add-on for Jovannys WickSound API

First of all, all Credits goes to @Jovanny for his WickSound API!
(I hope it’s okay for you to publish this add-on out of nowhere)
Check his API out before reading this Topic!

So, recently I researched and tested a lot of things with audio in the Wick Editor.
While doing this I found a way to better organize and control Sounds with Jovannys API.

Here we are:

window.WickSoundController = class {
    constructor() {
        this.instances = [];
    }
   
    createSound(assetName) {
        let sound = new WickSound(assetName);
        this.instances.push(sound);
        return sound;
    }

    deleteSound(instance) {
        let i = this.instances.indexOf(instance);
        this.instances.splice(i, 1);
    }

    deleteAllSounds() {
        this.instances = [];
    }
   
    getSound(sound) {
        return this.instances[sound];
    }
   
    getAllSounds() {
        return this.instances;
    }

    howlerVolume(volume) {
        /*
            This method is used to change the volume of EVERY sound
            in this Wick project, even across multiple instances of the
            WickSoundController. The values for the volume of each WickSound instance
            won't change.
        */
        if(volume === null || volume==undefined){
            return Howler.volume();
        }
        Howler.volume(volume);
        if(volume<0) {
            Howler.volume(0);
        } else if(volume>1) {
            Howler.volume(1);
        }
    }
   
    volume(volume) {
        /*
            This method is used to change the volume of every WickSound instance
            in the current WickSoundController instance. The values for the volume of these WickSound instances
            will change to 1 single value.
        */
        if(volume === null || volume==undefined){
            let volumeArray = [];
            for(let i in this.instances) {
                if (i !== "max") {
                    volumeArray.push(this.instances[i].volume());
                }
            }
            return volumeArray;
        }
       
        let vol = volume;
        if(volume<0) {
            vol = 0;
        } else if(volume>1) {
            vol = 1;
        }
       
        for (let i in this.instances) {
            if (i !== "max") {
                this.instances[i].volume(vol);
            }
        }
    }
  
    mute() {
        /*
            This method is used to mute every WickSound instance
            in the current WickSoundController instance.
            The Howler doesn't get muted.
        */
        for (let i in this.instances) {
            if (i !== "max") {
                this.instances[i].mute();
            }
        }
    }

    unmute() {
        /*
            This method is used to unmute every WickSound instance
            in the current WickSoundController instance.
            The Howler doesn't get muted.
        */
        for (let i in this.instances) {
            if (i !== "max") {
                this.instances[i].unmute();
            }
        }
    }
   
    muteHowler() {
        // This method is used to mute the complete Howler, so it will affect ALL sounds in this Wick project.
        Howler.mute(true);
    }

    unmuteHowler() {
        // This method is used to unmute the complete Howler, so it will affect ALL sounds in this Wick project.
        Howler.mute(false);
    }
   
    stereo(pan) {
        if(pan === null || pan==undefined){
            let panArray = [];
            for(let i in this.instances) {
                if (i !== "max") {
                    panArray.push(this.instances[i].stereo());
                }
            }
            return panArray;
        }
       
        let p = pan;
        if(pan<-1) {
            p = -1;
        } else if(pan>1) {
            p = 1;
        }
       
        for (let i in this.instances) {
            if (i !== "max") {
                this.instances[i].stereo(p);
            }
        }
    }

    play() {
        for (let i in this.instances) {
            if (i !== "max") {
                if (!this.instances[i].isPlaying()) {
                    this.instances[i].play();
                }
            }
        }
    }

    stop() {
        for (let i in this.instances) {
            if (i !== "max") {
                if (this.instances[i].isPlaying()) {
                    this.instances[i].stop();
                }
            }
        }
    }

    pause() {
        for (let i in this.instances) {
            if (i !== "max") {
                if (this.instances[i].isPlaying()) {
                    this.instances[i].pause();
                }
            }
        }
    }
   
    isPlaying() {
        let isPlayingArray = [];
        for(let i in this.instances) {
            if (i !== "max") {
                isPlayingArray.push(this.instances[i].isPlaying());
            }
        }
        return isPlayingArray;
    }

    currentTimes() {
        let currentTimesArray = [];
        for(let i in this.instances) {
            if (i !== "max") {
                currentTimesArray.push(this.instances[i].currently());
            }
        }
        return currentTimesArray;
    }

    durations() {
        let durationsArray = [];
        for(let i in this.instances) {
            if (i !== "max") {
                durationsArray.push(this.instances[i].duration());
            }
        }
        return durationsArray;
    }
};
simplified but not working code
window.WickSoundController = class {
    constructor() {
        this.instances = [];
    }
    createSound(assetName) {
    }
    deleteSound(instance) {
    }
    deleteAllSounds() {
    }
    getSound(sound) {
    }
    getAllSounds() {
    }
    howlerVolume(volume) {
    }
    volume(volume) {
    }
    mute() {
    }
    unmute() {
    }
    muteHowler() {
    }
    unmuteHowler() {
    }
    stereo(pan) {
    }
    play() {
    }
    stop() {
    }
    pause() {
    }
    isPlaying() {
    }
    currentTimes() {
    }
    durations() {
    }
};

To use the WickSoundController add-on you need to have Jovannys WickSound API implemented.
After you implemented it, you can just copy the code above and paste it after Jovannys API.

Here is a example of what you can do with the WickSoundController:

// create a new controller for your sounds
let SoundController = new WickSoundController();

// create as many sounds as you want to be controlled by this controller
let sound1 = SoundController.createSound("mysound1.mp3");
let sound2 = SoundController.createSound("mysound2.mp3");
let sound3 = SoundController.createSound("mysound3.mp3");
let sound4 = SoundController.createSound("mysound4.mp3");

// delete a sound of a controller
SoundController.deleteSound(sound4);

// delete all sounds of a controller
SoundController.deleteAllSounds();

// get a sound of a controller
let getSound1 = SoundController.getSound(0);

// get all sounds of a controller
let getAllSounds = SoundController.getAllSounds();

// change volume of Howler
SoundController.howlerVolume(0.8);

// get volume of Howler
let howlerVolume = SoundController.howlerVolume();

// get volume of all sounds in an array
let volume = SoundController.volume();

// set volume of all sounds
SoundController.volume(0.5);

// mute all sounds
SoundController.mute();

// unmute all sounds
SoundController.unmute();

// mute Howler
SoundController.muteHowler();

// unmute Howler
SoundController.unmuteHowler();

// get the stereo pan of all sounds in an array
let stereo = SoundController.stereo();

// set the stereo pan of all sounds
SoundController.stereo(-0.7);

// play all sounds
SoundController.play();

// stop all sounds
SoundController.stop();

// pause all sounds
SoundController.pause();

// get the isPlaying status of every Sound in an array
let isPlaying = SoundController.isPlaying();

// get the current time of every sound in an array
let currentTimes = SoundController.currentTimes();

// get the duration of every sound in an array
let durations = SoundController.durations();

// you can still use the WickSound API as normal to control a specific sound
sound1.stop();
sound2.play();
sound3.loop(true);

I currently don’t have an example file to show you. Maybe I’m posting one here sometime.

1 Like