Verilog: MIDI receiver port fails when more than two keys are pressed at the same time
I see two potential issues.

First of all, your in input is asynchronous to your internal clock, so you must synchronize is before using it in your state machine. The specific problem involves the transition from IDLE (encoded 2'b01) to BYTE_CUR (encoded 2'b10) &mdash; this requires both state variables to change, and the asynchronous input could cause them to be evaluated differently, resulting in a transition to state 2'b00 or 2'b11, which is not what you intend.

Second, you have this three-bit counter called byteNo. (BTW, this is also adversely affected by the asynchronous input.) You seem to be assuming that every message is 6 bytes long, and that the note number is the second byte of the message. I'm not sure where you get this &mdash; it isn't in any MIDI specification that I've seen.

In general, channel messages are 3 bytes long, comprising a status byte (e.g., "note on") and two data bytes (e.g., note number and velocity). Most MIDI devices will omit the second and subsequent status bytes when sending multiple "note on" messages in rapid succession, which means that you could be looking at a stream of bytes like:

Note On | Note # | Vel. | Note # | Vel. | Note # | Vel. | ...


In other words, you need a much more sophisticated state machine that keeps track of the most recent status byte and then parses the subsequent data bytes accordingly.