2014-11-04 05:44:59 +00:00
|
|
|
define(["Tone/core/Tone", "Tone/component/AmplitudeEnvelope", "Tone/component/ScaledEnvelope",
|
|
|
|
"Tone/source/OmniOscillator", "Tone/signal/Signal", "Tone/component/Filter", "Tone/instrument/Monophonic"],
|
2014-08-24 16:26:04 +00:00
|
|
|
function(Tone){
|
|
|
|
|
|
|
|
"use strict";
|
2014-08-21 04:59:11 +00:00
|
|
|
|
|
|
|
/**
|
2015-06-14 04:32:17 +00:00
|
|
|
* @class Tone.MonoSynth is composed of one oscillator, one filter, and two envelopes.
|
|
|
|
* The amplitude of the Tone.Oscillator and the cutoff frequency of the
|
|
|
|
* Tone.Filter are controlled by Tone.Envelopes.
|
2015-06-14 00:20:36 +00:00
|
|
|
*
|
2014-08-21 04:59:11 +00:00
|
|
|
* @constructor
|
2014-09-03 23:05:09 +00:00
|
|
|
* @extends {Tone.Monophonic}
|
2015-06-14 03:15:57 +00:00
|
|
|
* @param {Object} [options] the options available for the synth
|
2014-08-25 14:23:37 +00:00
|
|
|
* see defaults below
|
2014-08-21 04:59:11 +00:00
|
|
|
*/
|
|
|
|
Tone.MonoSynth = function(options){
|
|
|
|
|
|
|
|
//get the defaults
|
2014-09-05 15:32:33 +00:00
|
|
|
options = this.defaultArg(options, Tone.MonoSynth.defaults);
|
2014-09-03 23:05:09 +00:00
|
|
|
Tone.Monophonic.call(this, options);
|
2014-08-21 04:59:11 +00:00
|
|
|
|
|
|
|
/**
|
2015-06-14 03:15:57 +00:00
|
|
|
* The oscillator.
|
2014-10-01 02:49:48 +00:00
|
|
|
* @type {Tone.OmniOscillator}
|
2014-08-26 01:19:18 +00:00
|
|
|
*/
|
2014-10-01 02:49:48 +00:00
|
|
|
this.oscillator = new Tone.OmniOscillator(options.oscillator);
|
2014-08-26 01:19:18 +00:00
|
|
|
|
2014-08-21 04:59:11 +00:00
|
|
|
/**
|
2015-06-14 03:15:57 +00:00
|
|
|
* The frequency control.
|
2015-06-14 00:20:36 +00:00
|
|
|
* @type {Frequency}
|
|
|
|
* @signal
|
2014-08-21 04:59:11 +00:00
|
|
|
*/
|
2014-09-02 04:25:38 +00:00
|
|
|
this.frequency = this.oscillator.frequency;
|
2014-08-21 04:59:11 +00:00
|
|
|
|
|
|
|
/**
|
2015-06-14 03:15:57 +00:00
|
|
|
* The detune control.
|
2015-06-14 00:20:36 +00:00
|
|
|
* @type {Cents}
|
|
|
|
* @signal
|
2014-08-21 04:59:11 +00:00
|
|
|
*/
|
2014-09-02 04:25:38 +00:00
|
|
|
this.detune = this.oscillator.detune;
|
2014-08-21 04:59:11 +00:00
|
|
|
|
|
|
|
/**
|
2015-06-14 03:15:57 +00:00
|
|
|
* The filter.
|
2014-08-24 16:26:04 +00:00
|
|
|
* @type {Tone.Filter}
|
2014-08-21 04:59:11 +00:00
|
|
|
*/
|
2014-09-02 04:25:38 +00:00
|
|
|
this.filter = new Tone.Filter(options.filter);
|
2014-08-21 04:59:11 +00:00
|
|
|
|
|
|
|
/**
|
2015-06-14 03:15:57 +00:00
|
|
|
* The filter envelope.
|
2015-06-15 15:27:13 +00:00
|
|
|
* @type {Tone.ScaledEnvelope}
|
2014-08-21 04:59:11 +00:00
|
|
|
*/
|
2014-11-04 05:44:59 +00:00
|
|
|
this.filterEnvelope = new Tone.ScaledEnvelope(options.filterEnvelope);
|
2014-08-21 04:59:11 +00:00
|
|
|
|
|
|
|
/**
|
2015-06-14 03:15:57 +00:00
|
|
|
* The amplitude envelope.
|
2015-06-15 15:27:13 +00:00
|
|
|
* @type {Tone.AmplitudeEnvelope}
|
2014-08-21 04:59:11 +00:00
|
|
|
*/
|
2014-10-28 18:51:22 +00:00
|
|
|
this.envelope = new Tone.AmplitudeEnvelope(options.envelope);
|
2014-09-02 04:25:38 +00:00
|
|
|
|
2014-08-21 04:59:11 +00:00
|
|
|
//connect the oscillators to the output
|
2014-12-01 02:32:09 +00:00
|
|
|
this.oscillator.chain(this.filter, this.envelope, this.output);
|
2014-08-21 04:59:11 +00:00
|
|
|
//start the oscillators
|
2014-09-02 04:25:38 +00:00
|
|
|
this.oscillator.start();
|
2014-10-28 18:51:22 +00:00
|
|
|
//connect the filter envelope
|
2014-09-02 04:25:38 +00:00
|
|
|
this.filterEnvelope.connect(this.filter.frequency);
|
2015-04-18 14:54:08 +00:00
|
|
|
this._readOnly(["oscillator", "frequency", "detune", "filter", "filterEnvelope", "envelope"]);
|
2014-08-21 04:59:11 +00:00
|
|
|
};
|
|
|
|
|
2014-09-03 23:05:09 +00:00
|
|
|
Tone.extend(Tone.MonoSynth, Tone.Monophonic);
|
2014-08-21 04:59:11 +00:00
|
|
|
|
|
|
|
/**
|
2014-09-04 18:04:58 +00:00
|
|
|
* @const
|
2014-08-21 04:59:11 +00:00
|
|
|
* @static
|
2014-09-06 19:56:23 +00:00
|
|
|
* @type {Object}
|
2014-08-21 04:59:11 +00:00
|
|
|
*/
|
2014-09-05 15:32:33 +00:00
|
|
|
Tone.MonoSynth.defaults = {
|
2015-05-13 03:48:13 +00:00
|
|
|
"frequency" : "C4",
|
|
|
|
"detune" : 0,
|
2014-10-01 02:49:48 +00:00
|
|
|
"oscillator" : {
|
|
|
|
"type" : "square"
|
|
|
|
},
|
2014-08-24 16:26:04 +00:00
|
|
|
"filter" : {
|
|
|
|
"Q" : 6,
|
2014-09-02 04:25:38 +00:00
|
|
|
"type" : "lowpass",
|
|
|
|
"rolloff" : -24
|
2014-08-24 16:26:04 +00:00
|
|
|
},
|
|
|
|
"envelope" : {
|
|
|
|
"attack" : 0.005,
|
|
|
|
"decay" : 0.1,
|
|
|
|
"sustain" : 0.9,
|
|
|
|
"release" : 1
|
|
|
|
},
|
|
|
|
"filterEnvelope" : {
|
|
|
|
"attack" : 0.06,
|
|
|
|
"decay" : 0.2,
|
|
|
|
"sustain" : 0.5,
|
|
|
|
"release" : 2,
|
2014-09-12 00:36:17 +00:00
|
|
|
"min" : 20,
|
2014-11-02 01:55:59 +00:00
|
|
|
"max" : 4000,
|
|
|
|
"exponent" : 2
|
2014-08-24 16:26:04 +00:00
|
|
|
}
|
2014-08-21 04:59:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* start the attack portion of the envelope
|
2015-06-14 00:20:36 +00:00
|
|
|
* @param {Time} [time=now] the time the attack should start
|
|
|
|
* @param {NormalRange} [velocity=1] the velocity of the note (0-1)
|
2015-06-14 00:54:29 +00:00
|
|
|
* @returns {Tone.MonoSynth} this
|
2015-06-14 02:47:07 +00:00
|
|
|
* @private
|
2014-08-21 04:59:11 +00:00
|
|
|
*/
|
2015-06-14 02:47:07 +00:00
|
|
|
Tone.MonoSynth.prototype._triggerEnvelopeAttack = function(time, velocity){
|
2014-08-21 04:59:11 +00:00
|
|
|
//the envelopes
|
2014-09-03 23:05:09 +00:00
|
|
|
this.envelope.triggerAttack(time, velocity);
|
2015-02-02 18:30:36 +00:00
|
|
|
this.filterEnvelope.triggerAttack(time);
|
|
|
|
return this;
|
2014-08-21 04:59:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* start the release portion of the envelope
|
2015-06-14 00:20:36 +00:00
|
|
|
* @param {Time} [time=now] the time the release should start
|
2015-06-14 00:54:29 +00:00
|
|
|
* @returns {Tone.MonoSynth} this
|
2015-06-14 02:47:07 +00:00
|
|
|
* @private
|
2014-08-21 04:59:11 +00:00
|
|
|
*/
|
2015-06-14 02:47:07 +00:00
|
|
|
Tone.MonoSynth.prototype._triggerEnvelopeRelease = function(time){
|
2014-08-21 04:59:11 +00:00
|
|
|
this.envelope.triggerRelease(time);
|
2014-09-03 21:31:29 +00:00
|
|
|
this.filterEnvelope.triggerRelease(time);
|
2015-02-02 18:30:36 +00:00
|
|
|
return this;
|
2014-08-21 04:59:11 +00:00
|
|
|
};
|
|
|
|
|
2014-08-24 16:26:04 +00:00
|
|
|
|
2014-08-21 04:59:11 +00:00
|
|
|
/**
|
|
|
|
* clean up
|
2015-06-14 00:54:29 +00:00
|
|
|
* @returns {Tone.MonoSynth} this
|
2014-08-21 04:59:11 +00:00
|
|
|
*/
|
|
|
|
Tone.MonoSynth.prototype.dispose = function(){
|
2014-09-03 23:05:09 +00:00
|
|
|
Tone.Monophonic.prototype.dispose.call(this);
|
2015-04-18 14:54:08 +00:00
|
|
|
this._writable(["oscillator", "frequency", "detune", "filter", "filterEnvelope", "envelope"]);
|
2014-09-02 04:25:38 +00:00
|
|
|
this.oscillator.dispose();
|
2014-10-28 18:51:22 +00:00
|
|
|
this.oscillator = null;
|
2014-08-21 04:59:11 +00:00
|
|
|
this.envelope.dispose();
|
2014-10-28 18:51:22 +00:00
|
|
|
this.envelope = null;
|
2014-08-21 04:59:11 +00:00
|
|
|
this.filterEnvelope.dispose();
|
|
|
|
this.filterEnvelope = null;
|
2014-10-28 18:51:22 +00:00
|
|
|
this.filter.dispose();
|
2014-09-02 04:25:38 +00:00
|
|
|
this.filter = null;
|
2014-09-09 19:30:36 +00:00
|
|
|
this.frequency = null;
|
|
|
|
this.detune = null;
|
2015-02-02 18:30:36 +00:00
|
|
|
return this;
|
2014-08-21 04:59:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return Tone.MonoSynth;
|
|
|
|
});
|