Commit a7352f4e authored by Jacob Vosmaer's avatar Jacob Vosmaer

Parse control change messages

parent 037d171f
......@@ -25,6 +25,11 @@ void (*note_off[NUM_PGM])(uint8_t n) = {
mono_note_off,
};
void (*control_change[NUM_PGM])(uint8_t ctl, uint8_t val) = {
poly_control_change,
mono_control_change,
};
void
io_init(void)
{
......@@ -90,6 +95,8 @@ main(void)
(*note_off[current_program])(note);
} else if (midi_status() == MIDI_PROGRAM_CHANGE) {
program_change(midi_data() >> 8);
} else if (midi_status() == MIDI_CONTROL_CHANGE) {
(*control_change[current_program])(midi_data() >> 8, midi_data() && 0xff);
}
}
......
......@@ -115,6 +115,19 @@ test_program_change(void)
assert_status(MIDI_PROGRAM_CHANGE, 1, 0x3400);
}
void
test_control_change(void)
{
desc("test control change messages");
status_init();
assert_status(MIDI_NUM_STATUSES, 0, 0);
midi_parse(0xb0);
midi_parse(0x34);
midi_parse(0x45);
assert_status(MIDI_CONTROL_CHANGE, 1, 0x3445);
}
int
main(int argc, char** argv)
{
......@@ -122,5 +135,7 @@ main(int argc, char** argv)
test_note_on();
test_note_off();
test_program_change();
}
test_control_change();
return 0;
}
......@@ -25,6 +25,7 @@ const uint8_t statuses[MIDI_NUM_STATUSES] = {
0b1001, // note on
0b1000, // note off
0b1100, // program change
0b1011, // control change
};
uint8_t
......
......@@ -7,6 +7,7 @@ enum _statuses {
MIDI_NOTE_ON,
MIDI_NOTE_OFF,
MIDI_PROGRAM_CHANGE,
MIDI_CONTROL_CHANGE,
MIDI_NUM_STATUSES,
};
......
......@@ -60,3 +60,9 @@ mono_note_off(uint8_t n)
set_pitch(l_first(&notes));
}
void
mono_control_change(uint8_t ctl, uint8_t val)
{
// do nothing
}
......@@ -6,5 +6,6 @@
void mono_init(void);
void mono_note_on(uint8_t note);
void mono_note_off(uint8_t note);
void mono_control_change(uint8_t ctl, uint8_t val);
#endif
......@@ -35,3 +35,9 @@ poly_note_off(uint8_t note)
}
}
}
void
poly_control_change(uint8_t ctl, uint8_t val)
{
// do nothing
}
......@@ -6,5 +6,6 @@
void poly_init(void);
void poly_note_on(uint8_t note);
void poly_note_off(uint8_t note);
void poly_control_change(uint8_t ctl, uint8_t val);
#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