Your checkMIDI function wont work.
To start with its a blocking function. As soon as some other MIDI event is sent that does not contain 3 bytes it will become out of sync or hang.
Then you need to take care of something called running status.
Note on/off are not always 3 bytes if the status byte is the same as the last one.