diff --git a/src/MIDI.cpp b/src/MIDI.cpp index 24bb14c..590f8d3 100644 --- a/src/MIDI.cpp +++ b/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 diff --git a/src/MIDI.h b/src/MIDI.h index b672808..421447a 100644 --- a/src/MIDI.h +++ b/src/MIDI.h @@ -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 // ----------------------------------------------------------------------------- diff --git a/src/midi_Inline.hpp b/src/midi_Inline.hpp index d8d919d..2838091 100644 --- a/src/midi_Inline.hpp +++ b/src/midi_Inline.hpp @@ -164,42 +164,6 @@ void MidiInterface::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 -byte MidiInterface::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::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 -byte MidiInterface::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