Script for launching PD patch with MIDI without aconnect


#1

For various reasons I’d like to launch a PD patch on my raspi with the Pisound without pressing the button - I’d like to have it run on startup. I’m using a headless Pi running the latest “lite” raspbian and the latest PD version.

My patch includes MIDI input. I’m currently able to get this working by launching the patch in the background, and then using aconnect to connect the MIDI input (either from the Pisound DIN connectors or USB) to my PD patch.

At the moment I am putting the following line at the bottom of /etc/profile to get it to launch at startup:
puredata -stderr -nogui -alsa -audioadddev pisound -alsamidi -channels 2 -r 48000 -mididev 1 mypatch.pd $@ &

that launches the patch fine, but then I have to type "connect 20:0 128:0 to get the MIDI working. I’d much prefer this to happen automatically. I imagine there’s a good way to script this but I don’t really know what it is, any tips?


#2

ah ha, I have found a solution, though it feels terrible…

after my launch command, if I do this it works:
sleep 3 aconnect 'Teensy MIDI':0 'Pure Data':0
but this feels like a bad solution, since I guess it’s just waiting for long enough that hopefully the patch will be launched and the MIDI ports in Pure Data will be available.


#3

Hey! We see the same difficulty of setting up MIDI software connections over and over again, so we’ve come up with a tiny program running in the background which we haven’t announced yet, but will do that soon :slight_smile:

What it does is it sits in the background, waiting for MIDI software / hardware ports to appear in the system, then it automatically connects the very first Input / Output pair of software and hardware ports together.

Anyway, I think your scenario is perfect to give it a try, you can find the code here: https://github.com/BlokasLabs/amidiauto

To install (you may have to first install libasound2-dev via apt-get):

git clone https://github.com/BlokasLabs/amidiauto
cd amidiauto
make
sudo make install

Then to get it started automatically, add to the script you use to start PD, above puredata line:

amidiauto &

(the & makes it run in the background)


Headless Pi: Start to Finish
#4

oh cool thanks! I’ll give that a try.

I seem to remember that when I first got the Pisound this wasn’t an issue, I never had to use aconnect. Is it something that got changed in a Raspberry Pi update or something? It seems like the forums are full of people finding this confusing these days.


#5

If you launched via the button or the app, then we do the connections in a similar fashion to your solution. :slight_smile:


#6

hmm maybe I’m clueless about how compiling things works, but when I do the make command after cloning from GitHub I get an error:
g+±4.9 -c -O3 amidiauto.cpp -o amidiauto.o
make: g+±4.9: Command not found
Makefile:33: recipe for target ‘amidiauto.o’ failed
make: *** [amidiauto.o] Error 127


#7

Please edit the Makefile, and change CXX=g++-4.9 to CXX=g++.

Or do sudo apt install g++-4.9 - we’re using 4.9 version of GCC to support the Raspbian’s older Wheezy version.


#8

I edited the makefile as you said and it compiled.

And, more excitingly, this solution works for me so far! I put amidiauto & before my launch script and the patch connected to my USB MIDI controller automatically. It’s great!

The only downside appears to be that for the first minute or so the MIDI connect comes in and out, I guess as all the various connections are made? I’m not really sure, I may have been imagining it. I’ll let you know how it goes. Thanks!


#9

I’m not sure I understood what you mean by this, do you mean the data flow gets interrupted?

Yeah, it will even autoconnect MIDI controllers that were just plugged on the fly :slight_smile: So there should be no more need to rerun any scripts or restart software for this purpose.


#10

yes that’s what I meant, though I recognise that isn’t very clear! I’ll test it some more later this week and let you know if it continues. it certainly wasn’t a big deal anyway.


#11

I would love to see a how to video on how to set this up if anyone has a link to it. Ta