import { moduleName, streamDeck, getPermission } from "../../MaterialDeck.js"; export class SoundboardControl{ constructor(){ this.active = false; this.offset = 0; this.activeSounds = []; } async updateAll(){ if (this.active == false) return; for (let device of streamDeck.buttonContext) { if (device?.buttons == undefined) continue; for (let i=0; i 0) ? true : false; const play = (this.activeSounds[soundNr] == undefined) ? true : false; this.prePlaySound(soundNr,repeat,play); } else if (mode == 'offset') { //Offset let offset = parseInt(settings.offset); if (isNaN(offset)) offset = 0; this.offset = offset; this.updateAll(); } else if (mode == 'stopAll') { //Stop All Sounds for (let i=0; i p.id == soundId); if (sound == undefined) return; src = sound.path; } let volume = game.settings.get(moduleName,'soundboardSettings').volume[soundNr]/100; volume = AudioHelper.inputToVolume(volume); let payload = { "msgType": "playSound", "trackNr": soundNr, "src": src, "repeat": repeat, "play": play, "volume": volume }; game.socket.emit(`module.MaterialDeck`, payload); this.playSound(soundNr,src,play,repeat,volume) } async playSound(soundNr,src,play,repeat,volume){ if (play){ volume *= game.settings.get("core", "globalAmbientVolume"); let newSound = new Sound(src); if(newSound.loaded == false) await newSound.load({autoplay:true}); newSound.on('end', ()=>{ if (repeat == false) { this.activeSounds[soundNr] = undefined; this.updateAll(); } }); newSound.play({loop:repeat,volume:volume}); this.activeSounds[soundNr] = newSound; } else { if (this.activeSounds[soundNr] != undefined) this.activeSounds[soundNr].stop(); this.activeSounds[soundNr] = undefined; } this.updateAll(); } }