We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I am working on a p5.js with sound library, and using p5 Phrase and p5 Part for making multiple sound files play at once.
I was able to addPhrase() but the removePhrase() function inside the mousePressed function does not work at all. How can I toggle between adding and removing phrases from the p5 Part, which would turn on/off the specific sound file?
Thank you!
var box, drum, myPart;
var drumPhrase;
var boxPhrase;
var boxPat = [1, 0, 0, 2, 0, 2, 0, 0];
var drumPat = [0, 1, 1, 0, 2, 0, 1, 0];
function preload() {
box = loadSound('sound/noise.mp3');
drum = loadSound('sound/drum1.wav');
}
function setup() {
noStroke();
fill(255);
textAlign(CENTER);
masterVolume(0.1);
boxPhrase = new p5.Phrase('box', playBox, boxPat);
drumPhrase = new p5.Phrase('drum', playDrum, drumPat);
myPart = new p5.Part();
myPart.addPhrase(boxPhrase);
myPart.addPhrase(drumPhrase);
myPart.setBPM(60);
masterVolume(0.1);
myPart.start();
}
function draw() {
background(0);
}
function playBox(time, playbackRate) {
box.rate(playbackRate);
box.play(time);
}
function playDrum(time, playbackRate) {
drum.rate(playbackRate);
drum.play(time);
}
function mousePressed() {
myPart.removePhrase(box);
}