Commit 037d171f authored by Jacob Vosmaer's avatar Jacob Vosmaer

Use function pointer arrays

parent 2fb6742b
......@@ -15,6 +15,16 @@ enum _programs {
};
uint8_t current_program;
void (*note_on[NUM_PGM])(uint8_t n) = {
poly_note_on,
mono_note_on,
};
void (*note_off[NUM_PGM])(uint8_t n) = {
poly_note_off,
mono_note_off,
};
void
io_init(void)
{
......@@ -51,40 +61,6 @@ program_change(uint8_t pgm)
}
}
void
note_on(uint8_t note)
{
if (note > 127) {
return;
}
switch (current_program) {
case PGM_POLY:
poly_note_on(note);
return;
case PGM_MONO:
mono_note_on(note);
return;
}
}
void
note_off(uint8_t note)
{
if (note > 127) {
return;
}
switch (current_program) {
case PGM_POLY:
poly_note_off(note);
return;
case PGM_MONO:
mono_note_off(note);
return;
}
}
int
main(void)
{
......@@ -105,13 +81,13 @@ main(void)
uint8_t velocity = midi_data() & 0xff;
if (velocity > 0) {
note_on(note);
(*note_on[current_program])(note);
} else {
note_off(note);
(*note_off[current_program])(note);
}
} else if (midi_status() == MIDI_NOTE_OFF) {
uint8_t note = midi_data() >> 8;
note_off(note);
(*note_off[current_program])(note);
} else if (midi_status() == MIDI_PROGRAM_CHANGE) {
program_change(midi_data() >> 8);
}
......
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