The hardest part

At least, for me. Now I have to code something that enables me to select banks and instruments on my synth module. I’ve settled for pyliblo to talk to ZynAddSubFX but I’m just no coder. My elbow now rests on “Learning Python” from O’Reilly, I started reading it like a year ago but never got past chapter 3 or something. Time to persist, I’ve been wanting to be able to code a little bit for years now.

As a note to self, and maybe it’s helpful for others too, what follows are some of the relevant OSC messages to change banks and instruments in ZynAddSubFX.

Changing banks can be done with /loadbank. pyliblo comes with an example script and loading a bank with works as follows: 7777 /loadbank ,i 3

7777 is the port ZynAddSubFX runs on. The /loadbank message wants an integer (,i) and ,i 3 loads the fourth bank (Choir and Voice) as ZynAddSubFX starts counting from 0. Bear in mind that this will only load the bank, it won’t change the instrument that is loaded. To load an instrument from a loaded bank the following incantation does the trick: 7777 /setprogram ,c $'\x03'

So /setprogram loads an instrument from an active bank. It takes a character (,c) as an argument because the program numbers are in hex. But hex are multiple characters so you have to add some escape sequences to make it work (and I lost it there so I could be completely wrong). The above command should load the fourth instrument from the Choir and Voice bank (Voice OOH) as that bank should have been loaded by the previous /loadbank message.

It is also possible to load instrument (.xiz) files. This can be done with the /load_xiz message: 7777 /load_xiz 0 "/usr/share/zynaddsubfx/banks/Bass/0001-Bass 1.xiz"

This will load the Bass 1 instrument fom the Bass bank into part 1 (remember that ZynAddSubFX starts counting from 0). So to load the Bass 2 instrument into part 2 you’d do the following: 7777 /load_xiz 1 "/usr/share/zynaddsubfx/banks/Bass/0002-Bass 2.xiz"

So now I have to incorporate this stuff into Python code that gets called when I press buttons on my LCD display. These are the mappings I’d like to accomplish:

  • Up: toggle next bank and display first instrument from that bank
  • Down: toggle previous bank and display first instrument from that bank
  • Left: toggle previous instrument and display instrument
  • Right: toggle next instrument and display instrument
  • Select: select displayed instrument

That shouldn’t be too hard right? Well, first hurdle, pyliblo can only send or dump OSC messages, it doesn’t seem to be able to handle return messages from the OSC server (ZynAddSubFX in this case). To be continued…

Edit: of course sending just messages with pyliblo won’t handle any return messages, you will need a receiving part. But maybe I should take a look at using MIDI with mididings for instance. Thanks Georg Mill for the tip!

The hardest part

3 thoughts on “The hardest part

  1. Why don’t you use midi commands directly? OSC is usualy used to send commands over network connected devices. Maybe it is easier to install oscprompt on rpi2, ssh client on your smartphone and connect via ssh your smartphone and the pi2. Than you may run oscprompt and copy some osc commands into the prompt. So you could manage the zyn witthout rewriting everything. With the tab function you can scroll through the commands you have previously entered, so no need for writing/copying the commands twice.
    Have fun.

    1. jeremy says:

      Hi Georg, MIDI could be an option too. Maybe it’s even easier, I know mididings and that’s Python too so it might even be easier to set up than OSC. I’ll give it a go 🙂

  2. Marc van Doornik says:

    Hi Jeremy,

    You seem to have gotten quite far in getting a workable RPi synth going, congrats! I myself am currently working on something rather similar, only running Pure Data instead of zyn. Mine will get a hardware patchbay and a bunch of knobs and can load patches on the fly from a USB drive, all of which are working fairly well at the moment.

    The only thing I have trouble with right now seems to be midi over USB. For some reason events get dropped occasionally, resulting in notes not playing or hanging until I restart the patch. Weird thing is these events don’t even get seen by ALSA. Did you have the same issues with your box? I’m running Minibian on an RPi 3, alsa midi, jackd at 48kHz and three 128-byte buffers. Any ideas?

    (Trouwens, ik wist niet of je een voorkeur zou hebben voor Nederlands of Engels in de commentaren, Engels leek me het nuttigst voor je internationale gasten. Coole blog, BTW!)

Leave a Reply

Your email address will not be published. Required fields are marked *