2014-12-19 21:27:50 +00:00
|
|
|
define(["Tone/core/Tone", "Tone/core/Master", "Tone/core/Note"], function(Tone){
|
2014-09-17 04:19:30 +00:00
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @class Base-class for all instruments
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @extends {Tone}
|
|
|
|
*/
|
|
|
|
Tone.Instrument = function(){
|
|
|
|
|
|
|
|
/**
|
|
|
|
* the output
|
|
|
|
* @type {GainNode}
|
2015-02-28 04:24:51 +00:00
|
|
|
* @private
|
2014-09-17 04:19:30 +00:00
|
|
|
*/
|
|
|
|
this.output = this.context.createGain();
|
2015-02-10 16:40:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* the volume of the output in decibels
|
2015-06-14 00:20:36 +00:00
|
|
|
* @type {Decibels}
|
|
|
|
* @signal
|
2015-02-10 16:40:04 +00:00
|
|
|
*/
|
2015-05-23 22:57:05 +00:00
|
|
|
this.volume = new Tone.Signal(this.output.gain, Tone.Type.Decibels);
|
2015-04-18 14:54:08 +00:00
|
|
|
this._readOnly(["volume"]);
|
2014-09-17 04:19:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Tone.extend(Tone.Instrument);
|
|
|
|
|
2015-05-23 22:16:34 +00:00
|
|
|
/**
|
|
|
|
* the default attributes
|
|
|
|
* @type {object}
|
|
|
|
*/
|
|
|
|
Tone.Instrument.defaults = {
|
|
|
|
/** the volume of the output in decibels */
|
|
|
|
"volume" : 0
|
|
|
|
};
|
|
|
|
|
2014-09-17 04:19:30 +00:00
|
|
|
/**
|
|
|
|
* @abstract
|
2014-09-20 22:57:44 +00:00
|
|
|
* @param {string|number} note the note to trigger
|
2015-06-14 00:20:36 +00:00
|
|
|
* @param {Time} [time=now] the time to trigger the ntoe
|
2014-12-02 06:42:08 +00:00
|
|
|
* @param {number} [velocity=1] the velocity to trigger the note
|
2014-09-17 04:19:30 +00:00
|
|
|
*/
|
|
|
|
Tone.Instrument.prototype.triggerAttack = function(){};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @abstract
|
2015-06-14 00:20:36 +00:00
|
|
|
* @param {Time} [time=now] when to trigger the release
|
2014-09-17 04:19:30 +00:00
|
|
|
*/
|
|
|
|
Tone.Instrument.prototype.triggerRelease = function(){};
|
|
|
|
|
|
|
|
/**
|
2015-06-14 03:15:57 +00:00
|
|
|
* Trigger the attack and then the release after the duration.
|
2014-09-20 22:57:44 +00:00
|
|
|
* @param {string|number} note the note to trigger
|
2015-06-14 00:20:36 +00:00
|
|
|
* @param {Time} duration the duration of the note
|
|
|
|
* @param {Time} [time=now] the time of the attack
|
|
|
|
* @param {NormalRange} [velocity=1] the velocity
|
2015-06-14 00:54:29 +00:00
|
|
|
* @returns {Tone.Instrument} this
|
2015-06-14 03:15:57 +00:00
|
|
|
* @example
|
|
|
|
* //trigger "C4" for the duration of an 8th note
|
|
|
|
* synth.triggerAttackRelease("C4", "8n");
|
2014-09-17 04:19:30 +00:00
|
|
|
*/
|
2014-09-20 22:57:44 +00:00
|
|
|
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);
|
2015-02-02 18:30:36 +00:00
|
|
|
return this;
|
2014-09-20 22:57:44 +00:00
|
|
|
};
|
2014-09-17 04:19:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* clean up
|
2015-06-14 00:54:29 +00:00
|
|
|
* @returns {Tone.Instrument} this
|
2014-09-17 04:19:30 +00:00
|
|
|
*/
|
|
|
|
Tone.Instrument.prototype.dispose = function(){
|
|
|
|
Tone.prototype.dispose.call(this);
|
2015-04-18 14:54:08 +00:00
|
|
|
this._writable(["volume"]);
|
2015-02-10 16:40:04 +00:00
|
|
|
this.volume.dispose();
|
|
|
|
this.volume = null;
|
2015-02-02 18:30:36 +00:00
|
|
|
return this;
|
2014-09-17 04:19:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return Tone.Instrument;
|
|
|
|
});
|