Tone.js/Tone/component/Merge.js

63 lines
1.3 KiB
JavaScript
Raw Normal View History

2014-04-06 20:51:30 +00:00
define(["Tone/core/Tone"], function(Tone){
"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}
*/
Tone.Merge = function(){
2014-06-17 15:40:01 +00:00
2015-02-02 17:49:13 +00:00
Tone.call(this, 2, 1);
2014-06-17 15:40:01 +00:00
/**
* the left input channel
* alias for input 0
2014-06-17 15:40:01 +00:00
* @type {GainNode}
*/
this.left = this.input[0] = this.context.createGain();
2014-06-17 15:40:01 +00:00
/**
* the right input channel
* alias for input 1
2014-06-17 15:40:01 +00:00
* @type {GainNode}
*/
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);
//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
};
Tone.extend(Tone.Merge);
2014-06-20 04:38:14 +00:00
/**
* clean up
2015-02-02 17:49:13 +00:00
* @returns {Tone.Merge} `this`
2014-06-20 04:38:14 +00:00
*/
Tone.Merge.prototype.dispose = function(){
2014-08-24 19:46:55 +00:00
Tone.prototype.dispose.call(this);
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();
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;
2015-02-02 17:49:13 +00:00
return this;
2014-06-20 04:38:14 +00:00
};
return Tone.Merge;
2014-06-17 15:40:01 +00:00
});