#include <MIDI_Interfaces/BLEMIDI/BLEMIDIPacketBuilder.hpp>
Class for building MIDI over Bluetooth Low Energy packets.
Definition at line 10 of file BLEMIDIPacketBuilder.hpp.
|
| BLEMIDIPacketBuilder (size_t capacity=20) |
|
void | reset () |
| Reset the builder to start a new packet.
|
|
void | setCapacity (uint16_t capacity) |
| Set the maximum capacity of the buffer.
|
|
uint16_t | getSize () const |
| Get the size of the current packet.
|
|
const uint8_t * | getBuffer () const |
| Get a pointer to the packet data buffer.
|
|
bool | empty () const |
| Check if the packet buffer is empty.
|
|
const std::vector< uint8_t > & | getPacket () const |
| Return the packet as a vector of bytes.
|
|
bool | add3B (uint8_t header, uint8_t data1, uint8_t data2, uint16_t timestamp) |
| Try adding a 3-byte MIDI channel voice message to the packet.
|
|
bool | add2B (uint8_t header, uint8_t data1, uint16_t timestamp) |
| Try adding a 2-byte MIDI channel voice message to the packet.
|
|
bool | addRealTime (uint8_t rt, uint16_t timestamp) |
| Try adding a MIDI real-time message to the packet.
|
|
bool | addSysCommon (uint8_t num_data, uint8_t header, uint8_t data1, uint8_t data2, uint16_t timestamp) |
| Try adding a MIDI system common message to the packet.
|
|
bool | addSysEx (const uint8_t *&data, size_t &length, uint16_t timestamp) |
| Try adding (part of) a SysEx message to the packet.
|
|
void | continueSysEx (const uint8_t *&data, size_t &length, uint16_t timestamp) |
| Add a SysEx continuation to the packet.
|
|
|
bool | hasSpaceFor (size_t bytes) const |
| Check if the buffer has space left.
|
|
void | initBuffer (uint16_t timestamp) |
| If this is the first byte/message in the packet, add the header containing the 6 most significant bits of the timestamp.
|
|
template<bool ThreeBytes> |
bool | addImpl (uint8_t header, uint8_t data1, uint8_t data2, uint16_t timestamp) |
| Try adding a 2-byte or 3-byte MIDI channel voice message to the packet.
|
|
|
static constexpr uint8_t | getTimestampMSB (uint16_t timestamp) |
| Timestamp[0]: 0b10hh hhhh.
|
|
static constexpr uint8_t | getTimestampLSB (uint16_t timestamp) |
| Timestamp[1]: 0b1lll llll.
|
|
◆ BLEMIDIPacketBuilder()
◆ hasSpaceFor()
bool hasSpaceFor |
( |
size_t | bytes | ) |
const |
|
inlineprivate |
◆ getTimestampMSB()
static constexpr uint8_t getTimestampMSB |
( |
uint16_t | timestamp | ) |
|
|
inlinestaticconstexprprivate |
◆ getTimestampLSB()
static constexpr uint8_t getTimestampLSB |
( |
uint16_t | timestamp | ) |
|
|
inlinestaticconstexprprivate |
◆ initBuffer()
void initBuffer |
( |
uint16_t | timestamp | ) |
|
|
inlineprivate |
If this is the first byte/message in the packet, add the header containing the 6 most significant bits of the timestamp.
Definition at line 37 of file BLEMIDIPacketBuilder.hpp.
◆ addImpl()
template<bool ThreeBytes>
bool addImpl |
( |
uint8_t | header, |
|
|
uint8_t | data1, |
|
|
uint8_t | data2, |
|
|
uint16_t | timestamp ) |
|
private |
Try adding a 2-byte or 3-byte MIDI channel voice message to the packet.
- Template Parameters
-
ThreeBytes | Set to true for a 3-byte message, false for a 2-byte message. |
- Parameters
-
header | MIDI status byte. |
data1 | MIDI data byte 1. |
data2 | MIDI data byte 2 (if ThreeBytes == true ). |
timestamp | 13-bit BLE-MIDI timestamp. |
- Return values
-
true | Successfully added message to the packet. |
false | Buffer is too full, send the current packet, reset the packet builder, and try again. |
Definition at line 6 of file BLEMIDIPacketBuilder.cpp.
◆ reset()
◆ setCapacity()
void setCapacity |
( |
uint16_t | capacity | ) |
|
Set the maximum capacity of the buffer.
Set this to the MTU of the BLE link minus three bytes (for notify overhead).
Definition at line 53 of file BLEMIDIPacketBuilder.cpp.
◆ getSize()
uint16_t getSize |
( |
| ) |
const |
|
inline |
◆ getBuffer()
const uint8_t * getBuffer |
( |
| ) |
const |
|
inline |
◆ empty()
◆ getPacket()
const std::vector< uint8_t > & getPacket |
( |
| ) |
const |
|
inline |
◆ add3B()
bool add3B |
( |
uint8_t | header, |
|
|
uint8_t | data1, |
|
|
uint8_t | data2, |
|
|
uint16_t | timestamp ) |
Try adding a 3-byte MIDI channel voice message to the packet.
- Parameters
-
header | MIDI status byte. |
data1 | MIDI data byte 1. |
data2 | MIDI data byte 2. |
timestamp | 13-bit BLE-MIDI timestamp. |
- Return values
-
true | Successfully added message to the packet. |
false | Buffer is too full, send the current packet, reset the packet builder, and try again. |
Definition at line 60 of file BLEMIDIPacketBuilder.cpp.
◆ add2B()
bool add2B |
( |
uint8_t | header, |
|
|
uint8_t | data1, |
|
|
uint16_t | timestamp ) |
Try adding a 2-byte MIDI channel voice message to the packet.
- Parameters
-
header | MIDI status byte. |
data1 | MIDI data byte 1. |
timestamp | 13-bit BLE-MIDI timestamp. |
- Return values
-
true | Successfully added message to the packet. |
false | Buffer is too full, send the current packet, reset the packet builder, and try again. |
Definition at line 66 of file BLEMIDIPacketBuilder.cpp.
◆ addRealTime()
bool addRealTime |
( |
uint8_t | rt, |
|
|
uint16_t | timestamp ) |
Try adding a MIDI real-time message to the packet.
- Parameters
-
rt | MIDI real-time byte. |
timestamp | 13-bit BLE-MIDI timestamp. |
- Return values
-
true | Successfully added message to the packet. |
false | Buffer is too full, send the current packet, reset the packet builder, and try again. |
Definition at line 72 of file BLEMIDIPacketBuilder.cpp.
◆ addSysCommon()
bool addSysCommon |
( |
uint8_t | num_data, |
|
|
uint8_t | header, |
|
|
uint8_t | data1, |
|
|
uint8_t | data2, |
|
|
uint16_t | timestamp ) |
Try adding a MIDI system common message to the packet.
- Parameters
-
num_data | The number of data bytes (0, 1 or 2). |
header | System common status byte. |
data1 | MIDI data byte 1. |
data2 | MIDI data byte 2. |
timestamp | 13-bit BLE-MIDI timestamp. |
- Return values
-
true | Successfully added message to the packet. |
false | Buffer is too full, send the current packet, reset the packet builder, and try again. |
Definition at line 85 of file BLEMIDIPacketBuilder.cpp.
◆ addSysEx()
bool addSysEx |
( |
const uint8_t *& | data, |
|
|
size_t & | length, |
|
|
uint16_t | timestamp ) |
Try adding (part of) a SysEx message to the packet.
- Parameters
-
[in,out] | data | Pointer to the first byte of the SysEx message. At the end, this will point to the first byte to send in the next packet, or nullptr if the message was finished. |
[in,out] | length | The number of bytes in the SysEx message. At the end, this will be set to remaining number of bytes to send in the next packet. |
[in] | timestamp | 13-bit BLE-MIDI timestamp. |
- Return values
-
true | Successfully added (part of) the message to the packet. |
false | Buffer is too full, send the current packet, reset the packet builder, and try again. |
If the message fits in a single packet, length
is set to 0
(no remaining data bytes) and data
is set to nullptr
.
For example:
const uint8_t *data = (...);
size_t length = (...);
uint16_t timestamp = (...);
if (!packetbuilder.
addSysEx(data, length, timestamp)) {
packetbuilder.
addSysEx(data, length, timestamp)
}
while (data) {
}
Class for building MIDI over Bluetooth Low Energy packets.
const uint8_t * getBuffer() const
Get a pointer to the packet data buffer.
uint16_t getSize() const
Get the size of the current packet.
void continueSysEx(const uint8_t *&data, size_t &length, uint16_t timestamp)
Add a SysEx continuation to the packet.
bool addSysEx(const uint8_t *&data, size_t &length, uint16_t timestamp)
Try adding (part of) a SysEx message to the packet.
void reset()
Reset the builder to start a new packet.
Definition at line 105 of file BLEMIDIPacketBuilder.cpp.
◆ continueSysEx()
void continueSysEx |
( |
const uint8_t *& | data, |
|
|
size_t & | length, |
|
|
uint16_t | timestamp ) |
Add a SysEx continuation to the packet.
- Parameters
-
[in,out] | data | Pointer to the first byte of the SysEx message to send in this continuation packet. At the end, this will point to the first byte to send in the next packet, or nullptr if the message was finished. |
[in,out] | length | The number of remaining bytes in the SysEx message. At the end, this will be set to remaining number of bytes to send in the next packet. |
[in] | timestamp | 13-bit BLE-MIDI timestamp. |
If the message can be completed in a single packet, length
is set to 0
(no remaining data bytes) and data
is set to nullptr
.
- See also
- addSysEx()
Definition at line 137 of file BLEMIDIPacketBuilder.cpp.
◆ runningHeader
uint8_t runningHeader = 0 |
|
private |
◆ runningTimestamp
uint8_t runningTimestamp = 0 |
|
private |
◆ buffer
std::vector<uint8_t> buffer = std::vector<uint8_t>(0) |
|
private |
◆ SysExStart
constexpr const uint8_t SysExStart |
|
staticconstexprprivate |
◆ SysExEnd
constexpr const uint8_t SysExEnd |
|
staticconstexprprivate |
The documentation for this class was generated from the following files: