FastLED 3.9.15
Loading...
Searching...
No Matches

◆ encodeSysEx()

unsigned encodeSysEx ( const byte * inData,
byte * outSysEx,
unsigned inLength,
bool inFlipHeaderBits )

Encode System Exclusive messages. SysEx messages are encoded to guarantee transmission of data bytes higher than 127 without breaking the MIDI protocol. Use this static method to convert the data you want to send.

Parameters
inDataThe data to encode.
outSysExThe output buffer where to store the encoded message.
inLengthThe length of the input buffer.
inFlipHeaderBitsTrue for Korg and other who store MSB in reverse order
Returns
The length of the encoded output buffer.
See also
decodeSysEx Code inspired from Ruin & Wesen's SysEx encoder/decoder - http://ruinwesen.com

Definition at line 46 of file MIDI.cpp.

50{
51 unsigned outLength = 0; // Num bytes in output array.
52 byte count = 0; // Num 7bytes in a block.
53 outSysEx[0] = 0;
54
55 for (unsigned i = 0; i < inLength; ++i)
56 {
57 const byte data = inData[i];
58 const byte msb = data >> 7;
59 const byte body = data & 0x7f;
60
61 outSysEx[0] |= (msb << (inFlipHeaderBits ? count : (6 - count)));
62 outSysEx[1 + count] = body;
63
64 if (count++ == 6)
65 {
66 outSysEx += 8;
67 outLength += 8;
68 outSysEx[0] = 0;
69 count = 0;
70 }
71 }
72 return outLength + count + (count != 0 ? 1 : 0);
73}