I tried to test all basic and most common use-case scenarios here and
some more weird as well. It tests cases where the parser needs to handle
problematic MIDI messages as well as ALSA Sequencer events.
It is really simple to add new tests, so others are welcome to do so.
This plugin implements the Central role of MIDI over Bluetooth
Low-Energy (BLE-MIDI) 1.0 specification as published by MMA in
November/2015.
It was implmemented as a bluetoothd plugin because of latency requirements
of MIDI. There are still room for improvements on this regard.
Like previsouly mentioned, it only implements the Central role, but
since all parsing and state-machine code is in libmidi.[hc] it should be
simple to implement the Peripheral role as a GATT service as well.
Files added:
* profiles/midi/midi.c: Actual GATT plugin
* profiles/midi/libmidi.[ch]: MIDI parsers
Techinal notes
==============
This plugin doesn't require any new threads. It relies on notifications
from a device to parse and render proper events that are queued in the
kernel, causing no blocks at all. Even if an error occur, it will be
handled and returned control to bluetoothd.
It also adds a new file descriptor to be read using struct io. That is
necessary to read events from applications and render raw BLE packets to
be sent to the device with a write without response command. It doesn't
block as well.
This patch introduces ALSA as dependency. But this feature is disabled
by default. To enable it, pass --enable-midi to the configure script.
Even though this introduces ALSA dependency, it is not an audio plugin.
It is rather a MIDI plugin, which is a byte stream protocol with low
throughput but requires low-latency.
Observations
============
I have tested on a normal laptop Arch-linux (x86_64) and a Raspberry Pi 2
(ARM Cortex-A8) and it works very well. As I mentioned, the latency can
always be improved.
I will still maintain a personal branch on my github[1] so others can
contribute there and I can test before sending to BlueZ.
IMPORTAT: the timestamp support is incomplete since ALSA doesn't support the
way MIDI over BLE expects (asign timestamp to an event without scheduling).
We are working on ALSA to support this.
Credits
=======
I would like to send kudos to ROLI Ltd. which allowed my to work
on this as part of my full-time job.
[1] https://github.com/ftonello/bluez/
The bt_ad structure provides an abstraction for easy translation of defined
Advertisement Data fields into the resulting raw bytes needed by the Bluetooth
HCI LE Set Advertising Data command.
Setting MALLOC_CHECK_=3 causes additional checks in glibc for malloc()
usage errors, abort()ing the test if those trigger. MALLOC_PERTURB_=69
causes free()'d memory to be poisoned with 0x45, leading to crashes in
case of use-after-free.
Together, both are useful for spotting more errors during "make check"
Introducing src/advertising which will implement the
org.bluez.LEAdvertisingManager1 D-Bus interface defined in
doc/advertising-api.txt. Each LE-capable controller gets
an instance of the interface.
This patch introduces src/gatt-manager, which will implement the
org.bluez.GattManager1 API outlined in doc/gatt-api.txt. The old
src/gatt-dbus code has been removed to start from a clean slate.
This patch introduces src/gatt-database.* which handles incoming ATT
connections, manages per-adapter shared/gatt-db instances, and routes
connections to the corresponding device object. This is the layer that
will perform all the CCC management and Service Changed handling.