Sonic Pi + Sunvox + Linux + Midi

@Martin I also found this very informative, and chatted with the author

http://tedfelix.com/linux/linux-midi.html

he recommends Patchage which looks like a potential alternative to a2jmidi, do you have any experience ?

Hi,

yes I have tried it but basically it seems to do the same as the connection panel in qjackctl. And no, I do not think it is an alternative. a2jmidi is “is an application that bridges between the system MIDI ports and JACK.” As such it seems indispensible if you are working with applications which do not natively provide midi functionality in the jack-world (hope I did phrase this correctly). But maybe patchage does handle that also? I don’t know.

I did experiment with Carla (on Github). (Still I have to start a2jmidi_bridge in the background, see above.) I will have to put some further work into it, but it seems you can setup and manage your audio environement (including all softsynths as plugins) for Sonic Pi (and other) sessions quite well. See this video for a more indepth view…

Martin

By the way, my (very clumsy, but working) start script look like that:

#! /bin/bash
jackd -d alsa --device hw:USB --rate 44100 --period 256 & # Scarlett 2i2
sleep 1
qjackctl &
sleep 1
a2jmidi_bridge &
sleep 1
~/bin/carla2.0/Carla ~/projects/sonicpi/playground/config/carla/audio-test.carxp &
sonicpi &

The (brute force, but working) stop script once I am done and want to revive pulse-audio:

#! /bin/bash
killall -9 sonicpi sonic-pi m2o o2m beam.smp ruby &
killall -9 carla &
killall -9 a2jmidi_bridge &
killall -9 jackd jackdbus qjackctl &
killall -9 jackd jackdbus qjackctl sonicpi sonic-pi m2o o2m beam.smp

Any suggestions how to do this in a more elegant way are very appreciated :wink: .

1 Like

@Martin ok thanks very much I will experiment some more and report back!

One other thought. Can Sonic Pi be made to work on Linux with ALSA ? Or does it only work with Jack ?

Hi, as far as I know, it requires Jack. But - as I wrote - it should not be a problem to get sunvox integrated. I did ran it on my computer a few weeks ago, but didn’t do much with it. If I’ll find the time I will check again but I can’t promise anything.

@samaaron can u give official confirmation that SP on Linux requires Jack (not Alsa) ?

Yes, Sonic Pi on Linux currently requires jack due to SuperCollider requiring jack.

I believe there was some work on making an ALSA backend to SuperCollider, but it had issues :frowning:

A pure ALSA backend would be ace.

1 Like

Hmm I think I am not far away but no sound yet. See image below. I changed the Sunvox MIDI setting to Jack and it appeared in the writeable ports window. Am wondering why I can’t see SP in the readable ports window. I have a2jmidid running (as you can see in the Qjackctl window) but TBH not sure it is really required … SP only works with Jack and I have configured Sunvox to use Jack so not sure there is any ALSA component that needs bridging.

I feel like there is a missing connection somewhere, that maybe I need to patch SP to Sunvox via the Qjackctl patch bay. I have a feeling we are not very far away, all help welcome!

@Martin @samaaron

Well done for making progress. It’s quite possible that Sonic Pi’s MIDI system isn’t coming through jack but ALSA, whilst the audio is going through jack. You might want to ask some questions about osmid over on GitHub (osmid is the internal system Sonic Pi uses for MIDI): https://github.com/llloret/osmid

Just a shot into the dark: I have in my jack-config (via qjackctl) under Settings - Parameter - Midi-Driver: seq. Might have something to do with it.

In any case I have no problems at all to get any Midi-signal routed via jack.

By the way, just to clear things up @juzbo : jack does depend on alsa but does provide much better ways to connect audio stuff than alsa. That is why it works on top of alsa. At least this is what I understood so far.

By the way, the screenshot you provided do not show any connections as far as I see. In my case I connect e. g. the Arturia Minilab to midi-through. midi-though goes into the a2jmidi_bridge. Then I can route this one to any softsynth. I will try and provide some screens of my setup - though I don’t know exactly when I have the time to do that…

@Martin do you have any references to Sonic Pi / SuperCollider in the Midi -> Readable Clients window ?

So my current major concern is that I whilst I see SuperCollider in Connections -> Audio, I can’t see any reference to SuperCollider in either Connections -> MIDI or Connections -> ALSA. This is true whether I am running a2jmidid or not. It is also in contrast to how Sunvox behaves, which when connected shows an entry in Connections -> Audio and also in Connections -> JACK (writeable). So it feels to me like the problem is on the SP side.

I feel like there are definitely people out there who have managed to get SP on Linux driving a hardware synth via MIDI. If so, what do you see in Connections -> MIDI and/or in Connections -> ALSA ?

@Martin @samaaron @robin.newman

Working!

I will document properly later when I have a bit more time. Many thanks to @Martin for his tips regarding a2jmidid and missing connections in QJackCtl -> Connections -> MIDI; these proved to be the key.

:grinning::ok_hand:

Glad to hear that :slight_smile:

So I thought it might be worth documenting how to get MIDI working with SP on Linux (Ubuntu 16.04) as, despite being relatively experienced, I struggled; and is a worthwhile goal because MIDI connectivity opens up a world of different sound possibilities for SP outside of the native SuperCollider engine.

This is written with the Sunvox softsynth in mind as a target (Sunvox is MIDI enabled) but what goes here almost certainly goes for other MIDI targets, whether software or hardware.

Linux Sound Background

I am absolutely not an expert here and encourage you to go read Ted Felix’s excellent guide -

http://tedfelix.com/linux/linux-midi.html

but in summary -

  • ALSA (Advanced Linux Sound Architecture) is the part of the Linux kernel that talks to your sound-related hardware (sound cards and MIDI interfaces)
  • JACK is an extra layer over ALSA offering low latency and the ability to synchronize multiple audio sources

We need to use JACK rather than ALSA here because SuperCollider only works with JACK.

qjackctl

qjackctl is the best way to configure and manage JACK connections.

  • Setup -> Interface -> [ensure your native soundcard is picked; may require some experimentation]
  • Setup -> Midi Driver -> seq [this should be enabled by default]
  • Start [hit the start button]

a2jmidid

Now if you happened to connect a Korg NanoKey keyboard to your Linux machine and launch Sunvox in its standard ALSA mode, everything “just works”. But if you configure/launch qjackctl and configure Sunvox for JACK, stuff no longer “just works” :frowning:

This is because ALSA MIDI and JACK MIDI are apparently different things.

:frowning:

Specifically, Sunvox can work with either, but the NanoKey seems to want to work in ALSA MIDI mode; so you force Sunvox to work in JACK MIDI mode, the two can no longer speak.

[why do all MIDI Readable Clients, whether NanoKey, SP or other, seem to want to work in ALSA MIDI mode only ?]

Fortunately this can be resolved by using a2jmidid, which bridges ALSA MIDI connections to JACK MIDI connections, so that our MIDI Readable Client can now talk to our MIDI Writeable Client.

a2jmidid --export-hw

Sunvox

Sunvox (http://www.warmplace.ru/soft/sunvox/) is an absolutely terrific sounding softsynth written by Russia’s equivalent of @samaaron, a guy called Alexander Zolotov. It is available for pretty much every platform you can name (Windows/Mac/Linux/ioS/Android). It is MIDI enabled. It can work with all the different Linux sound systems including ALSA and JACK. I am not paid to promote it :slight_smile:

Because SuperCollider only works with JACK we need to configure Sunvox to also use JACK; if you have JACK running and try to launch Sunvox in its default (ALSA) configuration, it will likely hang. So -

Preferences -> Audio -> Driver = JACK
Preferences -> MIDI -> MIDI Controller 1 = JACK

[you’ll probably need to do this in separate stages; configure Audio first without JACK running; then shutdown Sunvox, launch qjackctl (see above), re- launch Sunvox and configure MIDI, now JACK is shown as an available MIDI option]

Sonic Pi

Launch SP as normal :slight_smile:

Connecting SP and Sunvox via qjackctl

Ready to go. So, assuming -

  • qjackctl is running
  • a2jmidid is running
  • Sunvox is running and has been configured to use JACK as per above
  • SP is running

then your qjackctl Connect -> MIDI tab should look as follows

[I have added the connection manually, by selecting a source/target from each window and clicking ‘Connect’]

Then assuming you have a Sunvox module selected in the Sunvox UI, a quick SP script should allow you to hear a sound played in Sunvox.

midi_note_on 50
sleep 1
midi_note_off 50

All done. Phew! A world of possibilities opens up. I’m off to but a MIDI-to-CV controller for my Erica Pico :slight_smile:

Thanks to @Martin for some very helpful pointers.

2 Likes

Hi @juzbo,

wow! Thanks a lot for taking the time to document your achievements.

I guess I will give Sunvox another try. Actually the only thing which has prevented me from doing so is the abundance of nice softsynths on Linux :wink: If I don’t just want to spent my available time trying out all the options (but rather make some music), it is just to much and I have to consciously leave aside things.

Martin

I’d say that was worth a ‘sticky’ and moving to a tech-support post… very well laid out and clear.

2 thumbs up… would read again.

Eli…

1 Like

Update: you can simplify the setup by adding a2jmidid -e & to Execute Script on Startup in qjackctl Setup -> Options

a2jmidid -e & is not starting on Ubuntu Studio 17.10 and I feel this makes Sonic Pi less connected.

Instead run in terminal and start jack