How to trigger samples from external events?

Hi guys,

I’m new to sonic pi however I have loved experimenting with the sounds and realizing the different directions in how you can use the software. I have been asked as part of a university project to create something child friendly that plays samples when triggered. I had the idea of coding a raspberry pi and using the samples given then putting it inside a lego box and connecting buttons to the raspberry pi so the kids can buttons and trigger the samples, however Im still learning and very confused about most online tutorials does anybody know where I can find the information to help me start a project like this?

Hi Matt,

I think Robin has done some experiments with getting Sonic Pi 3 working with the GPIO pins on a Raspberry Pi That might give you a starting point in terms of setting up a trigger to play samples. Maybe @robin.newman would like to chime in if he’s discovered any other approaches?

Thanks Xavier thats really helpful and thank you for replying so quickly :grin:

Hi Matt
As @xavierriley has said I have done a fair bit on triggering Sonic Pi from external events. As well as the example he highlights, I have also used a PS3 wireless controller to control sonic pi, and I frequently use the program TouchOSC (on an iPad or Android) to control Sonic Pi. For the GPIO control (which is probably closest to what you are trying to do) I use a python script to detect events from the GPIO pins and then use the python library pythonosc to send OSC messages to Sonic Pi to control it.
I have written articles on the projects here for the ps3 controller and here for the GPIO input control.
I suggest you get familiar with how OSC messages work on Sonic PI detailed in Section 12 of the built in Tutorial and then you can try the hardware connection.
You will find it great fun to do!

I have also wondered about doing this using some type of key press event to trigger samples or sounds in Sonic Pi and then hooking up a Makey Makey and creating a makeshift triggering device. That would definitely work well in the Child friendly department.

To piggyback off of this, does anyone know about writing key press events in Ruby that would work in Sonic Pi? I’ve poked around a little on line in Ruby forums and resources but what I’ve found did necessarily seem compatible with SPi.

Triggering events from keypresses is something that the GUI still needs to learn how to do. This has been planned for a while now, but is currently stalled for obvious reasons :slight_smile:

Maybe this could help a little bit? I’ve tinkered my “Utz Utz Box” with 20 switches … switches -> GPIO Raspberry 2 -> OSC -> WLAN -> Sonic Pi running on another Computer.