Orange Pi USB MIDI Host
I was looking for a way to get my Deluge to play nice with other USB MIDI devices while waiting for the 3.0 firmware to come out. I happened to have an Orange Pi +2E laying around, knew that this had been done with a Raspberry Pi, and thought “how hard could this be?”
Turns out, not so hard.
Side note: I found this guide by Neuma Studio very helpful and have adapted many parts of it for my own writeup. Credit for the ruby script goes to Morten Johannes Ervik and can be found here.
If you are not familiar with the setup of armbian the getting started guide can be very helpful.
You’ll need the legacy armbian image for Orange Pi or MIDI will not work correctly, for the Orange Pi +2E the link is at the bottom of this page. Write the armbian image to your microSD of choice (4GB is a good size, 2GB is fine if you use overlayroot to set the filesystem read only), connect your your Orange Pi to a TV/keyboard (if using wireless) or to an ethernet cable if you prefer to set it up that way.
Boot the Pi, setup the new root password, new user account, display resolution (if using a TV) and reboot to resize the filesystem. If you are using a 2GB microSD card you will always get a notice on boot that you need to reboot to resize, this will go away when you enable overlayroot.
Set up the wireless and update the system using apt.
nmtui-connect
apt update
apt upgrade
Install ruby.
apt install ruby
I disable the nodm service as I think it’s a waste of time to load X on something that t will not have a monitor attached.
sudo systemctl disable nodm
I also disable the NetworkManager-wait-online service as it usually adds ~30 seconds or so to the boot time.
sudo systemctl disable NetworkManager-wait-online
You can use the systemd-analyze blame command if you are curious to see what services take how long to start up and remove any more you don’t see any use for.
At this point you should follow the entire section called CONFIGURING AUTOMATIC MIDI CONNECTION at the Neuma Studio blog. Remove or comment out the line in the script that says names « name as that part is not required for this application and will cause errors when you run the script.
I will copy the section (lightly edited due to formatting issues) here just in case something happens to the source page:
issue the command
sudo nano /usr/local/bin/connectall.rb
and copy the following content (all credits for this goes to the author of this page). (to save and exit from nano editor, issue ctrl + O followed by ctrl + X)
#!/usr/bin/ruby
#
t = `aconnect -i -l`
ports = []
t.lines.each do |l|
/client (\d*)\:/=~l
port = $1
# we skip empty lines and the "Through" port
unless $1.nil? || $1 == '0' || /Through/=~l
ports << port
#names << name
end
end
ports.each do |p1|
ports.each do |p2|
unless p1 == p2 # probably not a good idea to connect a port to itself
system "aconnect #{p1}:0 #{p2}:0"
end
end
end
issue the command
sudo chmod +x /usr/local/bin/connectall.rb
You can test the auto-connection with command
connectall.rb
and checking results with
aconnect -l
Configure automatic MIDI connection/disconnection on USB device connect/disconnect:
sudo nano /etc/udev/rules.d/33-midiusb.rules
copy the following content and save the file
ACTION=="add|remove", SUBSYSTEM=="usb", DRIVER=="usb", RUN+="/usr/local/bin/connectall.rb"
issue the following commands:
sudo udevadm control --reload
sudo service udev restart
Configure MIDI connection at system boot: sudo nano /lib/systemd/system/midi.service
copy the following content and save the file
[Unit]
Description=Initial USB MIDI connect
[Service]
ExecStart=/usr/local/bin/connectall.rb
[Install]
WantedBy=multi-user.target
issue the following commands:
sudo systemctl daemon-reload
sudo systemctl enable midi.service
sudo systemctl start midi.service
To test automatic connection, you can use the command aconnect -l
If you want to make your system read-only so that you can yank the power any time without worrying about hurting the OS, setup overlayroot.
You need an ODROID XU4 or Allwinner A10, A20 or H3 board with legacy kernel where we added support for overlayfs. Works only on Ubuntu Xenial.
Login as root and execute:
apt-get install overlayroot
echo 'overlayroot="tmpfs"' >> /etc/overlayroot.conf
reboot
After your system boots up it will always remain as is. If you want to make any permanent changes, you need to run:
overlayroot-chroot
For some reason running overlayroot-chroot does not appear to be enough for me when I want to make further changes. If I want to make changes after overlayroot is enabled I have to run the following commands:
sudo overlayroot-chroot
sudo mount -o remount,rw /dev/mmcblk0p1
Then I edit the file /etc/overlayroot.conf and change the last line from
overlayroot="tmpfs"
to
overlayroot="disabled"
I am then able to reboot and make any changes I want. When I want the system to go back to read-only I edit /etc/overlayroot.conf and change the last line back to tmpfs.
At this point you should be able to reboot your Orange Pi and have a MIDI host that automatically inter-connects any USB MIDI devices you connect to it. If you setup overlayroot you should be able to power up/off the Orange Pi repeatedly without worrying about filesystem corruption.
Thanks to everyone whose work I stole for this little project.
rm