FabGL2 2.0.0
Graphics, audio, GUI and retro-computing library for the ESP32 (ESP-IDF)
Loading...
Searching...
No Matches
BLEMIDI Class Reference

MIDI input over Bluetooth Low Energy (BLE-MIDI peripheral). More...

#include <blemidi.h>

Public Member Functions

bool begin (char const *deviceName, int queueSize=64)
 Starts the Bluetooth stack and advertises the BLE-MIDI service.
bool connected ()
 Determines whether a central is connected.
int droppedMessages ()
 Number of messages discarded because the queue was full.
bool getMessage (MIDIMessage *msg)
 Gets the next received message (non blocking).

Static Public Member Functions

static void releaseClassicBTMemory ()
 Releases the internal RAM reserved for classic Bluetooth (BR/EDR), about 15 KB.

Public Attributes

Delegate onMessages
 Called after one or more messages have been queued.

Detailed Description

MIDI input over Bluetooth Low Energy (BLE-MIDI peripheral).

The device advertises the standard BLE-MIDI service with the specified name: a central (an iPad, a Mac, a BLE-MIDI adapter like CME WIDI...) connects to it and writes MIDI packets. Packets are decoded (running status, several messages per packet, timestamps) and the messages are put in a queue, read with getMessage(). System exclusive messages and Active Sensing are discarded. One connection at a time.

The NimBLE host must be enabled in sdkconfig (otherwise begin() returns false):

CONFIG_BT_ENABLED=y
CONFIG_BT_NIMBLE_ENABLED=y
CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y
CONFIG_BT_NIMBLE_MAX_CONNECTIONS=1
CONFIG_BTDM_CTRL_BLE_MAX_CONN=1
CONFIG_BT_NIMBLE_ROLE_CENTRAL=n
CONFIG_BT_NIMBLE_ROLE_OBSERVER=n
CONFIG_BT_NIMBLE_PINNED_TO_CORE_0=y
CONFIG_BTDM_CTRL_PINNED_TO_CORE_0=y

Memory: on the ESP32 Bluetooth reserves about 23 KB of internal RAM at boot (after releaseClassicBTMemory()) and adds 13 KB of static data; NimBLE and the controller then allocate about 30-40 KB (less with smaller NimBLE pools, see the Synth example sdkconfig.defaults). The reserved area splits the internal RAM in smaller regions: the display frame buffer may get fewer lines than requested.

Example:

fabgl::BLEMIDI midi;

extern "C" void app_main() {
  fabgl::BLEMIDI::releaseClassicBTMemory();   // before allocating the display
  ...
  midi.begin("FabGL MIDI");
  while (true) {
    fabgl::MIDIMessage msg;
    while (midi.getMessage(&msg))
      printf("%02X %02X %02X\n", msg.status, msg.data1, msg.data2);
    vTaskDelay(1);
  }
}

Definition at line 104 of file blemidi.h.


The documentation for this class was generated from the following files: