So i wrote a code handling polyphonic MIDI - nothing really complicated (it needs to be optimized for some peculiar cases like having error into the messages)
Code: Select all
void handleMidiInput()
{
if (Serial.available() > 0)
{
byte incoming_byte = Serial.read() ;
switch (MIDI_reception_state)
{
//STATUS BYTE
case 0 :
if (incoming_byte == 0x90)
{
MIDI_reception_state = 1 ;
MIDI_message_type = note_ON ;
}
if (incoming_byte == 0x80)
{
MIDI_reception_state = 1 ;
MIDI_message_type = note_OFF ;
}
break ;
//NOTE
case 1 :
note_data = incoming_byte ;
MIDI_reception_state = 2 ;
break ;
//VELOCITY
case 2 :
if ((MIDI_message_type == note_ON && incoming_byte == 0) || MIDI_message_type == note_OFF)
{
MIDI_reception_state = 0 ;
keyOff(note_data) ;
}
if (MIDI_message_type == note_ON && incoming_byte != 0)
{
MIDI_reception_state = 0 ;
keyOn(note_data) ;
}
break ;
}
}
}
a note off message (0x80)
a note on message (0x90) with velocity zero
For the first case, everything is working without any problem
For the second case, when sending notes too quickly, the code seems to ignore some messages.
Anyone solved that problem ? I saw different posts on different forums with those note on with zero velocity zero as note off messages but none gave a real solution to my problem.