2019-01-27 18:05:20 +00:00
|
|
|
import Test from "helper/Test";
|
|
|
|
import Buffers from "Tone/core/Buffers";
|
|
|
|
import Buffer from "Tone/core/Buffer";
|
|
|
|
|
|
|
|
var testFile = "./audio/sine.wav";
|
|
|
|
var testFile2 = "./audio/hh.wav";
|
|
|
|
|
|
|
|
describe("Buffers", function(){
|
|
|
|
it("can be created and disposed", function(){
|
|
|
|
var buff = new Buffers(testFile);
|
|
|
|
buff.dispose();
|
|
|
|
Test.wasDisposed(buff);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("loads a file from an object string", function(done){
|
|
|
|
var buffer = new Buffers({
|
|
|
|
"sine" : testFile
|
|
|
|
}, function(buff){
|
|
|
|
expect(buff).to.be.instanceof(Buffers);
|
|
|
|
buffer.dispose();
|
|
|
|
done();
|
2016-06-14 23:57:01 +00:00
|
|
|
});
|
2019-01-27 18:05:20 +00:00
|
|
|
});
|
2016-06-14 23:57:01 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
it("loads a file from an array", function(done){
|
|
|
|
var buffer = new Buffers([testFile], function(buff){
|
|
|
|
expect(buff).to.be.instanceof(Buffers);
|
|
|
|
buffer.dispose();
|
|
|
|
done();
|
2016-06-14 23:57:01 +00:00
|
|
|
});
|
2019-01-27 18:05:20 +00:00
|
|
|
});
|
2016-06-14 23:57:01 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
it("can get a buffer loaded from an object", function(done){
|
|
|
|
var buffer = new Buffers({
|
|
|
|
"sine" : testFile,
|
|
|
|
"kick" : testFile2
|
|
|
|
}, function(buff){
|
|
|
|
expect(buff.get("kick")).to.be.instanceof(Buffer);
|
|
|
|
buffer.dispose();
|
|
|
|
done();
|
2016-06-14 23:57:01 +00:00
|
|
|
});
|
2019-01-27 18:05:20 +00:00
|
|
|
});
|
2016-06-14 23:57:01 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
it("tests if it has a buffer", function(done){
|
|
|
|
var buffer = new Buffers({
|
|
|
|
"sine" : testFile,
|
|
|
|
"kick" : testFile2
|
|
|
|
}, function(buff){
|
|
|
|
expect(buffer.has("kick")).to.be.true;
|
|
|
|
expect(buffer.has("sine")).to.be.true;
|
|
|
|
expect(buffer.has("nope")).to.be.false;
|
|
|
|
buffer.dispose();
|
|
|
|
done();
|
2016-06-14 23:57:01 +00:00
|
|
|
});
|
2019-01-27 18:05:20 +00:00
|
|
|
});
|
2016-06-14 23:57:01 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
it("can pass in buffers as object and options object in second arg", function(done){
|
|
|
|
var buffer = new Buffers({
|
|
|
|
"sine" : "sine.wav"
|
|
|
|
}, {
|
|
|
|
"onload" : function(){
|
2016-08-19 22:03:11 +00:00
|
|
|
expect(buffer.has("sine")).to.be.true;
|
|
|
|
buffer.dispose();
|
|
|
|
done();
|
2019-01-27 18:05:20 +00:00
|
|
|
},
|
|
|
|
"baseUrl" : "./audio/"
|
2016-08-19 22:03:11 +00:00
|
|
|
});
|
2019-01-27 18:05:20 +00:00
|
|
|
});
|
2016-08-19 22:03:11 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
it("reports itself as loaded", function(done){
|
|
|
|
var buffer = new Buffers({
|
|
|
|
"sine" : testFile,
|
|
|
|
"kick" : testFile2
|
|
|
|
}, function(buff){
|
|
|
|
expect(buffer.loaded).to.be.true;
|
|
|
|
buffer.dispose();
|
|
|
|
done();
|
2017-05-14 02:16:05 +00:00
|
|
|
});
|
2019-01-27 18:05:20 +00:00
|
|
|
expect(buffer.loaded).to.be.false;
|
|
|
|
});
|
2017-05-14 02:16:05 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
it("can get a buffer loaded from an array", function(done){
|
|
|
|
var buffer = new Buffers([testFile, testFile2], function(buff){
|
|
|
|
expect(buff.get(0)).to.be.instanceof(Buffer);
|
|
|
|
expect(buff.get(1)).to.be.instanceof(Buffer);
|
|
|
|
buffer.dispose();
|
|
|
|
done();
|
2016-08-19 22:03:11 +00:00
|
|
|
});
|
2019-01-27 18:05:20 +00:00
|
|
|
});
|
2016-08-19 22:03:11 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
it("can load from a base url", function(done){
|
|
|
|
var buffer = new Buffers(["hh.wav"], function(buff){
|
|
|
|
expect(buff.get(0)).to.be.instanceof(Buffer);
|
|
|
|
buffer.dispose();
|
|
|
|
done();
|
|
|
|
}, "./audio/");
|
|
|
|
});
|
2016-06-14 23:57:01 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
it("can add a buffer", function(done){
|
|
|
|
var buffer = new Buffers();
|
|
|
|
buffer.add("name", testFile, function(){
|
|
|
|
expect(buffer.get("name")).to.be.instanceof(Buffer);
|
|
|
|
buffer.dispose();
|
|
|
|
done();
|
2016-06-14 23:57:01 +00:00
|
|
|
});
|
2019-01-27 18:05:20 +00:00
|
|
|
});
|
2016-06-14 23:57:01 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
it("can add a buffer url", function(done){
|
|
|
|
var buffer = new Buffers();
|
|
|
|
buffer.add("name", testFile, function(){
|
|
|
|
expect(buffer.get("name")).to.be.instanceof(Buffer);
|
|
|
|
buffer.dispose();
|
|
|
|
done();
|
2016-06-14 23:57:01 +00:00
|
|
|
});
|
2019-01-27 18:05:20 +00:00
|
|
|
});
|
2016-06-14 23:57:01 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
it("throws an error if no buffer exists with that name or index", function(){
|
|
|
|
var buffer = new Buffers();
|
|
|
|
expect(function(){
|
|
|
|
buffer.get("nope");
|
|
|
|
}).to.throw(Error);
|
|
|
|
buffer.dispose();
|
|
|
|
});
|
2016-06-14 23:57:01 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
it("can add a Tone.Buffer", function(){
|
|
|
|
var buff = new Buffer();
|
|
|
|
var buffer = new Buffers();
|
|
|
|
buffer.add("name", buff);
|
|
|
|
expect(buffer.get("name")).to.equal(buff);
|
|
|
|
});
|
2017-06-19 21:11:44 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
it("can add an AudioBuffer", function(done){
|
|
|
|
Buffer.load(testFile, function(buff){
|
2016-06-14 23:57:01 +00:00
|
|
|
var buffer = new Buffers();
|
|
|
|
buffer.add("name", buff);
|
2019-01-27 18:05:20 +00:00
|
|
|
expect(buffer.get("name").get()).to.equal(buff);
|
|
|
|
done();
|
2017-06-19 21:11:44 +00:00
|
|
|
});
|
2019-01-27 18:05:20 +00:00
|
|
|
});
|
2017-06-19 21:11:44 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
it("can be constructed with Tone.Buffers", function(){
|
|
|
|
var buff = new Buffer();
|
|
|
|
var buffer = new Buffers({
|
|
|
|
"buff" : buff
|
2016-06-14 23:57:01 +00:00
|
|
|
});
|
2019-01-27 18:05:20 +00:00
|
|
|
expect(buffer.get("buff")).to.equal(buff);
|
2016-06-14 23:57:01 +00:00
|
|
|
});
|
2019-01-27 18:05:20 +00:00
|
|
|
|
2017-12-30 16:26:29 +00:00
|
|
|
});
|
2019-01-27 18:05:20 +00:00
|
|
|
|