Added Midi namespace
This commit is contained in:
parent
335cad374d
commit
04753598cb
|
|
@ -12,6 +12,10 @@
|
||||||
|
|
||||||
BEGIN_BLEMIDI_NAMESPACE
|
BEGIN_BLEMIDI_NAMESPACE
|
||||||
|
|
||||||
|
using namespace MIDI_NAMESPACE;
|
||||||
|
|
||||||
|
#define MIDI_TYPE 0x80
|
||||||
|
|
||||||
template <class T, class _Settings = DefaultSettings>
|
template <class T, class _Settings = DefaultSettings>
|
||||||
class BLEMIDI_Transport
|
class BLEMIDI_Transport
|
||||||
{
|
{
|
||||||
|
|
@ -75,7 +79,7 @@ public:
|
||||||
|
|
||||||
void endTransmission()
|
void endTransmission()
|
||||||
{
|
{
|
||||||
if (mTxBuffer[mTxIndex - 1] == 0xF7)
|
if (mTxBuffer[mTxIndex - 1] == SystemExclusiveEnd)
|
||||||
{
|
{
|
||||||
if (mTxIndex >= sizeof(mTxBuffer))
|
if (mTxIndex >= sizeof(mTxBuffer))
|
||||||
{
|
{
|
||||||
|
|
@ -88,7 +92,7 @@ public:
|
||||||
{
|
{
|
||||||
mTxBuffer[mTxIndex - 1] = mTimestampLow; // or generate new ?
|
mTxBuffer[mTxIndex - 1] = mTimestampLow; // or generate new ?
|
||||||
}
|
}
|
||||||
mTxBuffer[mTxIndex++] = 0xF7;
|
mTxBuffer[mTxIndex++] = SystemExclusiveEnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
mBleClass.write(mTxBuffer, mTxIndex);
|
mBleClass.write(mTxBuffer, mTxIndex);
|
||||||
|
|
@ -235,7 +239,7 @@ public:
|
||||||
// lastStatus used to capture runningStatus
|
// lastStatus used to capture runningStatus
|
||||||
byte lastStatus;
|
byte lastStatus;
|
||||||
// previousStatus used to continue a runningStatus interrupted by a timeStamp or a System Message.
|
// previousStatus used to continue a runningStatus interrupted by a timeStamp or a System Message.
|
||||||
byte previousStatus = 0x00;
|
byte previousStatus = InvalidType;
|
||||||
|
|
||||||
byte headerByte = buffer[lPtr++];
|
byte headerByte = buffer[lPtr++];
|
||||||
|
|
||||||
|
|
@ -247,10 +251,10 @@ public:
|
||||||
bool sysExContinuation = false;
|
bool sysExContinuation = false;
|
||||||
bool runningStatusContinuation = false;
|
bool runningStatusContinuation = false;
|
||||||
|
|
||||||
if (timestampByte >= 80) // if bit 7 is 1, it's a timestampByte
|
if (timestampByte >= MIDI_TYPE) // if bit 7 is 1, it's a timestampByte
|
||||||
{
|
{
|
||||||
auto timestampLow = 0x7f & timestampByte;
|
timestamp = setMidiTimestamp(headerByte, timestampByte);
|
||||||
timestamp = timestampLow + (timestampHigh << 7);
|
// what do to with the timestamp?
|
||||||
}
|
}
|
||||||
else // if bit 7 is 0, it's the Continuation of a previous SysEx
|
else // if bit 7 is 0, it's the Continuation of a previous SysEx
|
||||||
{
|
{
|
||||||
|
|
@ -263,12 +267,12 @@ public:
|
||||||
{
|
{
|
||||||
lastStatus = buffer[lPtr];
|
lastStatus = buffer[lPtr];
|
||||||
|
|
||||||
if (previousStatus == 0x00)
|
if (previousStatus == InvalidType)
|
||||||
{
|
{
|
||||||
if ((lastStatus < 0x80) && !sysExContinuation)
|
if ((lastStatus < MIDI_TYPE) && !sysExContinuation)
|
||||||
return; // Status message not present and it is not a runningStatus continuation, bail
|
return; // Status message not present and it is not a runningStatus continuation, bail
|
||||||
}
|
}
|
||||||
else if (lastStatus < 0x80)
|
else if (lastStatus < MIDI_TYPE)
|
||||||
{
|
{
|
||||||
lastStatus = previousStatus;
|
lastStatus = previousStatus;
|
||||||
runningStatusContinuation = true;
|
runningStatusContinuation = true;
|
||||||
|
|
@ -276,7 +280,7 @@ public:
|
||||||
|
|
||||||
// Point to next non-data byte
|
// Point to next non-data byte
|
||||||
rPtr = lPtr;
|
rPtr = lPtr;
|
||||||
while ((buffer[rPtr + 1] < 0x80) && (rPtr < (length - 1)))
|
while ((buffer[rPtr + 1] < MIDI_TYPE) && (rPtr < (length - 1)))
|
||||||
rPtr++;
|
rPtr++;
|
||||||
|
|
||||||
if (!runningStatusContinuation)
|
if (!runningStatusContinuation)
|
||||||
|
|
@ -285,15 +289,15 @@ public:
|
||||||
|
|
||||||
auto midiType = lastStatus & 0xF0;
|
auto midiType = lastStatus & 0xF0;
|
||||||
if (sysExContinuation)
|
if (sysExContinuation)
|
||||||
midiType = 0xF0;
|
midiType = SystemExclusive;
|
||||||
|
|
||||||
switch (midiType)
|
switch (midiType)
|
||||||
{
|
{
|
||||||
case 0x80:
|
case NoteOff:
|
||||||
case 0x90:
|
case NoteOn:
|
||||||
case 0xA0:
|
case AfterTouchPoly:
|
||||||
case 0xB0:
|
case ControlChange:
|
||||||
case 0xE0:
|
case PitchBend:
|
||||||
#ifdef RUNNING_ENABLE
|
#ifdef RUNNING_ENABLE
|
||||||
mBleClass.add(lastStatus);
|
mBleClass.add(lastStatus);
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -306,8 +310,8 @@ public:
|
||||||
mBleClass.add(buffer[i + 2]);
|
mBleClass.add(buffer[i + 2]);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 0xC0:
|
case ProgramChange:
|
||||||
case 0xD0:
|
case AfterTouchChannel:
|
||||||
#ifdef RUNNING_ENABLE
|
#ifdef RUNNING_ENABLE
|
||||||
mBleClass.add(lastStatus);
|
mBleClass.add(lastStatus);
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -319,7 +323,7 @@ public:
|
||||||
mBleClass.add(buffer[i + 1]);
|
mBleClass.add(buffer[i + 1]);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 0xF0:
|
case SystemExclusive:
|
||||||
mBleClass.add(lastStatus);
|
mBleClass.add(lastStatus);
|
||||||
for (auto i = lPtr; i < rPtr; i++)
|
for (auto i = lPtr; i < rPtr; i++)
|
||||||
mBleClass.add(buffer[i + 1]);
|
mBleClass.add(buffer[i + 1]);
|
||||||
|
|
@ -335,15 +339,15 @@ public:
|
||||||
#ifndef RUNNING_ENABLE
|
#ifndef RUNNING_ENABLE
|
||||||
auto midiType = lastStatus & 0xF0;
|
auto midiType = lastStatus & 0xF0;
|
||||||
if (sysExContinuation)
|
if (sysExContinuation)
|
||||||
midiType = 0xF0;
|
midiType = SystemExclusive;
|
||||||
|
|
||||||
switch (midiType)
|
switch (midiType)
|
||||||
{
|
{
|
||||||
case 0x80:
|
case NoteOff:
|
||||||
case 0x90:
|
case NoteOn:
|
||||||
case 0xA0:
|
case AfterTouchPoly:
|
||||||
case 0xB0:
|
case ControlChange:
|
||||||
case 0xE0:
|
case PitchBend:
|
||||||
//3 bytes full Midi -> 2 bytes runningStatus
|
//3 bytes full Midi -> 2 bytes runningStatus
|
||||||
for (auto i = lPtr; i <= rPtr; i = i + 2)
|
for (auto i = lPtr; i <= rPtr; i = i + 2)
|
||||||
{
|
{
|
||||||
|
|
@ -352,8 +356,8 @@ public:
|
||||||
mBleClass.add(buffer[i + 1]);
|
mBleClass.add(buffer[i + 1]);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 0xC0:
|
case ProgramChange:
|
||||||
case 0xD0:
|
case AfterTouchChannel:
|
||||||
//2 bytes full Midi -> 1 byte runningStatus
|
//2 bytes full Midi -> 1 byte runningStatus
|
||||||
for (auto i = lPtr; i <= rPtr; i = i + 1)
|
for (auto i = lPtr; i <= rPtr; i = i + 1)
|
||||||
{
|
{
|
||||||
|
|
@ -376,16 +380,16 @@ public:
|
||||||
if (++rPtr >= length)
|
if (++rPtr >= length)
|
||||||
return; // end of packet
|
return; // end of packet
|
||||||
|
|
||||||
if (lastStatus < 0xf0) //exclude System Message. They must not be RunningStatus
|
if (lastStatus < SystemExclusive) //exclude System Message. They must not be RunningStatus
|
||||||
{
|
{
|
||||||
previousStatus = lastStatus;
|
previousStatus = lastStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
timestampByte = buffer[rPtr++];
|
timestampByte = buffer[rPtr++];
|
||||||
if (timestampByte >= 80) // is bit 7 set?
|
if (timestampByte >= MIDI_TYPE) // is bit 7 set?
|
||||||
{
|
{
|
||||||
auto timestampLow = 0x7f & timestampByte;
|
timestamp = setMidiTimestamp(headerByte, timestampByte);
|
||||||
timestamp = timestampLow + (timestampHigh << 7);
|
// what do to with the timestamp?
|
||||||
}
|
}
|
||||||
|
|
||||||
// Point to next status
|
// Point to next status
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue