import{O as i}from"./index-T8LZyOXI.js";import{A as r}from"./abstractSoundSource-DbLwT3xt.js";import{A as o}from"./audioEngine-DWueLylS.js";class l extends r{constructor(t,s,e){super(t,s,e,3),this._newestInstance=null,this._privateInstances=new Set,this._state=1,this._instances=this._privateInstances,this.onEndedObservable=new i,this._onInstanceEnded=n=>{this._newestInstance===n&&(this._newestInstance=null),this._privateInstances.delete(n),this._instances.size===0&&(this._state=1,this.onEndedObservable.notifyObservers(this)),n.dispose()}}get activeInstancesCount(){return this._instances.size}get autoplay(){return this._options.autoplay}get currentTime(){const t=this._getNewestInstance();return t?t.currentTime:0}set currentTime(t){this.startOffset=t;const s=this._getNewestInstance();s&&(s.currentTime=t)}get loop(){return this._options.loop}set loop(t){this._options.loop=t}get maxInstances(){return this._options.maxInstances}set maxInstances(t){this._options.maxInstances=t}get startOffset(){return this._options.startOffset}set startOffset(t){this._options.startOffset=t}get state(){return this._state}dispose(){super.dispose(),this.stop(),this._newestInstance=null,this._privateInstances.clear(),this.onEndedObservable.clear()}pause(){const t=this._instances.values();for(let s=t.next();!s.done;s=t.next())s.value.pause();this._state=5}resume(){if(this._state!==5)return;const t=this._instances.values();for(let s=t.next();!s.done;s=t.next())s.value.resume();this._state=3}_beforePlay(t){if(this.state===5&&this._instances.size>0){this.resume();return}t.onEndedObservable.addOnce(this._onInstanceEnded),this._privateInstances.add(t),this._newestInstance=t}_afterPlay(t){this._state=t.state}_getNewestInstance(){if(this._instances.size===0)return null;if(!this._newestInstance){const t=this._instances.values();for(let s=t.next();!s.done;s=t.next())this._newestInstance=s.value}return this._newestInstance}_setState(t){this._state=t}_stopExcessInstances(){if(this.maxInstances<1/0){const t=Array.from(this._instances).filter(e=>e.state===3).length-this.maxInstances,s=this._instances.values();for(let e=0;e<t;e++)s.next().value.stop()}}}class u extends o{constructor(t){super(t.engine,2),this._state=1,this.onEndedObservable=new i,this.onErrorObservable=new i,this.onStateChangedObservable=new i,this._sound=t}get state(){return this._state}dispose(){super.dispose(),this.stop(),this.onEndedObservable.clear(),this.onStateChangedObservable.clear()}_setState(t){this._state!==t&&(this._state=t,this.onStateChangedObservable.notifyObservers(this),this._state===1&&this.onEndedObservable.notifyObservers(this))}}export{l as A,u as _};
