2016-03-21 19:20:04 +00:00
|
|
|
define(["Tone/instrument/PolySynth", "helper/Basic", "helper/InstrumentTests", "helper/OutputAudioStereo",
|
|
|
|
"helper/Meter", "Tone/instrument/Instrument", "Test", "helper/OutputAudio", "Tone/instrument/MonoSynth"],
|
|
|
|
function (PolySynth, Basic, InstrumentTests, OutputAudioStereo, Meter, Instrument, Test, OutputAudio, MonoSynth) {
|
2016-02-04 19:31:02 +00:00
|
|
|
|
|
|
|
describe("PolySynth", function(){
|
|
|
|
|
|
|
|
Basic(PolySynth);
|
|
|
|
InstrumentTests(PolySynth, "C4");
|
|
|
|
|
2016-03-21 19:20:04 +00:00
|
|
|
context("PolySynth Tests", function(){
|
2016-02-04 19:31:02 +00:00
|
|
|
|
|
|
|
it ("extends Tone.Instrument", function(){
|
|
|
|
var polySynth = new PolySynth();
|
|
|
|
expect(polySynth).to.be.an.instanceof(Instrument);
|
|
|
|
polySynth.dispose();
|
|
|
|
});
|
|
|
|
|
|
|
|
it ("can connect the output", function(){
|
|
|
|
var polySynth = new PolySynth();
|
|
|
|
polySynth.connect(Test);
|
|
|
|
polySynth.dispose();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("makes a sound", function(done){
|
|
|
|
var polySynth;
|
|
|
|
OutputAudio(function(dest){
|
2016-03-21 19:20:04 +00:00
|
|
|
polySynth = new PolySynth(2);
|
2016-02-04 19:31:02 +00:00
|
|
|
polySynth.connect(dest);
|
|
|
|
polySynth.triggerAttack("C4");
|
|
|
|
}, function(){
|
|
|
|
polySynth.dispose();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-05-14 23:55:51 +00:00
|
|
|
it("triggerAttackRelease can take an array of durations", function(done){
|
|
|
|
var polySynth;
|
|
|
|
OutputAudio(function(dest){
|
|
|
|
polySynth = new PolySynth(2);
|
|
|
|
polySynth.connect(dest);
|
|
|
|
polySynth.triggerAttackRelease(["C4", "D4"], [0.1, 0.2]);
|
|
|
|
}, function(){
|
|
|
|
polySynth.dispose();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-02-04 19:31:02 +00:00
|
|
|
it("is silent before being triggered", function(done){
|
|
|
|
var polySynth;
|
|
|
|
var meter = new Meter(0.3);
|
|
|
|
meter.before(function(dest){
|
|
|
|
polySynth = new PolySynth();
|
|
|
|
polySynth.connect(dest);
|
|
|
|
});
|
|
|
|
meter.test(function(level){
|
|
|
|
expect(level).to.equal(0);
|
|
|
|
});
|
|
|
|
meter.after(function(){
|
|
|
|
polySynth.dispose();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
meter.run();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("be scheduled to start in the future", function(done){
|
|
|
|
var polySynth;
|
|
|
|
var meter = new Meter(0.3);
|
|
|
|
meter.before(function(dest){
|
|
|
|
polySynth = new PolySynth();
|
|
|
|
polySynth.connect(dest);
|
|
|
|
polySynth.triggerAttack("C4", 0.1);
|
|
|
|
});
|
|
|
|
meter.test(function(sample, time){
|
|
|
|
if (sample > 0.2){
|
|
|
|
expect(time).to.be.at.least(0.1);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
meter.after(function(){
|
|
|
|
polySynth.dispose();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
meter.run();
|
|
|
|
});
|
|
|
|
|
2016-03-21 19:20:04 +00:00
|
|
|
});
|
2016-02-04 19:31:02 +00:00
|
|
|
|
|
|
|
context("API", function(){
|
|
|
|
|
|
|
|
it ("can be constructed with an options object", function(){
|
2016-03-21 19:20:04 +00:00
|
|
|
var polySynth = new PolySynth(4, MonoSynth, {
|
2016-02-04 19:31:02 +00:00
|
|
|
"envelope" : {
|
|
|
|
"sustain" : 0.3
|
|
|
|
}
|
|
|
|
});
|
2016-03-21 19:20:04 +00:00
|
|
|
expect(polySynth.get().envelope.sustain).to.equal(0.3);
|
2016-02-04 19:31:02 +00:00
|
|
|
polySynth.dispose();
|
|
|
|
});
|
|
|
|
|
|
|
|
it ("can get/set attributes", function(){
|
|
|
|
var polySynth = new PolySynth();
|
|
|
|
polySynth.set({
|
|
|
|
"envelope.decay" : 0.24
|
|
|
|
});
|
|
|
|
expect(polySynth.get().envelope.decay).to.equal(0.24);
|
|
|
|
polySynth.dispose();
|
2016-03-21 19:20:04 +00:00
|
|
|
});
|
2016-02-04 19:31:02 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|