diff options
author | Christian Pointner <equinox@spreadspace.org> | 2015-10-12 03:05:28 +0200 |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2015-10-12 03:05:28 +0200 |
commit | b5cbc933c90ce8d5e34a7bce3e7c500e41f6e243 (patch) | |
tree | c9cd570ed926b4a65de33fbea1135647b45dbfac /apps | |
parent | triggering language switch using midi works (diff) |
language specific done data
Diffstat (limited to 'apps')
-rw-r--r-- | apps/midi.c | 32 | ||||
-rw-r--r-- | apps/midi.h | 12 | ||||
-rw-r--r-- | apps/mixer.c | 12 | ||||
-rw-r--r-- | apps/mixer.h | 1 |
4 files changed, 45 insertions, 12 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; diff --git a/apps/midi.h b/apps/midi.h index 643dac8..cb3bd90 100644 --- a/apps/midi.h +++ b/apps/midi.h @@ -28,11 +28,21 @@ #include "mixer.h" +struct midi_struct; + typedef struct { + struct midi_struct* self_; + u_int8_t* buf_; + int len_; +} midi_done_data_t; + +struct midi_struct { snd_rawmidi_t* input_; u_int8_t buf_[3]; int read_idx_; -} midi_t; + midi_done_data_t done_data_[2]; +}; +typedef struct midi_struct midi_t; int midi_init(midi_t* m, const char* device); int midi_get_poll_fd_count(midi_t* m); diff --git a/apps/mixer.c b/apps/mixer.c index 78a0d29..50684ca 100644 --- a/apps/mixer.c +++ b/apps/mixer.c @@ -121,7 +121,6 @@ int mixer_init(mixer_t* x, const char* name, const char* device) x->name_ = name; x->output_ = NULL; - x->pfd_count_ = 0; slist_init(&(x->langs_), free_lang_entry); slist_init(&(x->tasks_), free_task_entry); int ret = snd_rawmidi_open(NULL, &(x->output_), device, SND_RAWMIDI_NONBLOCK); @@ -223,19 +222,18 @@ void mixer_print_tasks(mixer_t* x) int mixer_get_poll_fd_count(mixer_t* x) { - return (x->pfd_count_ = snd_rawmidi_poll_descriptors_count(x->output_)); + return snd_rawmidi_poll_descriptors_count(x->output_); } int mixer_get_poll_fds(mixer_t* x, struct pollfd *pfds, int npfds) { - if(slist_length(&(x->tasks_))) - return snd_rawmidi_poll_descriptors(x->output_, pfds, npfds); - else { + int ret = snd_rawmidi_poll_descriptors(x->output_, pfds, npfds); + if(!slist_length(&(x->tasks_))) { int i; - for(i = 0; i < x->pfd_count_; ++i) + for(i = 0; i < ret; ++i) pfds[i].fd = -1; } - return x->pfd_count_; + return ret; } int mixer_handle_revents(mixer_t* x, struct pollfd *pfds, int npfds) diff --git a/apps/mixer.h b/apps/mixer.h index ffa3104..5d9c666 100644 --- a/apps/mixer.h +++ b/apps/mixer.h @@ -46,7 +46,6 @@ typedef struct { typedef struct { const char* name_; snd_rawmidi_t* output_; - int pfd_count_; slist_t langs_; slist_t tasks_; } mixer_t; |