Tone.js/gulp/fragments/p5-after.frag

35 lines
1 KiB
GLSL
Raw Normal View History

2015-08-18 16:53:06 +00:00
///////////////////////////////////////////////////////////////////////////
2016-03-24 15:41:02 +00:00
// P5 PRELOAD SHIM
2015-08-18 16:53:06 +00:00
///////////////////////////////////////////////////////////////////////////
Tone.registeredPreload = function(callback){
return function(){
callback();
}
};
//overwrite load function
Tone.Buffer.load = function (url, callback) {
var handle = Tone.registeredPreload();
var request = new XMLHttpRequest();
2015-09-29 00:58:38 +00:00
request.open("GET", url, true);
request.responseType = "arraybuffer";
2015-08-18 16:53:06 +00:00
// decode asynchronously
request.onload = function () {
Tone.context.decodeAudioData(request.response, function (buff) {
if (!buff) {
2015-09-29 00:58:38 +00:00
throw new Error("could not decode audio data:" + url);
2015-08-18 16:53:06 +00:00
}
callback(buff);
handle();
});
};
//send the request
request.send();
return request;
};
p5.prototype.registerPreloadMethod("registeredPreload", Tone);
2016-03-24 15:41:02 +00:00
return Tone
}));