Commit 8f02e62d authored by Knut Aldrin's avatar Knut Aldrin
Browse files

Ignore unsupported status bytes and messages to other channels

parent c7dd7830
Loading
Loading
Loading
Loading
+65 −45
Original line number Diff line number Diff line
@@ -28,7 +28,8 @@ uint8_t midi_current_byte;
enum {
	FREE,
	NOTE_ON,
	NOTE_OFF
	NOTE_OFF,
	IGNORE
} midi_state;

void midi_init(uint8_t channel, note_t* notes_struct, midi_channel_t* channel_struct)
@@ -53,20 +54,35 @@ void midi_init(uint8_t channel, note_t* notes_struct, midi_channel_t* channel_st
}

uint8_t parse_status( char input ) {
	// Status byte?
	if( input & MIDI_STATUS_bm ) {

		// Check that they want to speak to us
		if( ( input & MIDI_CHANNEL_MASK ) == midi_channel->channel ) {
      switch ( input & MIDI_STATUS_MASK ) {
			  case MIDI_note_off_gc:
			  	midi_state = NOTE_OFF;
			  	midi_current_byte = 0;
				return 1;
			  	break;

		  	case MIDI_note_on_gc:
		  		midi_state = NOTE_ON;
		  		midi_current_byte = 0;
				return 1;
		  		break;

        default:
          // Not supported yet
          midi_state = IGNORE;
          midi_current_byte = 0;
          break;
		  }
    }

		// No status
		// Return 1 cause we intercepted a status byte
		return 1;
	}
	else {
		// Not a status byte
		return 0;
	}
}
@@ -77,6 +93,7 @@ void parse_midi(char input)
	switch (midi_state)
	{
		case FREE:
		case IGNORE:
			//check channel
			parse_status( input );
			break;
@@ -144,6 +161,9 @@ void parse_midi(char input)

			break;

		default:
			// WTF? Unknown state
			tesla_panic();
	}

}