@@ -22,19 +22,8 @@ define(function (require) {
22
22
p5 . MonoSynth = function ( ) {
23
23
AudioVoice . call ( this ) ;
24
24
25
- // this.ac = p5sound.audiocontext;
26
-
27
- // this.output = this.ac.createGain();
28
-
29
- // this.attack = 0.02;
30
- // this.decay=0.25;
31
- // this.sustain=0.05;
32
- // this.release=0.35;
33
-
34
- // default voice
35
25
this . oscillator = new p5 . Oscillator ( ) ;
36
26
37
- // envelope
38
27
this . env = new p5 . Env ( ) ;
39
28
this . env . setRange ( 1 , 0 ) ;
40
29
this . env . setExp ( true ) ;
@@ -99,9 +88,12 @@ define(function (require) {
99
88
100
89
// set range of env (TO DO: allow this to be scheduled in advance)
101
90
var vel = velocity || 1 ;
102
- this . env . setRange ( vel , 0 ) ;
91
+ // this.env.setRange(vel, 0);
92
+
93
+ // this.env.play(this.output, secondsFromNow, susTime);
103
94
104
- this . env . play ( this . output , secondsFromNow , susTime ) ;
95
+ this . triggerAttack ( note , velocity , secondsFromNow ) ;
96
+ this . triggerRelease ( secondsFromNow + susTime ) ;
105
97
} ;
106
98
107
99
/**
@@ -133,7 +125,6 @@ define(function (require) {
133
125
p5 . MonoSynth . prototype . triggerRelease = function ( secondsFromNow ) {
134
126
this . env . ramp ( this . output , secondsFromNow , 0 ) ;
135
127
this . _isOn = false ;
136
- // this.env.triggerRelease(this.output, secondsFromNow);
137
128
} ;
138
129
139
130
@@ -151,10 +142,13 @@ define(function (require) {
151
142
*/
152
143
153
144
p5 . MonoSynth . prototype . setParams = function ( params ) {
154
-
155
145
} ;
156
146
157
-
147
+ /**
148
+ * loads preset values
149
+ * @param {String } preset A preset that has been written for MonoSynth
150
+ * @return {Object } Return the MonoSynth
151
+ */
158
152
p5 . MonoSynth . prototype . loadPreset = function ( preset ) {
159
153
var options = this [ preset ] ;
160
154
this . oscillator . setType ( options . oscillator . type ) ;
@@ -219,6 +213,7 @@ define(function (require) {
219
213
'res' : 1
220
214
}
221
215
} ;
216
+
222
217
/**
223
218
* Set values like a traditional
224
219
* <a href="https://en.wikipedia.org/wiki/Synthesizer#/media/File:ADSR_parameter.svg">
@@ -246,6 +241,13 @@ define(function (require) {
246
241
} ;
247
242
248
243
244
+ /**
245
+ * Getters and Setters
246
+ * @param {Number } attack
247
+ * @param {Number } decay
248
+ * @param {Number } sustain
249
+ * @param {Number } release
250
+ */
249
251
Object . defineProperties ( p5 . MonoSynth , {
250
252
'attack' : {
251
253
get : function ( ) {
@@ -285,12 +287,18 @@ define(function (require) {
285
287
} ,
286
288
} ) ;
287
289
290
+ /**
291
+ * MonoSynth amp
292
+ * @method amp
293
+ * @param {Number } vol desired volume
294
+ * @param {Number } [rampTime] Time to reach new volume
295
+ * @return {Number } new volume value
296
+ */
288
297
p5 . MonoSynth . prototype . amp = function ( vol , rampTime ) {
289
298
var t = rampTime || 0 ;
290
299
if ( typeof vol !== 'undefined' ) {
291
300
this . oscillator . amp ( vol , t ) ;
292
301
}
293
-
294
302
return this . oscillator . amp ( ) . value ;
295
303
} ;
296
304
@@ -322,7 +330,7 @@ define(function (require) {
322
330
* @method dispose
323
331
*/
324
332
p5 . MonoSynth . prototype . dispose = function ( ) {
325
- AudioVoice . prototype . disposed . apply ( this ) ;
333
+ AudioVoice . prototype . dispose . apply ( this ) ;
326
334
327
335
this . filter . dispose ( ) ;
328
336
this . env . dispose ( ) ;
0 commit comments