Skip to content
This repository has been archived by the owner on May 16, 2023. It is now read-only.

event listener added on each event callback #101

Open
err0r500 opened this issue Jul 8, 2022 · 0 comments
Open

event listener added on each event callback #101

err0r500 opened this issue Jul 8, 2022 · 0 comments

Comments

@err0r500
Copy link

err0r500 commented Jul 8, 2022

Hi,

I try to loop on a sample by adding a onended event to it (once). The problem is : when run in a browser, the JS event listeners count increment on each loop. It seems that something can't be garbage collected but I can't figure out what.

Here's a minimal example that reproduces the issue (I try to avoid references to global vars in the play function, without success):

const AudioContext = window.AudioContext || window.webkitAudioContext || false;
const ac = new AudioContext();

const play = (organ, now) => {
  organ.play("C2").stop(now + 3);
};

Soundfont.instrument(ac, "drawbar_organ").then((organ) => {
  organ.on("ended", () => play(organ, ac.currentTime));

  play(organ, ac.currentTime);
});
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant