throws error when polysynth is used with a non monophonic class

fixes #939
This commit is contained in:
Yotam Mann 2021-10-13 15:29:23 -04:00
parent 3f835efce6
commit 4f5353e7f0
2 changed files with 8 additions and 0 deletions

View file

@ -278,6 +278,13 @@ describe("PolySynth", () => {
polySynth.dispose(); polySynth.dispose();
}); });
it("throws an error when used without a monophonic synth", () => {
expect(() => {
// @ts-ignore
new PolySynth(PluckSynth);
}).throws(Error)
});
it("can pass in the volume", () => { it("can pass in the volume", () => {
const polySynth = new PolySynth({ const polySynth = new PolySynth({
volume: -12, volume: -12,

View file

@ -176,6 +176,7 @@ export class PolySynth<Voice extends Monophonic<any> = Synth> extends Instrument
context: this.context, context: this.context,
onsilence: this._makeVoiceAvailable.bind(this), onsilence: this._makeVoiceAvailable.bind(this),
})); }));
assert(voice instanceof Monophonic, "Voice must extend Monophonic class");
voice.connect(this.output); voice.connect(this.output);
this._voices.push(voice); this._voices.push(voice);
return voice; return voice;