further cleanup

This commit is contained in:
lathoub 2021-08-02 22:05:04 +02:00
parent a76ebc82c6
commit 802f7a3c9c
1 changed files with 17 additions and 16 deletions

View File

@ -171,7 +171,7 @@ protected:
static uint16_t setMidiTimestamp(uint8_t header, uint8_t timestamp) static uint16_t setMidiTimestamp(uint8_t header, uint8_t timestamp)
{ {
auto timestampHigh = 0x3f & header; auto timestampHigh = 0x3f & header;
auto timestampLow = 0x7f & timestamp; auto timestampLow = 0x7f & timestamp;
return (timestampLow + (timestampHigh << 7)); return (timestampLow + (timestampHigh << 7));
} }
@ -230,23 +230,23 @@ public:
// lastStatus used to capture runningStatus // lastStatus used to capture runningStatus
byte lastStatus; byte lastStatus;
byte headerByte = buffer[lPtr++]; lPtr++;
auto signatureIs1 = CHECK_BIT(headerByte, 7 - 1); byte headerByte = buffer[lPtr];
auto reservedIs0 = !CHECK_BIT(headerByte, 6 - 1); auto signatureIs1 = CHECK_BIT(headerByte, 7 - 1); // must be 1
auto reservedIs0 = !CHECK_BIT(headerByte, 6 - 1); // must be 0
auto timestampHigh = 0x3f & headerByte; auto timestampHigh = 0x3f & headerByte;
byte timestampByte = buffer[lPtr++]; lPtr++;
signatureIs1 = CHECK_BIT(timestampByte, 7 - 1); byte timestampByte = buffer[lPtr];
uint16_t timestamp = 0; uint16_t timestamp = 0;
bool sysExContinuation = false; bool sysExContinuation = false;
if (signatureIs1) if (CHECK_BIT(timestampByte, 7 - 1)) // if bit 7 is 1, it's a timestampByte
{ {
timestamp = setMidiTimestamp(headerByte, timestampByte); timestamp = setMidiTimestamp(headerByte, timestampByte);
} }
else else // if bit 7 is 0, it's the Continuation of a previous SysEx
{ {
sysExContinuation = true; sysExContinuation = true;
lPtr--; lPtr--;
@ -298,7 +298,7 @@ public:
case MIDI_NAMESPACE::MidiType::AfterTouchPoly: case MIDI_NAMESPACE::MidiType::AfterTouchPoly:
case MIDI_NAMESPACE::MidiType::ControlChange: case MIDI_NAMESPACE::MidiType::ControlChange:
case MIDI_NAMESPACE::MidiType::PitchBend: case MIDI_NAMESPACE::MidiType::PitchBend:
for (auto i = lPtr; i < rPtr; i = i + 2) for (byte i = lPtr; i < rPtr; i = i + 2)
{ {
mBleClass.add(lastStatus); mBleClass.add(lastStatus);
mBleClass.add(buffer[i + 1]); mBleClass.add(buffer[i + 1]);
@ -307,7 +307,7 @@ public:
break; break;
case MIDI_NAMESPACE::MidiType::ProgramChange: case MIDI_NAMESPACE::MidiType::ProgramChange:
case MIDI_NAMESPACE::MidiType::AfterTouchChannel: case MIDI_NAMESPACE::MidiType::AfterTouchChannel:
for (auto i = lPtr; i < rPtr; i = i + 1) for (byte i = lPtr; i < rPtr; i = i + 1)
{ {
mBleClass.add(lastStatus); mBleClass.add(lastStatus);
mBleClass.add(buffer[i + 1]); mBleClass.add(buffer[i + 1]);
@ -315,16 +315,16 @@ public:
break; break;
case MIDI_NAMESPACE::MidiType::SystemExclusive: case MIDI_NAMESPACE::MidiType::SystemExclusive:
mBleClass.add(buffer[lPtr]); mBleClass.add(buffer[lPtr]);
for (auto i = lPtr; i < rPtr; i++) for (byte i = lPtr; i < rPtr; i++)
mBleClass.add(buffer[i + 1]); mBleClass.add(buffer[i + 1]);
rPtr++; rPtr++;
if (rPtr >= length) if (rPtr >= length)
return; // end of packet return; // end of packet
timestampByte = buffer[rPtr++]; rPtr++;
signatureIs1 = CHECK_BIT(timestampByte, 7 - 1); timestampByte = buffer[rPtr];
if (signatureIs1) if (CHECK_BIT(timestampByte, 7 - 1))
{ {
timestamp = setMidiTimestamp(headerByte, timestampByte); timestamp = setMidiTimestamp(headerByte, timestampByte);
} }
@ -342,7 +342,8 @@ public:
if (rPtr >= length) if (rPtr >= length)
return; // end of packet return; // end of packet
timestampByte = buffer[rPtr++]; rPtr++;
timestampByte = buffer[rPtr];
signatureIs1 = CHECK_BIT(timestampByte, 7 - 1); signatureIs1 = CHECK_BIT(timestampByte, 7 - 1);
if (signatureIs1) if (signatureIs1)
{ {