Tone.js/Tone/instrument/Instrument.js

78 lines
1.9 KiB
JavaScript
Raw Normal View History

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}
*/
this.output = this.context.createGain();
};
Tone.extend(Tone.Instrument);
/**
* @abstract
2014-09-20 22:57:44 +00:00
* @param {string|number} note the note to trigger
2014-12-02 06:42:08 +00:00
* @param {Tone.Time} [time=now] the time to trigger the ntoe
* @param {number} [velocity=1] the velocity to trigger the note
2014-09-17 04:19:30 +00:00
*/
Tone.Instrument.prototype.triggerAttack = function(){};
/**
* @abstract
2014-12-02 06:42:08 +00:00
* @param {Tone.Time} [time=now] when to trigger the release
2014-09-17 04:19:30 +00:00
*/
Tone.Instrument.prototype.triggerRelease = function(){};
/**
2014-09-20 22:57:44 +00:00
* trigger the attack and then the release
* @param {string|number} note the note to trigger
2014-12-02 06:42:08 +00:00
* @param {Tone.Time} duration the duration of the note
* @param {Tone.Time} [time=now] the time of the attack
2014-09-20 22:57:44 +00:00
* @param {number} velocity the velocity
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);
};
2014-09-17 04:19:30 +00:00
/**
* bulk setter
* @param {Object} params the params
*/
Tone.Instrument.prototype.set = function(params) {
if (!this.isUndef(params.volume)) this.setVolume(params.volume);
};
/**
* gets the setVolume method from {@link Tone.Master}
* @method
*/
Tone.Instrument.prototype.setVolume = Tone.Master.setVolume;
/**
* gets the setVolume method from {@link Tone.Master}
2014-09-17 04:19:30 +00:00
* @method
*/
Tone.Instrument.prototype.setVolume = Tone.Master.setVolume;
2014-09-17 04:19:30 +00:00
/**
* clean up
*/
Tone.Instrument.prototype.dispose = function(){
Tone.prototype.dispose.call(this);
};
return Tone.Instrument;
});