diff --git a/src/MIDI.h b/src/MIDI.h index fb8c0b4..5575e32 100644 --- a/src/MIDI.h +++ b/src/MIDI.h @@ -130,6 +130,7 @@ public: public: static inline MidiType getTypeFromStatusByte(byte inStatus); + static inline Channel getChannelFromStatusByte(byte inStatus); static inline bool isChannelMessage(MidiType inType); private: diff --git a/src/MIDI.hpp b/src/MIDI.hpp index 3b375bf..641f706 100644 --- a/src/MIDI.hpp +++ b/src/MIDI.hpp @@ -550,9 +550,9 @@ bool MidiInterface::parse() if (mPendingMessageIndex >= (mPendingMessageExpectedLenght - 1)) { - mMessage.type = getTypeFromStatusByte(mPendingMessage[0]); - mMessage.channel = (mPendingMessage[0] & 0x0f) + 1; - mMessage.data1 = mPendingMessage[1]; + mMessage.type = getTypeFromStatusByte(mPendingMessage[0]); + mMessage.channel = getChannelFromStatusByte(mPendingMessage[0]); + mMessage.data1 = mPendingMessage[1]; // Save data2 only if applicable if (mPendingMessageExpectedLenght == 3) @@ -725,7 +725,7 @@ bool MidiInterface::parse() mMessage.type = getTypeFromStatusByte(mPendingMessage[0]); if (isChannelMessage(mMessage.type)) - mMessage.channel = (mPendingMessage[0] & 0x0f) + 1; + mMessage.channel = getChannelFromStatusByte(mPendingMessage[0]); else mMessage.channel = 0; @@ -948,6 +948,14 @@ MidiType MidiInterface::getTypeFromStatusByte(byte inStatus) return (MidiType)inStatus; } +/*! \brief Returns channel in the range 1-16 + */ +template +inline Channel MidiInterface::getChannelFromStatusByte(byte inStatus) +{ + return (inStatus & 0x0f) + 1; +} + template bool MidiInterface::isChannelMessage(MidiType inType) {