2014-04-06 20:51:30 +00:00
|
|
|
define(["Tone/core/Tone"], function(Tone){
|
2014-04-05 22:05:42 +00:00
|
|
|
|
2014-09-04 04:41:40 +00:00
|
|
|
"use strict";
|
|
|
|
|
2014-06-17 15:40:01 +00:00
|
|
|
/**
|
2014-07-04 17:47:56 +00:00
|
|
|
* @class merge a left and a right channel into a single stereo channel
|
|
|
|
* instead of connecting to the input, connect to either the left, or right input.
|
|
|
|
* default input for connect is left input.
|
2014-06-17 15:40:01 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @extends {Tone}
|
|
|
|
*/
|
2014-04-05 22:05:42 +00:00
|
|
|
Tone.Merge = function(){
|
2014-06-17 15:40:01 +00:00
|
|
|
|
2014-08-20 21:09:58 +00:00
|
|
|
/**
|
|
|
|
* the output node
|
|
|
|
* @type {GainNode}
|
|
|
|
*/
|
|
|
|
this.output = this.context.createGain();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* the two input nodes
|
|
|
|
* @type {Array.<GainNode>}
|
|
|
|
*/
|
|
|
|
this.input = new Array(2);
|
2014-04-05 22:05:42 +00:00
|
|
|
|
2014-06-17 15:40:01 +00:00
|
|
|
/**
|
|
|
|
* the left input channel
|
2014-08-20 21:09:58 +00:00
|
|
|
* alias for input 0
|
2014-06-17 15:40:01 +00:00
|
|
|
* @type {GainNode}
|
|
|
|
*/
|
2014-08-20 21:09:58 +00:00
|
|
|
this.left = this.input[0] = this.context.createGain();
|
|
|
|
|
2014-06-17 15:40:01 +00:00
|
|
|
/**
|
|
|
|
* the right input channel
|
2014-08-20 21:09:58 +00:00
|
|
|
* alias for input 1
|
2014-06-17 15:40:01 +00:00
|
|
|
* @type {GainNode}
|
|
|
|
*/
|
2014-08-20 21:09:58 +00:00
|
|
|
this.right = this.input[1] = this.context.createGain();
|
|
|
|
|
2014-06-17 15:40:01 +00:00
|
|
|
/**
|
|
|
|
* the merger node for the two channels
|
|
|
|
* @type {ChannelMergerNode}
|
2014-08-24 21:48:28 +00:00
|
|
|
* @private
|
2014-06-17 15:40:01 +00:00
|
|
|
*/
|
2014-08-24 21:48:28 +00:00
|
|
|
this._merger = this.context.createChannelMerger(2);
|
2014-04-05 22:05:42 +00:00
|
|
|
|
|
|
|
//connections
|
2014-08-24 21:48:28 +00:00
|
|
|
this.left.connect(this._merger, 0, 0);
|
|
|
|
this.right.connect(this._merger, 0, 1);
|
|
|
|
this._merger.connect(this.output);
|
2014-06-17 15:40:01 +00:00
|
|
|
};
|
2014-04-05 22:05:42 +00:00
|
|
|
|
|
|
|
Tone.extend(Tone.Merge);
|
|
|
|
|
2014-06-20 04:38:14 +00:00
|
|
|
/**
|
|
|
|
* clean up
|
|
|
|
*/
|
|
|
|
Tone.Merge.prototype.dispose = function(){
|
2014-08-24 19:46:55 +00:00
|
|
|
Tone.prototype.dispose.call(this);
|
2014-08-20 21:09:58 +00:00
|
|
|
this.left.disconnect();
|
2014-06-20 04:38:14 +00:00
|
|
|
this.right.disconnect();
|
2014-08-24 21:48:28 +00:00
|
|
|
this._merger.disconnect();
|
2014-08-20 21:09:58 +00:00
|
|
|
this.left = null;
|
2014-06-20 04:38:14 +00:00
|
|
|
this.right = null;
|
2014-08-24 21:48:28 +00:00
|
|
|
this._merger = null;
|
2014-06-20 04:38:14 +00:00
|
|
|
};
|
|
|
|
|
2014-04-05 22:05:42 +00:00
|
|
|
return Tone.Merge;
|
2014-06-17 15:40:01 +00:00
|
|
|
});
|