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

p5 rhythm labp5 節奏實驗台

OAVp5.drums.edit('bd(3,8), …') swaps the rhythm like typing it, OAVp5.drums.undo() goes back a line, OAVp5.drums.strudelUrl opens the line in Strudel; rhythmChanged() says what the line is now.OAVp5.drums.edit('bd(3,8), …') 像打字一樣換節奏,OAVp5.drums.undo() 回上一行,OAVp5.drums.strudelUrl 把這一行帶去 Strudel;rhythmChanged() 告訴你現在是哪一行。

Try these three things試試這三件事

  1. Press 1, 2, 3 or 4: edit() swaps the whole line, the circle and the drum card change at once, and the line is listed under it.
  2. Press Z: undo() goes back one line, as the ↶ on the drum card does. Click a cell or type in the card's line, and rhythmChanged() still tells this page.
  3. Press S: strudelUrl opens the same rhythm at strudel.cc in a new tab.
  1. 按 1、2、3 或 4:edit() 換掉整行,圓圈和鼓機卡馬上跟著變,那一行列在旁邊。
  2. 按 Z:undo() 回到上一行,跟鼓機卡的 ↶ 一樣。點格子或在卡上的那一行打字,rhythmChanged() 一樣會告訴這個頁面。
  3. 按 S:strudelUrl 用新分頁在 strudel.cc 打開同一段節奏。

Needs: QWERTY keys.需要:電腦鍵盤。 No hardware? Use Drum machine.沒有硬體?用鼓機。

Read these lines讀這幾行

  • sketch.js:50–51 edit() plays a line as if it were typed on the card and answers { ok, error }.edit() 像在卡上打字一樣換一行,回答 { ok, error }。
  • sketch.js:52–53 undo() goes back one line and says whether there was one.undo() 回上一行,並告訴你有沒有上一行。
  • sketch.js:54–56 strudelUrl is the line as a strudel.cc link; window.open takes it to a new tab.strudelUrl 是這一行在 strudel.cc 的連結,window.open 用新分頁打開。

In the docs文件裡: The cells and the line edit each other格子和那一行互相改

Next: 04 WebToe stage →下一個:04 WebToe 舞台 → All examples所有範例