Reworked encoding/decoding methods to support larger arrays.
This commit is contained in:
parent
287b3625db
commit
6fbc9bd5a7
61
src/MIDI.cpp
61
src/MIDI.cpp
|
|
@ -45,27 +45,30 @@ BEGIN_MIDI_NAMESPACE
|
||||||
\return The lenght of the encoded output buffer.
|
\return The lenght of the encoded output buffer.
|
||||||
@see decodeSysEx
|
@see decodeSysEx
|
||||||
*/
|
*/
|
||||||
byte encodeSysEx(const byte* inData, byte* outSysEx, byte inLength)
|
unsigned encodeSysEx(const byte* inData, byte* outSysEx, unsigned inLength)
|
||||||
{
|
{
|
||||||
byte retlen = 0;
|
unsigned outLength = 0; // Num bytes in output array.
|
||||||
byte compteur;
|
byte count = 0; // Num 7bytes in a block.
|
||||||
byte count7 = 0;
|
outSysEx[0] = 0;
|
||||||
|
|
||||||
outSysEx[0] = 0;
|
for (unsigned i = 0; i < inLength; ++i)
|
||||||
for (compteur = 0; compteur < inLength; compteur++) {
|
{
|
||||||
byte c = inData[compteur] & 0x7F;
|
const byte data = inData[i];
|
||||||
byte msb = inData[compteur] >> 7;
|
const byte msb = data >> 7;
|
||||||
outSysEx[0] |= msb << count7;
|
const byte body = data & 0x7f;
|
||||||
outSysEx[1 + count7] = c;
|
|
||||||
|
outSysEx[0] |= (msb << count);
|
||||||
|
outSysEx[1 + count] = body;
|
||||||
|
|
||||||
if (count7++ == 6) {
|
if (count++ == 6)
|
||||||
outSysEx += 8;
|
{
|
||||||
retlen += 8;
|
outSysEx += 8;
|
||||||
|
outLength += 8;
|
||||||
outSysEx[0] = 0;
|
outSysEx[0] = 0;
|
||||||
count7 = 0;
|
count = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return retlen + count7 + ((count7 != 0)?1:0);
|
return outLength + count + (count != 0 ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! \brief Decode System Exclusive messages.
|
/*! \brief Decode System Exclusive messages.
|
||||||
|
|
@ -78,24 +81,24 @@ byte encodeSysEx(const byte* inData, byte* outSysEx, byte inLength)
|
||||||
\return The lenght of the output buffer.
|
\return The lenght of the output buffer.
|
||||||
@see encodeSysEx @see getSysExArrayLength
|
@see encodeSysEx @see getSysExArrayLength
|
||||||
*/
|
*/
|
||||||
byte decodeSysEx(const byte* inSysEx, byte* outData, byte inLength)
|
unsigned decodeSysEx(const byte* inSysEx, byte* outData, unsigned inLength)
|
||||||
{
|
{
|
||||||
byte cnt;
|
unsigned count = 0;
|
||||||
byte cnt2 = 0;
|
byte msbStorage = 0;
|
||||||
byte bits = 0;
|
|
||||||
|
|
||||||
for (cnt = 0; cnt < inLength; ++cnt) {
|
for (unsigned i = 0; i < inLength; ++i)
|
||||||
|
{
|
||||||
if ((cnt % 8) == 0) {
|
if ((i % 8) == 0)
|
||||||
bits = inSysEx[cnt];
|
{
|
||||||
|
msbStorage = inSysEx[i];
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
outData[cnt2++] = inSysEx[cnt] | ((bits & 1) << 7);
|
{
|
||||||
bits >>= 1;
|
outData[count++] = inSysEx[i] | ((msbStorage & 1) << 7);
|
||||||
|
msbStorage >>= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return cnt2;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
END_MIDI_NAMESPACE
|
END_MIDI_NAMESPACE
|
||||||
|
|
|
||||||
|
|
@ -223,8 +223,8 @@ private:
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
byte encodeSysEx(const byte* inData, byte* outSysEx, byte inLenght);
|
unsigned encodeSysEx(const byte* inData, byte* outSysEx, unsigned inLenght);
|
||||||
byte decodeSysEx(const byte* inSysEx, byte* outData, byte inLenght);
|
unsigned decodeSysEx(const byte* inSysEx, byte* outData, unsigned inLenght);
|
||||||
|
|
||||||
END_MIDI_NAMESPACE
|
END_MIDI_NAMESPACE
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue