Tone.js/test/helper/InstrumentTests.js

109 lines
2.8 KiB
JavaScript
Raw Normal View History

2016-09-26 01:36:32 +00:00
define(["helper/OutputAudio", "Tone/instrument/Instrument", "helper/OutputAudioStereo",
2017-02-20 21:45:32 +00:00
"Test", "helper/Offline"],
function (OutputAudio, Instrument, OutputAudioStereo, Test, Offline) {
2015-08-31 15:37:10 +00:00
return function(Constr, note, constrArg, optionsIndex){
2015-08-31 15:37:10 +00:00
context("Instrument Tests", function(){
it ("extends Tone.Instrument", function(){
var instance = new Constr(constrArg);
2015-08-31 15:37:10 +00:00
expect(instance).to.be.an.instanceof(Instrument);
instance.dispose();
});
it ("can connect the output", function(){
var instance = new Constr(constrArg);
2015-08-31 15:37:10 +00:00
instance.connect(Test);
instance.dispose();
});
it ("can set the volume", function(){
if (!optionsIndex){
var instance = new Constr({
"volume" : -10
});
}else if (optionsIndex === 1){
var instance = new Constr(constrArg, {
"volume" : -10
});
}
2015-08-31 15:37:10 +00:00
expect(instance.volume.value).to.be.closeTo(-10, 0.1);
instance.dispose();
});
it("makes a sound", function(){
return OutputAudio(function(){
var instance = new Constr(constrArg);
instance.toMaster();
2015-08-31 15:37:10 +00:00
instance.triggerAttack(note);
});
});
it("produces sound in both channels", function(){
return OutputAudioStereo(function(){
var instance = new Constr(constrArg);
instance.toMaster();
2015-08-31 15:37:10 +00:00
instance.triggerAttack(note);
});
});
it("is silent before being triggered", function(){
return Offline(function(){
var instance = new Constr(constrArg);
instance.toMaster();
}).then(function(buffer){
expect(buffer.isSilent()).to.be.true;
});
});
if (Constr.prototype.triggerRelease){
it("can trigger release after attack", function(){
return Offline(function(){
var instance = new Constr(constrArg);
instance.toMaster();
if (note){
instance.triggerAttack(note, 0.05);
} else {
instance.triggerAttack(0.05);
}
instance.triggerRelease(0.1);
}, 0.2).then(function(buffer){
expect(buffer.getFirstSoundTime()).to.be.within(0.05, 0.1);
});
});
it("can combine triggerAttack and triggerRelease", function(){
return Offline(function(){
var instance = new Constr(constrArg);
instance.toMaster();
if (note){
instance.triggerAttackRelease(note, 0.1, 0.05);
} else {
instance.triggerAttackRelease(0.1, 0.05);
}
}, 0.2).then(function(buffer){
expect(buffer.getFirstSoundTime()).to.be.within(0.05, 0.1);
});
});
}
it("be scheduled to start in the future", function(){
return Offline(function(){
var instance = new Constr(constrArg);
instance.toMaster();
2015-08-31 15:37:10 +00:00
if (note){
instance.triggerAttack(note, 0.1);
} else {
instance.triggerAttack(0.1);
}
}, 0.2).then(function(buffer){
expect(buffer.getFirstSoundTime()).to.be.within(0.1, 0.15);
2015-08-31 15:37:10 +00:00
});
});
});
};
});