no longer throws error when no buffer is set

just doesn’t play instead
This commit is contained in:
Yotam Mann 2016-08-09 01:14:21 -04:00
parent 438abe481a
commit 9a74728858

View file

@ -121,10 +121,7 @@ define(["Tone/core/Tone", "Tone/core/Buffer", "Tone/source/Source"], function (T
throw new Error("Tone.BufferSource: can only be started once."); throw new Error("Tone.BufferSource: can only be started once.");
} }
if (!this.buffer){ if (this.buffer){
throw new Error("Tone.BufferSource: no buffer set.");
}
time = this.toSeconds(time); time = this.toSeconds(time);
//if it's a loop the default offset is the loopstart point //if it's a loop the default offset is the loopstart point
if (this.loop){ if (this.loop){
@ -163,6 +160,7 @@ define(["Tone/core/Tone", "Tone/core/Buffer", "Tone/source/Source"], function (T
duration = this.toSeconds(duration); duration = this.toSeconds(duration);
this.stop(time + duration + fadeInTime, fadeInTime); this.stop(time + duration + fadeInTime, fadeInTime);
} }
}
return this; return this;
}; };
@ -175,9 +173,7 @@ define(["Tone/core/Tone", "Tone/core/Buffer", "Tone/source/Source"], function (T
* @return {Tone.BufferSource} this * @return {Tone.BufferSource} this
*/ */
Tone.BufferSource.prototype.stop = function(time, fadeOutTime){ Tone.BufferSource.prototype.stop = function(time, fadeOutTime){
if (!this.buffer){ if (this.buffer){
throw new Error("Tone.BufferSource: no buffer set.");
}
time = this.toSeconds(time); time = this.toSeconds(time);
@ -200,6 +196,7 @@ define(["Tone/core/Tone", "Tone/core/Buffer", "Tone/source/Source"], function (T
this._gainNode.gain.setValueAtTime(0, time); this._gainNode.gain.setValueAtTime(0, time);
} }
this._source.stop(time); this._source.stop(time);
}
return this; return this;
}; };
@ -252,7 +249,11 @@ define(["Tone/core/Tone", "Tone/core/Buffer", "Tone/source/Source"], function (T
*/ */
Object.defineProperty(Tone.BufferSource.prototype, "buffer", { Object.defineProperty(Tone.BufferSource.prototype, "buffer", {
get : function(){ get : function(){
if (this._source){
return this._source.buffer; return this._source.buffer;
} else {
return null;
}
}, },
set : function(buffer){ set : function(buffer){
if (buffer instanceof Tone.Buffer){ if (buffer instanceof Tone.Buffer){