Tone.js/test/helper/InstrumentTests.js
2016-09-25 21:36:32 -04:00

103 lines
No EOL
2.6 KiB
JavaScript

define(["helper/OutputAudio", "Tone/instrument/Instrument", "helper/OutputAudioStereo",
"Test", "helper/Offline", "helper/Meter", "helper/APITest"],
function (OutputAudio, Instrument, OutputAudioStereo, Test, Offline, Meter, APITest) {
return function(Constr, note, constrArg){
context("Instrument Tests", function(){
it ("extends Tone.Instrument", function(){
var instance = new Constr(constrArg);
expect(instance).to.be.an.instanceof(Instrument);
instance.dispose();
});
it ("can connect the output", function(){
var instance = new Constr(constrArg);
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(constrArg);
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(constrArg);
instance.connect(dest);
instance.triggerAttack(note);
}, function(){
instance.dispose();
done();
});
});
it("is silent before being triggered", function(done){
var instance;
var meter = new Meter(0.3);
meter.before(function(dest){
instance = new Constr(constrArg);
instance.connect(dest);
});
meter.test(function(level){
expect(level).to.equal(0);
});
meter.after(function(){
instance.dispose();
done();
});
meter.run();
});
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(constrArg);
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();
});
});
context("Instrument Tests: API", function(){
APITest.method(Constr, "triggerAttack", ["Frequency", "Time=", "NormalRange="]);
APITest.method(Constr, "triggerRelease", ["Time="]);
APITest.method(Constr, "triggerAttackRelease", ["Frequency", "Time=", "Time=", "NormalRange="]);
});
};
});