polysynth does not reschedule event if disposed

This commit is contained in:
Stuart Keith 2021-03-21 20:40:11 +11:00
parent 0346ca0c09
commit e3a611ffaa
2 changed files with 17 additions and 1 deletions

View file

@ -121,6 +121,20 @@ describe("PolySynth", () => {
});
});
it("can stop all sounds scheduled to start in the future when disposed", () => {
return Offline(() => {
const polySynth = new PolySynth();
polySynth.set({ envelope: { release: 0.1 } });
polySynth.toDestination();
polySynth.triggerAttackRelease(["C4", "E4", "G4", "B4"], 0.2);
return atTime(0.1, () => {
polySynth.dispose();
});
}, 0.3).then((buffer) => {
expect(buffer.isSilent()).to.be.true;
});
});
it("can be synced to the transport", () => {
return Offline(({ transport }) => {
const polySynth = new PolySynth(Synth, {

View file

@ -250,7 +250,9 @@ export class PolySynth<Voice extends Monophonic<any> = Synth> extends Instrument
} else {
// schedule it to start in the future
this.context.setTimeout(() => {
this._scheduleEvent(type, notes, time, velocity);
if (!this.disposed) {
this._scheduleEvent(type, notes, time, velocity);
}
}, time - this.now());
}
}