noteIsDown()#
函式oav-p5noteIsDown(n)
鍵 n(MIDI 號碼,或像 'C4' 這樣的音名)按著的時候是 true。
就是 MIDI 版的 keyIsDown()。noteIsDown('C4') 跟 noteIsDown(60) 一樣:C4 是中央 C。不是音符的名稱('H4'、'C-2')會讓草圖停下來,並用一張卡片告訴你怎麼寫。
參數
| 名稱 | 型別 | 說明 |
|---|---|---|
n | Number | String | 哪個鍵:MIDI 號碼(60)或音名('C4'、'c#4'、'Db3')。 |
回傳
Boolean 那個鍵現在按著就是 true。
範例
function setup() {
createCanvas(400, 300);
}
function draw() {
background(20);
fill(noteIsDown('C4') ? color(255, 211, 107) : 80);
circle(width / 2, height / 2, 140); // lights up while middle C is held
}相關
noteIsPressed只要有任何一個鍵按著,就是 true。noteNumber()把像'C4'這樣的音名轉成 MIDI 號碼,0 到 127。notePressed()你來定義這個函式。每當有一個鍵(或打擊墊)按下,oav-p5 就呼叫它。