pixijs / sound

WebAudio API playback library, with filters. Modern audio playback for modern browsers.
https://pixijs.io/sound/examples/
MIT License
409 stars 67 forks source link

Fix difficulty transpiling filters #245

Closed bigtimebuddy closed 1 year ago

bigtimebuddy commented 1 year ago

User on Discord had problems with transpiling with Babel with @babel/plugin-transform-parameters because of the conditional super() calls with the filters. This PR refactors the constructors to rework how to deal with legacy.

Before

class DistortionFilter extends Filter {
  constructor(amount = 0) {
    var __super = (...args) => {
      super(...args);
    };
    if (getInstance().useLegacy) {
      __super(null);
      return;
    }
    const { context } = getInstance();
    const distortion = context.audioContext.createWaveShaper();
    __super(distortion);
    this._distortion = distortion;
    this.amount = amount;
  }
}

After

class DistortionFilter extends Filter {
  constructor(amount = 0) {
    let distortion;
    if (!getInstance().useLegacy) {
      const { audioContext } = getInstance().context;
      distortion = audioContext.createWaveShaper();
    }
    super(distortion);
    this._distortion = distortion;
    this.amount = amount;
  }
}