@@ -16,7 +16,7 @@ define(function (require) {
16
16
* @constructor
17
17
*
18
18
* @param {Number } [synthVoice] A monophonic synth voice inheriting
19
- * the AudioVoice class. Defaults ot p5.MonoSynth
19
+ * the AudioVoice class. Defaults to p5.MonoSynth
20
20
*
21
21
* @param {Number } [polyValue] Number of voices, defaults to 8;
22
22
*
@@ -158,10 +158,10 @@ define(function (require) {
158
158
* @param {Number } [releaseTime] Time in seconds from now (defaults to 0)
159
159
**/
160
160
p5 . PolySynth . prototype . setADSR = function ( a , d , s , r ) {
161
- this . audiovoices . forEach ( function ( voice ) {
161
+ this . audiovoices . forEach ( function ( voice ) {
162
162
voice . setADSR ( a , d , s , r ) ;
163
- } )
164
- }
163
+ } ) ;
164
+ } ;
165
165
166
166
/**
167
167
* Trigger the Attack, and Decay portion of a MonoSynth.
@@ -205,16 +205,33 @@ define(function (require) {
205
205
206
206
this . notes [ note ] = currentVoice ;
207
207
208
- this . _voicesInUse . setValueAtTime ( this . _voicesInUse . value + 1 , t ) ;
208
+ //this._voicesInUse.setValueAtTime(this._voicesInUse.getValueAtTime(t) + 1, t);
209
+
210
+ var previousVal = this . _voicesInUse . _searchBefore ( t ) === null ? 0 : this . _voicesInUse . _searchBefore ( t ) . value ;
211
+ this . _voicesInUse . setValueAtTime ( previousVal + 1 , t ) ;
212
+ this . _updateAfter ( t , 1 ) ;
209
213
210
214
this . _newest = currentVoice ;
211
215
212
216
this . audiovoices [ currentVoice ] . triggerAttack ( note , velocity , tFromNow ) ;
213
217
214
218
} ;
215
219
220
+ p5 . PolySynth . prototype . _updateAfter = function ( time , value ) {
221
+
222
+ if ( this . _voicesInUse . _searchAfter ( time ) === null ) {
223
+ return ;
224
+ } else {
225
+ this . _voicesInUse . _searchAfter ( time ) . value += value ;
226
+ var nextTime = this . _voicesInUse . _searchAfter ( time ) . time ;
227
+ this . _updateAfter ( nextTime , value ) ;
228
+ }
229
+ }
230
+
231
+
232
+
216
233
/**
217
- * Trigger the Release of a MonoSynth note. This is similar to releasing
234
+ * Trigger the Release of an AudioVoice note. This is similar to releasing
218
235
* the key on a piano and letting the sound fade according to the
219
236
* release level and release time.
220
237
*
@@ -236,8 +253,14 @@ define(function (require) {
236
253
var tFromNow = secondsFromNow || 0 ;
237
254
var t = now + tFromNow ;
238
255
239
- this . _voicesInUse . setValueAtTime ( this . _voicesInUse . value - 1 , t ) ;
240
- this . audiovoices [ this . notes [ note ] ] . triggerRelease ( secondsFromNow ) ;
256
+ // this._voicesInUse.setValueAtTime(this._voicesInUse.getValueAtTime(t)-1, t);
257
+ // console.log('value at time: '+ t +' value '+this._voicesInUse.getValueAtTime(t));
258
+ var previousVal = this . _voicesInUse . _searchBefore ( t ) === null ? 0 : this . _voicesInUse . _searchBefore ( t ) . value ;
259
+ this . _voicesInUse . setValueAtTime ( previousVal - 1 , t ) ;
260
+ this . _updateAfter ( t , - 1 ) ;
261
+
262
+
263
+ this . audiovoices [ this . notes [ note ] ] . triggerRelease ( tFromNow ) ;
241
264
this . notes [ note ] = undefined ;
242
265
243
266
this . _newest = this . _newest === 0 ? 0 : ( this . _newest - 1 ) % ( this . polyValue - 1 ) ;
0 commit comments