mirror of
https://github.com/Tonejs/Tone.js
synced 2025-01-09 18:38:46 +00:00
27 lines
623 B
JavaScript
27 lines
623 B
JavaScript
|
// Adds the register preload method to Tone.js
|
||
|
// simply include this after Tone.js and p5.js
|
||
|
|
||
|
if (!Tone && !p5){
|
||
|
throw new Error("p5.js and Tone.js need to be loaded first");
|
||
|
}
|
||
|
|
||
|
(function(){
|
||
|
Tone.registeredPreload = function(callback){
|
||
|
return function(){
|
||
|
callback();
|
||
|
};
|
||
|
};
|
||
|
|
||
|
var originalToneBufferLoad = Tone.Buffer.load;
|
||
|
|
||
|
//overwrite load function
|
||
|
Tone.Buffer.load = function (url, callback) {
|
||
|
var handle = Tone.registeredPreload();
|
||
|
return originalToneBufferLoad(url).then(function(buffer){
|
||
|
handle();
|
||
|
callback(buffer);
|
||
|
});
|
||
|
};
|
||
|
|
||
|
p5.prototype.registerPreloadMethod("registeredPreload", Tone);
|
||
|
}());
|