Tone.isDefined replaces !Tone.isUndef

This commit is contained in:
Yotam Mann 2018-03-05 11:32:08 -05:00
parent 64fe046996
commit a80ae0656b
11 changed files with 52 additions and 41 deletions

View file

@ -246,13 +246,13 @@ define(["Tone/core/Tone", "Tone/core/Context"], function(Tone) {
* @return {Tone.AudioNode} this * @return {Tone.AudioNode} this
*/ */
Tone.AudioNode.prototype.dispose = function() { Tone.AudioNode.prototype.dispose = function() {
if (!Tone.isUndef(this.input)){ if (Tone.isDefined(this.input)){
if (this.input instanceof AudioNode){ if (this.input instanceof AudioNode){
this.input.disconnect(); this.input.disconnect();
} }
this.input = null; this.input = null;
} }
if (!Tone.isUndef(this.output)){ if (Tone.isDefined(this.output)){
if (this.output instanceof AudioNode){ if (this.output instanceof AudioNode){
this.output.disconnect(); this.output.disconnect();
} }

View file

@ -52,7 +52,7 @@ define(["Tone/core/Tone", "Tone/type/Type", "Tone/core/AudioNode", "Tone/core/Ti
*/ */
this._events = new Tone.Timeline(1000); this._events = new Tone.Timeline(1000);
if (!Tone.isUndef(options.value) && this._param){ if (Tone.isDefined(options.value) && this._param){
this.value = options.value; this.value = options.value;
} }
}; };

View file

@ -2,7 +2,7 @@
* Tone.js * Tone.js
* @author Yotam Mann * @author Yotam Mann
* @license http://opensource.org/licenses/MIT MIT License * @license http://opensource.org/licenses/MIT MIT License
* @copyright 2014-2017 Yotam Mann * @copyright 2014-2018 Yotam Mann
*/ */
define(function(){ define(function(){
@ -24,7 +24,7 @@ define(function(){
/** /**
* @memberOf Tone# * @memberOf Tone#
* @returns {string} returns the name of the class as a string * @returns {String} returns the name of the class as a string
*/ */
Tone.prototype.toString = function(){ Tone.prototype.toString = function(){
for (var className in Tone){ for (var className in Tone){
@ -57,8 +57,8 @@ define(function(){
* The last argument is an optional ramp time which * The last argument is an optional ramp time which
* will ramp any signal values to their destination value * will ramp any signal values to their destination value
* over the duration of the rampTime. * over the duration of the rampTime.
* @param {Object|string} params * @param {Object|String} params
* @param {number=} value * @param {Number=} value
* @param {Time=} rampTime * @param {Time=} rampTime
* @returns {Tone} this * @returns {Tone} this
* @memberOf Tone# * @memberOf Tone#
@ -183,7 +183,7 @@ define(function(){
subRet[attr] = param.value; subRet[attr] = param.value;
} else if (param instanceof Tone){ } else if (param instanceof Tone){
subRet[attr] = param.get(); subRet[attr] = param.get();
} else if (!Tone.isFunction(param) && !Tone.isUndef(param)){ } else if (!Tone.isFunction(param) && Tone.isDefined(param)){
subRet[attr] = param; subRet[attr] = param;
} }
} }
@ -193,15 +193,15 @@ define(function(){
/** /**
* collect all of the default attributes in one * collect all of the default attributes in one
* @private * @private
* @param {function} constr the constructor to find the defaults from * @param {Function} constr the constructor to find the defaults from
* @return {Array} all of the attributes which belong to the class * @return {Array} all of the attributes which belong to the class
*/ */
Tone.prototype._collectDefaults = function(constr){ Tone.prototype._collectDefaults = function(constr){
var ret = []; var ret = [];
if (!Tone.isUndef(constr.defaults)){ if (Tone.isDefined(constr.defaults)){
ret = Object.keys(constr.defaults); ret = Object.keys(constr.defaults);
} }
if (!Tone.isUndef(constr._super)){ if (Tone.isDefined(constr._super)){
var superDefs = this._collectDefaults(constr._super); var superDefs = this._collectDefaults(constr._super);
//filter out repeats //filter out repeats
for (var i = 0; i < superDefs.length; i++){ for (var i = 0; i < superDefs.length; i++){
@ -234,7 +234,7 @@ define(function(){
options[keys[i]] = values[i]; options[keys[i]] = values[i];
} }
} }
if (!Tone.isUndef(constr.defaults)){ if (Tone.isDefined(constr.defaults)){
return Tone.defaultArg(options, constr.defaults); return Tone.defaultArg(options, constr.defaults);
} else if (Tone.isObject(constr)){ } else if (Tone.isObject(constr)){
return Tone.defaultArg(options, constr); return Tone.defaultArg(options, constr);
@ -299,9 +299,9 @@ define(function(){
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
/** /**
* test if the arg is undefined * Test if the arg is undefined
* @param {*} arg the argument to test * @param {*} arg the argument to test
* @returns {boolean} true if the arg is undefined * @returns {Boolean} true if the arg is undefined
* @static * @static
* @memberOf Tone * @memberOf Tone
*/ */
@ -310,9 +310,20 @@ define(function(){
}; };
/** /**
* test if the arg is a function * Test if the arg is not undefined
* @param {*} arg the argument to test * @param {*} arg the argument to test
* @returns {boolean} true if the arg is a function * @returns {Boolean} true if the arg is undefined
* @static
* @memberOf Tone
*/
Tone.isDefined = function(val){
return !Tone.isUndef(val);
};
/**
* Test if the arg is a function
* @param {*} arg the argument to test
* @returns {Boolean} true if the arg is a function
* @static * @static
* @memberOf Tone * @memberOf Tone
*/ */
@ -323,7 +334,7 @@ define(function(){
/** /**
* Test if the argument is a number. * Test if the argument is a number.
* @param {*} arg the argument to test * @param {*} arg the argument to test
* @returns {boolean} true if the arg is a number * @returns {Boolean} true if the arg is a number
* @static * @static
* @memberOf Tone * @memberOf Tone
*/ */
@ -334,7 +345,7 @@ define(function(){
/** /**
* Test if the given argument is an object literal (i.e. `{}`); * Test if the given argument is an object literal (i.e. `{}`);
* @param {*} arg the argument to test * @param {*} arg the argument to test
* @returns {boolean} true if the arg is an object literal. * @returns {Boolean} true if the arg is an object literal.
* @static * @static
* @memberOf Tone * @memberOf Tone
*/ */
@ -345,7 +356,7 @@ define(function(){
/** /**
* Test if the argument is a boolean. * Test if the argument is a boolean.
* @param {*} arg the argument to test * @param {*} arg the argument to test
* @returns {boolean} true if the arg is a boolean * @returns {Boolean} true if the arg is a boolean
* @static * @static
* @memberOf Tone * @memberOf Tone
*/ */
@ -356,7 +367,7 @@ define(function(){
/** /**
* Test if the argument is an Array * Test if the argument is an Array
* @param {*} arg the argument to test * @param {*} arg the argument to test
* @returns {boolean} true if the arg is an array * @returns {Boolean} true if the arg is an array
* @static * @static
* @memberOf Tone * @memberOf Tone
*/ */
@ -367,7 +378,7 @@ define(function(){
/** /**
* Test if the argument is a string. * Test if the argument is a string.
* @param {*} arg the argument to test * @param {*} arg the argument to test
* @returns {boolean} true if the arg is a string * @returns {Boolean} true if the arg is a string
* @static * @static
* @memberOf Tone * @memberOf Tone
*/ */
@ -379,7 +390,7 @@ define(function(){
* Test if the argument is in the form of a note in scientific pitch notation. * Test if the argument is in the form of a note in scientific pitch notation.
* e.g. "C4" * e.g. "C4"
* @param {*} arg the argument to test * @param {*} arg the argument to test
* @returns {boolean} true if the arg is a string * @returns {Boolean} true if the arg is a string
* @static * @static
* @memberOf Tone * @memberOf Tone
*/ */
@ -396,7 +407,7 @@ define(function(){
/** /**
* Make the property not writable. Internal use only. * Make the property not writable. Internal use only.
* @private * @private
* @param {string} property the property to make not writable * @param {String} property the property to make not writable
*/ */
Tone.prototype._readOnly = function(property){ Tone.prototype._readOnly = function(property){
if (Array.isArray(property)){ if (Array.isArray(property)){
@ -414,7 +425,7 @@ define(function(){
/** /**
* Make an attribute writeable. Interal use only. * Make an attribute writeable. Interal use only.
* @private * @private
* @param {string} property the property to make writable * @param {String} property the property to make writable
*/ */
Tone.prototype._writable = function(property){ Tone.prototype._writable = function(property){
if (Array.isArray(property)){ if (Array.isArray(property)){
@ -430,7 +441,7 @@ define(function(){
/** /**
* Possible play states. * Possible play states.
* @enum {string} * @enum {String}
*/ */
Tone.State = { Tone.State = {
Started : "started", Started : "started",
@ -479,7 +490,7 @@ define(function(){
/** /**
* Convert an interval (in semitones) to a frequency ratio. * Convert an interval (in semitones) to a frequency ratio.
* @param {Interval} interval the number of semitones above the base note * @param {Interval} interval the number of semitones above the base note
* @return {number} the frequency ratio * @return {Number} the frequency ratio
* @static * @static
* @memberOf Tone * @memberOf Tone
* @example * @example
@ -527,8 +538,8 @@ define(function(){
* *
* @memberOf Tone * @memberOf Tone
* @static * @static
* @param {function} child * @param {Function} child
* @param {function=} parent (optional) parent to inherit from * @param {Function=} parent (optional) parent to inherit from
* if no parent is supplied, the child * if no parent is supplied, the child
* will inherit from Tone * will inherit from Tone
*/ */
@ -652,7 +663,7 @@ define(function(){
*/ */
Object.defineProperty(Tone, "initialized", { Object.defineProperty(Tone, "initialized", {
get : function(){ get : function(){
return !Tone.isUndef(window.TONE_AUDIO_CONTEXT); return Tone.isDefined(window.TONE_AUDIO_CONTEXT);
} }
}); });

View file

@ -374,7 +374,7 @@ define(["Tone/core/Tone", "Tone/core/Clock", "Tone/type/Type", "Tone/core/Timeli
*/ */
Tone.Transport.prototype.start = function(time, offset){ Tone.Transport.prototype.start = function(time, offset){
//start the clock //start the clock
if (!Tone.isUndef(offset)){ if (Tone.isDefined(offset)){
offset = this.toTicks(offset); offset = this.toTicks(offset);
} }
this._clock.start(time, offset); this._clock.start(time, offset);

View file

@ -141,7 +141,7 @@ define(["Tone/core/Tone", "Tone/core/Transport", "Tone/type/Type", "Tone/core/Ti
this._state.forEachFrom(after, function(event){ this._state.forEachFrom(after, function(event){
var duration; var duration;
if (event.state === Tone.State.Started){ if (event.state === Tone.State.Started){
if (!Tone.isUndef(event.id)){ if (Tone.isDefined(event.id)){
Tone.Transport.clear(event.id); Tone.Transport.clear(event.id);
} }
var startTick = event.time + Math.round(this.startOffset / this._playbackRate); var startTick = event.time + Math.round(this.startOffset / this._playbackRate);

View file

@ -175,14 +175,14 @@ define(["Tone/core/Tone", "Tone/event/Event", "Tone/type/Type", "Tone/core/Trans
for (var i = 0; i < this._events.length; i++){ for (var i = 0; i < this._events.length; i++){
var event = this._events[i]; var event = this._events[i];
if (Math.abs(time.toTicks() - event.startOffset) < tickTime){ if (Math.abs(time.toTicks() - event.startOffset) < tickTime){
if (!Tone.isUndef(value)){ if (Tone.isDefined(value)){
event.value = value; event.value = value;
} }
return event; return event;
} }
} }
//if there was no event at that time, create one //if there was no event at that time, create one
if (!Tone.isUndef(value)){ if (Tone.isDefined(value)){
this.add(time, value); this.add(time, value);
//return the new event //return the new event
return this._events[this._events.length - 1]; return this._events[this._events.length - 1];
@ -274,7 +274,7 @@ define(["Tone/core/Tone", "Tone/event/Event", "Tone/type/Type", "Tone/core/Trans
if (event instanceof Tone.Part){ if (event instanceof Tone.Part){
event.remove(time, value); event.remove(time, value);
} else if (event.startOffset === time){ } else if (event.startOffset === time){
if (Tone.isUndef(value) || (!Tone.isUndef(value) && event.value === value)){ if (Tone.isUndef(value) || (Tone.isDefined(value) && event.value === value)){
this._events.splice(i, 1); this._events.splice(i, 1);
event.dispose(); event.dispose();
} }

View file

@ -42,14 +42,14 @@ define(["Tone/core/Tone", "Tone/event/Part", "Tone/core/Transport"], function(To
this._subdivision = this.toTicks(options.subdivision); this._subdivision = this.toTicks(options.subdivision);
//if no time was passed in, the loop end is the end of the cycle //if no time was passed in, the loop end is the end of the cycle
if (Tone.isUndef(options.loopEnd) && !Tone.isUndef(events)){ if (Tone.isUndef(options.loopEnd) && Tone.isDefined(events)){
this._loopEnd = (events.length * this._subdivision); this._loopEnd = (events.length * this._subdivision);
} }
//defaults to looping //defaults to looping
this._loop = true; this._loop = true;
//add all of the events //add all of the events
if (!Tone.isUndef(events)){ if (Tone.isDefined(events)){
for (var i = 0; i < events.length; i++){ for (var i = 0; i < events.length; i++){
this.add(i, events[i]); this.add(i, events[i]);
} }

View file

@ -209,7 +209,7 @@ define(["Tone/core/Tone", "Tone/core/Buffer", "Tone/source/Source", "Tone/core/G
var computedDur = this.toSeconds(Tone.defaultArg(duration, this.buffer.duration - (offset % this.buffer.duration))); var computedDur = this.toSeconds(Tone.defaultArg(duration, this.buffer.duration - (offset % this.buffer.duration)));
computedDur = Math.max(computedDur, 0); computedDur = Math.max(computedDur, 0);
if (!Tone.isUndef(duration)){ if (Tone.isDefined(duration)){
//clip the duration when not looping //clip the duration when not looping
if (!this.loop){ if (!this.loop){
computedDur = Math.min(computedDur, this.buffer.duration - (offset % this.buffer.duration)); computedDur = Math.min(computedDur, this.buffer.duration - (offset % this.buffer.duration));

View file

@ -76,7 +76,7 @@ define(["Tone/core/Tone", "Tone/signal/TickSignal", "Tone/core/TimelineState",
time = this.toSeconds(time); time = this.toSeconds(time);
if (this._state.getValueAtTime(time) !== Tone.State.Started){ if (this._state.getValueAtTime(time) !== Tone.State.Started){
this._state.setStateAtTime(Tone.State.Started, time); this._state.setStateAtTime(Tone.State.Started, time);
if (!Tone.isUndef(offset)){ if (Tone.isDefined(offset)){
this.setTicksAtTime(offset, time); this.setTicksAtTime(offset, time);
} }
} }

View file

@ -99,7 +99,7 @@ define(["Tone/core/Tone", "Tone/component/Volume", "Tone/core/AudioNode"], funct
//didn't find a matching device //didn't find a matching device
if (!device && devices.length > 0){ if (!device && devices.length > 0){
device = devices[0]; device = devices[0];
} else if (!device && !Tone.isUndef(labelOrId)){ } else if (!device && Tone.isDefined(labelOrId)){
throw new Error("Tone.UserMedia: no matching device: "+labelOrId); throw new Error("Tone.UserMedia: no matching device: "+labelOrId);
} }
} }
@ -273,7 +273,7 @@ define(["Tone/core/Tone", "Tone/component/Volume", "Tone/core/AudioNode"], funct
*/ */
Object.defineProperty(Tone.UserMedia, "supported", { Object.defineProperty(Tone.UserMedia, "supported", {
get : function(){ get : function(){
return !Tone.isUndef(navigator.mediaDevices) && Tone.isFunction(navigator.mediaDevices.getUserMedia); return Tone.isDefined(navigator.mediaDevices) && Tone.isFunction(navigator.mediaDevices.getUserMedia);
} }
}); });

View file

@ -283,7 +283,7 @@ define(["Tone/core/Tone"], function(Tone) {
} }
} }
} }
if (!Tone.isUndef(this._units)){ if (Tone.isDefined(this._units)){
var expr = this._expressions[this._units]; var expr = this._expressions[this._units];
var matching = this._val.toString().trim().match(expr.regexp); var matching = this._val.toString().trim().match(expr.regexp);
if (matching){ if (matching){