Skip to main content

Connecting the SPOKE board with Sonic Pi in Chrome

In a recent post (First play with a SPOKE capacitive touch MIDI board), I shared some first impressions of getting the SPOKE board connected, trying the web-based examples, and using it as drums in GarageBand. At the end of that post, I mentioned that the next thing I wanted to try was looking at the coding side of things.,


Image taken from the spoke website of the spoke board
image taken from https://www.spokeboard.com/



Because the SPOKE board acts as a MIDI controller, my mind immediately went back to Sonic Pi. As I mentioned in an earlier post (Spooky Hot-Cross Buns - Sonic Pi), I have no musical ability at all, but I really enjoy creating with Sonic Pi—it is free, fun, and a brilliant bit of software. Putting the two together seemed like an obvious next step.

For this experiment, I connected the SPOKE board as before, but instead of using an installed desktop app, I ran the web version of Sonic Pi (https://sonic-pi.net/code.html) straight in Chrome with no special set-up. This is a really useful option when you are working on a machine that has internet access but no administrative rights to install software.

The only thing I needed to do in Sonic Pi was go into the preferences to enable MIDI (see below).

Shows enabling the midi preferences
Screenshot of Sonic Pi MIDI preference


Once that was ticked, touching the pads on the SPOKE board started registering in Sonic Pi's cues log straight away.

Next, I tried the standard MIDI code from the Sonic Pi tutorials. The messages were clearly coming in, and the board and browser were talking to each other, but no sound was playing at all.

After a bit of searching, I found a post on the Sonic Pi forum that solved the problem: https://in-thread.sonic-pi.net/t/midi-keyboard-with-sonic-pi-no-audio/4202/8.

The issue was down to how Sonic Pi matches the MIDI device in the sync command, and how MIDI controllers often send a velocity of 0 when you lift your finger off a pad. Using the advice from the forum (and changing the synth to :blade), I ended up with this short bit of code:

Ruby
use_synth :blade
live_loop :midi_piano do
  use_real_time
  n,v = sync "/midi*/note_on"
  play n,amp: v/127.0,sustain: 0.2 if v>0
end

Using the wildcard /midi*/note_on tells Sonic Pi to listen for a note_on signal from any connected MIDI port without getting tripped up by the exact device name, and use_real_time keeps the delay down so it reacts as soon as you touch a pad. Adding if v>0 at the end stops it from trying to trigger a silent note when you take your finger off the board.

Touch a pad on the SPOKE board, and you now get the :blade synth playing right out of the browser. It is a really nice, immediate way to link physical touch to live-coded sound without needing to install anything.

The next things I want to try revolve around two areas:

  1. Digging deeper into the Sonic Pi coding to make it do a bit more than just play single notes. I don't have any particular ideas on what yet, so if you have any suggestions or things you would like to see tried, please drop them in the comments below!

  2. Playing more with the physical side of the SPOKE board. Because the board is made up of capacitive touch connectors, you can attach crocodile clips, copper tape, or conductive objects to it—in some respects, it is like a MIDI version of the brilliant Makey Makey devices. Combining that physical making side with Sonic Pi should be a lot of fun.




All opinions in this blog are the Author's and should not in any way be seen as reflecting the views of any organisation the Author has any association with. Twitter @scottturneruon

Comments

Popular posts from this blog

Programming Anki's Vector robot

With the sad news that Anki is shutting down ( https://www.vox.com/2019/4/29/18522966/anki-robot-cozmo-staff-layoffs-robotics-toys-boris-sofman ) I thought it was time I start playing with the SDK for the Vector robot. In this short post, I providing a quick overview of getting going with this with a simple program based on the tutorials Anki provide. Installation I am using a Mac (more details are available here  https://developer.anki.com/vector/docs/install-macos.html ) but there are instructions for Windows and Linux. - You need the Vector to have been set-up previous on a tablet, and an account set-up on the Anki Cloud. - Install Homebrew - available here  https://brew.sh/ - Using Homebrew to install Python3  brew install python3 -Now install the SDK  python3 - m pip install -- user anki_vector - Lst but not least configure the set-up  python3 - m anki_vector . configure - that is it. The configuration tool tells you where the serial...

Speech Recognition in Scratch 3 - turning Hello into Bonjour!

The Raspberry Pi Foundation recently released a programming activity Alien Language , with support Dale from Machine Learning for Kids , that is a brilliant use of Scratch 3 - Speech Recognition to control a sprite in an alien language. Do the activity, and it is very much worth doing, and it will make sense! I  would also recommend going to the  machinelearningforkids.co.uk   site anyway it is full of exciting things to do (for example loads of activities  https://machinelearningforkids.co.uk/#!/worksheets  ) . Scratch 3 has lots of extensions that are accessible through the Extension button in the Scratch 3 editor (see below) which add new fun new blocks to play with. The critical thing for this post is  Machine Learning for Kids  have created a Scratch 3 template with their own extensions for Scratch 3 within it  https://machinelearningforkids.co.uk/scratch3/ . One of which is a Speech to Text extension (see below). You must use this one ...

Scratch and web-cams in Scratch 3

Scratch 3 was launched on 2nd January 2019, so I wanted to know would Webcams still work with Scratch 3 as it did with Scratch 2. For example, in a previous post  Scratch, webcams, cats and explosions  the cat (Scratch) moved across the screen and a button burst when the object moved in the camera onto it.  Can the same thing be done in Scratch 3? The short answer is yes, but it is done slightly differently. The first change the video capture is not there in the blocks automatically; but is an extension that needs to be added. First, you need to add the extension blocks for video sensing. Go to the little icon at the bottom left of the screen (as shown below) this takes you to the extensions menu. Next, find the Video Sensing option and selected. The webcam, if enabled, with start automatically. A video sensing set of blocks is now in the list of block options.  The rest is very similar to doing this in Scratch 2. Moving ...