-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstrument.js
45 lines (37 loc) · 994 Bytes
/
instrument.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
'use strict';
var Tone = require('tone');
/**
* Provide a Instrument wrapper for Tone
* @return {object}
*/
module.exports = function() {
var Instrument = function(synthClass) {
this.synthClass = synthClass;
this.synth = false;
}
Instrument.prototype.play = function (note, duration, delay) {
if (this.synth) {
this.synth.triggerAttackRelease(note, duration, delay);
}
}
Instrument.prototype.get = function (channels) {
if (channels > 1) {
this.synth = new Tone.PolySynth(channels, this.synthClass).toMaster();
this.synth.set(this.options);
} else {
this.synth = new this.synthClass(this.options).toMaster();
}
return this;
}
Instrument.prototype.set = function (options) {
this.options = options;
}
Instrument.prototype.destroy = function(delay) {
setTimeout((function(){
if (this.synth) {
this.synth.disconnect();
}
}).bind(this), delay * 1000)
}
return Instrument;
}();