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
我已经试过这样做了,但不起作用。 –