diff options
Diffstat (limited to 'apps/midi.c')
-rw-r--r-- | apps/midi.c | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/apps/midi.c b/apps/midi.c index 6e14bc8..861c95e 100644 --- a/apps/midi.c +++ b/apps/midi.c @@ -29,6 +29,14 @@ #include "midi.h" +#define NOTE_EN 0x00 +#define NOTE_DE 0x01 + +#define EN_IDX 0 +u_int8_t done_data_en[] = { 0xB0, NOTE_EN, 0x01, 0xB0, NOTE_DE, 0x00 }; + +#define DE_IDX 1 +u_int8_t done_data_de[] = { 0xB0, NOTE_EN, 0x00, 0xB0, NOTE_DE, 0x01 }; int midi_init(midi_t* m, const char* device) { @@ -37,6 +45,15 @@ int midi_init(midi_t* m, const char* device) m->input_ = NULL; memset(m->buf_, 0, sizeof(m->buf_)); m->read_idx_ = 0; + + m->done_data_[EN_IDX].self_ = m; + m->done_data_[EN_IDX].buf_ = done_data_en; + m->done_data_[EN_IDX].len_ = sizeof(done_data_en); + + m->done_data_[DE_IDX].self_ = m; + m->done_data_[DE_IDX].buf_ = done_data_de; + m->done_data_[DE_IDX].len_ = sizeof(done_data_de); + int ret = snd_rawmidi_open(&(m->input_), NULL, device, SND_RAWMIDI_NONBLOCK); if(ret < 0) { error(0, 0, "MIDI: cannot open port '%s': %s", device, snd_strerror(ret)); @@ -58,15 +75,24 @@ int midi_get_poll_fds(midi_t* m, struct pollfd *pfds, int npfds) void midi_switch_lang_done(void* data) { - printf("language switching is done: %s\n", (char*)data); + assert(data); + midi_done_data_t* d = data; + assert(d->self_); + + int i; + printf("MIDI done: "); + for(i = 0; i < d->len_; ++i) { + printf("0x%02X%s", d->buf_[i], (i && !((i+1) % 3)) ? ", " : " "); + } + printf("\n"); } static int midi_handle_note_on(midi_t* m, mixer_t* x) { int ret = 0; switch(m->buf_[1]) { - case 0x00: ret = mixer_switch_lang(x, "en", &midi_switch_lang_done, " -> EN"); break; - case 0x01: ret = mixer_switch_lang(x, "de", &midi_switch_lang_done, " -> DE"); break; + case NOTE_EN: ret = mixer_switch_lang(x, "en", &midi_switch_lang_done, &(m->done_data_[EN_IDX])); break; + case NOTE_DE: ret = mixer_switch_lang(x, "de", &midi_switch_lang_done, &(m->done_data_[DE_IDX])); break; default: printf("ignoring unknown note\n"); break; } return ret; |