2015-02-20 05:58:29 +00:00
|
|
|
define(["Tone/core/Tone", "Tone/signal/Signal"], function(Tone){
|
2014-09-04 04:41:40 +00:00
|
|
|
|
|
|
|
"use strict";
|
2014-06-19 02:35:31 +00:00
|
|
|
|
2014-06-18 19:39:10 +00:00
|
|
|
/**
|
2015-02-20 05:58:29 +00:00
|
|
|
* @class A single master output which is connected to the
|
|
|
|
* AudioDestinationNode. It provides useful conveniences
|
|
|
|
* such as the ability to set the global volume and mute
|
|
|
|
* the entire application. Additionally, it accepts
|
|
|
|
* a master send/receive for adding final compression,
|
2015-02-26 16:26:23 +00:00
|
|
|
* limiting or effects to your application. <br><br>
|
|
|
|
* Like the Transport, the Master output is created for you
|
|
|
|
* on initialization. It does not need to be created.
|
2014-06-18 19:39:10 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @extends {Tone}
|
|
|
|
*/
|
2014-09-11 17:00:59 +00:00
|
|
|
Tone.Master = function(){
|
2014-04-05 22:05:42 +00:00
|
|
|
Tone.call(this);
|
2015-02-20 05:58:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* the unmuted volume
|
|
|
|
* @type {number}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._unmutedVolume = 1;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* the volume of the output in decibels
|
|
|
|
* @type {Tone.Signal}
|
|
|
|
*/
|
|
|
|
this.volume = new Tone.Signal(this.output.gain, Tone.Signal.Units.Decibels);
|
2014-10-01 18:47:45 +00:00
|
|
|
|
2014-12-19 21:32:59 +00:00
|
|
|
//connections
|
|
|
|
this.input.chain(this.output, this.context.destination);
|
2014-06-18 19:39:10 +00:00
|
|
|
};
|
2014-04-05 22:05:42 +00:00
|
|
|
|
2014-09-11 17:00:59 +00:00
|
|
|
Tone.extend(Tone.Master);
|
2014-04-05 22:05:42 +00:00
|
|
|
|
2014-06-19 02:35:31 +00:00
|
|
|
/**
|
2015-03-07 19:17:16 +00:00
|
|
|
* Mute the output
|
2015-01-06 03:46:19 +00:00
|
|
|
* @returns {Tone.Master} `this`
|
2014-06-19 02:35:31 +00:00
|
|
|
*/
|
2015-02-20 05:58:29 +00:00
|
|
|
Tone.Master.prototype.mute = function(){
|
|
|
|
this._unmutedVolume = this.volume.value;
|
|
|
|
//maybe it should ramp here?
|
|
|
|
this.volume.value = -Infinity;
|
2015-01-06 03:46:19 +00:00
|
|
|
return this;
|
2014-06-19 02:35:31 +00:00
|
|
|
};
|
|
|
|
|
2014-06-21 17:06:37 +00:00
|
|
|
/**
|
2015-02-20 05:58:29 +00:00
|
|
|
* Unmute the output. Will return the volume to it's value before
|
|
|
|
* the output was muted.
|
|
|
|
* @returns {Tone.Master} `this`
|
2014-06-21 17:06:37 +00:00
|
|
|
*/
|
2015-03-07 19:17:16 +00:00
|
|
|
Tone.Master.prototype.unmute = function(){
|
2015-02-20 05:58:29 +00:00
|
|
|
this.volume.value = this._unmutedVolume;
|
2015-01-06 03:46:19 +00:00
|
|
|
return this;
|
2014-06-21 17:06:37 +00:00
|
|
|
};
|
|
|
|
|
2014-12-19 21:32:59 +00:00
|
|
|
/**
|
|
|
|
* route the master signal to the node's input.
|
|
|
|
* NOTE: this will disconnect the previously connected node
|
|
|
|
* @param {AudioNode|Tone} node the node to use as the entry
|
|
|
|
* point to the master chain
|
2015-01-06 03:46:19 +00:00
|
|
|
* @returns {Tone.Master} `this`
|
2014-12-19 21:32:59 +00:00
|
|
|
*/
|
|
|
|
Tone.Master.prototype.send = function(node){
|
|
|
|
//disconnect the previous node
|
|
|
|
this.input.disconnect();
|
|
|
|
this.input.connect(node);
|
2015-01-06 03:46:19 +00:00
|
|
|
return this;
|
2014-12-19 21:32:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* the master effects chain return point
|
|
|
|
* @param {AudioNode|Tone} node the node to connect
|
2015-01-06 03:46:19 +00:00
|
|
|
* @returns {Tone.Master} `this`
|
2014-12-19 21:32:59 +00:00
|
|
|
*/
|
|
|
|
Tone.Master.prototype.receive = function(node){
|
|
|
|
node.connect(this.output);
|
2015-01-06 03:46:19 +00:00
|
|
|
return this;
|
2014-12-19 21:32:59 +00:00
|
|
|
};
|
|
|
|
|
2014-04-05 22:05:42 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2014-06-18 19:39:10 +00:00
|
|
|
// AUGMENT TONE's PROTOTYPE
|
2014-04-05 22:05:42 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2014-06-18 19:39:10 +00:00
|
|
|
/**
|
|
|
|
* connect 'this' to the master output
|
2014-09-25 03:43:10 +00:00
|
|
|
* defined in "Tone/core/Master"
|
2015-01-06 03:46:19 +00:00
|
|
|
* @returns {Tone} `this`
|
2014-06-18 19:39:10 +00:00
|
|
|
*/
|
2014-04-05 22:05:42 +00:00
|
|
|
Tone.prototype.toMaster = function(){
|
|
|
|
this.connect(Tone.Master);
|
2015-01-06 03:46:19 +00:00
|
|
|
return this;
|
2014-06-18 19:39:10 +00:00
|
|
|
};
|
2014-04-05 22:05:42 +00:00
|
|
|
|
2014-06-18 19:39:10 +00:00
|
|
|
/**
|
|
|
|
* Also augment AudioNode's prototype to include toMaster
|
|
|
|
* as a convenience
|
2015-01-06 03:46:19 +00:00
|
|
|
* @returns {AudioNode} `this`
|
2014-06-18 19:39:10 +00:00
|
|
|
*/
|
2014-04-05 22:05:42 +00:00
|
|
|
AudioNode.prototype.toMaster = function(){
|
|
|
|
this.connect(Tone.Master);
|
2015-01-06 03:46:19 +00:00
|
|
|
return this;
|
2014-06-18 19:39:10 +00:00
|
|
|
};
|
2014-04-05 22:05:42 +00:00
|
|
|
|
2014-09-11 17:00:59 +00:00
|
|
|
var MasterConstructor = Tone.Master;
|
|
|
|
|
2014-06-19 02:35:31 +00:00
|
|
|
/**
|
2014-07-30 17:55:24 +00:00
|
|
|
* initialize the module and listen for new audio contexts
|
2014-06-19 02:35:31 +00:00
|
|
|
*/
|
2014-07-30 17:55:24 +00:00
|
|
|
Tone._initAudioContext(function(){
|
2014-10-16 04:49:31 +00:00
|
|
|
//a single master output
|
|
|
|
if (!Tone.prototype.isUndef(Tone.Master)){
|
2014-10-19 20:08:40 +00:00
|
|
|
Tone.Master = new MasterConstructor();
|
2014-10-16 04:49:31 +00:00
|
|
|
} else {
|
2014-12-19 21:32:59 +00:00
|
|
|
MasterConstructor.prototype.dispose.call(Tone.Master);
|
2014-10-16 04:49:31 +00:00
|
|
|
MasterConstructor.call(Tone.Master);
|
|
|
|
}
|
2014-07-30 17:55:24 +00:00
|
|
|
});
|
2014-04-11 23:17:01 +00:00
|
|
|
|
2014-04-05 22:05:42 +00:00
|
|
|
return Tone.Master;
|
2014-06-18 19:46:31 +00:00
|
|
|
});
|