Skip to content

Commit d516f6c

Browse files
committed
Sound will no longer stop when removing effects.
1 parent 7564169 commit d516f6c

5 files changed

Lines changed: 68 additions & 1 deletion

File tree

distr/Pizzicato.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,13 +419,21 @@
419419
if (index === -1)
420420
return;
421421

422+
var shouldResumePlaying = this.playing;
423+
424+
if (shouldResumePlaying)
425+
this.pause();
426+
422427
this.fadeNode.disconnect();
423428

424429
for (var i = 0; i < this.effects.length; i++)
425430
this.effects[i].outputNode.disconnect();
426431

427432
this.effects.splice(index, 1);
428433
this.connectEffects();
434+
435+
if (shouldResumePlaying)
436+
this.play();
429437
}
430438
},
431439

distr/Pizzicato.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

site/Pizzicato.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,13 +419,21 @@
419419
if (index === -1)
420420
return;
421421

422+
var shouldResumePlaying = this.playing;
423+
424+
if (shouldResumePlaying)
425+
this.pause();
426+
422427
this.fadeNode.disconnect();
423428

424429
for (var i = 0; i < this.effects.length; i++)
425430
this.effects[i].outputNode.disconnect();
426431

427432
this.effects.splice(index, 1);
428433
this.connectEffects();
434+
435+
if (shouldResumePlaying)
436+
this.play();
429437
}
430438
},
431439

src/Sound.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,13 +263,21 @@ Pizzicato.Sound.prototype = Object.create(Pizzicato.Events, {
263263
if (index === -1)
264264
return;
265265

266+
var shouldResumePlaying = this.playing;
267+
268+
if (shouldResumePlaying)
269+
this.pause();
270+
266271
this.fadeNode.disconnect();
267272

268273
for (var i = 0; i < this.effects.length; i++)
269274
this.effects[i].outputNode.disconnect();
270275

271276
this.effects.splice(index, 1);
272277
this.connectEffects();
278+
279+
if (shouldResumePlaying)
280+
this.play();
273281
}
274282
},
275283

tests/Sound.test.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,5 +281,48 @@ describe('Sound', function() {
281281
done();
282282
});
283283
}, 5000);
284+
285+
it('should continue playing when effects are added', function(done) {
286+
var endCallback = jasmine.createSpy('endCallback');
287+
288+
var sound = new Pizzicato.Sound('base/tests/click.wav', function() {
289+
290+
var delay = new Pz.Effects.Delay();
291+
292+
sound.play();
293+
sound.addEffect(delay);
294+
expect(sound.playing).toBe(true);
295+
296+
setTimeout(function() {
297+
expect(endCallback).toHaveBeenCalled();
298+
done();
299+
}, 2000);
300+
});
301+
302+
sound.on('end', endCallback);
303+
304+
}, 5500);
305+
306+
it('should continue playing when effects are removed', function(done) {
307+
var endCallback = jasmine.createSpy('endCallback');
308+
var delay = new Pz.Effects.Delay();
309+
310+
var sound = new Pizzicato.Sound('base/tests/click.wav', function() {
311+
312+
sound.play();
313+
sound.removeEffect(delay);
314+
315+
expect(sound.playing).toBe(true);
316+
317+
setTimeout(function() {
318+
expect(endCallback).toHaveBeenCalled();
319+
done();
320+
}, 2000);
321+
});
322+
323+
sound.on('end', endCallback);
324+
sound.addEffect(delay);
325+
326+
}, 5500);
284327
});
285328
});

0 commit comments

Comments
 (0)