MIDI over BLE implementation
Subsystems (2)
v4 cover MIDI over BLE implementation
This patchset implements the MIDI over BLE spec, more information on patch #1.
Patch #2 is some unit-tests to make sure the MIDI parser works properly.
Felipe F. Tonello (2):
profiles/midi: Added MIDI over BLE profile implementation unit/test-midi: Added libmidi use-case tests
Makefile.am | 14 +- Makefile.plugins | 8 + configure.ac | 11 + profiles/midi/libmidi.c | 412 +++++++++++++++++++++++++++++++ profiles/midi/libmidi.h | 150 ++++++++++++ profiles/midi/midi.c | 490 +++++++++++++++++++++++++++++++++++++ unit/test-midi.c | 628 ++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 1712 insertions(+), 1 deletion(-) create mode 100644 profiles/midi/libmidi.c create mode 100644 profiles/midi/libmidi.h create mode 100644 profiles/midi/midi.c create mode 100644 unit/test-midi.c
Signature · 1 line
2.10.2
PATCH v4 1/2 profiles/midi: Added MIDI over BLE profile implementation
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/
--- Makefile.am | 4 +- Makefile.plugins | 8 + configure.ac | 11 ++ profiles/midi/libmidi.c | 412 ++++++++++++++++++++++++++++++++++++++++ profiles/midi/libmidi.h | 150 +++++++++++++++ profiles/midi/midi.c | 490 ++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 1074 insertions(+), 1 deletion(-) create mode 100644 profiles/midi/libmidi.c create mode 100644 profiles/midi/libmidi.h create mode 100644 profiles/midi/midi.c
Makefile.am +3 -1
@@ -147,6 +147,7 @@ gobex_sources = gobex/gobex.h gobex/gobex.c \ builtin_modules = builtin_sources = builtin_nodist = +builtin_ldadd = include Makefile.plugins
@@ -191,7 +192,8 @@ src_bluetoothd_SOURCES = $(builtin_sources) \ src_bluetoothd_LDADD = lib/libbluetooth-internal.la \ gdbus/libgdbus-internal.la \ src/libshared-glib.la \ - @BACKTRACE_LIBS@ @GLIB_LIBS@ @DBUS_LIBS@ -ldl -lrt + @BACKTRACE_LIBS@ @GLIB_LIBS@ @DBUS_LIBS@ -ldl -lrt \ + $(builtin_ldadd) src_bluetoothd_LDFLAGS = $(AM_LDFLAGS) -Wl,--export-dynamic \ -Wl,--version-script=$(srcdir)/src/bluetooth.ver
Makefile.plugins +8 -0
@@ -95,6 +95,14 @@ builtin_sources += profiles/scanparam/scan.c builtin_modules += deviceinfo builtin_sources += profiles/deviceinfo/deviceinfo.c +if MIDI +builtin_modules += midi +builtin_sources += profiles/midi/midi.c \ + profiles/midi/libmidi.h \ + profiles/midi/libmidi.c +builtin_ldadd += @ALSA_LIBS@ +endif + if SIXAXIS plugin_LTLIBRARIES += plugins/sixaxis.la plugins_sixaxis_la_SOURCES = plugins/sixaxis.c
configure.ac +11 -0
@@ -212,6 +212,17 @@ AC_ARG_ENABLE(cups, AC_HELP_STRING([--disable-cups], [disable CUPS printer support]), [enable_cups=${enableval}]) AM_CONDITIONAL(CUPS, test "${enable_cups}" != "no") +AC_ARG_ENABLE(midi, AC_HELP_STRING([--enable-midi], + [enable MIDI support]), [enable_midi=${enableval}]) +AM_CONDITIONAL(MIDI, test "${enable_midi}" = "yes") + +if (test "${enable_midi}" = "yes"); then + PKG_CHECK_MODULES(ALSA, alsa, dummy=yes, + AC_MSG_ERROR(ALSA lib is required for MIDI support)) + AC_SUBST(ALSA_CFLAGS) + AC_SUBST(ALSA_LIBS) +fi + AC_ARG_ENABLE(obex, AC_HELP_STRING([--disable-obex], [disable OBEX profile support]), [enable_obex=${enableval}]) if (test "${enable_obex}" != "no"); then
profiles/midi/libmidi.c new file +412 -0
412 lines not on this page · raw message
profiles/midi/libmidi.h new file +150 -0
150 lines not on this page · raw message
profiles/midi/midi.c new file +490 -0
490 lines not on this page · raw message
Signature · 1 line
2.10.2
PATCH v4 2/2 unit/test-midi: Added libmidi use-case tests
In reply to Felipe F. TonelloI 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.
--- Makefile.am | 10 + unit/test-midi.c | 628 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 638 insertions(+) create mode 100644 unit/test-midi.c
Makefile.am +10 -0
@@ -423,6 +423,16 @@ unit_test_gattrib_LDADD = lib/libbluetooth-internal.la \ src/libshared-glib.la \ @GLIB_LIBS@ @DBUS_LIBS@ -ldl -lrt +if MIDI +unit_tests += unit/test-midi +unit_test_midi_CFLAGS = $(AM_CFLAGS) @ALSA_CFLAGS@ -DMIDI_TEST +unit_test_midi_SOURCES = unit/test-midi.c \ + profiles/midi/libmidi.h \ + profiles/midi/libmidi.c +unit_test_midi_LDADD = src/libshared-glib.la \ + @GLIB_LIBS@ @ALSA_LIBS@ +endif + if MAINTAINER_MODE noinst_PROGRAMS += $(unit_tests) endif
unit/test-midi.c new file +628 -0
628 lines not on this page · raw message
Signature · 1 line
2.10.2
Luiz Augusto von Dentz
maintainerHi Felipe,
Quoted 21 lines · Felipe F. Tonello
This patchset implements the MIDI over BLE spec, more information on patch #1.
Patch #2 is some unit-tests to make sure the MIDI parser works properly.
Felipe F. Tonello (2):
profiles/midi: Added MIDI over BLE profile implementation unit/test-midi: Added libmidi use-case testsMakefile.am | 14 +- Makefile.plugins | 8 + configure.ac | 11 + profiles/midi/libmidi.c | 412 +++++++++++++++++++++++++++++++ profiles/midi/libmidi.h | 150 ++++++++++++ profiles/midi/midi.c | 490 +++++++++++++++++++++++++++++++++++++ unit/test-midi.c | 628 ++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 1712 insertions(+), 1 deletion(-) create mode 100644 profiles/midi/libmidi.c create mode 100644 profiles/midi/libmidi.h create mode 100644 profiles/midi/midi.c create mode 100644 unit/test-midi.c
Quoted 2 lines
--
2.10.2
Looks like there is something not quite rigth:
https://paste.fedoraproject.org/513667/48284373/
Signature · 1 line
Luiz Augusto von Dentz
Hi Luiz,
Quoted 25 lines · Luiz Augusto von Dentz
Hi Felipe,
Quoted 21 lines · Felipe F. Tonello
This patchset implements the MIDI over BLE spec, more information on patch #1.
Patch #2 is some unit-tests to make sure the MIDI parser works properly.
Felipe F. Tonello (2):
profiles/midi: Added MIDI over BLE profile implementation unit/test-midi: Added libmidi use-case testsMakefile.am | 14 +- Makefile.plugins | 8 + configure.ac | 11 + profiles/midi/libmidi.c | 412 +++++++++++++++++++++++++++++++ profiles/midi/libmidi.h | 150 ++++++++++++ profiles/midi/midi.c | 490 +++++++++++++++++++++++++++++++++++++ unit/test-midi.c | 628 ++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 1712 insertions(+), 1 deletion(-) create mode 100644 profiles/midi/libmidi.c create mode 100644 profiles/midi/libmidi.h create mode 100644 profiles/midi/midi.c create mode 100644 unit/test-midi.c
Quoted 7 lines
Quoted 2 lines
--
2.10.2Looks like there is something not quite rigth:
Weird... What command did you run to get this?
Signature · 1 line
Felipe
Luiz Augusto von Dentz
maintainerHi Felipe,
Quoted 31 lines · Felipe Ferreri Tonello
Hi Luiz,
Quoted 28 lines · Luiz Augusto von Dentz
Hi Felipe,
Quoted 23 lines · Felipe F. Tonello
This patchset implements the MIDI over BLE spec, more information on patch #1.
Patch #2 is some unit-tests to make sure the MIDI parser works properly.
Felipe F. Tonello (2):
profiles/midi: Added MIDI over BLE profile implementation unit/test-midi: Added libmidi use-case testsMakefile.am | 14 +- Makefile.plugins | 8 + configure.ac | 11 + profiles/midi/libmidi.c | 412 +++++++++++++++++++++++++++++++ profiles/midi/libmidi.h | 150 ++++++++++++ profiles/midi/midi.c | 490 +++++++++++++++++++++++++++++++++++++ unit/test-midi.c | 628 ++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 1712 insertions(+), 1 deletion(-) create mode 100644 profiles/midi/libmidi.c create mode 100644 profiles/midi/libmidi.h create mode 100644 profiles/midi/midi.c create mode 100644 unit/test-midi.c--
2.10.2
Quoted 6 lines
Quoted 4 lines
Looks like there is something not quite rigth:
Weird... What command did you run to get this?
Ive just run make check with --enable-midi.
Quoted 2 lines
--
Felipe
Signature · 1 line
Luiz Augusto von Dentz