Fixed stuff, using struct & methods rather than union.

This commit is contained in:
Francois Best 2016-10-13 18:30:49 +02:00
parent 3da8bb013e
commit cf7885d79b
1 changed files with 47 additions and 13 deletions

View File

@ -28,7 +28,7 @@
#pragma once #pragma once
#include "midi_Namespace.h" #include "midi_Defs.h"
BEGIN_MIDI_NAMESPACE BEGIN_MIDI_NAMESPACE
@ -69,9 +69,10 @@ struct CodeIndexNumbers
case noteOff: case noteOff:
case controlChange: case controlChange:
case pitchBend: case pitchBend:
case polyKeyPress: case polyPressure:
case systemCommon3Bytes: case systemCommon3Bytes:
case sysExEnds3Bytes: case sysExEnds3Bytes:
case sysExStart:
return 3; return 3;
case programChange: case programChange:
@ -87,7 +88,7 @@ struct CodeIndexNumbers
default: default:
break; break;
} }
return 0; return 0; // Can be any length (1, 2 or 3).
} }
}; };
@ -95,17 +96,50 @@ struct CodeIndexNumbers
struct UsbMidiEventPacket struct UsbMidiEventPacket
{ {
union public:
inline UsbMidiEventPacket()
{ {
uint32_t mRawData; memset(mData, 0, 4 * sizeof(byte));
struct }
public:
inline void setHeader(byte inCableNumber, byte inCodeIndexNumber)
{ {
byte mCableNumber:4; const byte msb = (0x0f & inCableNumber) << 4;
byte mCodeIndexNumber:4; const byte lsb = (0x0f & inCodeIndexNumber);
byte mMidi[3]; mData[0] = msb | lsb;
}; }
byte mDataArray[4]; inline void setMidiData(const byte* inData)
}; {
mData[1] = *inData++;
mData[2] = *inData++;
mData[3] = *inData;
}
inline byte getCableNumber() const
{
return mData[0] >> 4;
}
inline byte getCodeIndexNumber() const
{
return mData[0] & 0x0f;
}
inline const byte* getMidiData() const
{
return mData + 1;
}
inline byte* getMidiData()
{
return mData + 1;
}
inline UsbMidiEventPacket& operator=(const byte* inData)
{
mData[0] = *inData++;
setMidiData(inData);
return *this;
}
public:
byte mData[4];
}; };
END_MIDI_NAMESPACE END_MIDI_NAMESPACE