Example 24 · Anything can be an instrument範例 24 · 什麼都能當樂器

p5 note namesp5 音名

noteIsDown('C4') works like noteIsDown(60): write note names (C4, c#4, Db3) wherever a note number goes; noteNumber(), noteName() and noteFreq() convert.noteIsDown('C4') 跟 noteIsDown(60) 一樣:收音符號碼的地方都能直接寫音名(C4、c#4、Db3)。noteNumber()、noteName()、noteFreq() 幫你換算。

Try these three things試試這三件事

  1. Play C4, E4 and G4 on a keyboard (or the on-screen one under 🎹): each shape lights up while its key is down.
  2. Hold all three at once, a C major chord: the shapes spin.
  3. Play any other key: the line under the shapes says its name and its frequency in Hz.
  1. 在鍵盤(或 🎹 打開的螢幕鍵盤)上彈 C4、E4、G4:按著的時候,對應的圖形會亮起來。
  2. 三個一起按住(C 大調和弦):三個圖形一起轉。
  3. 彈任何別的鍵:圖形下面那一行會寫出它的音名和赫茲。

Needs: MIDI controller.需要:MIDI 控制器。 No hardware? Use On-screen controller · Phone or iPad.沒有硬體?用螢幕上的控制器、手機或 iPad。

Read these lines讀這幾行

  • sketch.js:21 noteIsDown() takes a name as well as a number: 'C4' is 60.noteIsDown() 數字和音名都收:'C4' 就是 60。
  • sketch.js:34 noteNumber('C4') gives 60.noteNumber('C4') 回傳 60。
  • sketch.js:39 notePressed still hands you a number; noteName() writes it back as a name and noteFreq() gives Hz.notePressed 拿到的還是號碼;noteName() 把它寫回音名,noteFreq() 算出赫茲。

In the docs文件裡: Note names音名

Next: 25 p5 numbers that move →下一個:25 p5 會動的數值 → All examples所有範例