Commit 44c7c8a1 authored by Jacob Vosmaer's avatar Jacob Vosmaer

Shrink main

parent 7c73ffe5
......@@ -17,6 +17,12 @@ enum _programs {
};
static uint8_t current_program = NUM_PGM;
void (*pgm_init[NUM_PGM])(void) = {
poly_init,
poly2_init,
mono_init,
};
void (*note_on[NUM_PGM])(uint8_t n) = {
poly_note_on,
poly2_note_on,
......@@ -80,17 +86,7 @@ program_change(uint8_t pgm)
gate_off(v);
}
switch (pgm) {
case PGM_POLY:
poly_init();
return;
case PGM_POLY2:
poly2_init();
return;
case PGM_MONO:
mono_init();
return;
}
(*pgm_init[current_program])();
}
int
......@@ -114,32 +110,28 @@ main(void)
continue;
}
if (status == MIDI_NOTE_ON) {
uint8_t note = data1;
uint8_t velocity = data2;
if (velocity > 0) {
(*note_on[current_program])(note);
switch (status) {
case MIDI_NOTE_ON:
if (data2 > 0) {
(*note_on[current_program])(data1);
} else {
(*note_off[current_program])(note);
(*note_off[current_program])(data1);
}
} else if (status == MIDI_NOTE_OFF) {
uint8_t note = data1;
(*note_off[current_program])(note);
} else if (status == MIDI_PROGRAM_CHANGE) {
uint8_t pgm = data1;
program_change(pgm);
} else if (status == MIDI_CONTROL_CHANGE) {
uint8_t ctl = data1;
uint8_t val = data2;
(*control_change[current_program])(ctl, val);
} else if (status == MIDI_PITCH_BEND) {
uint8_t lsb = data1;
uint8_t msb = data2;
(*pitch_bend[current_program])((msb << 7) | lsb);
break;
case MIDI_NOTE_OFF:
(*note_off[current_program])(data1);
break;
case MIDI_PROGRAM_CHANGE:
program_change(data1);
break;
case MIDI_CONTROL_CHANGE:
(*control_change[current_program])(data1, data2);
break;
case MIDI_PITCH_BEND:
(*pitch_bend[current_program])((data2 << 7) | data1);
break;
}
}
return 0;
}
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