Script for launching PD patch with MIDI without aconnect

Hey, could you please describe the issue you are facing, it’s a pretty broad topic with many expectations one may have and different possible solutions.

Keep in mind that MIDI on Linux works differently than on other major OSes, unfortunately this is not in our control, we have to abide by Linux standards in order to be able to interoperate with existing MIDI software. That said, what we can do is we can try to improve the situation, and that’s what we did with the amidiauto service which is integrated by default in Patchbox OS image. Please see this documentation page: amidiauto - Patchbox OS Documentation

1 Like

Hi, thanks for your quick response. Sorry for the tone of my post, but I’ve been very frustrated by this problem.

I’m trying to use the DIN midi in on the pisound to communicate with PD. I am using a Pi 3B+ with Rasbian stretch.

I installed amidiauto per the instructions on https://community.blokas.io/t/script-for-launching-pd-patch-with-midi-without-aconnect/1010/3?u=amazingrolo

I have also installed the pisound software and updated it with pisound-config (it was already up to date.)

When I type amidiauto in the terminal window (with or without the &) I get an error:

pi@raspberrypi:~ $ Reading ‘/etc/amidiauto.conf’ failed! (-2)
Using default ‘allow all’ rule.
Allowing ‘’ -> '

I look in /etc and there is no amidiauto.conf. Could this be the problem?

Then I launch PD (0.49.0 Plain vanilla, no externals) using the app menu in the Pi desktop. Under the PD preferences I am able to change the audio device to pisound, but when I try to set the midi device, there is only “none”. When I open the “test audio and midi” patch from the Media menu, the audio in and out work, but not midi. The red light next to the midi in jack on the pisound flashes, as well as a red led in the upper corner left of the word “pisound” when I play my midi device.

Please let me know if I can give you more information about the problem. Any help you can give would be greatly appreciated!

Thanks,

Karl

Hey, I discovered the problem. I hadn’t selected ALSA midi in PD. I tried it before I installed amidiauto, with no results, so I assumed it didn’t matter.
It would be really nice if there was somewhere in the main Pisound documentation that explains how to get this to work. I wasted many hours tracking down the problem.

Thanks!

Karl

Yes, ALSA MIDI backend is the best choice for MIDI on Linux. It all works based on virtual ports that must be interconnected together, according to your needs. This design has an additional step that users must be aware of, but provides for a lot of flexibility. Other OSes typically have audio/MIDI software list the MIDI devices, so you can pick the ones you want to use, which is straightforward.

As for making the connections, aconnect is the command line utility to use, and we’ve built amidiauto to automatically connect things for the most common use case of hardware interacting with software MIDI ports, and it also allows customization of that logic in the /etc/amidiauto.conf file for specific use cases.

Btw, once installed, amidiauto automatically registers a systemd service to run in the background, so these commands have to be used:

  • sudo systemctl status amidiauto - check whether it’s running.
  • sudo systemctl enable amidiauto - enable amidiauto to start automatically on boot.
  • sudo systemctl disable amidiauto - disable autostart on boot.
  • sudo systemctl start amidiauto - start amidiauto.
  • sudo systemctl stop amidiauto - stop amidiauto. If autostart is enabled, it will start again on next boot automatically.

We’d recommend using the Patchbox OS image for use with PD and other audio software - it already has the audio programs preconfigured to work smoothly, and if you update the patchbox config utility, it allows configuring a PD patch to be automatically started on system boot via the module submenu.

Also PD can be started via The Button and Pisound App, both of these ways of launching PD provide the right config to the PD process and takes care of MIDI connections.

1 Like

I updated patchbox-config but could not see any option to start a Pd patch at boot. There is no module submenu

Try running sudo apt install -y patchbox-cli to update the patchbox config tool.

1 Like

Ah, now I have the modules section. I thought apt-get update, upgrade, dist-upgrade would bring me up to date.

I went to /usr/local/puredata-patches and made mkdir testpatch, touch testpatch/startup.pd
then ran the patchbox-config again but could not see my patch in the puredata module list.
How can I run my own patch?

Use ‘main.pd’ for the entry point.

1 Like

That works. Thanks.

One question related to amidiauto which I couldn’t find any details how to set up the config file so that the RTMidiOut client is connected with PureData Midi Input from startup? I need to manually configure this every time once the RPi has booted, and it’s a bit inconvenient if I’m not around. Thank you for your help with this!

You’ll have to add a rule for that in /etc/amidiauto.conf. What is the output of aconnect -l when all the software is running?

Many thanks for your kind offer to help! This is the log I receive after typing aconnect -l

patch@patchbox:~ $ aconnect -l
client 0: ‘System’ [type=kernel]
0 'Timer ’
1 'Announce ’
Connecting To: 128:0, 129:0
client 14: ‘Midi Through’ [type=kernel]
0 ‘Midi Through Port-0’
Connecting To: 129:0[real:0]
Connected From: 129:0
client 16: ‘LilyPad USB’ [type=kernel,card=0]
0 ‘LilyPad USB MIDI 1’
Connecting To: 129:0[real:0], 131:0, 130:0
Connected From: 129:0, 131:1, 133:0
client 20: ‘LilyPad USB Plus’ [type=kernel,card=1]
0 ‘LilyPad USB Plus MIDI 1’
Connecting To: 129:0[real:0], 131:0, 130:0
Connected From: 129:0, 131:1, 133:0
client 24: ‘LilyPad USB Plus’ [type=kernel,card=2]
0 ‘LilyPad USB Plus MIDI 1’
Connecting To: 129:0[real:0], 131:0, 130:0
Connected From: 129:0, 131:1, 133:0
client 28: ‘Arduino Leonardo’ [type=kernel,card=3]
0 ‘Arduino Leonardo MIDI 1’
Connecting To: 129:0[real:0], 131:0, 130:0
Connected From: 129:0, 131:1, 133:0
client 40: ‘pisound’ [type=kernel,card=6]
0 ‘pisound MIDI PS-1M0GXQD’
Connecting To: 129:0[real:0], 131:0, 130:0
Connected From: 129:0, 131:1, 133:0
client 130: ‘pisound-ctl’ [type=user,pid=735]
0 'pisound-ctl ’
Connecting To: 129:0[real:0], 131:0
Connected From: 129:0, 16:0, 20:0, 24:0, 28:0, 40:0, 133:0
client 131: ‘Pure Data’ [type=user,pid=953]
0 ‘Pure Data Midi-In 1’
Connected From: 16:0, 20:0, 24:0, 28:0, 40:0, 130:0, 129:0
1 ‘Pure Data Midi-Out 1’
Connecting To: 16:0, 20:0, 24:0, 28:0, 40:0, 129:0[real:0]
client 132: ‘RtMidiIn Client’ [type=user,pid=1358]
0 'TouchOSC Bridge ’
Connected From: 133:0, 129:0
client 133: ‘RtMidiOut Client’ [type=user,pid=1358]
0 ‘RtMidiIn Client:TouchOSC Bridge 132:0’

Try adding this line to /etc/amidiauto.conf, under [allow] section:

RtMidiOut -> Pure Data Midi-In

Then do:

sudo systemctl restart amidiauto

This adds a rule to amidiauto to always make this software connection, when these software MIDI ports appear.

Many thanks for the suggestion! What should I do if /etc/amidiauto doesn’t exist?

Create a simple text file at /etc/amidiauto.conf, with the following contents:

[allow]
* <-> *
RtMidiOut -> Pure Data Midi-In

The * <-> * allow rule is the default behavior, in case the config file is not there or its parsing fails. It means to automatically connect all hardware and software ports together, which is usually a common expectation in most basic cases. As RtMidiOut and PD ports are both software, explicit rules have to be written to make amidiauto do the connection.

1 Like

Many thanks for your great support as usual. I tried following your instructions, but after creating the file and entering

sudo systemctl restart amidiauto

nothing seems to have changed. I triple-checked the spelling to make sure no mistake was introduced on my end. Could you have a look at the attached images and let me know what might be the issue?


Try this amidiauto.conf instead:

[allow]
* <-> *
RtMidiOut -> Pure Data

Also, you may check journalctl -u amidiauto to see the output of amidiauto - it should print out whether it’s using the rules file. Hit ‘End’ key to see the latest log lines.

Many thanks for the suggestion, this did the trick!

So it has to be

RtMidiOut -> Pure Data

instead of

RtMidiOut -> Pure Data Midi-In

1 Like

does this work with amidiminder as well?

Reading the description on Github makes me believe so:

  1. It also Watches any connections you make with aconnect or that your software makes, and remembers them too.
1 Like