2019-08-12 04:14:59 +00:00
|
|
|
import { expect } from "chai";
|
|
|
|
import { Offline } from "test/helper/Offline";
|
|
|
|
import { Monophonic } from "Tone/instrument/Monophonic";
|
|
|
|
|
|
|
|
export function MonophonicTest(Constr, note, constrArg?): void {
|
|
|
|
|
|
|
|
context("Monophonic Tests", () => {
|
|
|
|
|
2019-09-14 22:06:46 +00:00
|
|
|
it("has an onsilence callback which is invoked after the release has finished", () => {
|
2019-08-12 04:14:59 +00:00
|
|
|
let wasInvoked = false;
|
|
|
|
return Offline(() => {
|
|
|
|
const instance = new Constr(constrArg);
|
|
|
|
instance.toDestination();
|
|
|
|
instance.triggerAttackRelease(note, 0.1, 0);
|
|
|
|
instance.onsilence = () => wasInvoked = true;
|
|
|
|
}, 2).then(() => {
|
|
|
|
expect(wasInvoked).to.equal(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-09-14 22:06:46 +00:00
|
|
|
it("invokes onsilence callback when the sustain is set to 0", () => {
|
2019-08-12 04:14:59 +00:00
|
|
|
let wasInvoked = false;
|
|
|
|
return Offline(() => {
|
|
|
|
const instance = new Constr(constrArg);
|
|
|
|
instance.toDestination();
|
2019-11-03 22:45:50 +00:00
|
|
|
if (instance.envelope) {
|
|
|
|
instance.envelope.sustain = 0;
|
|
|
|
} else if (instance.voice0) {
|
|
|
|
// DuoSynth is a special case
|
|
|
|
instance.voice0.envelope.sustain = 0;
|
|
|
|
instance.voice1.envelope.sustain = 0;
|
|
|
|
}
|
2019-08-12 04:14:59 +00:00
|
|
|
instance.triggerAttack(note, 0);
|
|
|
|
instance.onsilence = () => wasInvoked = true;
|
|
|
|
}, 2).then(() => {
|
|
|
|
expect(wasInvoked).to.equal(true);
|
|
|
|
});
|
|
|
|
});
|
2019-09-04 00:09:11 +00:00
|
|
|
|
2019-09-14 22:06:46 +00:00
|
|
|
it("can pass in the detune into the constructor", () => {
|
2019-09-04 00:09:11 +00:00
|
|
|
const instance = new Constr({
|
|
|
|
detune: -100,
|
|
|
|
});
|
|
|
|
expect(instance.detune.value).to.be.closeTo(-100, 0.1);
|
|
|
|
instance.dispose();
|
|
|
|
});
|
2019-08-12 04:14:59 +00:00
|
|
|
});
|
|
|
|
}
|