Documenting and Playing Drum Sheets with Sonic Pi

2 minute read

Back in the old days, I learned how to play drums by jotting down the beats of each song. As paper drum sheets are hard to organize and modify, I yearned for something able to document those sheets electronically. Although now many apps that can achieve this, I just don’t like GUI.

Recently, I learned how to document and even play drum sheets within a text editor thanks to the development of Sonic Pi, which allows user to code their music and play it! It is a Ruby-based domain-specific language for music synthesis. I feel it super cool because it has features such as synchronizable threads for multiple concurrent soundtracks.

So how do we document drum sheets using Sonic Pi? I found a wrapper on github and the input looks like this:

  # program your pattern here - each item in the list represents 1/4 of a beat
  # for each item, enter a number between 0 and 9 (0=silent,9=loudest)
  hat   [5, 0, 5, 0,  5, 0, 5, 0,  5, 0, 5, 0,  5, 0, 5, 0]
  kick  [9, 0, 9, 0,  0, 0, 0, 0,  9, 0, 0, 3,  0, 0, 0, 0]
  snare [0, 0, 0, 0,  9, 0, 0, 2,  0, 1, 0, 0,  9, 0, 0, 1]

Copy-and-paste the entire code into Sonic Pi’s editor and hit the run button. It is indeed playable.

However, the input seems unnatural to me because it emphasizes on volumes instead of the instruments. By introducing variables and adding more sounds, I managed to make the input look like the following. The entire code is avaible here on github. By fine-tuing the color scheme of my editor, I made it even more readable and straightforward.

  x = 2 # Closed hi-hat
  o = 4 # Half-open hi-hat / normal hit for other instruments
  Q = 5 # Heavy hit
  b = 2 # Normal bass drum kick

  hat   [x, 0, x, 0,  x, 0, x, 0,  x, 0, x, 0,  x, 0, 0, o]
  snare [0, 0, 0, 0,  Q, 0, 0, Q,  0, o, 0, 0,  Q, 0, 0, 0]
  kick  [b, 0, b, 0,  0, 0, 0, 0,  b, 0, 0, b,  0, 0, 0, b]
  tom1  [0, 0, 0, 0,  0, 0, 0, 0,  0, 0, 0, 0,  0, Q, 0, 0]
  tom2  [0, 0, 0, 0,  0, 0, 0, 0,  0, 0, 0, 0,  0, 0, Q, 0]
  tom3  [0, 0, 0, 0,  0, 0, 0, 0,  0, 0, 0, 0,  0, 0, 0, 0]

Now we know how to document drum sheets, but I am not satisfied with the workflow because Sonic Pi’s editor is not suitable for programming at all. After some search, I found an Atom package that supports playing music within the editor itself (with Sonic Pi running in the background). Now I can edit the code and instantly test it simply with alt+r.

Some features I wish:

  • Pure CLI support (e.g., launching at CLI and taking arguments)
  • Multi-file support for better modularity

Some further ideas:

  • This enables people to form remote bands! People can contribute their code and jam online/offline.
  • Music generation with style transfer using neural networks as in image processing.

Categories:

Updated: