Singleton bridge between BLE-MIDI centrals and the platform MidiSystem. More...
#include <ble_midi_registry.hpp>
Public Member Functions | |
| void | register_input (const std::string &port_id, const std::string &name) |
| Publish a connected peripheral's input port. | |
| void | register_output (const std::string &port_id, const std::string &name, std::function< void(const std::vector< uint8_t > &)> sink) |
| Publish a connected peripheral's output port ("ble-midi-out:<peripheral-id>"). | |
| void | unregister_input (const std::string &port_id) |
| Remove a previously published port (on disconnect). | |
| void | unregister_output (const std::string &port_id) |
| void | deliver_message (const std::string &port_id, const std::vector< uint8_t > &bytes, double timestamp_sec) |
| Deliver a decoded MIDI message from the central to the host callback attached to port_id (if the host has opened that input). | |
| std::vector< MidiPortInfo > | list_inputs () const |
| Currently-published BLE input / output ports, for the platform MidiSystem to merge into enumerate_inputs() / enumerate_outputs(). | |
| std::vector< MidiPortInfo > | list_outputs () const |
| bool | is_input (const std::string &port_id) const |
| True if port_id is a registered BLE input / output (so the platform MidiInput/MidiOutput knows to route through the registry rather than the raw OS transport). | |
| bool | is_output (const std::string &port_id) const |
| bool | attach_input (const std::string &port_id, MidiInputCallback callback, MidiSysexCallback sysex_callback) |
| Attach the host's MidiInput delivery callback to a BLE input port. | |
| void | detach_input (const std::string &port_id) |
| Detach the host's MidiInput delivery callback (on MidiInput::close()). | |
| std::function< void(const std::vector< uint8_t > &)> | output_sink (const std::string &port_id) const |
| Fetch a forwarding handle for a BLE output port so the host's MidiOutput can forward sent events. | |
Static Public Member Functions | |
| static BleMidiPortRegistry & | instance () |
Singleton bridge between BLE-MIDI centrals and the platform MidiSystem.
Thread-safe: the central touches it from its D-Bus worker thread while the MidiSystem / host touch it from the UI / audio-setup thread.
| bool pulp::midi::BleMidiPortRegistry::attach_input | ( | const std::string & | port_id, |
| MidiInputCallback | callback, | ||
| MidiSysexCallback | sysex_callback ) |
Attach the host's MidiInput delivery callback to a BLE input port.
The registry forwards every deliver_message() for that port to it until the input is closed (detach_input) or the port is unregistered. Returns false if port_id is not a registered BLE input.
| void pulp::midi::BleMidiPortRegistry::deliver_message | ( | const std::string & | port_id, |
| const std::vector< uint8_t > & | bytes, | ||
| double | timestamp_sec ) |
Deliver a decoded MIDI message from the central to the host callback attached to port_id (if the host has opened that input).
No-op when the port is unknown or unopened. Called from the central's worker thread.
| void pulp::midi::BleMidiPortRegistry::detach_input | ( | const std::string & | port_id | ) |
Detach the host's MidiInput delivery callback (on MidiInput::close()).
|
static |
| bool pulp::midi::BleMidiPortRegistry::is_input | ( | const std::string & | port_id | ) | const |
True if port_id is a registered BLE input / output (so the platform MidiInput/MidiOutput knows to route through the registry rather than the raw OS transport).
| bool pulp::midi::BleMidiPortRegistry::is_output | ( | const std::string & | port_id | ) | const |
| std::vector< MidiPortInfo > pulp::midi::BleMidiPortRegistry::list_inputs | ( | ) | const |
Currently-published BLE input / output ports, for the platform MidiSystem to merge into enumerate_inputs() / enumerate_outputs().
| std::vector< MidiPortInfo > pulp::midi::BleMidiPortRegistry::list_outputs | ( | ) | const |
| std::function< void(const std::vector< uint8_t > &)> pulp::midi::BleMidiPortRegistry::output_sink | ( | const std::string & | port_id | ) | const |
Fetch a forwarding handle for a BLE output port so the host's MidiOutput can forward sent events.
Returns an empty function if the port is unknown; a previously fetched handle becomes a no-op after unregister_output().
| void pulp::midi::BleMidiPortRegistry::register_input | ( | const std::string & | port_id, |
| const std::string & | name ) |
Publish a connected peripheral's input port.
port_id is "ble-midi-in:<peripheral-id>"; name is the human-readable peripheral name shown in port pickers. Idempotent per port_id.
| void pulp::midi::BleMidiPortRegistry::register_output | ( | const std::string & | port_id, |
| const std::string & | name, | ||
| std::function< void(const std::vector< uint8_t > &)> | sink ) |
Publish a connected peripheral's output port ("ble-midi-out:<peripheral-id>").
sink is invoked with raw MIDI bytes when the host sends to the opened MidiOutput; the central encodes them into a BLE packet and performs the GATT write. Idempotent per port_id.
| void pulp::midi::BleMidiPortRegistry::unregister_input | ( | const std::string & | port_id | ) |
Remove a previously published port (on disconnect).
Clears any attached host callback so a stale GATT notification cannot resurrect it.
| void pulp::midi::BleMidiPortRegistry::unregister_output | ( | const std::string & | port_id | ) |