Helper method.

This commit is contained in:
Francois Best 2014-04-01 09:04:31 +02:00
parent 240cd22021
commit b041abaca3
2 changed files with 13 additions and 4 deletions

View File

@ -130,6 +130,7 @@ public:
public: public:
static inline MidiType getTypeFromStatusByte(byte inStatus); static inline MidiType getTypeFromStatusByte(byte inStatus);
static inline Channel getChannelFromStatusByte(byte inStatus);
static inline bool isChannelMessage(MidiType inType); static inline bool isChannelMessage(MidiType inType);
private: private:

View File

@ -550,9 +550,9 @@ bool MidiInterface<SerialPort>::parse()
if (mPendingMessageIndex >= (mPendingMessageExpectedLenght - 1)) if (mPendingMessageIndex >= (mPendingMessageExpectedLenght - 1))
{ {
mMessage.type = getTypeFromStatusByte(mPendingMessage[0]); mMessage.type = getTypeFromStatusByte(mPendingMessage[0]);
mMessage.channel = (mPendingMessage[0] & 0x0f) + 1; mMessage.channel = getChannelFromStatusByte(mPendingMessage[0]);
mMessage.data1 = mPendingMessage[1]; mMessage.data1 = mPendingMessage[1];
// Save data2 only if applicable // Save data2 only if applicable
if (mPendingMessageExpectedLenght == 3) if (mPendingMessageExpectedLenght == 3)
@ -725,7 +725,7 @@ bool MidiInterface<SerialPort>::parse()
mMessage.type = getTypeFromStatusByte(mPendingMessage[0]); mMessage.type = getTypeFromStatusByte(mPendingMessage[0]);
if (isChannelMessage(mMessage.type)) if (isChannelMessage(mMessage.type))
mMessage.channel = (mPendingMessage[0] & 0x0f) + 1; mMessage.channel = getChannelFromStatusByte(mPendingMessage[0]);
else else
mMessage.channel = 0; mMessage.channel = 0;
@ -948,6 +948,14 @@ MidiType MidiInterface<SerialPort>::getTypeFromStatusByte(byte inStatus)
return (MidiType)inStatus; return (MidiType)inStatus;
} }
/*! \brief Returns channel in the range 1-16
*/
template<class SerialPort>
inline Channel MidiInterface<SerialPort>::getChannelFromStatusByte(byte inStatus)
{
return (inStatus & 0x0f) + 1;
}
template<class SerialPort> template<class SerialPort>
bool MidiInterface<SerialPort>::isChannelMessage(MidiType inType) bool MidiInterface<SerialPort>::isChannelMessage(MidiType inType)
{ {