diff options
author | Christian Pointner <equinox@spreadspace.org> | 2015-10-12 02:20:36 +0200 |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2015-10-12 02:20:36 +0200 |
commit | eafed8b32fecb70a279969bbcabe319c691281b8 (patch) | |
tree | c3fd66acad196a2d27f7c2f1d79d79f312eb2cde | |
parent | reading of seperate midi messages works now (diff) |
triggering language switch using midi works
-rw-r--r-- | apps/dolmetschctl.c | 7 | ||||
-rw-r--r-- | apps/midi.c | 38 |
2 files changed, 33 insertions, 12 deletions
diff --git a/apps/dolmetschctl.c b/apps/dolmetschctl.c index 1cbd770..b998042 100644 --- a/apps/dolmetschctl.c +++ b/apps/dolmetschctl.c @@ -72,13 +72,6 @@ int main_loop(mixer_t* x, midi_t* m, osc_t* o) return -1; } - mixer_print_langs(x); - - mixer_switch_lang(x, "en", &print_string, "hello world!"); - mixer_switch_lang(x, "de", &print_string, "hallo welt!"); - - mixer_print_tasks(x); - printf("main_loop running with %d pollfds...\n", npfds); for (;;) { mixer_get_poll_fds(x, &(pfds[mixer_npfds_offset]), mixer_npfds); diff --git a/apps/midi.c b/apps/midi.c index 1a9bc94..6e14bc8 100644 --- a/apps/midi.c +++ b/apps/midi.c @@ -56,16 +56,44 @@ int midi_get_poll_fds(midi_t* m, struct pollfd *pfds, int npfds) return snd_rawmidi_poll_descriptors(m->input_, pfds, npfds); } -static int midi_handle_message(midi_t* m, mixer_t* x) +void midi_switch_lang_done(void* data) { - int i; - printf("MIDI: "); - for (i = 0; i < sizeof(m->buf_); ++i) - printf("%02X%c", m->buf_[i], (i >= (sizeof(m->buf_)-1)) ? '\n' : ' '); + printf("language switching is done: %s\n", (char*)data); +} +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; + default: printf("ignoring unknown note\n"); break; + } + return ret; +} + +static int midi_handle_note_off(midi_t* m, mixer_t* x) +{ return 0; } +static int midi_handle_message(midi_t* m, mixer_t* x) +{ + /* int i; */ + /* printf("MIDI: "); */ + /* for (i = 0; i < sizeof(m->buf_); ++i) */ + /* printf("%02X%c", m->buf_[i], (i >= (sizeof(m->buf_)-1)) ? '\n' : ' '); */ + + int ret = 0; + switch(m->buf_[0]) { + case 0x90: ret = midi_handle_note_on(m, x); break; + case 0x80: ret = midi_handle_note_off(m, x); break; + default: printf("ignoring unknown midi command\n"); break; + } + + return ret; +} + int midi_handle_revents(midi_t* m, struct pollfd *pfds, int npfds, mixer_t* x) { int err; |