Skip to content

Commit

Permalink
don't invoke onload when setting a loaded buffer
Browse files Browse the repository at this point in the history
addresses #382 and #376
  • Loading branch information
tambien committed Aug 31, 2018
1 parent e754799 commit 34e2605
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions Tone/core/Buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,12 @@ define(["../core/Tone", "../core/Emitter", "../type/Type", "../shim/AudioBuffer"
* @type {Function}
* @private
*/
this._onload = Tone.noOp;
this.onload = Tone.noOp;

if (options.url instanceof AudioBuffer || options.url instanceof Tone.Buffer){
this.set(options.url);
// setup the onload callback if it's not loaded yet
if (!this.loaded){
this._onload = options.onload;
this.onload = options.onload;
}
} else if (Tone.isString(options.url)){
this.load(options.url).then(options.onload).catch(options.onerror);
Expand Down Expand Up @@ -92,12 +91,14 @@ define(["../core/Tone", "../core/Emitter", "../type/Type", "../shim/AudioBuffer"
*/
Tone.Buffer.prototype.set = function(buffer){
if (buffer instanceof Tone.Buffer){
//if it's loaded, set it
if (buffer.loaded){
this._buffer = buffer.get();
} else {
buffer._onload = function(){
//otherwise when it's loaded, invoke it's callback
buffer.onload = function(){
this.set(buffer);
this._onload(this);
this.onload(this);
}.bind(this);
}
} else {
Expand Down Expand Up @@ -133,7 +134,7 @@ define(["../core/Tone", "../core/Emitter", "../type/Type", "../shim/AudioBuffer"
this._xhr = null;
this.set(buff);
load(this);
this._onload(this);
this.onload(this);
if (onload){
onload(this);
}
Expand Down

0 comments on commit 34e2605

Please sign in to comment.