...
 
Commits (2)
......@@ -80,10 +80,11 @@ main(void)
if (!midi_read()) {
continue;
}
uint16_t data = midi_data();
if (midi_status() == MIDI_NOTE_ON) {
uint8_t note = midi_data() >> 8;
uint8_t velocity = midi_data() & 0xff;
uint8_t note = data >> 8;
uint8_t velocity = data & 0xff;
if (velocity > 0) {
(*note_on[current_program])(note);
......@@ -91,14 +92,14 @@ main(void)
(*note_off[current_program])(note);
}
} else if (midi_status() == MIDI_NOTE_OFF) {
uint8_t note = midi_data() >> 8;
uint8_t note = data >> 8;
(*note_off[current_program])(note);
} else if (midi_status() == MIDI_PROGRAM_CHANGE) {
uint8_t pgm = midi_data() >> 8;
uint8_t pgm = data >> 8;
program_change(pgm);
} else if (midi_status() == MIDI_CONTROL_CHANGE) {
uint8_t ctl = midi_data() >> 8;
uint8_t val = midi_data() & 0xff;
uint8_t ctl = data >> 8;
uint8_t val = data & 0xff;
(*control_change[current_program])(ctl, val);
}
}
......
......@@ -34,7 +34,7 @@ test_note_on(void)
// real time garbage
midi_parse(0xf8);
assert_status(MIDI_NOTE_ON, 1, 0x1070);
assert_status(MIDI_NOTE_ON, 0, 0);
midi_parse(0x11);
midi_parse(0xf8);
midi_parse(0x25);
......
......@@ -38,6 +38,13 @@ data_len(uint8_t st)
return 2;
}
void
clear_data()
{
parsed_len = 0;
data = 0;
}
uint8_t
midi_status(void)
{
......@@ -46,7 +53,9 @@ midi_status(void)
uint16_t midi_data(void)
{
return data;
uint16_t result = data;
clear_data();
return result;
}
uint8_t
......@@ -55,13 +64,6 @@ midi_available(void)
return (status < MIDI_NUM_STATUSES) && (data_len(status) == parsed_len);
}
void
clear_data()
{
parsed_len = 0;
data = 0;
}
void
reset_status()
{
......
......@@ -16,10 +16,10 @@ static struct list notes = {
void set_pitch(uint8_t n);
const uint8_t detune_factor[NUM_VOICES] = {
1,
-1,
2,
-2,
10,
-10,
9,
-9,
};
static uint8_t detune_amount;
......