MIDIDecoder bug fixes

This commit is contained in:
Jack Andersen 2016-06-22 11:44:37 -10:00
parent 315998381c
commit e4c625c55a
1 changed files with 121 additions and 107 deletions

View File

@ -51,101 +51,23 @@ MIDIDecoder::receiveBytes(std::vector<uint8_t>::const_iterator begin,
else else
it--; it--;
uint8_t chan = m_status & 0xf; if (m_status == 0xff)
switch (Status(m_status & 0xf0))
{
case Status::NoteOff:
{ {
/* Meta events (ignored for now) */
if (it == end) if (it == end)
return begin; return begin;
a = *it++; a = *it++;
if (it == end)
return begin; uint32_t length;
b = *it++; _readContinuedValue(it, end, length);
m_out.noteOff(chan, clamp7(a), clamp7(b)); it += length;
break;
} }
case Status::NoteOn: else
{ {
if (it == end) uint8_t chan = m_status & 0xf;
return begin; switch (Status(m_status & 0xf0))
a = *it++;
if (it == end)
return begin;
b = *it++;
m_out.noteOn(chan, clamp7(a), clamp7(b));
break;
}
case Status::NotePressure:
{
if (it == end)
return begin;
a = *it++;
if (it == end)
return begin;
b = *it++;
m_out.notePressure(chan, clamp7(a), clamp7(b));
break;
}
case Status::ControlChange:
{
if (it == end)
return begin;
a = *it++;
if (it == end)
return begin;
b = *it++;
m_out.controlChange(chan, clamp7(a), clamp7(b));
break;
}
case Status::ProgramChange:
{
if (it == end)
return begin;
a = *it++;
m_out.programChange(chan, clamp7(a));
break;
}
case Status::ChannelPressure:
{
if (it == end)
return begin;
a = *it++;
m_out.channelPressure(chan, clamp7(a));
break;
}
case Status::PitchBend:
{
if (it == end)
return begin;
a = *it++;
if (it == end)
return begin;
b = *it++;
m_out.pitchBend(chan, clamp7(b) * 128 + clamp7(a));
break;
}
case Status::SysEx:
{
switch (Status(m_status & 0xff))
{ {
case Status::SysEx: case Status::NoteOff:
{
uint32_t len;
if (!_readContinuedValue(it, end, len) || end - it < len)
return begin;
m_out.sysex(&*it, len);
break;
}
case Status::TimecodeQuarterFrame:
{
if (it == end)
return begin;
a = *it++;
m_out.timeCodeQuarterFrame(a >> 4 & 0x7, a & 0xf);
break;
}
case Status::SongPositionPointer:
{ {
if (it == end) if (it == end)
return begin; return begin;
@ -153,40 +75,132 @@ MIDIDecoder::receiveBytes(std::vector<uint8_t>::const_iterator begin,
if (it == end) if (it == end)
return begin; return begin;
b = *it++; b = *it++;
m_out.songPositionPointer(clamp7(b) * 128 + clamp7(a)); m_out.noteOff(chan, clamp7(a), clamp7(b));
break; break;
} }
case Status::SongSelect: case Status::NoteOn:
{ {
if (it == end) if (it == end)
return begin; return begin;
a = *it++; a = *it++;
m_out.songSelect(clamp7(a)); if (it == end)
return begin;
b = *it++;
m_out.noteOn(chan, clamp7(a), clamp7(b));
break; break;
} }
case Status::TuneRequest: case Status::NotePressure:
m_out.tuneRequest(); {
if (it == end)
return begin;
a = *it++;
if (it == end)
return begin;
b = *it++;
m_out.notePressure(chan, clamp7(a), clamp7(b));
break; break;
case Status::Start: }
m_out.startSeq(); case Status::ControlChange:
{
if (it == end)
return begin;
a = *it++;
if (it == end)
return begin;
b = *it++;
m_out.controlChange(chan, clamp7(a), clamp7(b));
break; break;
case Status::Continue: }
m_out.continueSeq(); case Status::ProgramChange:
{
if (it == end)
return begin;
a = *it++;
m_out.programChange(chan, clamp7(a));
break; break;
case Status::Stop: }
m_out.stopSeq(); case Status::ChannelPressure:
{
if (it == end)
return begin;
a = *it++;
m_out.channelPressure(chan, clamp7(a));
break; break;
case Status::Reset: }
m_out.reset(); case Status::PitchBend:
{
if (it == end)
return begin;
a = *it++;
if (it == end)
return begin;
b = *it++;
m_out.pitchBend(chan, clamp7(b) * 128 + clamp7(a));
break; break;
case Status::SysExTerm: }
case Status::TimingClock: case Status::SysEx:
case Status::ActiveSensing: {
switch (Status(m_status & 0xff))
{
case Status::SysEx:
{
uint32_t len;
if (!_readContinuedValue(it, end, len) || end - it < len)
return begin;
m_out.sysex(&*it, len);
break;
}
case Status::TimecodeQuarterFrame:
{
if (it == end)
return begin;
a = *it++;
m_out.timeCodeQuarterFrame(a >> 4 & 0x7, a & 0xf);
break;
}
case Status::SongPositionPointer:
{
if (it == end)
return begin;
a = *it++;
if (it == end)
return begin;
b = *it++;
m_out.songPositionPointer(clamp7(b) * 128 + clamp7(a));
break;
}
case Status::SongSelect:
{
if (it == end)
return begin;
a = *it++;
m_out.songSelect(clamp7(a));
break;
}
case Status::TuneRequest:
m_out.tuneRequest();
break;
case Status::Start:
m_out.startSeq();
break;
case Status::Continue:
m_out.continueSeq();
break;
case Status::Stop:
m_out.stopSeq();
break;
case Status::Reset:
m_out.reset();
break;
case Status::SysExTerm:
case Status::TimingClock:
case Status::ActiveSensing:
default: break;
}
break;
}
default: break; default: break;
} }
break;
}
default: break;
} }
return it; return it;