Tone.js/Tone/component/Merge.js

76 lines
1.7 KiB
JavaScript
Raw Normal View History

define(["Tone/core/Tone", "Tone/core/AudioNode"], function(Tone){
"use strict";
2014-06-17 15:40:01 +00:00
/**
* @class Tone.Merge brings two signals into the left and right
2015-07-02 00:19:58 +00:00
* channels of a single stereo channel.
2014-06-17 15:40:01 +00:00
*
* @constructor
* @extends {Tone.AudioNode}
2015-02-27 21:53:10 +00:00
* @example
2015-07-02 00:19:58 +00:00
* var merge = new Tone.Merge().toMaster();
* //routing a sine tone in the left channel
* //and noise in the right channel
* var osc = new Tone.Oscillator().connect(merge.left);
* var noise = new Tone.Noise().connect(merge.right);
* //starting our oscillators
* noise.start();
* osc.start();
2014-06-17 15:40:01 +00:00
*/
Tone.Merge = function(){
2014-06-17 15:40:01 +00:00
Tone.AudioNode.call(this);
2016-09-20 03:02:42 +00:00
this.createInsOuts(2, 0);
2014-06-17 15:40:01 +00:00
/**
2015-02-27 21:53:10 +00:00
* The left input channel.
2015-06-20 23:25:49 +00:00
* Alias for <code>input[0]</code>
2014-06-17 15:40:01 +00:00
* @type {GainNode}
*/
2016-09-20 03:02:42 +00:00
this.left = this.input[0] = new Tone.Gain();
2014-06-17 15:40:01 +00:00
/**
2015-02-27 21:53:10 +00:00
* The right input channel.
2015-06-20 23:25:49 +00:00
* Alias for <code>input[1]</code>.
2014-06-17 15:40:01 +00:00
* @type {GainNode}
*/
2016-09-20 03:02:42 +00:00
this.right = this.input[1] = new Tone.Gain();
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
*/
2015-03-03 15:26:46 +00:00
this._merger = this.output = 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.left.channelCount = 1;
this.right.channelCount = 1;
this.left.channelCountMode = "explicit";
this.right.channelCountMode = "explicit";
2014-06-17 15:40:01 +00:00
};
Tone.extend(Tone.Merge, Tone.AudioNode);
2014-06-20 04:38:14 +00:00
/**
2015-06-20 23:25:49 +00:00
* Clean up.
* @returns {Tone.Merge} this
2014-06-20 04:38:14 +00:00
*/
Tone.Merge.prototype.dispose = function(){
Tone.AudioNode.prototype.dispose.call(this);
2016-09-20 03:02:42 +00:00
this.left.dispose();
this.left = null;
2016-09-20 03:02:42 +00:00
this.right.dispose();
2014-06-20 04:38:14 +00:00
this.right = null;
2015-03-03 15:26:46 +00:00
this._merger.disconnect();
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
});