2017-08-27 21:50:31 +00:00
|
|
|
define(["Tone/core/Tone", "Tone/core/AudioNode"], 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
|
|
|
/**
|
2017-08-27 21:50:31 +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
|
2017-08-27 21:50:31 +00:00
|
|
|
* @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
|
|
|
*/
|
2014-04-05 22:05:42 +00:00
|
|
|
Tone.Merge = function(){
|
2014-06-17 15:40:01 +00:00
|
|
|
|
2017-08-27 21:50:31 +00:00
|
|
|
Tone.AudioNode.call(this);
|
2016-09-20 03:02:42 +00:00
|
|
|
this.createInsOuts(2, 0);
|
2014-04-05 22:05:42 +00:00
|
|
|
|
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-08-20 21:09:58 +00:00
|
|
|
|
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-08-20 21:09:58 +00:00
|
|
|
|
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);
|
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);
|
2015-12-06 00:06:20 +00:00
|
|
|
|
|
|
|
this.left.channelCount = 1;
|
|
|
|
this.right.channelCount = 1;
|
|
|
|
this.left.channelCountMode = "explicit";
|
|
|
|
this.right.channelCountMode = "explicit";
|
2014-06-17 15:40:01 +00:00
|
|
|
};
|
2014-04-05 22:05:42 +00:00
|
|
|
|
2017-08-27 21:50:31 +00:00
|
|
|
Tone.extend(Tone.Merge, Tone.AudioNode);
|
2014-04-05 22:05:42 +00:00
|
|
|
|
2014-06-20 04:38:14 +00:00
|
|
|
/**
|
2015-06-20 23:25:49 +00:00
|
|
|
* Clean up.
|
2015-06-14 00:54:29 +00:00
|
|
|
* @returns {Tone.Merge} this
|
2014-06-20 04:38:14 +00:00
|
|
|
*/
|
|
|
|
Tone.Merge.prototype.dispose = function(){
|
2017-08-27 21:50:31 +00:00
|
|
|
Tone.AudioNode.prototype.dispose.call(this);
|
2016-09-20 03:02:42 +00:00
|
|
|
this.left.dispose();
|
2014-08-20 21:09:58 +00:00
|
|
|
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;
|
2017-08-27 21:50:31 +00:00
|
|
|
};
|
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
|
|
|
});
|