Tablet as Drum Pad for Sonic Pi

You just got tired of programming Sonic Pi and wished you could just hammer on some drums? If you have an Android tablet or handy and a PC or a Mac with Sonic Pi installed, I will show you how you can use your tablet as a simple drum pad for Sonic Pi. This will involve installing the free Android App “OSC Controller” on your tablet, configuring your Sonic Pi und some Sonic Pi programming for listening to the OSC Controller. The same configurations work probably with a phone, but for a drum pad it is nice to have a somewhat larger display.

Install OSC Controller on Android

The first step is to install some Android App on your tablet (or phone), which can send OSC commands over the network to your Sonic Pi. I use a free Android App called OSC Controller. It is pretty simple to configure, but also quite limited. For me, this was an advantage when starting with OSC: You cannot get lost in dozens of cryptically named configurations.

Open Play Store, search for “OSC Controller” by Adam Katz and install it. The app is free and it needs only permissions for network access. This is justified, as you will play over the network.

When you start the app for the first time, you will see the network configuration page. When used with your local WLAN, you have to find the local IP Address of your PC first. You see this when you enter ipconfig in the command line tool. Probably it will be something like 192.168…

Confire the network connection in OSC Controller App
Confire the network connection in OSC Controller App

The default port of Sonic Pi for OSC is 4559 and the OSC Path field I left empty. You can save your configuration with the “Export”-Button. In my case, this worked, but I was not able to import a saved configuration later on, the screen just hangs and I have to close the app and start it again.

Now you are ready to activate the connection with the “START”-Button. Tap on the blue “Controls”-Button to change into the first of the four displays with sliders, buttons and other controls. Go to the last display with 24 Buttons (the last of the four wide buttons at the top of the screen). I found this the most useful for a drum pad.

Configure Sonic Pi

By default, Sonic Pi is not configured to receive OSC messages over the networt. Open Prefs in Sonic Pi, click on the I/O-Register and activate “Receive Remote OSC Messages”. Be sure that OSC server is also activated.

Configure Sonic Pi for OSC
Configure Sonic Pi for OSC

If both your configurations – on the tablet and in Sonic Pi – are correct and the connection is activated in “OSC Controller” you can test your configuration. Just tap one of the buttons or use one of the sliders in any of the four displays on your tablet. In Sonic Pi you should see something like “/osc/gridButton4 [1.0]” in the cues window.

OSC Listeners in Sonic Pi

A little bit of programming is necessary to tell Sonic Pi how it should react to the OSC commands it gets from the tablet. For each control you want to use, you must have at least one listener. A listener is an endlessly looping live_loop which reacts to command with a defined address and does something. In my case we will play a drum sample. I start with the three toms:

live_loop :my_osc_tom_lo_loop do
  use_real_time
  a = sync "/osc/tomlo"
  if a == [1.0] then
    sample :drum_tom_lo_hard, amp: 1
  end
end

live_loop :my_osc_tom_mid_loop do
  use_real_time
  a = sync "/osc/tommid"
  if a == [1.0] then
    sample :drum_tom_mid_hard, amp: 1
  end
end

live_loop :my_osc_tom_high_loop do
  use_real_time
  a = sync "/osc/tomhi"
  if a == [1.0] then
    sample :drum_tom_hi_hard, amp: 1
  end
end

Now run your Sonic Pi script. Nothing will happen, yet.

Configure the controls

Now we have nearly finished: In our last step we go back to the OSC Control app and configure three buttons for the three toms: Open display four with the buttons, tap on the edit button at the top right and then on the first button. In the field Address you write “/tomlo” and in the label field something like “tom low” or whatever you need to recognize the button later on. Confirm your entry with the Update button.

The same you do with button 2 and 3. The address has always to be the same like the part after /osc in your listener, which is /tommid and /tomhi.

When you’re done with you control configurations, don’t forget to leave the edit mode by tapping on the edit button. Now you can start hammering: just tab on the configured buttons and you should hear the sound in Sonic Pi.

Configure the first button control in the OSC Controller app
Configure the first button control in the OSC Controller app

Why?

One question remains to be answered: Why the hell should I go through all the trouble with configuring and programming? Dozens of good standalone drum pad apps on Android work without the need of a computer or Sonic Pi.

Maybe you just have a better sound card on your PC? My reason was that I already used Sonic Pi and wanted some visual control for it. The example with the drums is just a start. You can confire and control all sort of OSC commands with the controls of the Android app.

Comments are closed.