Loading Ruby gems for use within a Sonic Pi buffer


I’m trying to figure out how to load a Ruby gem for use within a Sonic Pi buffer. Has anyone tried doing this?

I found this related thread from 2015: https://groups.google.com/forum/#!msg/sonic-pi/QgX82sXcHqY/wNpxGLhggmUJ

I’m interested to hear your thoughts on that discussion. Here are mine: I get that Sonic Pi != Ruby, but I love that I can use plain old Ruby objects in Sonic Pi and it’d be really cool to know how to package them up and share them. Ruby gems come to mind.

One of the projects I’m working on uses a genetic algorithm to “evolve” music. I published a gem for working with genetic algorithms and have been using it alongside the sonic-pi-cli Ruby gem. I’m getting some pretty cool results and would like to be able to load “population” objects from the gem within a Sonic Pi buffer and live code with them.

If there’s no support for loading Ruby gems into the Sonic Pi buffer environment, I suppose I can put all my code in one file and require it - I’m pretty sure this would work. Then to share, I guess i could create a rake task to do it, so for anyone to use it they’d have to do something like the following:

gem install evolvable; rake compile_sonic_pi_file

but ideally I could skip the rake command and just do something like this in the Sonic Pi buffer:

require ‘path/to/gem’


Apologies - but using generic Ruby gems isn’t supported and likely never will.

I have quite strong plans already to move away from Ruby for a future version of Sonic Pi (although keeping things as similar as possible to how they currently are).

1 Like

Ah, okay. I won’t waste any time on this then! It’s probably an unusual use case, I was just thinking it’d be pretty cool to live code with some of the custom abstractions I’m working on. My main project is just using Ruby objects to basically compose Sonic Pi code, so not having this support won’t pose any problems for that. I’m also currently going through the tutorial and having a ton of fun with it. Sonic Pi is awesome, thanks!

1 Like

Can you enumerate what you consider the pros and cons of ruby are and what alternatives you are considering? Are you considering a new language or an alternative existing language?

1 Like