Tone.js/Tone/signal/SignalBase.js

46 lines
1.2 KiB
JavaScript
Raw Normal View History

define(["Tone/core/Tone"], function(Tone){
"use strict";
/**
* @class Base class for all Signals
*
* @constructor
2014-12-02 05:27:28 +00:00
* @extends {Tone}
*/
Tone.SignalBase = function(){
};
Tone.extend(Tone.SignalBase);
/**
2015-02-27 18:40:35 +00:00
* When signals connect to other signals or AudioParams,
* they take over the output value of that signal or AudioParam.
* For all other nodes, the behavior is the same as a normal `connect`.
*
* @override
* @param {AudioParam|AudioNode|Tone.Signal|Tone} node
2014-12-02 06:42:08 +00:00
* @param {number} [outputNumber=0]
* @param {number} [inputNumber=0]
2015-02-02 03:56:33 +00:00
* @returns {Tone.SignalBase} `this`
*/
Tone.SignalBase.prototype.connect = function(node, outputNumber, inputNumber){
//zero it out so that the signal can have full control
2015-02-23 05:30:53 +00:00
if (node.constructor === Tone.Signal){
2015-02-21 19:05:58 +00:00
//cancel changes
node._value.cancelScheduledValues(0);
//reset the value
node._value.value = 0;
//mark the value as overridden
node.overridden = true;
} else if (node instanceof AudioParam){
2015-02-23 05:30:53 +00:00
node.cancelScheduledValues(0);
node.value = 0;
}
Tone.prototype.connect.call(this, node, outputNumber, inputNumber);
2015-02-02 03:56:33 +00:00
return this;
};
return Tone.SignalBase;
});