5#include <AH/STL/vector>
14 std::vector<uint8_t>
buffer = std::vector<uint8_t>(0);
23 return bytes <= size_t(
buffer.capacity() -
buffer.size());
28 return ((timestamp >> 7) & 0x3F) | 0x80;
32 return timestamp | 0x80;
64 template <
bool ThreeBytes>
65 bool addImpl(uint8_t header, uint8_t data1, uint8_t data2,
106 bool add3B(uint8_t header, uint8_t data1, uint8_t data2,
125 bool add2B(uint8_t header, uint8_t data1, uint16_t timestamp);
163 bool addSysCommon(uint8_t num_data, uint8_t header, uint8_t data1,
164 uint8_t data2, uint16_t timestamp);
210 bool addSysEx(
const uint8_t *&data,
size_t &length, uint16_t timestamp);
@ SysExStart
Start of System Exclusive.
@ SysExEnd
End of System Exclusive.
#define BEGIN_CS_NAMESPACE
Class for building MIDI over Bluetooth Low Energy packets.
const uint8_t * getBuffer() const
Get a pointer to the packet data buffer.
std::vector< uint8_t > buffer
uint16_t getSize() const
Get the size of the current packet.
void setCapacity(uint16_t capacity)
Set the maximum capacity of the buffer.
void continueSysEx(const uint8_t *&data, size_t &length, uint16_t timestamp)
Add a SysEx continuation to the packet.
static constexpr const uint8_t SysExEnd
bool addSysEx(const uint8_t *&data, size_t &length, uint16_t timestamp)
Try adding (part of) a SysEx message to the packet.
bool hasSpaceFor(size_t bytes) const
Check if the buffer has space left.
static constexpr uint8_t getTimestampLSB(uint16_t timestamp)
Timestamp[1]: 0b1lll llll.
BLEMIDIPacketBuilder(size_t capacity=20)
static constexpr uint8_t getTimestampMSB(uint16_t timestamp)
Timestamp[0]: 0b10hh hhhh.
bool empty() const
Check if the packet buffer is empty.
bool add2B(uint8_t header, uint8_t data1, uint16_t timestamp)
Try adding a 2-byte MIDI channel voice 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 addRealTime(uint8_t rt, uint16_t timestamp)
Try adding a MIDI real-time message to the packet.
static constexpr const uint8_t SysExStart
const std::vector< uint8_t > & getPacket() const
Return the packet as a vector of bytes.
void reset()
Reset the builder to start a new packet.
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.
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.
void initBuffer(uint16_t timestamp)
If this is the first byte/message in the packet, add the header containing the 6 most significant bit...