Skip to content

Commit 650c9ce

Browse files
committed
fixed issue: processing/p5.js-sound#297
1 parent a7a2a22 commit 650c9ce

File tree

5 files changed

+64
-9
lines changed

5 files changed

+64
-9
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<head>
2+
<script language="javascript" type="text/javascript" src="../../lib/p5.js"></script>
3+
4+
<script language="javascript" type="text/javascript" src="../../lib/addons/p5.dom.js"></script>
5+
6+
<script language="javascript" type="text/javascript" src="../../lib/p5.sound.js"></script>
7+
8+
<script language="javascript" type="text/javascript" src="sketch.js"></script>
9+
10+
</head>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
function setup() {
2+
background(0);
3+
noStroke();
4+
fill(255);
5+
textAlign(CENTER);
6+
text('click to play', width/2, height/2);
7+
8+
mySound = loadSound('../files/beat.mp3');
9+
10+
// schedule calls to changeText
11+
var firstCueId = mySound.addCue(0.50, changeText, "hello" );
12+
mySound.addCue(1.00, changeText, "p5" );
13+
var thirdCueId = mySound.addCue(1.50, changeText, "what" );
14+
mySound.addCue(2.00, changeText, "do" );
15+
mySound.addCue(2.50, changeText, "you" );
16+
mySound.addCue(3.00, changeText, "want" );
17+
mySound.addCue(4.00, changeText, "to" );
18+
mySound.addCue(5.00, changeText, "make" );
19+
mySound.addCue(6.00, changeText, "?" );
20+
21+
//remove the first cue
22+
mySound.removeCue(firstCueId);
23+
24+
//remove the third cue
25+
mySound.removeCue(thirdCueId);
26+
}
27+
28+
function changeText(val) {
29+
background(0);
30+
text(val, width/2, height/2);
31+
}
32+
33+
function mouseClicked() {
34+
if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) {
35+
if (mySound.isPlaying() ) {
36+
mySound.stop();
37+
} else {
38+
mySound.play();
39+
}
40+
}
41+
}

lib/p5.sound.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! p5.sound.js v0.3.8 2018-06-15 */
1+
/*! p5.sound.js v0.3.8 2018-06-20 */
22
/**
33
* p5.sound extends p5 with <a href="http://caniuse.com/audio-api"
44
* target="_blank">Web Audio</a> functionality including audio input,
@@ -881,6 +881,7 @@ soundfile = function () {
881881
this._pauseTime = 0;
882882
// cues for scheduling events with addCue() removeCue()
883883
this._cues = [];
884+
this._cueIDCounter = 0;
884885
// position of the most recently played sample
885886
this._lastPos = 0;
886887
this._counterNode = null;
@@ -2195,7 +2196,8 @@ soundfile = function () {
21952196
for (var i = 0; i < cueLength; i++) {
21962197
var cue = this._cues[i];
21972198
if (cue.id === id) {
2198-
this.cues.splice(i, 1);
2199+
this._cues.splice(i, 1);
2200+
break;
21992201
}
22002202
}
22012203
if (this._cues.length === 0) {

lib/p5.sound.min.js

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/soundfile.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ define(function (require) {
8888

8989
// cues for scheduling events with addCue() removeCue()
9090
this._cues = [];
91+
this._cueIDCounter = 0;
9192

9293
// position of the most recently played sample
9394
this._lastPos = 0;
@@ -1595,7 +1596,8 @@ define(function (require) {
15951596
for (var i = 0; i < cueLength; i++) {
15961597
var cue = this._cues[i];
15971598
if (cue.id === id) {
1598-
this.cues.splice(i, 1);
1599+
this._cues.splice(i, 1);
1600+
break;
15991601
}
16001602
}
16011603

0 commit comments

Comments
 (0)