Sonic Pi

Hi, I just bumped into Sonic Pi project and I am wondering if it would be possible to integrate it into Zynthian. I would use external hdmi display for it, but it would be cool if Sonic Pi could be used as a separate layer on Zynthian.

3 Likes

I think Mr @C0d3man has something to say about … :wink:

Sonic-Pi uses supercollider-server (scsynth) as backend and sends messages via OSC. sonic-pi seems to be “only” the frontend. IMHO: first there is a scsynth-engine needed.

Hmmmmm… I have to think about that. Sounds easy… but who will know?

1 Like

Hi @pavel @jofemodo

I tried to add sonic-pi from the buster-repo (apt-get install sonic-pi) but there were problems getting sonic-pi running. So I decided to write my own recipe:

install_supercollider.sh (927 Bytes)
install_osmid.sh (167 Bytes)
install_sonic-pi.sh (891 Bytes)

After some changes I got the binary of sonic-pi running, but there are some problems with starting background services (seems to be a problem with a path: the start script (/zynthian/zynthian-sw/plugins/sonic-pi/app/gui/qt/rp-app-bin) seems to look at /usr instead of /zynthian/zynthian-sw/plugins/sonic-pi/).

Has anyone an idea what is going wrong?

[EDIT] Ok, I found that running “cd /zynthian/zynthian-sw/plugins/sonic-pi/app/gui/qt/build && sonic-pi” starts scsynth in the background - but after that, nothing happens… have to check the files in /root/.sonic-pi/log

[EDIT2] Maybe this is also necessary:

mkdir -p /usr/lib/SuperCollider/plugins
ln -s /usr/local/share/SuperCollider /usr/lib/SuperCollider/plugins/

Regards, Holger

1 Like

Ok, got sonic-pi/supercollider/sc3-plugins running (all from github)! :smile:

The build scripts are here:

install_supercollider.sh
install_osmid.sh
install_sonic-pi.sh

(maybe you have to run apt update before starting any script)

After installation you have to login via ssh (ssh -X root@zynthian.local) and start sonic-pi by typing:

/zynthian/zynthian-sw/plugins/sonic-pi/app/gui/qt/build/sonic-pi

If everything works, Zynthian engine code for supercollider and sonic-pi could be created.

Regards, Holger

P.S.: Thanks @jofemodo for the autoconnector! sonic-pi works without problems after starting :smiley:

4 Likes

HI @pavel,

I have tried to find some sonic-pi code which does “something” usable, like a drum pattern or a MIDI-synth - but found nothing. Do you have an idea where to find such code?

Regards, Holger

There are some examples here: http://sonic-pi.net/#examples

in_thread do
  use_synth :fm
  sleep 2
  loop do
    28.times do
       sample :drum_bass_hard, amp: 0.8
       sleep 0.25
       play :e2, release: 0.2
       sample :elec_cymbal, rate: 12, amp: 0.6
       sleep 0.25
     end
     sleep 4
   end
 end

 use_synth :tb303
 with_fx :reverb do |rev|
   loop do
     control rev, mix: rrand(0, 0.3)
     with_fx :slicer, phase: 0.125 do
       sample :ambi_lunar_land, sustain: 0, release: 8, amp: 2
     end

     control rev, mix: rrand(0, 0.6)
     r = rrand(0.05, 0.3)
     64.times do
       play chord(:e3, :minor).choose, release: r, cutoff: rrand(50, 90), amp: 0.5
       sleep 0.125
     end

     control rev, mix: rrand(0, 0.6)
     r = rrand(0.1, 0.2)
     with_synth :prophet do
       32.times do
         sleep 0.125
         play chord(:a3, :m7).choose, release: r, cutoff: rrand(40, 130), amp: 0.7
       end
     end

     control rev, mix: rrand(0, 0.6)
     r = rrand(0.05, 0.3)
     32.times do
       play chord(:e3, :minor).choose, release: r, cutoff: rrand(110, 130), amp: 0.4
       sleep 0.125
     end

     control rev, mix: rrand(0, 0.6)
     with_fx :echo, phase: 0.25, decay: 8 do
       16.times do
         play chord([:e2, :e3, :e4].choose, :m7).choose, release: 0.05, cutoff: rrand(50, 129), amp: 0.5
         sleep 0.125
       end
     end
   end
 end

Hi @ll,

there is a cool tool available for Sonic-Pi: sonic-pi-tool. With this tool you can start/stop the server and send ready-to-play scripts to the server from command line. No need for the GUI! So a sonic-pi-engine is much more easier to implement.

Here is the recipe for my installation:

cd $ZYNTHIAN_PLUGINS_SRC_DIR
sudo apt-get install -y --no-install-recommends cargo
git clone https://github.com/lpil/sonic-pi-tool.git
cd sonic-pi-tool
cargo install --git https://github.com/lpil/sonic-pi-tool/ --force
ln -s /root/.cargo/bin/sonic-pi-tool /usr/local/bin/
mkdir -p /usr/lib/sonic-pi
ln -s /home/pi/zynthian-sw/plugins/sonic-pi/app/server/ruby /usr/lib/sonic-pi/server
cd $ZYNTHIAN_PLUGINS_SRC_DIR

For testing, login via ssh zynthian.local and fire up:

sonic-pi-tool start-server >/dev/null 2>&1 # or with debug output: sonic-pi-tool start-server

and in another ssh-session:

echo "play :C4" | sonic-pi-tool eval-stdin

or

sonic-pi-tool eval-file path/to/code.rb

Have fun!

Regards, Holger

1 Like

Hey :slight_smile: Just bumping that up a bit to know if recent progress has been done.
Notably: since sonic-pi 3 and above support MIDI in/out, have you been able to use it from a MIDI keyboard/seq connected to the Zynthian :slight_smile: ?
I just ordered a Zynthian and would really like to run sonic-pi on it!

In fact this might work. There are always two things to do:

  1. get the sound generator running (which is basically done)
  2. integrate the sound generator into Zynthian as an engine

The latter is still missing. It’s not difficult in principle, as these are relatively well documented Python scripts. What makes the case of sonic-pi (and similar “sound programming languages”) more complicated: they are so flexible that you cannot simply run every program. Zynthian has certain interfaces (and names for them) that you would have to use in your code for everything to work. So you don’t have fixed interfaces and a set of patches for like you do with a “normal” synth, but somehow you either have to adapt the programs to a certain scheme for Zynthian or have more or less intelligent software do it for you.

So it is missing in addition:

  1. an adapter or framework for sonic-pi programs to make them run on the zynthian.

I hope I made you curious enough to build something like this :smile:?

Regards, Holger

but somehow you either have to adapt the programs to a certain scheme for Zynthian

I’m not sure what you mean by this. Do you mean you are able to run tailored-fit Sonic PI programs on the Zynthian but not to reuse other programs from the Sonic PI community? Or that even the most basic programs cannot work? Sonic PI doesn’t let you configure which USB/MIDI/audio devices it’s listening from/sending to?

(So far I haven’t even been able to properly get sound out of Sonic PI either on Ubuntu or Windows ^^, athough SuperCollider words, but the Rasperry Pi should be its platform of choice)

I’m not quite sure how easy it will be with sonic-pi to make the MIDI and audio connections, but in general I think the problem will be getting (sonic-pi) programs to run directly (just by uploading).

For simple programs this may work, as the autorouter will automatically connect the MIDI and audio connections. But with complex setups this might be more difficult.

Probably it depends on a test. The best thing will be to just start and run only sonic-pi with a default program. Then you can think about how to organize the programs as sound patches and how to get them into Zynthian.

It will be interesting if you have programs that should play loops, synced to MIDI clock, load samples, use multiple MIDI interfaces etc.

Regards, Holger