rserota / wad

Web Audio DAW. Use the Web Audio API for dynamic sound synthesis. It's like jQuery for your ears.
MIT License
1.89k stars 160 forks source link

Calling stop on a nonplaying sound gives an error #88

Closed frastlin closed 6 years ago

frastlin commented 6 years ago

Hello, I am trying to stop all sounds at once. I don't know exactly what sounds are playing at any one moment in time, but I have a list of all sounds. I did the following code to stop all sounds:

sound_list.map(sound=>sound.stop())

I get the following error:

TypeError: this.gain[0] is undefined
["./node_modules/web-audio-daw/build/wad.js"]/</<["./src/wad.js"]/</Wad</Wad.prototype.stop
C:/path_to_project/node_modules/web-audio-daw/build/wad.js:3272
  3269 |     }
  3270 | }
  3271 | if ( !label ) {
> 3272 |     this.gain[0].gain.cancelScheduledValues(context.currentTime);
  3273 |     this.gain[0].gain.setValueAtTime(this.gain[0].gain.value, context.currentTime);
  3274 |     this.gain[0].gain.linearRampToValueAtTime(.0001, context.currentTime + this.env.release);
  3275 | }
frastlin commented 6 years ago

Note that a playing attribute may do the trick as well, then I don't need to stop a stopped sound. Something like: sound.play

true

rserota commented 6 years ago

In the latest version, calling stop on a Wad that has never played will log a harmless warning instead of throwing an error.