Moved encode/decode sysex out of MidiInterface.
This commit is contained in:
parent
2c4f926de7
commit
d8b0d6f838
62
src/MIDI.cpp
62
src/MIDI.cpp
|
|
@ -52,5 +52,67 @@
|
|||
|
||||
BEGIN_MIDI_NAMESPACE
|
||||
|
||||
/*! \brief 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.
|
||||
\param inData The data to encode.
|
||||
\param outSysEx The output buffer where to store the encoded message.
|
||||
\param inLength The lenght of the input buffer.
|
||||
\return The lenght of the encoded output buffer.
|
||||
@see decodeSysEx
|
||||
*/
|
||||
byte encodeSysEx(const byte* inData, byte* outSysEx, byte inLength)
|
||||
{
|
||||
byte retlen = 0;
|
||||
byte compteur;
|
||||
byte count7 = 0;
|
||||
|
||||
outSysEx[0] = 0;
|
||||
for (compteur = 0; compteur < inLength; compteur++) {
|
||||
byte c = inData[compteur] & 0x7F;
|
||||
byte msb = inData[compteur] >> 7;
|
||||
outSysEx[0] |= msb << count7;
|
||||
outSysEx[1 + count7] = c;
|
||||
|
||||
if (count7++ == 6) {
|
||||
outSysEx += 8;
|
||||
retlen += 8;
|
||||
outSysEx[0] = 0;
|
||||
count7 = 0;
|
||||
}
|
||||
}
|
||||
return retlen + count7 + ((count7 != 0)?1:0);
|
||||
}
|
||||
|
||||
/*! \brief Decode 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 reassemble
|
||||
your received message.
|
||||
\param inSysEx The SysEx data received from MIDI in.
|
||||
\param outData The output buffer where to store the decrypted message.
|
||||
\param inLength The lenght of the input buffer.
|
||||
\return The lenght of the output buffer.
|
||||
@see encodeSysEx @see getSysExArrayLength
|
||||
*/
|
||||
byte decodeSysEx(const byte* inSysEx, byte* outData, byte inLength)
|
||||
{
|
||||
byte cnt;
|
||||
byte cnt2 = 0;
|
||||
byte bits = 0;
|
||||
|
||||
for (cnt = 0; cnt < inLength; ++cnt) {
|
||||
|
||||
if ((cnt % 8) == 0) {
|
||||
bits = inSysEx[cnt];
|
||||
}
|
||||
else {
|
||||
outData[cnt2++] = inSysEx[cnt] | ((bits & 1) << 7);
|
||||
bits >>= 1;
|
||||
}
|
||||
|
||||
}
|
||||
return cnt2;
|
||||
}
|
||||
|
||||
END_MIDI_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -79,9 +79,6 @@ public:
|
|||
DataByte inData2,
|
||||
Channel inChannel);
|
||||
|
||||
public:
|
||||
static byte decodeSysEx(const byte* inSysEx, byte* outData, byte inLenght);
|
||||
|
||||
private:
|
||||
inline StatusByte getStatus(MidiType inType,
|
||||
Channel inChannel) const;
|
||||
|
|
@ -113,7 +110,6 @@ public:
|
|||
|
||||
public:
|
||||
static inline MidiType getTypeFromStatusByte(const byte inStatus);
|
||||
static byte encodeSysEx(const byte* inData, byte* outSysEx, byte inLenght);
|
||||
|
||||
private:
|
||||
bool inputFilter(Channel inChannel);
|
||||
|
|
@ -220,6 +216,11 @@ private:
|
|||
SerialPort& mSerial;
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
byte encodeSysEx(const byte* inData, byte* outSysEx, byte inLenght);
|
||||
byte decodeSysEx(const byte* inSysEx, byte* outData, byte inLenght);
|
||||
|
||||
END_MIDI_NAMESPACE
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -164,42 +164,6 @@ void MidiInterface<SerialPort>::send(MidiType inType,
|
|||
sendRealTime(inType); // System Real-time and 1 byte.
|
||||
}
|
||||
|
||||
/*! \brief 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.
|
||||
\param inData The data to encode.
|
||||
\param outSysEx The output buffer where to store the encoded message.
|
||||
\param inLength The lenght of the input buffer.
|
||||
\return The lenght of the encoded output buffer.
|
||||
@see decodeSysEx
|
||||
*/
|
||||
template<class SerialPort>
|
||||
byte MidiInterface<SerialPort>::encodeSysEx(const byte* inData,
|
||||
byte* outSysEx,
|
||||
byte inLength)
|
||||
{
|
||||
byte retlen = 0;
|
||||
byte compteur;
|
||||
byte count7 = 0;
|
||||
|
||||
outSysEx[0] = 0;
|
||||
for (compteur = 0; compteur < inLength; compteur++) {
|
||||
byte c = inData[compteur] & 0x7F;
|
||||
byte msb = inData[compteur] >> 7;
|
||||
outSysEx[0] |= msb << count7;
|
||||
outSysEx[1 + count7] = c;
|
||||
|
||||
if (count7++ == 6) {
|
||||
outSysEx += 8;
|
||||
retlen += 8;
|
||||
outSysEx[0] = 0;
|
||||
count7 = 0;
|
||||
}
|
||||
}
|
||||
return retlen + count7 + ((count7 != 0)?1:0);
|
||||
}
|
||||
|
||||
#endif // MIDI_BUILD_OUTPUT
|
||||
|
||||
|
||||
|
|
@ -628,42 +592,6 @@ void MidiInterface<SerialPort>::launchCallback()
|
|||
|
||||
#endif // MIDI_USE_CALLBACKS
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
/*! \brief Decode 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 reassemble
|
||||
your received message.
|
||||
\param inSysEx The SysEx data received from MIDI in.
|
||||
\param outData The output buffer where to store the decrypted message.
|
||||
\param inLength The lenght of the input buffer.
|
||||
\return The lenght of the output buffer.
|
||||
@see encodeSysEx @see getSysExArrayLength
|
||||
*/
|
||||
template<class SerialPort>
|
||||
byte MidiInterface<SerialPort>::decodeSysEx(const byte* inSysEx,
|
||||
byte* outData,
|
||||
byte inLength)
|
||||
{
|
||||
|
||||
byte cnt;
|
||||
byte cnt2 = 0;
|
||||
byte bits = 0;
|
||||
|
||||
for (cnt = 0; cnt < inLength; ++cnt) {
|
||||
|
||||
if ((cnt % 8) == 0) {
|
||||
bits = inSysEx[cnt];
|
||||
}
|
||||
else {
|
||||
outData[cnt2++] = inSysEx[cnt] | ((bits & 1) << 7);
|
||||
bits >>= 1;
|
||||
}
|
||||
|
||||
}
|
||||
return cnt2;
|
||||
}
|
||||
|
||||
#endif // MIDI_BUILD_INPUT
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue