Commit e2945671 authored by Jacob Vosmaer's avatar Jacob Vosmaer

Add midi_read_2

parent 0336ab4d
......@@ -109,34 +109,33 @@ main(void)
(*update_clock[current_program])(clock - prev_clock);
prev_clock = clock;
if (!midi_read()) {
uint8_t status, data1, data2;
if (midi_read_2(&status, &data1, &data2) == MIDI_READ_NO_DATA) {
continue;
}
uint16_t data = midi_data();
if (midi_status() == MIDI_NOTE_ON) {
uint8_t note = data >> 8;
uint8_t velocity = data & 0xff;
if (status == MIDI_NOTE_ON) {
uint8_t note = data1;
uint8_t velocity = data2;
if (velocity > 0) {
(*note_on[current_program])(note);
} else {
(*note_off[current_program])(note);
}
} else if (midi_status() == MIDI_NOTE_OFF) {
uint8_t note = data >> 8;
} else if (status == MIDI_NOTE_OFF) {
uint8_t note = data1;
(*note_off[current_program])(note);
} else if (midi_status() == MIDI_PROGRAM_CHANGE) {
uint8_t pgm = data >> 8;
} else if (status == MIDI_PROGRAM_CHANGE) {
uint8_t pgm = data1;
program_change(pgm);
} else if (midi_status() == MIDI_CONTROL_CHANGE) {
uint8_t ctl = data >> 8;
uint8_t val = data & 0xff;
} else if (status == MIDI_CONTROL_CHANGE) {
uint8_t ctl = data1;
uint8_t val = data2;
(*control_change[current_program])(ctl, val);
} else if (midi_status() == MIDI_PITCH_BEND) {
uint8_t lsb = data >> 8;
uint8_t msb = data & 0xff;
} else if (status == MIDI_PITCH_BEND) {
uint8_t lsb = data1;
uint8_t msb = data2;
(*pitch_bend[current_program])((msb << 7) | lsb);
}
}
......
......@@ -141,3 +141,19 @@ midi_read(void)
midi_parse(uart_data & 0xff);
return midi_available();
}
uint8_t
midi_read_2(uint8_t *status, uint8_t *data1, uint8_t *data2)
{
if (!midi_read()) {
return MIDI_READ_NO_DATA;
}
*status = midi_status();
uint16_t data_16 = midi_data();
*data1 = data_16 >> 8;
*data2 = data_16 & 0xff;
return MIDI_READ_OK;
}
......@@ -24,4 +24,11 @@ void midi_set_channel(uint8_t channel);
uint8_t midi_status(void);
uint16_t midi_data(void);
enum {
MIDI_READ_OK,
MIDI_READ_NO_DATA,
};
uint8_t midi_read_2(uint8_t *status, uint8_t *data1, uint8_t *data2);
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment