From a80ae0656bcc64be80d056f27d25d8142ebb432c Mon Sep 17 00:00:00 2001 From: Yotam Mann Date: Mon, 5 Mar 2018 11:32:08 -0500 Subject: [PATCH] Tone.isDefined replaces !Tone.isUndef --- Tone/core/AudioNode.js | 4 +-- Tone/core/Param.js | 2 +- Tone/core/Tone.js | 63 ++++++++++++++++++++++--------------- Tone/core/Transport.js | 2 +- Tone/event/Event.js | 2 +- Tone/event/Part.js | 6 ++-- Tone/event/Sequence.js | 4 +-- Tone/source/BufferSource.js | 2 +- Tone/source/TickSource.js | 2 +- Tone/source/UserMedia.js | 4 +-- Tone/type/TimeBase.js | 2 +- 11 files changed, 52 insertions(+), 41 deletions(-) diff --git a/Tone/core/AudioNode.js b/Tone/core/AudioNode.js index 216f0fc3..8c0607c1 100644 --- a/Tone/core/AudioNode.js +++ b/Tone/core/AudioNode.js @@ -246,13 +246,13 @@ define(["Tone/core/Tone", "Tone/core/Context"], function(Tone) { * @return {Tone.AudioNode} this */ Tone.AudioNode.prototype.dispose = function() { - if (!Tone.isUndef(this.input)){ + if (Tone.isDefined(this.input)){ if (this.input instanceof AudioNode){ this.input.disconnect(); } this.input = null; } - if (!Tone.isUndef(this.output)){ + if (Tone.isDefined(this.output)){ if (this.output instanceof AudioNode){ this.output.disconnect(); } diff --git a/Tone/core/Param.js b/Tone/core/Param.js index 495b726a..31108892 100644 --- a/Tone/core/Param.js +++ b/Tone/core/Param.js @@ -52,7 +52,7 @@ define(["Tone/core/Tone", "Tone/type/Type", "Tone/core/AudioNode", "Tone/core/Ti */ this._events = new Tone.Timeline(1000); - if (!Tone.isUndef(options.value) && this._param){ + if (Tone.isDefined(options.value) && this._param){ this.value = options.value; } }; diff --git a/Tone/core/Tone.js b/Tone/core/Tone.js index 4c57d1be..24ba12fb 100644 --- a/Tone/core/Tone.js +++ b/Tone/core/Tone.js @@ -2,7 +2,7 @@ * Tone.js * @author Yotam Mann * @license http://opensource.org/licenses/MIT MIT License - * @copyright 2014-2017 Yotam Mann + * @copyright 2014-2018 Yotam Mann */ define(function(){ @@ -24,7 +24,7 @@ define(function(){ /** * @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(){ for (var className in Tone){ @@ -57,8 +57,8 @@ define(function(){ * The last argument is an optional ramp time which * will ramp any signal values to their destination value * over the duration of the rampTime. - * @param {Object|string} params - * @param {number=} value + * @param {Object|String} params + * @param {Number=} value * @param {Time=} rampTime * @returns {Tone} this * @memberOf Tone# @@ -183,7 +183,7 @@ define(function(){ subRet[attr] = param.value; } else if (param instanceof Tone){ subRet[attr] = param.get(); - } else if (!Tone.isFunction(param) && !Tone.isUndef(param)){ + } else if (!Tone.isFunction(param) && Tone.isDefined(param)){ subRet[attr] = param; } } @@ -193,15 +193,15 @@ define(function(){ /** * collect all of the default attributes in one * @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 */ Tone.prototype._collectDefaults = function(constr){ var ret = []; - if (!Tone.isUndef(constr.defaults)){ + if (Tone.isDefined(constr.defaults)){ ret = Object.keys(constr.defaults); } - if (!Tone.isUndef(constr._super)){ + if (Tone.isDefined(constr._super)){ var superDefs = this._collectDefaults(constr._super); //filter out repeats for (var i = 0; i < superDefs.length; i++){ @@ -234,7 +234,7 @@ define(function(){ options[keys[i]] = values[i]; } } - if (!Tone.isUndef(constr.defaults)){ + if (Tone.isDefined(constr.defaults)){ return Tone.defaultArg(options, constr.defaults); } else if (Tone.isObject(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 - * @returns {boolean} true if the arg is undefined + * @returns {Boolean} true if the arg is undefined * @static * @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 - * @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 * @memberOf Tone */ @@ -323,7 +334,7 @@ define(function(){ /** * Test if the argument is a number. * @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 * @memberOf Tone */ @@ -334,7 +345,7 @@ define(function(){ /** * Test if the given argument is an object literal (i.e. `{}`); * @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 * @memberOf Tone */ @@ -345,7 +356,7 @@ define(function(){ /** * Test if the argument is a boolean. * @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 * @memberOf Tone */ @@ -356,7 +367,7 @@ define(function(){ /** * Test if the argument is an Array * @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 * @memberOf Tone */ @@ -367,7 +378,7 @@ define(function(){ /** * Test if the argument is a string. * @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 * @memberOf Tone */ @@ -379,7 +390,7 @@ define(function(){ * Test if the argument is in the form of a note in scientific pitch notation. * e.g. "C4" * @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 * @memberOf Tone */ @@ -396,7 +407,7 @@ define(function(){ /** * Make the property not writable. Internal use only. * @private - * @param {string} property the property to make not writable + * @param {String} property the property to make not writable */ Tone.prototype._readOnly = function(property){ if (Array.isArray(property)){ @@ -414,7 +425,7 @@ define(function(){ /** * Make an attribute writeable. Interal use only. * @private - * @param {string} property the property to make writable + * @param {String} property the property to make writable */ Tone.prototype._writable = function(property){ if (Array.isArray(property)){ @@ -430,7 +441,7 @@ define(function(){ /** * Possible play states. - * @enum {string} + * @enum {String} */ Tone.State = { Started : "started", @@ -479,7 +490,7 @@ define(function(){ /** * Convert an interval (in semitones) to a frequency ratio. * @param {Interval} interval the number of semitones above the base note - * @return {number} the frequency ratio + * @return {Number} the frequency ratio * @static * @memberOf Tone * @example @@ -527,8 +538,8 @@ define(function(){ * * @memberOf Tone * @static - * @param {function} child - * @param {function=} parent (optional) parent to inherit from + * @param {Function} child + * @param {Function=} parent (optional) parent to inherit from * if no parent is supplied, the child * will inherit from Tone */ @@ -652,7 +663,7 @@ define(function(){ */ Object.defineProperty(Tone, "initialized", { get : function(){ - return !Tone.isUndef(window.TONE_AUDIO_CONTEXT); + return Tone.isDefined(window.TONE_AUDIO_CONTEXT); } }); diff --git a/Tone/core/Transport.js b/Tone/core/Transport.js index 95fd4a3e..57347083 100644 --- a/Tone/core/Transport.js +++ b/Tone/core/Transport.js @@ -374,7 +374,7 @@ define(["Tone/core/Tone", "Tone/core/Clock", "Tone/type/Type", "Tone/core/Timeli */ Tone.Transport.prototype.start = function(time, offset){ //start the clock - if (!Tone.isUndef(offset)){ + if (Tone.isDefined(offset)){ offset = this.toTicks(offset); } this._clock.start(time, offset); diff --git a/Tone/event/Event.js b/Tone/event/Event.js index 1122a72d..40607dce 100644 --- a/Tone/event/Event.js +++ b/Tone/event/Event.js @@ -141,7 +141,7 @@ define(["Tone/core/Tone", "Tone/core/Transport", "Tone/type/Type", "Tone/core/Ti this._state.forEachFrom(after, function(event){ var duration; if (event.state === Tone.State.Started){ - if (!Tone.isUndef(event.id)){ + if (Tone.isDefined(event.id)){ Tone.Transport.clear(event.id); } var startTick = event.time + Math.round(this.startOffset / this._playbackRate); diff --git a/Tone/event/Part.js b/Tone/event/Part.js index bfbf7160..4c9a6df3 100644 --- a/Tone/event/Part.js +++ b/Tone/event/Part.js @@ -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++){ var event = this._events[i]; if (Math.abs(time.toTicks() - event.startOffset) < tickTime){ - if (!Tone.isUndef(value)){ + if (Tone.isDefined(value)){ event.value = value; } return event; } } //if there was no event at that time, create one - if (!Tone.isUndef(value)){ + if (Tone.isDefined(value)){ this.add(time, value); //return the new event 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){ event.remove(time, value); } 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); event.dispose(); } diff --git a/Tone/event/Sequence.js b/Tone/event/Sequence.js index f00fd013..cb05db31 100644 --- a/Tone/event/Sequence.js +++ b/Tone/event/Sequence.js @@ -42,14 +42,14 @@ define(["Tone/core/Tone", "Tone/event/Part", "Tone/core/Transport"], function(To this._subdivision = this.toTicks(options.subdivision); //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); } //defaults to looping this._loop = true; //add all of the events - if (!Tone.isUndef(events)){ + if (Tone.isDefined(events)){ for (var i = 0; i < events.length; i++){ this.add(i, events[i]); } diff --git a/Tone/source/BufferSource.js b/Tone/source/BufferSource.js index b9a216bd..e5322182 100644 --- a/Tone/source/BufferSource.js +++ b/Tone/source/BufferSource.js @@ -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))); computedDur = Math.max(computedDur, 0); - if (!Tone.isUndef(duration)){ + if (Tone.isDefined(duration)){ //clip the duration when not looping if (!this.loop){ computedDur = Math.min(computedDur, this.buffer.duration - (offset % this.buffer.duration)); diff --git a/Tone/source/TickSource.js b/Tone/source/TickSource.js index 6f586c01..3c6d8213 100644 --- a/Tone/source/TickSource.js +++ b/Tone/source/TickSource.js @@ -76,7 +76,7 @@ define(["Tone/core/Tone", "Tone/signal/TickSignal", "Tone/core/TimelineState", time = this.toSeconds(time); if (this._state.getValueAtTime(time) !== Tone.State.Started){ this._state.setStateAtTime(Tone.State.Started, time); - if (!Tone.isUndef(offset)){ + if (Tone.isDefined(offset)){ this.setTicksAtTime(offset, time); } } diff --git a/Tone/source/UserMedia.js b/Tone/source/UserMedia.js index d535a639..f13295a3 100644 --- a/Tone/source/UserMedia.js +++ b/Tone/source/UserMedia.js @@ -99,7 +99,7 @@ define(["Tone/core/Tone", "Tone/component/Volume", "Tone/core/AudioNode"], funct //didn't find a matching device if (!device && devices.length > 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); } } @@ -273,7 +273,7 @@ define(["Tone/core/Tone", "Tone/component/Volume", "Tone/core/AudioNode"], funct */ Object.defineProperty(Tone.UserMedia, "supported", { get : function(){ - return !Tone.isUndef(navigator.mediaDevices) && Tone.isFunction(navigator.mediaDevices.getUserMedia); + return Tone.isDefined(navigator.mediaDevices) && Tone.isFunction(navigator.mediaDevices.getUserMedia); } }); diff --git a/Tone/type/TimeBase.js b/Tone/type/TimeBase.js index 5c7f303f..da12eb43 100644 --- a/Tone/type/TimeBase.js +++ b/Tone/type/TimeBase.js @@ -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 matching = this._val.toString().trim().match(expr.regexp); if (matching){