instrument methods return this

This commit is contained in:
Yotam Mann 2015-02-02 13:30:36 -05:00
parent 754a9b77ca
commit 5e9a3981e0
9 changed files with 108 additions and 2 deletions

View file

@ -124,6 +124,7 @@ function(Tone){
*
* @param {Tone.Time} [time=now] the time the note will occur
* @param {number} [velocity=1] the velocity of the note
* @returns {Tone.AMSynth} `this`
*/
Tone.AMSynth.prototype.triggerEnvelopeAttack = function(time, velocity){
//the port glide
@ -133,39 +134,47 @@ function(Tone){
this.modulator.envelope.triggerAttack(time);
this.carrier.filterEnvelope.triggerAttack(time);
this.modulator.filterEnvelope.triggerAttack(time);
return this;
};
/**
* trigger the release portion of the note
*
* @param {Tone.Time} [time=now] the time the note will release
* @returns {Tone.AMSynth} `this`
*/
Tone.AMSynth.prototype.triggerEnvelopeRelease = function(time){
this.carrier.triggerRelease(time);
this.modulator.triggerRelease(time);
return this;
};
/**
* set the ratio between the two carrier and the modulator
* @param {number} ratio
* @returns {Tone.AMSynth} `this`
*/
Tone.AMSynth.prototype.setHarmonicity = function(ratio){
this._harmonicity.setValue(ratio);
return this;
};
/**
* bulk setter
* @param {Object} param
* @returns {Tone.AMSynth} `this`
*/
Tone.AMSynth.prototype.set = function(params){
if (!this.isUndef(params.harmonicity)) this.setHarmonicity(params.harmonicity);
if (!this.isUndef(params.carrier)) this.carrier.set(params.carrier);
if (!this.isUndef(params.modulator)) this.modulator.set(params.modulator);
Tone.Monophonic.prototype.set.call(this, params);
return this;
};
/**
* clean up
* @returns {Tone.AMSynth} `this`
*/
Tone.AMSynth.prototype.dispose = function(){
Tone.Monophonic.prototype.dispose.call(this);
@ -181,6 +190,7 @@ function(Tone){
this._modulationScale = null;
this._modulationNode.disconnect();
this._modulationNode = null;
return this;
};
return Tone.AMSynth;

View file

@ -140,6 +140,7 @@ function(Tone){
*
* @param {Tone.Time} [time=now] the time the attack should start
* @param {number} [velocity=1] the velocity of the note (0-1)
* @returns {Tone.DuoSynth} `this`
*/
Tone.DuoSynth.prototype.triggerEnvelopeAttack = function(time, velocity){
time = this.toSeconds(time);
@ -147,62 +148,76 @@ function(Tone){
this.voice1.envelope.triggerAttack(time, velocity);
this.voice0.filterEnvelope.triggerAttack(time);
this.voice1.filterEnvelope.triggerAttack(time);
return this;
};
/**
* start the release portion of the envelopes
*
* @param {Tone.Time} [time=now] the time the release should start
* @returns {Tone.DuoSynth} `this`
*/
Tone.DuoSynth.prototype.triggerEnvelopeRelease = function(time){
this.voice0.triggerRelease(time);
this.voice1.triggerRelease(time);
return this;
};
/**
* set the ratio between the two oscillator
* @param {number} ratio
* @returns {Tone.DuoSynth} `this`
*/
Tone.DuoSynth.prototype.setHarmonicity = function(ratio){
this._harmonicity.setValue(ratio);
return this;
};
/**
* the glide time between frequencies
* @param {Tone.Time} port
* @returns {Tone.DuoSynth} `this`
*/
Tone.DuoSynth.prototype.setPortamento = function(port){
this.portamento = this.toSeconds(port);
return this;
};
/**
* the delay before the vibrato kicks in
* @param {Tone.Time} delay
* @returns {Tone.DuoSynth} `this`
*/
Tone.DuoSynth.prototype.setVibratoDelay = function(delay){
this._vibratoDelay = this.toSeconds(delay);
return this;
};
/**
* the vibrato amount. 1 is full vib. 0 is none.
* @param {number} amount an amount between 0-1
* @returns {Tone.DuoSynth} `this`
*/
Tone.DuoSynth.prototype.setVibratoAmount = function(amount){
this._vibratoAmount = amount;
this._vibratoGain.gain.setValueAtTime(amount, this.now());
return this;
};
/**
* the rate of the vibrato
* @param {number} rate
* @returns {Tone.DuoSynth} `this`
*/
Tone.DuoSynth.prototype.setVibratoRate = function(rate){
this._vibrato.setFrequency(rate);
return this;
};
/**
* bulk setter
* @param {Object} param
* @returns {Tone.DuoSynth} `this`
*/
Tone.DuoSynth.prototype.set = function(params){
if (!this.isUndef(params.harmonicity)) this.setHarmonicity(params.harmonicity);
@ -212,10 +227,12 @@ function(Tone){
if (!this.isUndef(params.voice0)) this.voice0.set(params.voice0);
if (!this.isUndef(params.voice1)) this.voice1.set(params.voice1);
Tone.Monophonic.prototype.set.call(this, params);
return this;
};
/**
* clean up
* @returns {Tone.DuoSynth} `this`
*/
Tone.DuoSynth.prototype.dispose = function(){
Tone.Monophonic.prototype.dispose.call(this);
@ -231,6 +248,7 @@ function(Tone){
this._vibrato = null;
this._vibratoGain = null;
this._harmonicity = null;
return this;
};
return Tone.DuoSynth;

View file

@ -129,6 +129,7 @@ function(Tone){
*
* @param {Tone.Time} [time=now] the time the note will occur
* @param {number} [velocity=1] the velocity of the note
* @returns {Tone.FMSynth} `this`
*/
Tone.FMSynth.prototype.triggerEnvelopeAttack = function(time, velocity){
//the port glide
@ -138,37 +139,45 @@ function(Tone){
this.modulator.envelope.triggerAttack(time);
this.carrier.filterEnvelope.triggerAttack(time);
this.modulator.filterEnvelope.triggerAttack(time);
return this;
};
/**
* trigger the release portion of the note
*
* @param {Tone.Time} [time=now] the time the note will release
* @returns {Tone.FMSynth} `this`
*/
Tone.FMSynth.prototype.triggerEnvelopeRelease = function(time){
this.carrier.triggerRelease(time);
this.modulator.triggerRelease(time);
return this;
};
/**
* set the ratio between the two carrier and the modulator
* @param {number} ratio
* @returns {Tone.FMSynth} `this`
*/
Tone.FMSynth.prototype.setHarmonicity = function(ratio){
this._harmonicity.setValue(ratio);
return this;
};
/**
* set the modulation index
* @param {number} index
* @returns {Tone.FMSynth} `this`
*/
Tone.FMSynth.prototype.setModulationIndex = function(index){
this._modulationIndex.setValue(index);
return this;
};
/**
* bulk setter
* @param {Object} param
* @returns {Tone.FMSynth} `this`
*/
Tone.FMSynth.prototype.set = function(params){
if (!this.isUndef(params.harmonicity)) this.setHarmonicity(params.harmonicity);
@ -176,10 +185,12 @@ function(Tone){
if (!this.isUndef(params.carrier)) this.carrier.set(params.carrier);
if (!this.isUndef(params.modulator)) this.modulator.set(params.modulator);
Tone.Monophonic.prototype.set.call(this, params);
return this;
};
/**
* clean up
* @returns {Tone.FMSynth} `this`
*/
Tone.FMSynth.prototype.dispose = function(){
Tone.Monophonic.prototype.dispose.call(this);
@ -195,6 +206,7 @@ function(Tone){
this._modulationIndex = null;
this._harmonicity = null;
this._modulationNode = null;
return this;
};
return Tone.FMSynth;

View file

@ -39,20 +39,24 @@ define(["Tone/core/Tone", "Tone/core/Master", "Tone/core/Note"], function(Tone){
* @param {Tone.Time} duration the duration of the note
* @param {Tone.Time} [time=now] the time of the attack
* @param {number} velocity the velocity
* @returns {Tone.Instrument} `this`
*/
Tone.Instrument.prototype.triggerAttackRelease = function(note, duration, time, velocity){
time = this.toSeconds(time);
duration = this.toSeconds(duration);
this.triggerAttack(note, time, velocity);
this.triggerRelease(time + duration);
return this;
};
/**
* bulk setter
* @param {Object} params the params
* @returns {Tone.Instrument} `this`
*/
Tone.Instrument.prototype.set = function(params) {
if (!this.isUndef(params.volume)) this.setVolume(params.volume);
return this;
};
/**
@ -69,9 +73,11 @@ define(["Tone/core/Tone", "Tone/core/Master", "Tone/core/Note"], function(Tone){
/**
* clean up
* @returns {Tone.Instrument} `this`
*/
Tone.Instrument.prototype.dispose = function(){
Tone.prototype.dispose.call(this);
return this;
};
return Tone.Instrument;

View file

@ -110,28 +110,34 @@ function(Tone){
* start the attack portion of the envelope
* @param {Tone.Time} [time=now] the time the attack should start
* @param {number} [velocity=1] the velocity of the note (0-1)
* @returns {Tone.MonoSynth} `this`
*/
Tone.MonoSynth.prototype.triggerEnvelopeAttack = function(time, velocity){
//the envelopes
this.envelope.triggerAttack(time, velocity);
this.filterEnvelope.triggerAttack(time);
this.filterEnvelope.triggerAttack(time);
return this;
};
/**
* start the release portion of the envelope
* @param {Tone.Time} [time=now] the time the release should start
* @returns {Tone.MonoSynth} `this`
*/
Tone.MonoSynth.prototype.triggerEnvelopeRelease = function(time){
this.envelope.triggerRelease(time);
this.filterEnvelope.triggerRelease(time);
return this;
};
/**
* set the oscillator type
* @param {string} oscType the type of oscillator
* @returns {Tone.MonoSynth} `this`
*/
Tone.MonoSynth.prototype.setOscType = function(type){
this.oscillator.setType(type);
return this;
};
/**
@ -139,6 +145,7 @@ function(Tone){
* @param {Object} params all of the parameters as an object.
* params for envelope and filterEnvelope
* should be nested objects.
* @returns {Tone.MonoSynth} `this`
*/
Tone.MonoSynth.prototype.set = function(params){
if (!this.isUndef(params.detune)) this.detune.setValue(params.detune);
@ -147,10 +154,12 @@ function(Tone){
if (!this.isUndef(params.envelope)) this.envelope.set(params.envelope);
if (!this.isUndef(params.filter)) this.filter.set(params.filter);
Tone.Monophonic.prototype.set.call(this, params);
return this;
};
/**
* clean up
* @returns {Tone.MonoSynth} `this`
*/
Tone.MonoSynth.prototype.dispose = function(){
Tone.Monophonic.prototype.dispose.call(this);
@ -164,6 +173,7 @@ function(Tone){
this.filter = null;
this.frequency = null;
this.detune = null;
return this;
};
return Tone.MonoSynth;

View file

@ -41,19 +41,23 @@ define(["Tone/core/Tone", "Tone/instrument/Instrument", "Tone/signal/Signal"], f
* @param {string|string} note the note
* @param {Tone.Time} [time=now] the time, if not given is now
* @param {number} [velocity=1] velocity defaults to 1
* @returns {Tone.Monophonic} `this`
*/
Tone.Monophonic.prototype.triggerAttack = function(note, time, velocity) {
time = this.toSeconds(time);
this.triggerEnvelopeAttack(time, velocity);
this.setNote(note, time);
return this;
};
/**
* trigger the release portion of the envelope
* @param {Tone.Time} [time=now] if no time is given, the release happens immediatly
* @returns {Tone.Monophonic} `this`
*/
Tone.Monophonic.prototype.triggerRelease = function(time){
this.triggerEnvelopeRelease(time);
return this;
};
/**
@ -61,6 +65,7 @@ define(["Tone/core/Tone", "Tone/instrument/Instrument", "Tone/signal/Signal"], f
* @abstract
* @param {Tone.Time} [time=now] the time the attack should happen
* @param {number} [velocity=1] the velocity of the envelope
* @returns {Tone.Monophonic} `this`
*/
Tone.Monophonic.prototype.triggerEnvelopeAttack = function() {};
@ -69,6 +74,7 @@ define(["Tone/core/Tone", "Tone/instrument/Instrument", "Tone/signal/Signal"], f
* @abstract
* @param {Tone.Time} [time=now] the time the attack should happen
* @param {number} [velocity=1] the velocity of the envelope
* @returns {Tone.Monophonic} `this`
*/
Tone.Monophonic.prototype.triggerEnvelopeRelease = function() {};
@ -77,6 +83,7 @@ define(["Tone/core/Tone", "Tone/instrument/Instrument", "Tone/signal/Signal"], f
* @param {number|string} note if the note is a string, it will be
* parsed as (NoteName)(Octave) i.e. A4, C#3, etc
* otherwise it will be considered as the frequency
* @returns {Tone.Monophonic} `this`
*/
Tone.Monophonic.prototype.setNote = function(note, time){
note = this.toFrequency(note);
@ -88,33 +95,40 @@ define(["Tone/core/Tone", "Tone/instrument/Instrument", "Tone/signal/Signal"], f
} else {
this.frequency.setValueAtTime(note, time);
}
return this;
};
/**
* set the glide time between notes
* @param {Tone.Time} port glide time
* @returns {Tone.Monophonic} `this`
*/
Tone.Monophonic.prototype.setPortamento = function(port){
this.portamento = this.toSeconds(port);
return this;
};
/**
* bulk setter
* @param {Object} params the params
* @returns {Tone.Monophonic} `this`
*/
Tone.Monophonic.prototype.set = function(params) {
if (!this.isUndef(params.portamento)) this.setPortamento(params.portamento);
Tone.Instrument.prototype.set.call(this, params);
return this;
};
/**
* set the preset if it exists
* @param {string} presetName the name of the preset
* @returns {Tone.Monophonic} `this`
*/
Tone.Monophonic.prototype.setPreset = function(presetName){
if (!this.isUndef(this.preset) && this.preset.hasOwnProperty(presetName)){
this.set(this.preset[presetName]);
}
return this;
};
return Tone.Monophonic;

View file

@ -87,20 +87,24 @@ function(Tone){
* start the attack portion of the envelope
* @param {Tone.Time} [time=now] the time the attack should start
* @param {number} [velocity=1] the velocity of the note (0-1)
* @returns {Tone.NoiseSynth} `this`
*/
Tone.NoiseSynth.prototype.triggerAttack = function(time, velocity){
//the envelopes
this.envelope.triggerAttack(time, velocity);
this.filterEnvelope.triggerAttack(time);
this.filterEnvelope.triggerAttack(time);
return this;
};
/**
* start the release portion of the envelope
* @param {Tone.Time} [time=now] the time the release should start
* @returns {Tone.NoiseSynth} `this`
*/
Tone.NoiseSynth.prototype.triggerRelease = function(time){
this.envelope.triggerRelease(time);
this.filterEnvelope.triggerRelease(time);
return this;
};
/**
@ -108,6 +112,7 @@ function(Tone){
* @param {Tone.Time} duration the duration of the note
* @param {Tone.Time} [time=now] the time of the attack
* @param {number} [velocity=1] the velocity
* @returns {Tone.NoiseSynth} `this`
*/
Tone.NoiseSynth.prototype.triggerAttackRelease = function(duration, time, velocity){
time = this.toSeconds(time);
@ -115,14 +120,17 @@ function(Tone){
this.triggerAttack(time, velocity);
console.log(time + duration);
this.triggerRelease(time + duration);
return this;
};
/**
* set the oscillator type
* @param {string} oscType the type of oscillator
* @returns {Tone.NoiseSynth} `this`
*/
Tone.NoiseSynth.prototype.setNoiseType = function(type){
this.noise.setType(type);
return this;
};
/**
@ -130,16 +138,19 @@ function(Tone){
* @param {Object} params all of the parameters as an object.
* params for envelope and filterEnvelope
* should be nested objects.
* @returns {Tone.NoiseSynth} `this`
*/
Tone.NoiseSynth.prototype.set = function(params){
if (!this.isUndef(params.noise)) this.noise.set(params.noise);
if (!this.isUndef(params.filterEnvelope)) this.filterEnvelope.set(params.filterEnvelope);
if (!this.isUndef(params.envelope)) this.envelope.set(params.envelope);
if (!this.isUndef(params.filter)) this.filter.set(params.filter);
return this;
};
/**
* clean up
* @returns {Tone.NoiseSynth} `this`
*/
Tone.NoiseSynth.prototype.dispose = function(){
Tone.Instrument.prototype.dispose.call(this);
@ -151,6 +162,7 @@ function(Tone){
this.filterEnvelope = null;
this.filter.dispose();
this.filter = null;
return this;
};
return Tone.NoiseSynth;

View file

@ -68,6 +68,7 @@ define(["Tone/core/Tone", "Tone/instrument/Instrument", "Tone/source/Noise", "To
* trigger the attack portion
* @param {string|number} note the note name or frequency
* @param {Tone.Time} [time=now] the time of the note
* @returns {Tone.PluckSynth} `this`
*/
Tone.PluckSynth.prototype.triggerAttack = function(note, time) {
if (typeof note === "string"){
@ -78,46 +79,56 @@ define(["Tone/core/Tone", "Tone/instrument/Instrument", "Tone/source/Noise", "To
this._lfcf.setDelayTime(delayAmount, time);
this._noise.start(time);
this._noise.stop(time + delayAmount * this.attackNoise);
return this;
};
/**
* set the resonance of the instrument
* @param {number} resonance the resonance between (0, 1)
* @returns {Tone.PluckSynth} `this`
*/
Tone.PluckSynth.prototype.setResonance = function(resonance) {
this.resonance.setValue(resonance);
return this;
};
/**
* set the dampening of the instrument
* @param {number} dampening a frequency value of the lowpass filter
* nominal range of (1000, 10000)
* @returns {Tone.PluckSynth} `this`
*/
Tone.PluckSynth.prototype.setDampening = function(dampening) {
this.dampening.setValue(dampening);
return this;
};
/**
* set the length of the attack noise
* @param {number} attackNoise the length of the attack nosie.
* a value of 1 is normal.
* @returns {Tone.PluckSynth} `this`
*/
Tone.PluckSynth.prototype.setAttackNoise = function(attackNoise) {
this.attackNoise = attackNoise;
return this;
};
/**
* bulk setter
* @param {Object} param
* @returns {Tone.PluckSynth} `this`
*/
Tone.PluckSynth.prototype.set = function(params){
if (!this.isUndef(params.resonance)) this.setResonance(params.resonance);
if (!this.isUndef(params.dampening)) this.setDampening(params.dampening);
if (!this.isUndef(params.attackNoise)) this.setAttackNoise(params.attackNoise);
return this;
};
/**
* clean up
* @returns {Tone.PluckSynth} `this`
*/
Tone.PluckSynth.prototype.dispose = function(){
Tone.Instrument.prototype.dispose.call(this);
@ -127,6 +138,7 @@ define(["Tone/core/Tone", "Tone/instrument/Instrument", "Tone/source/Noise", "To
this._lfcf = null;
this.dampening = null;
this.resonance = null;
return this;
};
return Tone.PluckSynth;

View file

@ -81,6 +81,7 @@ function(Tone){
* over the array to play each of the notes
* @param {Tone.Time} [time=now] the start time of the note
* @param {number} [velocity=1] the velocity of the note
* @returns {Tone.PolySynth} `this`
*/
Tone.PolySynth.prototype.triggerAttack = function(value, time, velocity){
if (!Array.isArray(value)){
@ -97,6 +98,7 @@ function(Tone){
this._activeVoices[stringified] = voice;
}
}
return this;
};
/**
@ -108,11 +110,13 @@ function(Tone){
* @param {Tone.Time} duration the duration of the note
* @param {Tone.Time} [time=now] if no time is given, defaults to now
* @param {number} [velocity=1] the velocity of the attack (0-1)
* @returns {Tone.PolySynth} `this`
*/
Tone.PolySynth.prototype.triggerAttackRelease = function(value, duration, time, velocity){
time = this.toSeconds(time);
this.triggerAttack(value, time, velocity);
this.triggerRelease(value, time + this.toSeconds(duration));
return this;
};
/**
@ -121,6 +125,7 @@ function(Tone){
* if the value is an array, it will iterate
* over the array to play each of the notes
* @param {Tone.Time} [time=now] the release time of the note
* @returns {Tone.PolySynth} `this`
*/
Tone.PolySynth.prototype.triggerRelease = function(value, time){
if (!Array.isArray(value)){
@ -136,29 +141,35 @@ function(Tone){
this._activeVoices[stringified] = null;
}
}
return this;
};
/**
* set the options on all of the voices
* @param {Object} params
* @returns {Tone.PolySynth} `this`
*/
Tone.PolySynth.prototype.set = function(params){
for (var i = 0; i < this.voices.length; i++){
this.voices[i].set(params);
}
return this;
};
/**
* @param {string} presetName the preset name
* @returns {Tone.PolySynth} `this`
*/
Tone.PolySynth.prototype.setPreset = function(presetName){
for (var i = 0; i < this.voices.length; i++){
this.voices[i].setPreset(presetName);
}
return this;
};
/**
* clean up
* @returns {Tone.PolySynth} `this`
*/
Tone.PolySynth.prototype.dispose = function(){
Tone.Instrument.prototype.dispose.call(this);
@ -169,6 +180,7 @@ function(Tone){
this.voices = null;
this._activeVoices = null;
this._freeVoices = null;
return this;
};
return Tone.PolySynth;