14#include <esp_gattc_api.h>
27static constexpr size_t MAX_TX_MIDI_BYTES = 128;
39 BLEMidi(uint8_t *sysex_buffer, uint16_t sysex_capacity,
bool pair)
46 esp_ble_gattc_cb_param_t *param)
override;
53 void send_note_on(int32_t note, int32_t velocity, int32_t channel);
54 void send_note_off(int32_t note, int32_t velocity, int32_t channel);
110 void send_channel_(uint8_t status, int32_t channel, int32_t data1, int32_t data2,
size_t length);
Client for devices implementing the standard BLE-MIDI service, e.g.
BLEMidi(uint8_t *sysex_buffer, uint16_t sysex_capacity, bool pair)
sysex_buffer holds sysex_capacity bytes; longer SysEx messages are truncated.
void send_control_change(int32_t control_number, int32_t value, int32_t channel)
bool write_without_response_
void send_program_change(int32_t program, int32_t channel)
LazyCallbackManager< void(uint8_t, uint8_t, uint8_t)> note_on_callback_
float get_setup_priority() const override
LazyCallbackManager< void(uint8_t, uint8_t, uint8_t)> control_change_callback_
LazyCallbackManager< void(uint8_t, uint8_t, uint8_t)> note_off_callback_
LazyCallbackManager< void()> disconnect_callback_
void send_note_off(int32_t note, int32_t velocity, int32_t channel)
void send_channel_(uint8_t status, int32_t channel, int32_t data1, int32_t data2, size_t length)
Channel-voice message: the status byte takes the channel; out-of-range values are refused.
LazyCallbackManager< void(int16_t, uint8_t)> pitch_bend_callback_
void send_raw(const uint8_t *bytes, size_t length)
Send raw MIDI bytes (status byte followed by its data bytes).
void add_on_pitch_bend_callback(F &&callback)
(value, channel), value being -8192 to 8191
void dump_config() override
void add_on_program_change_callback(F &&callback)
(program, channel)
bool write_packet_(uint8_t *packet, size_t midi_length)
Write a packet whose MIDI bytes already sit at packet + 2; the header and timestamp are filled in.
void send_note_on(int32_t note, int32_t velocity, int32_t channel)
void add_on_note_on_callback(F &&callback)
(note, velocity, channel)
void gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t *param) override
void send_sysex(const uint8_t *payload, size_t length)
Send a System Exclusive message.
void send_pitch_bend(int32_t value, int32_t channel)
Pitch bend value is -8192 to 8191, centered on zero.
void fail_session_()
Set a warning and drop the link so that ble_client reconnects and the setup runs again.
void add_on_connect_callback(F &&callback)
void add_on_disconnect_callback(F &&callback)
LazyCallbackManager< void(ByteSpan)> message_callback_
LazyCallbackManager< void(ByteSpan)> sysex_callback_
LazyCallbackManager< void(uint8_t, uint8_t)> program_change_callback_
void add_on_message_callback(F &&callback)
The raw bytes of every decoded message.
void add_on_control_change_callback(F &&callback)
(control_number, value, channel)
bool is_ready() const
True once the MIDI characteristic has been discovered and notifications are enabled.
static void dispatch_message(void *ctx, const MidiMessage &message)
uint16_t characteristic_handle_
void add_on_sysex_callback(F &&callback)
The SysEx payload without the 0xF0/0xF7 wrappers.
void handle_message_(const MidiMessage &message)
void add_on_note_off_callback(F &&callback)
(note, velocity, channel); a Note On with velocity zero is reported here as well
bool write_midi_(const uint8_t *midi_bytes, size_t length)
Wrap MIDI bytes in a BLE-MIDI packet and write them to the MIDI characteristic.
LazyCallbackManager< void()> connect_callback_
Decoder for the BLE-MIDI packet format (Apple/MMA "Bluetooth Low EnergyMIDI" specification,...
const LogString * message
std::span< const uint8_t > ByteSpan
The bytes of a received message, valid for the duration of the automation.
constexpr float AFTER_BLUETOOTH