Parallel programming concepts with Sonic Pi

As a programmer and music lover, I have a lot of affection for Sonic Pi, a code-based music creation and performance tool. I discovered it whilst tinkering around on my Raspberry Pi, where it comes bundled with the Raspbian operating system, although versions for Windows and MacOS are also available.

Sonic Pi is a wonderful tool for introducing students to coding via music, and does not assume or require any prior programming experience. The online tutorial makes it straightforward to create your own compositions in no time at all. That is not to say that it isn’t a powerful tool. The beauty of learning to code with Sonic Pi is that it includes many commonly used programming concepts and structures, including functions, loops, conditionals and even threads.

Whilst writing my first composition with Sonic Pi, I realised that it is a great tool for introducing the concept of parallel programming. In this simple example, I have created an arrangement of a famous Beatles song, with each song component handled by its own unique function. The functions are then called using threads, so that different instrument parts are played simultaneously along side each other to form the verse and chorus sections. Sonic Pi also supports thread synchronisation, whereby a thread must wait for a cue from another thread before it is allowed to continue.

Written on October 28, 2019