...
 
Commits (2)
......@@ -16,20 +16,8 @@ enum midi_states {
MIDI_VELOCITY,
};
// MIDI note <-> 808 instrument mapping
#define BD_MIDI_NOTE 36 //C2
#define SD_MIDI_NOTE 38 //D2
#define LT_MIDI_NOTE 41 //F2
#define MT_MIDI_NOTE 43 //G2
#define HT_MIDI_NOTE 47 //B2
#define RM_MIDI_NOTE 37 //C#2
#define HC_MIDI_NOTE 39 //D#2
#define CW_MIDI_NOTE 56 //G#3
#define CY_MIDI_NOTE 49 //C#3
#define OH_MIDI_NOTE 46 //A#2
#define CH_MIDI_NOTE 42 //F#2
#define T1_MIDI_NOTE 60
#define T2_MIDI_NOTE 62
// sparse array populated by midi_init()
uint8_t midi_note_map[127] = {NUM_NOTES};
void
set_note_event(uint8_t note, uint8_t velocity)
......@@ -46,46 +34,9 @@ handle_note_on(uint8_t pitch, uint8_t velocity)
PORTC |= MIDI_ACTIVITY;
pulse_act = PULSE;
switch (pitch) {
case BD_MIDI_NOTE:
set_note_event(NOTE_BD, velocity);
break;
case SD_MIDI_NOTE:
set_note_event(NOTE_SD, velocity);
break;
case LT_MIDI_NOTE:
set_note_event(NOTE_LT, velocity);
break;
case MT_MIDI_NOTE:
set_note_event(NOTE_MT, velocity);
break;
case HT_MIDI_NOTE:
set_note_event(NOTE_HT, velocity);
break;
case RM_MIDI_NOTE:
set_note_event(NOTE_RM, velocity);
break;
case HC_MIDI_NOTE:
set_note_event(NOTE_HC, velocity);
break;
case CW_MIDI_NOTE:
set_note_event(NOTE_CW, velocity);
break;
case CY_MIDI_NOTE:
set_note_event(NOTE_CY, velocity);
break;
case OH_MIDI_NOTE:
set_note_event(NOTE_OH, velocity);
break;
case CH_MIDI_NOTE:
set_note_event(NOTE_CH, velocity);
break;
case T1_MIDI_NOTE:
set_note_event(NOTE_T1, velocity);
break;
case T2_MIDI_NOTE:
set_note_event(NOTE_T2, velocity);
break;
uint8_t note_event = midi_note_map[pitch];
if (note_event < NUM_NOTES) {
set_note_event(note_event, velocity);
}
}
......@@ -96,6 +47,20 @@ midi_init()
UBRR1L = 31;
UCSR1B = _BV(RXEN1);
midi_note_map[36] = NOTE_BD; //C2
midi_note_map[38] = NOTE_SD; //D2
midi_note_map[41] = NOTE_LT; //F2
midi_note_map[43] = NOTE_MT; //G2
midi_note_map[47] = NOTE_HT; //B2
midi_note_map[37] = NOTE_RM; //C#2
midi_note_map[39] = NOTE_HC; //D#2
midi_note_map[56] = NOTE_CW; //G#3
midi_note_map[49] = NOTE_CY; //C#3
midi_note_map[46] = NOTE_OH; //A#2
midi_note_map[42] = NOTE_CH; //F#2
midi_note_map[60] = NOTE_T1;
midi_note_map[62] = NOTE_T2;
}
static uint8_t midi_note_on_byte;
......
......@@ -178,12 +178,10 @@ main (void)
uint8_t midi_channel = 0;
for (uint8_t i = 0; 1; i++) {
if (i == 0) {
midi_channel = read_midi_channel();
midi_set_channel(midi_channel);
display_midi_channel(midi_channel);
}
for (;;) {
midi_channel = read_midi_channel();
midi_set_channel(midi_channel);
display_midi_channel(midi_channel);
midi_read();
parse_note_event();
......
......@@ -30,11 +30,10 @@ enum notes {
NOTE_OH,
NOTE_CH,
NOTE_T1,
NOTE_T2
NOTE_T2,
NUM_NOTES
};
#define NUM_NOTES 14
void midi_read();
void midi_init();
void midi_set_channel(uint8_t channel);
......