2016-05-13 22 views
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); 

} 
+0

リファレンスには、「removePhrase(phraseName)」と表示されます。ここで、_phraseName_は文字列識別子です。したがって、あなたのケースでは、それは 'myPart.removePhrase( 'box');' – michaPau

+0

私はそれをやろうとしましたが、うまくいきません... –

答えて

1

p5.soundにはバグがあり、p5.Part.removePhraseは機能しません。ここで

は修正だ:あなたのセットアップ()関数の最後に次のコードを追加します。

p5.Part.prototype.removePhrase = function (name) { 
    for (var i in this.phrases) { 
     if (this.phrases[i].name === name) { 
      this.phrases.splice(i, 1); 
     } 
    } 
}; 

これは、実際の作業コード付きバギー機能を置き換えます。

私はp5.jsの開発者に知らせて、バグを公式バージョンで修正できるようにします。