2014-09-14 19:32:30 +00:00
|
|
|
/* global it, describe */
|
2014-09-09 19:30:36 +00:00
|
|
|
|
|
|
|
define(["tests/Core", "chai", "Tone/instrument/DuoSynth", "Tone/instrument/MonoSynth", "Tone/instrument/FMSynth",
|
2015-01-06 02:56:25 +00:00
|
|
|
"Tone/instrument/PolySynth", "Tone/instrument/Sampler",
|
2014-11-30 03:03:28 +00:00
|
|
|
"tests/Common", "Tone/instrument/Instrument", "Tone/instrument/PluckSynth", "Tone/instrument/AMSynth",
|
2015-01-06 03:00:48 +00:00
|
|
|
"Tone/instrument/NoiseSynth", "Tone/core/Buffer"],
|
2015-01-06 02:56:25 +00:00
|
|
|
function(Tone, chai, DuoSynth, MonoSynth, FMSynth, PolySynth, Sampler, Test, Instrument,
|
2015-01-06 03:00:48 +00:00
|
|
|
PluckSynth, AMSynth, NoiseSynth, Buffer){
|
2014-09-09 19:30:36 +00:00
|
|
|
|
|
|
|
var expect = chai.expect;
|
|
|
|
|
2014-09-14 19:32:30 +00:00
|
|
|
Test.onlineContext();
|
|
|
|
|
2014-09-20 23:24:25 +00:00
|
|
|
function extendsInstrument(InstrumentFactory){
|
|
|
|
var inst = new InstrumentFactory();
|
|
|
|
expect(inst).to.be.instanceOf(Instrument);
|
|
|
|
inst.dispose();
|
|
|
|
}
|
|
|
|
|
2014-09-09 19:30:36 +00:00
|
|
|
describe("Tone.MonoSynth", function(){
|
|
|
|
it("can be created and disposed", function(){
|
|
|
|
var ms = new MonoSynth();
|
|
|
|
ms.dispose();
|
2014-09-20 23:24:25 +00:00
|
|
|
Test.wasDisposed(ms);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("extends Instrument", function(){
|
|
|
|
extendsInstrument(MonoSynth);
|
2014-09-09 19:30:36 +00:00
|
|
|
});
|
2014-10-13 21:15:58 +00:00
|
|
|
|
|
|
|
it("handles output connections", function(){
|
|
|
|
var ms = new MonoSynth();
|
|
|
|
Test.acceptsOutput(ms);
|
|
|
|
ms.dispose();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("outputs a sound", function(done){
|
|
|
|
var ms;
|
|
|
|
Test.outputsAudio(function(dest){
|
|
|
|
ms = new MonoSynth();
|
|
|
|
ms.connect(dest);
|
|
|
|
ms.triggerAttack("C4");
|
|
|
|
}, function(){
|
|
|
|
ms.dispose();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2014-09-09 19:30:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe("Tone.DuoSynth", function(){
|
|
|
|
it("can be created and disposed", function(){
|
|
|
|
var ds = new DuoSynth();
|
|
|
|
ds.dispose();
|
2014-09-20 23:24:25 +00:00
|
|
|
Test.wasDisposed(ds);
|
|
|
|
});
|
2014-10-13 21:15:58 +00:00
|
|
|
|
2014-09-20 23:24:25 +00:00
|
|
|
it("extends Instrument", function(){
|
|
|
|
extendsInstrument(DuoSynth);
|
2014-09-09 19:30:36 +00:00
|
|
|
});
|
2014-10-13 21:15:58 +00:00
|
|
|
|
|
|
|
it("handles output connections", function(){
|
|
|
|
var ds = new DuoSynth();
|
|
|
|
Test.acceptsOutput(ds);
|
|
|
|
ds.dispose();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("outputs a sound", function(done){
|
|
|
|
var ds;
|
|
|
|
Test.outputsAudio(function(dest){
|
|
|
|
ds = new DuoSynth();
|
|
|
|
ds.connect(dest);
|
|
|
|
ds.triggerAttack("C4");
|
|
|
|
}, function(){
|
|
|
|
ds.dispose();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2014-09-09 19:30:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe("Tone.FMSynth", function(){
|
|
|
|
it("can be created and disposed", function(){
|
|
|
|
var fms = new FMSynth();
|
|
|
|
fms.dispose();
|
2014-09-20 23:24:25 +00:00
|
|
|
Test.wasDisposed(fms);
|
|
|
|
});
|
2014-10-13 21:15:58 +00:00
|
|
|
|
2014-09-20 23:24:25 +00:00
|
|
|
it("extends Instrument", function(){
|
|
|
|
extendsInstrument(FMSynth);
|
2014-09-09 19:30:36 +00:00
|
|
|
});
|
2014-10-13 21:15:58 +00:00
|
|
|
|
|
|
|
it("handles output connections", function(){
|
|
|
|
var fms = new FMSynth();
|
|
|
|
Test.acceptsOutput(fms);
|
|
|
|
fms.dispose();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("outputs a sound", function(done){
|
|
|
|
var fms;
|
|
|
|
Test.outputsAudio(function(dest){
|
|
|
|
fms = new FMSynth();
|
|
|
|
fms.connect(dest);
|
|
|
|
fms.triggerAttack("C4");
|
|
|
|
}, function(){
|
|
|
|
fms.dispose();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2014-09-09 19:30:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe("Tone.PolySynth", function(){
|
|
|
|
it("can be created and disposed", function(){
|
|
|
|
var ps = new PolySynth();
|
|
|
|
ps.dispose();
|
2014-09-20 23:24:25 +00:00
|
|
|
Test.wasDisposed(ps);
|
|
|
|
});
|
2014-10-13 21:15:58 +00:00
|
|
|
|
2014-09-20 23:24:25 +00:00
|
|
|
it("extends Instrument", function(){
|
|
|
|
extendsInstrument(PolySynth);
|
2014-09-09 19:30:36 +00:00
|
|
|
});
|
2014-09-20 23:24:25 +00:00
|
|
|
|
2014-10-13 21:15:58 +00:00
|
|
|
it("handles output connections", function(){
|
|
|
|
var psynth = new PolySynth();
|
|
|
|
Test.acceptsOutput(psynth);
|
|
|
|
psynth.dispose();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("outputs a sound", function(done){
|
|
|
|
var psynth;
|
|
|
|
Test.outputsAudio(function(dest){
|
|
|
|
psynth = new PolySynth();
|
|
|
|
psynth.connect(dest);
|
|
|
|
psynth.triggerAttack("C4");
|
|
|
|
}, function(){
|
|
|
|
psynth.dispose();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2014-10-19 20:17:40 +00:00
|
|
|
|
|
|
|
it("accepts a chord", function(done){
|
|
|
|
var psynth;
|
|
|
|
Test.outputsAudio(function(dest){
|
|
|
|
psynth = new PolySynth(4, DuoSynth);
|
|
|
|
psynth.connect(dest);
|
|
|
|
psynth.triggerAttackRelease(["C4", "E4", "G4"], "8n");
|
|
|
|
}, function(){
|
|
|
|
psynth.dispose();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2014-09-09 19:30:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe("Tone.Sampler", function(){
|
|
|
|
it("can be created and disposed", function(){
|
|
|
|
var samp = new Sampler();
|
|
|
|
samp.dispose();
|
2014-09-20 23:24:25 +00:00
|
|
|
Test.wasDisposed(samp);
|
|
|
|
});
|
2014-10-13 21:15:58 +00:00
|
|
|
|
2014-09-20 23:24:25 +00:00
|
|
|
it("extends Instrument", function(){
|
|
|
|
extendsInstrument(Sampler);
|
2014-09-09 19:30:36 +00:00
|
|
|
});
|
2014-10-13 21:15:58 +00:00
|
|
|
|
|
|
|
it("handles output connections", function(){
|
|
|
|
var samp = new Sampler();
|
|
|
|
Test.acceptsOutput(samp);
|
|
|
|
samp.dispose();
|
|
|
|
});
|
2015-01-06 03:00:48 +00:00
|
|
|
|
|
|
|
it("flattens a nested object of samples", function(done){
|
|
|
|
var samp = new Sampler({
|
|
|
|
"A" : {
|
|
|
|
"1" : "./testAudio/kick.mp3"
|
|
|
|
},
|
|
|
|
"B" : "./testAudio/hh.mp3"
|
|
|
|
});
|
|
|
|
Buffer.onload = function(){
|
|
|
|
samp.setSample("A.1");
|
|
|
|
samp.dispose();
|
|
|
|
done();
|
|
|
|
};
|
|
|
|
});
|
2014-09-09 19:30:36 +00:00
|
|
|
});
|
|
|
|
|
2014-09-20 23:24:25 +00:00
|
|
|
describe("Tone.PluckSynth", function(){
|
|
|
|
it("can be created and disposed", function(){
|
|
|
|
var pluck = new PluckSynth();
|
|
|
|
pluck.dispose();
|
|
|
|
Test.wasDisposed(pluck);
|
|
|
|
});
|
2014-10-13 21:15:58 +00:00
|
|
|
|
2014-09-20 23:24:25 +00:00
|
|
|
it("extends Instrument", function(){
|
|
|
|
extendsInstrument(PluckSynth);
|
2014-09-09 19:30:36 +00:00
|
|
|
});
|
2014-10-13 21:15:58 +00:00
|
|
|
|
|
|
|
it("handles output connections", function(){
|
|
|
|
var psynth = new PluckSynth();
|
|
|
|
Test.acceptsOutput(psynth);
|
|
|
|
psynth.dispose();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("outputs a sound", function(done){
|
|
|
|
var psynth;
|
|
|
|
Test.outputsAudio(function(dest){
|
|
|
|
psynth = new PluckSynth();
|
|
|
|
psynth.connect(dest);
|
|
|
|
psynth.triggerAttack("C4");
|
|
|
|
}, function(){
|
|
|
|
psynth.dispose();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2014-09-09 19:30:36 +00:00
|
|
|
});
|
2014-11-03 16:43:42 +00:00
|
|
|
|
|
|
|
describe("Tone.AMSynth", function(){
|
|
|
|
it("can be created and disposed", function(){
|
|
|
|
var ams = new AMSynth();
|
|
|
|
ams.dispose();
|
|
|
|
Test.wasDisposed(ams);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("extends Instrument", function(){
|
|
|
|
extendsInstrument(AMSynth);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("handles output connections", function(){
|
|
|
|
var ams = new AMSynth();
|
|
|
|
Test.acceptsOutput(ams);
|
|
|
|
ams.dispose();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("outputs a sound", function(done){
|
|
|
|
var ams;
|
|
|
|
Test.outputsAudio(function(dest){
|
|
|
|
ams = new AMSynth();
|
|
|
|
ams.connect(dest);
|
|
|
|
ams.triggerAttack("C4");
|
|
|
|
}, function(){
|
|
|
|
ams.dispose();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2014-11-30 03:03:28 +00:00
|
|
|
|
|
|
|
describe("Tone.NoiseSynth", function(){
|
|
|
|
it("can be created and disposed", function(){
|
|
|
|
var noiseSynth = new NoiseSynth();
|
|
|
|
noiseSynth.dispose();
|
|
|
|
Test.wasDisposed(noiseSynth);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("extends Instrument", function(){
|
|
|
|
extendsInstrument(NoiseSynth);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("handles output connections", function(){
|
|
|
|
var noiseSynth = new NoiseSynth();
|
|
|
|
Test.acceptsOutput(noiseSynth);
|
|
|
|
noiseSynth.dispose();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("outputs a sound", function(done){
|
|
|
|
var noiseSynth;
|
|
|
|
Test.outputsAudio(function(dest){
|
|
|
|
noiseSynth = new NoiseSynth();
|
|
|
|
noiseSynth.connect(dest);
|
|
|
|
noiseSynth.triggerAttack();
|
|
|
|
}, function(){
|
|
|
|
noiseSynth.dispose();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2014-09-09 19:30:36 +00:00
|
|
|
});
|