Tone.js/test/helper/InstrumentTests.js
2015-10-21 10:53:43 -04:00

79 lines
No EOL
1.8 KiB
JavaScript

define(["helper/OutputAudio", "Tone/instrument/Instrument", "helper/OutputAudioStereo", "Test", "helper/Offline", "helper/Meter"],
function (OutputAudio, Instrument, OutputAudioStereo, Test, Offline, Meter) {
return function(Constr, note){
context("Instrument Tests", function(){
it ("extends Tone.Instrument", function(){
var instance = new Constr();
expect(instance).to.be.an.instanceof(Instrument);
instance.dispose();
});
it ("can connect the output", function(){
var instance = new Constr();
instance.connect(Test);
instance.dispose();
});
it ("can set the volume", function(){
var instance = new Constr({
"volume" : -10
});
expect(instance.volume.value).to.be.closeTo(-10, 0.1);
instance.dispose();
});
it("makes a sound", function(done){
var instance;
OutputAudio(function(dest){
instance = new Constr();
instance.connect(dest);
instance.triggerAttack(note);
}, function(){
instance.dispose();
done();
});
});
it("produces sound in both channels", function(done){
var instance;
OutputAudioStereo(function(dest){
instance = new Constr();
instance.connect(dest);
instance.triggerAttack(note);
}, function(){
instance.dispose();
done();
});
});
it("be scheduled to start in the future", function(done){
var instance;
var meter = new Meter(0.3);
meter.before(function(dest){
instance = new Constr();
instance.connect(dest);
if (note){
instance.triggerAttack(note, 0.1);
} else {
instance.triggerAttack(0.1);
}
});
meter.test(function(sample, time){
if (sample > 0.2){
expect(time).to.be.at.least(0.1);
}
});
meter.after(function(){
instance.dispose();
done();
});
meter.run();
});
});
};
});