Patchbox as BLE MIDI Device?

Ok, maybe I’m completely off in my expectations. Or it’s related to the issues with Apple devices. Or it’s something which works on Pi3B and not on Pi4B.

I want to plug USB-MIDI devices on my Pi and use my Patchbox setup as a kind of Bluetooth hub.
A bit like the WIDI Uhost. Or like a BLE MIDI dongle (Yamaha MD-BT01, WIDI Master, WIDI Jack…). Or like a BLE MIDI controller (Sensel Morph, Artiphon Orba, ROLI Lightpad, ODD Ball…). Or even like an Apple device in “Peripheral” mode (say with AC Sabre).

That’s probably too much to ask…?

Expected behaviour:

Making the Patchbox device Bluetooth discoverable makes it available in the list of Bluetooth MIDI devices in AUM on my iPad Pro or in Audio & MIDI Setup on my MacBook Air.

Observed behaviour

Pressing the button for 1s while in MODEP, the LEDs blink for 180s and nothing new appears in lists of Bluetooth MIDI devices.

Setup

Latest Patchbox release on a Raspberry Pi 4B (4GB) with the Pisound HAT.

Bluetooth Status

(via patchbox app on the Pi)

bluetooth_supported=1
bluetooth_service_active_state=active
bluetooth_service_sub_state=running
bluealsa_service_active_state=active
bluealsa_service_sub_state=running
hciuart_service_active_state=active
hciuart_service_sub_state=running
bluetooth_soft_blocked=no
bluetooth_hard_blocked=no

And…

patch@patchbox:~ $ sudo systemctl status pisound-ctl
● pisound-ctl.service - Bluetooth service for Pisound companion app.
   Loaded: loaded (/lib/systemd/system/pisound-ctl.service; enabled; vendor pres
   Active: active (running) since Wed 2021-10-06 03:11:28 BST; 6h ago
 Main PID: 441 (pisound-ctl)
    Tasks: 14 (limit: 4915)
   CGroup: /system.slice/pisound-ctl.service
           ├─ 441 /usr/bin/pisound-ctl
           ├─1289 /bin/sh /usr/bin/mec /etc/mec-blokas.json
           ├─1293 osc2midi pisound-ctl 127.0.0.1 40436
           └─1295 mec-app /etc/mec-blokas.json

Oct 06 03:12:02 patchbox pisound-ctl[441]: mec api initialise
Oct 06 03:12:02 patchbox pisound-ctl[441]: mecapi_proc start
Oct 06 03:12:02 patchbox pisound-ctl[441]: MecApi::MecApi
Oct 06 03:12:02 patchbox pisound-ctl[441]: MecApi_Impl::init
Oct 06 03:12:02 patchbox pisound-ctl[441]: KontrolDevice initialise
Oct 06 03:12:02 patchbox pisound-ctl[441]: KontrolDevice::init
Oct 06 03:12:02 patchbox pisound-ctl[441]: mec_app running
Oct 06 03:12:02 patchbox pisound-ctl[441]: kontrol device : listening on 6050
Oct 06 03:12:02 patchbox pisound-ctl[441]: KontrolDevice::init - complete
Oct 06 03:12:05 patchbox pisound-ctl[441]: KontrolDevice::new client 127.0.0.1 :

Relatedly:

patch@patchbox:~ $ sudo systemctl status bluetooth
● bluetooth.service - Bluetooth service
   Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; vendor preset
   Active: active (running) since Wed 2021-10-06 03:11:35 BST; 6h ago
     Docs: man:bluetoothd(8)
 Main PID: 634 (bluetoothd)
   Status: "Running"
    Tasks: 1 (limit: 4915)
   CGroup: /system.slice/bluetooth.service
           └─634 /usr/lib/bluetooth/bluetoothd

Oct 06 03:11:35 patchbox systemd[1]: Starting Bluetooth service...
Oct 06 03:11:35 patchbox bluetoothd[634]: Bluetooth daemon 5.50
Oct 06 03:11:35 patchbox systemd[1]: Started Bluetooth service.
Oct 06 03:11:35 patchbox bluetoothd[634]: Starting SDP server
Oct 06 03:11:35 patchbox bluetoothd[634]: Bluetooth management interface 1.18 in
Oct 06 03:11:35 patchbox bluetoothd[634]: Sap driver initialization failed.
Oct 06 03:11:35 patchbox bluetoothd[634]: sap-server: Operation not permitted (1
Oct 06 03:11:35 patchbox bluetoothd[634]: Endpoint registered: sender=:1.12 path
Oct 06 03:11:35 patchbox bluetoothd[634]: Endpoint registered: sender=:1.12 path
Oct 06 03:11:35 patchbox bluetoothd[634]: Failed to set privacy: Rejected (0x0b)
patch@patchbox:~ $ uname -a
Linux patchbox 5.10.63-v7l+ #1457 SMP Tue Sep 28 11:26:14 BST 2021 armv7l GNU/Linux

Comparison

I notice few differences from what @Giedrius had posted in March:

The sender is different (1.12 with empty path instead of 1.18 with a path).

The main difference, though, is that I’m using third-party apps Apple devices instead of the first-party app on Android.

So…

  1. Would a “BT discoverable” Patchbox setup show up as a Bluetooth MIDI device on an Android device?
  2. How about a Windows machine?
  3. Any other approach would allow me to use the Pi as a kind of Bluetooth MIDI hub/host/patchbay?

Following this as I just tried to set this exact same thing up too.

1 Like

By default there’s no service running ready to accept incoming BLE MIDI connections. However, looks like if you’d connect the Pi to some BLE MIDI device, an ALSA MIDI port would appear for it.

I’ve looked into this, and looks like there’s a btmidi-server program available to accept connections from phone devices. Unfortunately it’s not conveniently available just yet, but can be installed by running these commands:

(I probably had many of the libraries this depends on already installed, if you get compilation errors for missing headers or libraries, try to search the internet for which -dev apt packages to install, possibly running sudo apt build-dep libbluetooth3 would get the necessary libs)

git clone https://github.com/ftonello/bluez/ --branch midi-peripheral bluez
cd bluez
./bootstrap
./configure --enable-midi --prefix=/usr --mandir=/usr/share/man --sysconfdir=/etc --localstatedir=/var
make tools/btmidi-server
sudo cp tools/btmidi-server /usr/bin/btmidi-server

Then it can be started for example like this:

sudo btmidi-server -v -n "My Pi BLE MIDI"

More information is available here, as well as how to make this into a systemd .service: Raspberry Pi as USB/Bluetooth MIDI host

Not all Android software managed to work with this, but one that did was called Midi Commander

With the server running, once some device connects to it, a usable ALSA MIDI port should appear. (visible for example in aconnect -lio).

1 Like

Gonna try this later. Oddly enough I thought Midi Commander looked like the best option on an Android. Excited to see if this works.

1 Like

Well…I tried…

Here’s the packages I had to install to get bluez to compile (after running sudo apt update):
autotools-dev automake libtool glib2.0 libdbus-1-dev libudev-dev libical-dev libreadline-dev libbluetooth-dev

I can get the btmidi-server to run and I can get Midi Commander to connect to the Pi but it constantly disconnects/reconnects. I was able to map one of the buttons on my pedalboard to a button in Midi Commander but with the constant disconnecting I could could not get the button on the pedalboard to respond, even though MODEP showed the button being mapped to the correct channel.

The console output in btmidi-server showed this over and over:

MGMT_OP_ADD_ADVERTISING completed
Connect to 40:45:DA:22:12:78
att: > 12 06 00 01 00 …
att: ATT PDU received: 0x12
srv: Write Req - handle: 0x0006
att: ATT op 0x13
att: < 13 .
att: > 52 05 00 a7 c0 b0 00 00 R…
att: ATT PDU received: 0x52
srv: Write Cmd - handle: 0x0005
att: Physical link disconnected: Connection timed out
Device disconnected: Connection timed out

I will also add that I tried Midi Commander with 2 different devices. I think I will try and find some other MIDI app to see if possibly it’s on the app side, not the Pi side.

1 Like

a (partial?) alternative to bluez maybe is rtpmidid as discussed here: MODEP not detecting `rtpmidid` as a MIDI device

1 Like

Hello.
I have tried this before on a Ubuntu based disto.
I had the same problem.

Here is the fix to stop disconecting.

sudo apt install libell-dev

./configure --enable-midi --with-systemdsystemunitdir=/etc/systemd/system --enable-external-ell

I’ll try to get it working on patchboxos.