mirror of
https://github.com/Tonejs/Tone.js
synced 2024-11-15 08:17:07 +00:00
log and assert help in debugging classes
This commit is contained in:
parent
3d92d0fdf8
commit
ebbb1ef8bb
3 changed files with 76 additions and 5 deletions
|
@ -53,7 +53,7 @@ define(["Tone/core/Tone", "Tone/type/Type", "Tone/core/AudioNode", "Tone/core/Ti
|
|||
this._events = new Tone.Timeline(1000);
|
||||
|
||||
if (Tone.isDefined(options.value) && this._param){
|
||||
this.value = options.value;
|
||||
this.setValueAtTime(options.value, 0);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -192,7 +192,8 @@ define(["Tone/core/Tone", "Tone/type/Type", "Tone/core/AudioNode", "Tone/core/Ti
|
|||
Linear : "linearRampToValueAtTime",
|
||||
Exponential : "exponentialRampToValueAtTime",
|
||||
Target : "setTargetAtTime",
|
||||
SetValue : "setValueAtTime"
|
||||
SetValue : "setValueAtTime",
|
||||
Cancel : "cancelScheduledValues"
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -212,6 +213,7 @@ define(["Tone/core/Tone", "Tone/type/Type", "Tone/core/AudioNode", "Tone/core/Ti
|
|||
"value" : value,
|
||||
"time" : time,
|
||||
});
|
||||
this.log(Tone.Param.AutomationType.SetValue, value, time);
|
||||
this._param.setValueAtTime(value, time);
|
||||
return this;
|
||||
};
|
||||
|
@ -287,6 +289,7 @@ define(["Tone/core/Tone", "Tone/type/Type", "Tone/core/AudioNode", "Tone/core/Ti
|
|||
"value" : value,
|
||||
"time" : endTime,
|
||||
});
|
||||
this.log(Tone.Param.AutomationType.Linear, value, endTime);
|
||||
this._param.linearRampToValueAtTime(value, endTime);
|
||||
return this;
|
||||
};
|
||||
|
@ -309,6 +312,7 @@ define(["Tone/core/Tone", "Tone/type/Type", "Tone/core/AudioNode", "Tone/core/Ti
|
|||
"time" : endTime,
|
||||
"value" : value
|
||||
});
|
||||
this.log(Tone.Param.AutomationType.Exponential, value, endTime);
|
||||
this._param.exponentialRampToValueAtTime(value, endTime);
|
||||
return this;
|
||||
};
|
||||
|
@ -416,6 +420,7 @@ define(["Tone/core/Tone", "Tone/type/Type", "Tone/core/AudioNode", "Tone/core/Ti
|
|||
"time" : startTime,
|
||||
"constant" : timeConstant
|
||||
});
|
||||
this.log(Tone.Param.AutomationType.Target, value, startTime, timeConstant);
|
||||
this._param.setTargetAtTime(value, startTime, timeConstant);
|
||||
return this;
|
||||
};
|
||||
|
@ -453,6 +458,7 @@ define(["Tone/core/Tone", "Tone/type/Type", "Tone/core/AudioNode", "Tone/core/Ti
|
|||
time = this.toSeconds(time);
|
||||
this._events.cancel(time);
|
||||
this._param.cancelScheduledValues(time);
|
||||
this.log(Tone.Param.AutomationType.Cancel, time);
|
||||
return this;
|
||||
};
|
||||
|
||||
|
@ -464,6 +470,10 @@ define(["Tone/core/Tone", "Tone/type/Type", "Tone/core/AudioNode", "Tone/core/Ti
|
|||
*/
|
||||
Tone.Param.prototype.cancelAndHoldAtTime = function(time){
|
||||
var valueAtTime = this.getValueAtTime(time);
|
||||
|
||||
//remove the schedule events
|
||||
this._param.cancelScheduledValues(time);
|
||||
|
||||
//if there is an event at the given time
|
||||
//and that even is not a "set"
|
||||
var before = this._events.get(time);
|
||||
|
@ -478,7 +488,6 @@ define(["Tone/core/Tone", "Tone/type/Type", "Tone/core/AudioNode", "Tone/core/Ti
|
|||
} else if (after){
|
||||
//cancel the next event(s)
|
||||
this._events.cancel(after.time);
|
||||
this._param.cancelScheduledValues(time);
|
||||
if (after.type === Tone.Param.AutomationType.Linear){
|
||||
this.linearRampToValueAtTime(valueAtTime, time);
|
||||
} else if (after.type === Tone.Param.AutomationType.Exponential){
|
||||
|
|
|
@ -273,6 +273,44 @@ define(function(){
|
|||
}
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// DEBUGGING
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Print the outputs to the console log for debugging purposes.
|
||||
* Prints the contents only if either the object has a property
|
||||
* called `debug` set to true, or a variable called TONE_DEBUG_CLASS
|
||||
* is set to the name of the class.
|
||||
* @example
|
||||
* //prints all logs originating from Tone.OscillatorNode
|
||||
* window.TONE_DEBUG_CLASS = OscillatorNode
|
||||
* @param {*} args Any arguments to print to the console.
|
||||
* @private
|
||||
*/
|
||||
Tone.prototype.log = function(){
|
||||
//if the object is either set to debug = true
|
||||
//or if there is a string on the window with the class name
|
||||
if (this.debug || this.toString() === window.TONE_DEBUG_CLASS){
|
||||
var args = Array.from(arguments);
|
||||
args.unshift(this.toString()+":");
|
||||
// eslint-disable-next-line no-console
|
||||
console.log.apply(undefined, args);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Assert that the statement is true, otherwise invoke the error.
|
||||
* @param {Boolean} statement
|
||||
* @param {String} error The message which is passed into an Error
|
||||
* @private
|
||||
*/
|
||||
Tone.prototype.assert = function(statement, error){
|
||||
if (!statement){
|
||||
throw new Error(error);
|
||||
}
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// CONNECTIONS
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
@ -507,7 +545,8 @@ define(function(){
|
|||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Return the current time of the AudioContext clock.
|
||||
* Return the current time of the AudioContext clock plus
|
||||
* the lookAhead.
|
||||
* @return {Number} the currentTime from the AudioContext
|
||||
* @memberOf Tone#
|
||||
*/
|
||||
|
@ -516,7 +555,8 @@ define(function(){
|
|||
};
|
||||
|
||||
/**
|
||||
* Return the current time of the AudioContext clock.
|
||||
* Return the current time of the AudioContext clock plus
|
||||
* the lookAhead.
|
||||
* @return {Number} the currentTime from the AudioContext
|
||||
* @static
|
||||
* @memberOf Tone
|
||||
|
@ -525,6 +565,26 @@ define(function(){
|
|||
return Tone.context.now();
|
||||
};
|
||||
|
||||
/**
|
||||
* Return the current time of the AudioContext clock without
|
||||
* any lookAhead.
|
||||
* @return {Number} the currentTime from the AudioContext
|
||||
* @memberOf Tone#
|
||||
*/
|
||||
Tone.prototype.immediate = function(){
|
||||
return Tone.context.currentTime;
|
||||
};
|
||||
|
||||
/**
|
||||
* Return the current time of the AudioContext clock without
|
||||
* any lookAhead.
|
||||
* @return {Number} the currentTime from the AudioContext
|
||||
* @memberOf Tone
|
||||
*/
|
||||
Tone.immediate = function(){
|
||||
return Tone.context.currentTime;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// INHERITANCE
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -110,6 +110,7 @@ function(Tone){
|
|||
* @private
|
||||
*/
|
||||
Tone.Oscillator.prototype._start = function(time){
|
||||
this.log("start", time);
|
||||
//new oscillator with previous values
|
||||
this._oscillator = new Tone.OscillatorNode();
|
||||
if (this._wave){
|
||||
|
@ -133,6 +134,7 @@ function(Tone){
|
|||
* @returns {Tone.Oscillator} this
|
||||
*/
|
||||
Tone.Oscillator.prototype._stop = function(time){
|
||||
this.log("stop", time);
|
||||
if (this._oscillator){
|
||||
time = this.toSeconds(time);
|
||||
this._oscillator.stop(time);
|
||||
|
|
Loading…
Reference in a new issue