import{O as n}from"./index-6jOCfdig.js";import{A as a}from"./abstractSoundSource-Ao26OVlO.js";import{A as r}from"./audioEngine-CbOwYhF1.js";class l extends a{constructor(t,s){super(t,s,3),this._newestInstance=null,this._privateInstances=new Set,this._state=1,this._instances=this._privateInstances,this.onEndedObservable=new n,this._onInstanceEnded=e=>{this._newestInstance===e&&(this._newestInstance=null),this._privateInstances.delete(e),this._instances.size===0&&(this._state=1,this.onEndedObservable.notifyObservers(this)),e.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 r{constructor(t){super(t.engine,2),this._state=1,this.onEndedObservable=new n,this.onErrorObservable=new n,this.onStateChangedObservable=new n,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 _};
