Skip to main content

SONICPI / Ruby, Python, MIDI and OSC

I have a big curiosity on how we can use OSC or MIDI to send message from one app to another app, potentially to generate (realtime) synth sound, visualization, and animation.

This is especially a fun area and environment when we wanted to use CODE for CREATIVITY.

Sonic Pi (by Sam Aaron) is one app I really love to use when dealing with Synth and Sonic generator. I remember using ChucK in the past by Ge Wang, ChucK is also cool, but Sonic Pi is a lot more friendly.
http://sonic-pi.net

Sonic Pi multi-threaded ness and LIVE LOOP is really something new for me. But Sam made it easy enough so that we could generate "listener" very easily.

MAKING SOUND WITH CODE

There are plenty of ways we can "trigger" Sonic Pi to generate sound. Obviously we can just use the built in RUBY language inside Sonic Pi app. Fairly simple and fun language to use and you can generate some noise in no time!

Sonic Pi RUBY language documentation is really in depth and a full on programming guides. As a bonus, if you are into music creation, you will learn a thing or two about digital music creation.

Then, I started to have interest in OSC and MIDI, basically we can control Sonic Pi from the outside! (from other app, or other machine within the same network).

PYTHON SONIC FOR SONIC PI

The first tool I found is Python-Sonic module which I actually use a bit because I use Python often, especially with my Blender Sushi 3D project, of everything Blender with Nodes. You can download Python Sonic here:
https://github.com/gkvoelkl/python-sonic

SONIC PI 3 = OSC and MIDI 

I think, Sonic Pi 3 is special in particular, because it supports MIDI and OSC. This is the IO version of Sonic Pi. For Mac, you can get this app with MIDI and OSC feature. For Windows, you please do support Sam Aaron at his Patreon.

Anyways, I am using Mac and really enjoy this feature!

OSC TO SONIC PI

With OSC, I have tested few different tools. If you have iOS devices like iPad and iPhone, I highly recommend TOUCH OSC app. It provides Editor allowing you to create your own custom interface buttons, sliders, etc for OSC message.

If you manage to setup the OSC address, etc you will be controlling Sonic Pi using Touch OSC in no time. OSC is probably simpler than setting up MIDI.

What cool about Sonic Pi is that once we setup the OSC address, we can see "Cues" of message coming in.

MIDI TO SONIC PI


For me, setting up MIDI seems a little bit more tricky. Well although MIDI actually gives you cool Note On, Note Off and many handy features, especially when you are doing ANIMATION, once you get a hang of MIDI input and controls, you can trigger action using MIDI ON OFF.

If you are on Mac, get familiar with "Audio MIDI Setup" app. With this little app, you can connect iPhone MIDI app (TouchOSC, etc) with your computer for sending MIDI message into... Sonic Pi!

OSC actually can open up a lot of possibilities, especially if you want almost realtime interaction of user. So far, I am only touching the surface using Blender Game Engine to trigger sound via collision, for example.

MIDO MODULE MIDI

If you want to follow my experiment, I am using Python module called MIDO to actually send MIDI message in realtime into Sonic Pi.

With Mido, we can very, very easily send MIDI message and if Sonic Pi "Live Loop" running to listen to MIDI message, we will be able to generate sound easily.

What really cool about MIDI as control is that we have A LOT of MIDI format library somewhere out there on the Internet. Free or not free MIDI are out there if you search song title and MIDI, you are very likely can find it.

Here I am using Pineapple for writing snippet of Python codes. Mido module allows me to easily talk to Sonic Pi.

CONCLUSION

As a self-taught programmer, I found Sonic Pi to be my favourite app to explore coding, especially since we can listen to the code, generating noise, it is A LOT OF FUN.

My other favourite tools are Blender and Processing. For 3D and Visual. Processing language is often my biggest issue, but I do know Processing teach algorithm and interactivity.

Blender however, is Pythonic and I cannot emphasis more: Blender 3D is the coolest open source tool out there. I am using Blender with NODE add-on like Sverchok and Animation Nodes, and that is basically a lot of tools to try.


Comments

Popular posts from this blog

WOLFRAM / Making Text With Rainbow Color

Continuing with my Wolfram Mathematica Trial Experience... I watched and went through some more Mathematica introduction videos, read lots of Mathematica documentation and also going through the Wolfram Lab Online again a few times. There are some major learning curves and Mathematica is a lot different from normal programming language. Sometimes there is a lot of interesting "shortcuts", say like: FindFaces[] , WordCloud[] . Sometimes I got a little confused on how one can do iterations. Normally FOR LOOP concept is introduced early, but in Wolfram, because everything is EXPRESSIONS and ENTITY (like OBJECTS), sometimes it gets quite quirky. Mind you I am still in the first impression and having to look at many tutorials. Lots of NEAT EXAMPLES from documentation, but sometimes I got lost. I found Wolfram to be really awesome with LIST and generating list. It's almost too easy when it works visually. I cannot explain them with my own words yet, but there are ...

PYTHON / OpenCV, Recreate Uncanny Manga - Anime Style

Can you tell what it is? Computer Vision. Yesterday, I spend almost whole day exploring this opencv module using Python. What I discovered was revealing. Even at the very basic level, I could produce some interesting Image and Video manipulation using all the code collected from documentation and many, many blog tutorials. If you are a total noob like me, I am still getting used to knowing that the CV in OpenCV means Computer Vision! Actuallly, I recalled that I did try to get into OpenCV few years back ago, when I knew no Python and when Python opencv module was probably still early. It was all C++ code and it was a little bit too hard for me. I read a couple of books about opencv at the library, I did not understand a single thing. That was back then. Today, for strange reason, with a bit of knowledge of Python, I can go a little further. EDGE DETECT IN OPENCV Me holding you know what. What leads me this far is my curiosity on how we can replicate Wolfram Langu...

ML / Using Turi Create for Machine Learning Style Transfer

A few days ago, I found out about "Turi Create" , basically a Python module, a tool from Apple that allows non-Apple computer user to generate MLM aka Machine Learning Model that can be integrated inside iOS app on iPhone and iPad. The cool thing about Turi Create is that you can also use it for your own purpose in processing data using Machine Learning. https://developer.apple.com/videos/play/wwdc2018/712/ As an additional note, at WWDC 2018, Apple also presented XCode Playground tool for MacOS that allows user to easily generate this MLM model for all kind of purposes. The process is as simple as drag and drop for Image Classifier. It is quite fascinating and worth watching the video. STYLE TRANSFER From what I gather after a short research, there are a few applications of Machine Learning that we can use in application such as for Image Classification, Graphing, etc but one that interest me in particular is STYLE TRANSFER using Turi Create: https://apple.gith...