Tone.js/Tone/core/Bus.js

56 lines
1.4 KiB
JavaScript
Raw Normal View History

2014-04-16 04:23:58 +00:00
define(["Tone/core/Tone"], function(Tone){
"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
* 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);
this.chain(this.output, sendKnob, Buses[channelName]);
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
* 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-09-02 16:09:16 +00:00
* @param {AudioNode=} [input=this.input] if no input is selected, the
* input of the current node is
* chosen.
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-09-02 16:09:16 +00:00
input = this.defaultArg(input, this.input);
Buses[channelName].connect(input);
2014-06-15 22:32:49 +00:00
};
return Tone;
2014-04-16 04:23:58 +00:00
});