...
 
Commits (2)
...@@ -7,7 +7,6 @@ UART I/O and MIDI parsing. ...@@ -7,7 +7,6 @@ UART I/O and MIDI parsing.
*/ */
#include "midi.h" #include "midi.h"
#include "notes.h"
#include <avr/io.h> #include <avr/io.h>
void void
...@@ -30,11 +29,11 @@ midi_set_channel(uint8_t channel) ...@@ -30,11 +29,11 @@ midi_set_channel(uint8_t channel)
midi_channel = channel & 0xf; midi_channel = channel & 0xf;
} }
uint8_t status = MIDI_NO_STATUS; uint8_t status = MIDI_NUM_STATUSES;
uint16_t data = 0; uint16_t data = 0;
static uint8_t parsed_len = 0; static uint8_t parsed_len = 0;
const uint8_t statuses[MIDI_NO_STATUS] = { const uint8_t statuses[MIDI_NUM_STATUSES] = {
0b1001, // note on 0b1001, // note on
0b1000, // note off 0b1000, // note off
}; };
...@@ -60,7 +59,7 @@ uint16_t midi_data(void) ...@@ -60,7 +59,7 @@ uint16_t midi_data(void)
uint8_t uint8_t
midi_available(void) midi_available(void)
{ {
return (status < MIDI_NO_STATUS) && (data_len(status) == parsed_len); return (status < MIDI_NUM_STATUSES) && (data_len(status) == parsed_len);
} }
void void
...@@ -71,19 +70,19 @@ midi_parse(uint8_t midi_byte) ...@@ -71,19 +70,19 @@ midi_parse(uint8_t midi_byte)
return; return;
} }
for (uint8_t i = 0; i < MIDI_NO_STATUS; i++) { for (uint8_t i = 0; i < MIDI_NUM_STATUSES; i++) {
if (midi_byte == ((statuses[i] << 4) | midi_channel)) { if (midi_byte == ((statuses[i] << 4) | midi_channel)) {
status = i; status = i;
return; return;
} }
} }
if (status == MIDI_NO_STATUS) { if (status == MIDI_NUM_STATUSES) {
return; return;
} }
if (midi_byte & 0x80) { if (midi_byte & 0x80) {
status = MIDI_NO_STATUS; status = MIDI_NUM_STATUSES;
data = 0; data = 0;
return; return;
} }
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
enum _statuses { enum _statuses {
MIDI_NOTE_ON, MIDI_NOTE_ON,
MIDI_NOTE_OFF, MIDI_NOTE_OFF,
MIDI_NO_STATUS, MIDI_NUM_STATUSES,
}; };
uint8_t midi_read(); uint8_t midi_read();
......