2014-04-16 04:23:58 +00:00
|
|
|
define(["Tone/core/Tone"], function(Tone){
|
|
|
|
|
2014-09-04 04:41:40 +00:00
|
|
|
"use strict";
|
|
|
|
|
2014-06-15 22:32:49 +00:00
|
|
|
/**
|
|
|
|
* buses are another way of routing audio
|
|
|
|
*
|
|
|
|
* augments Tone.prototype to include send and recieve
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* All of the routes
|
|
|
|
*
|
|
|
|
* @type {Object}
|
2014-07-30 17:55:36 +00:00
|
|
|
* @static
|
|
|
|
* @private
|
2014-06-15 22:32:49 +00:00
|
|
|
*/
|
|
|
|
var Buses = {};
|
2014-04-16 04:23:58 +00:00
|
|
|
|
2014-06-15 22:32:49 +00:00
|
|
|
/**
|
|
|
|
* send signal to a channel name
|
2014-09-25 03:43:10 +00:00
|
|
|
* defined in "Tone/core/Bus"
|
2014-06-19 17:38:21 +00:00
|
|
|
*
|
2014-06-15 22:32:49 +00:00
|
|
|
* @param {string} channelName
|
|
|
|
* @param {number} amount
|
|
|
|
* @return {GainNode}
|
|
|
|
*/
|
2014-04-16 04:23:58 +00:00
|
|
|
Tone.prototype.send = function(channelName, amount){
|
|
|
|
if (!Buses.hasOwnProperty(channelName)){
|
|
|
|
Buses[channelName] = this.context.createGain();
|
|
|
|
}
|
|
|
|
var sendKnob = this.context.createGain();
|
|
|
|
sendKnob.gain.value = this.defaultArg(amount, 1);
|
2014-12-01 02:32:09 +00:00
|
|
|
this.output.chain(sendKnob, Buses[channelName]);
|
2014-04-16 04:23:58 +00:00
|
|
|
return sendKnob;
|
2014-06-15 22:32:49 +00:00
|
|
|
};
|
2014-04-16 04:23:58 +00:00
|
|
|
|
2014-06-15 22:32:49 +00:00
|
|
|
/**
|
2014-09-02 16:09:16 +00:00
|
|
|
* recieve the input from the desired channelName to the input
|
2014-09-25 03:43:10 +00:00
|
|
|
* defined in "Tone/core/Bus"
|
2014-06-19 17:38:21 +00:00
|
|
|
*
|
2014-06-15 22:32:49 +00:00
|
|
|
* @param {string} channelName
|
2014-12-02 06:42:08 +00:00
|
|
|
* @param {AudioNode} [input=this.input] if no input is selected, the
|
2014-09-02 16:09:16 +00:00
|
|
|
* input of the current node is
|
|
|
|
* chosen.
|
2015-01-06 04:33:05 +00:00
|
|
|
* @returns {Tone} `this`
|
2014-06-15 22:32:49 +00:00
|
|
|
*/
|
2014-09-02 16:09:16 +00:00
|
|
|
Tone.prototype.receive = function(channelName, input){
|
2014-04-16 04:23:58 +00:00
|
|
|
if (!Buses.hasOwnProperty(channelName)){
|
|
|
|
Buses[channelName] = this.context.createGain();
|
|
|
|
}
|
2014-12-08 05:44:40 +00:00
|
|
|
if (this.isUndef(input)){
|
|
|
|
input = this.input;
|
|
|
|
}
|
2014-09-02 16:09:16 +00:00
|
|
|
Buses[channelName].connect(input);
|
2015-01-06 04:33:05 +00:00
|
|
|
return this;
|
2014-06-15 22:32:49 +00:00
|
|
|
};
|
2014-09-25 03:43:10 +00:00
|
|
|
|
|
|
|
return Tone;
|
2014-04-16 04:23:58 +00:00
|
|
|
});
|