0
我正在與聲音庫p5.js一起工作,並使用p5短語和p5聲部一次播放多個聲音文件。p5.js聲音庫:如何添加/刪除p5。短語()來自p5。部分()?
我能夠addPhrase()
但mousePressed
功能內的removePhrase()
功能根本不起作用。 如何切換添加和刪除p5聲部中的短語,這會打開/關閉特定的聲音文件?
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);
}
該引用表示'removePhrase(phraseName)',其中_phraseName_是一個字符串標識符。所以在你的情況下,它應該是'myPart.removePhrase('box');' – michaPau
我已經試過這樣做了,但不起作用。 –