Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug when parsing midi with running status #14

Open
jcelerier opened this issue Jul 28, 2018 · 0 comments
Open

Bug when parsing midi with running status #14

jcelerier opened this issue Jul 28, 2018 · 0 comments

Comments

@jcelerier
Copy link

jcelerier commented Jul 28, 2018

Hello,
so, I'm working on a fork of this lib & rtmidi (https://github.com/jcelerier/RtMidi17), but I found a bug when parsing midi files with running status so it may be of interest for you :

here: https://github.com/ddiakopoulos/ModernMIDI/blob/master/src/midi_file_reader.cpp#L160

say that you have for instance the following midi bytes sequence:

 00 99 23 50 00 31 50 77 23 00
|-----------|--------|--------|
      1          2       3

1 is a note on, channel 10, note 35, velocity 80
2 is a note on, channel 10, note 49, velocity 80
3 is a note on, channel 10, note 35, velocity 0 which starts a bit later

now, after parsing the first note:

  • parseEvent is called with dataStart pointing on the second byte of 2 (0x31) since it's the first bit of the midi channel event
  • type = *dataStart++, hence dataStart points on the third byte of 2 (0x50) and type == 0x31
  • we enter the running status check :
if (((uint8_t) type & 0x80) == 0) 
{
  event->m->data[0] = (uint8_t) type;
  type = lastEventTypeByte;
}

after this, the data stored in the event looks like :

[31, 00, 00]

-> the type is wrong, and event->m->data[1] is never set !

Instead, it should be :

if (((uint8_t) type & 0x80) == 0)
{
  event->m->data[0] = (uint8_t) lastEventTypeByte;
  event->m->data[1] = (uint8_t) type;
  type = lastEventTypeByte;
}

after which the data looks like

[99, 31, 00]

and the switch can work correctly afterwards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant