sourav-das/stem-separator
3
1import EventEmitter from './event-emitter.js';2/** Base class for wavesurfer plugins */3export class BasePlugin extends EventEmitter {4 /** Create a plugin instance */5 constructor(options) {6 super();7 this.subscriptions = [];8 this.isDestroyed = false;9 this.options = options;10 }11 /** Called after this.wavesurfer is available */12 onInit() {13 return;14 }15 /** Do not call directly, only called by WavesSurfer internally */16 _init(wavesurfer) {17 // Reset state if plugin was previously destroyed18 if (this.isDestroyed) {19 this.subscriptions = [];20 this.isDestroyed = false;21 }22 this.wavesurfer = wavesurfer;23 this.onInit();24 }25 /** Destroy the plugin and unsubscribe from all events */26 destroy() {27 this.emit('destroy');28 this.subscriptions.forEach((unsubscribe) => unsubscribe());29 this.subscriptions = [];30 this.isDestroyed = true;31 this.wavesurfer = undefined;32 }33}34export default BasePlugin;35 