diff options
author | Christian Pointner <equinox@spreadspace.org> | 2015-10-12 02:10:33 +0200 |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2015-10-12 02:10:33 +0200 |
commit | 77a5006d1b0963194d841eea71e44cba511c862f (patch) | |
tree | be0e9ba9a3013f92b3f3b6cc864021734e5824b6 /apps | |
parent | writing of task buf works now (diff) |
reading of seperate midi messages works now
Diffstat (limited to 'apps')
-rw-r--r-- | apps/dolmetschctl.c | 4 | ||||
-rw-r--r-- | apps/midi.c | 29 | ||||
-rw-r--r-- | apps/midi.h | 6 | ||||
-rw-r--r-- | apps/mixer.c | 2 | ||||
-rw-r--r-- | apps/osc.c | 2 | ||||
-rw-r--r-- | apps/osc.h | 4 |
6 files changed, 33 insertions, 14 deletions
diff --git a/apps/dolmetschctl.c b/apps/dolmetschctl.c index 6a0bed9..1cbd770 100644 --- a/apps/dolmetschctl.c +++ b/apps/dolmetschctl.c @@ -99,11 +99,11 @@ int main_loop(mixer_t* x, midi_t* m, osc_t* o) if(ret) break; - ret = midi_handle_revents(m, &(pfds[midi_npfds_offset]), midi_npfds); + ret = midi_handle_revents(m, &(pfds[midi_npfds_offset]), midi_npfds, x); if(ret) break; - ret = osc_handle_revents(o, &(pfds[osc_npfds_offset]), osc_npfds); + ret = osc_handle_revents(o, &(pfds[osc_npfds_offset]), osc_npfds, x); if(ret) break; } diff --git a/apps/midi.c b/apps/midi.c index 955796e..1a9bc94 100644 --- a/apps/midi.c +++ b/apps/midi.c @@ -35,6 +35,8 @@ int midi_init(midi_t* m, const char* device) assert(m != NULL); m->input_ = NULL; + memset(m->buf_, 0, sizeof(m->buf_)); + m->read_idx_ = 0; 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)); @@ -54,7 +56,17 @@ int midi_get_poll_fds(midi_t* m, struct pollfd *pfds, int npfds) return snd_rawmidi_poll_descriptors(m->input_, pfds, npfds); } -int midi_handle_revents(midi_t* m, struct pollfd *pfds, int npfds) +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' : ' '); + + return 0; +} + +int midi_handle_revents(midi_t* m, struct pollfd *pfds, int npfds, mixer_t* x) { int err; unsigned short revents; @@ -69,19 +81,20 @@ int midi_handle_revents(midi_t* m, struct pollfd *pfds, int npfds) if(!(revents & POLLIN)) return 0; - u_int8_t buf[256]; - int ret = snd_rawmidi_read(m->input_, buf, sizeof(buf)); + int ret = snd_rawmidi_read(m->input_, &(m->buf_[m->read_idx_]), sizeof(m->buf_) - m->read_idx_); if(ret == -EAGAIN) return 0; if(ret < 0) { error(0, 0, "MIDI: cannot read from midi port: %s", snd_strerror(ret)); return -1; } - - int i; - printf("MIDI:%s", ret ? " ": " no data?\n"); - for (i = 0; i < ret; ++i) - printf("%02X%c", buf[i], (i >= (ret-1)) ? '\n' : ' '); + m->read_idx_ += ret; + if(m->read_idx_ >= sizeof(m->buf_)) { + ret = midi_handle_message(m, x); + memset(m->buf_, 0, sizeof(m->buf_)); + m->read_idx_ = 0; + return ret; + } return 0; } diff --git a/apps/midi.h b/apps/midi.h index 38b1a7c..643dac8 100644 --- a/apps/midi.h +++ b/apps/midi.h @@ -26,13 +26,17 @@ #include <alsa/asoundlib.h> #include <poll.h> +#include "mixer.h" + typedef struct { snd_rawmidi_t* input_; + u_int8_t buf_[3]; + int read_idx_; } midi_t; int midi_init(midi_t* m, const char* device); int midi_get_poll_fd_count(midi_t* m); int midi_get_poll_fds(midi_t* m, struct pollfd *pfds, int npfds); -int midi_handle_revents(midi_t* m, struct pollfd *pfds, int npfds); +int midi_handle_revents(midi_t* m, struct pollfd *pfds, int npfds, mixer_t* x); #endif diff --git a/apps/mixer.c b/apps/mixer.c index 558e632..78a0d29 100644 --- a/apps/mixer.c +++ b/apps/mixer.c @@ -260,7 +260,7 @@ int mixer_handle_revents(mixer_t* x, struct pollfd *pfds, int npfds) assert(task); assert(task->buf_); - int ret = snd_rawmidi_write(x->output_, &(task->buf_[task->write_idx_]), task->len_); + int ret = snd_rawmidi_write(x->output_, &(task->buf_[task->write_idx_]), task->len_ - task->write_idx_); if(ret == -EAGAIN) return 0; if(ret < 0) { @@ -81,7 +81,7 @@ int osc_get_poll_fds(osc_t* o, struct pollfd *pfds, int npfds) return 0; } -int osc_handle_revents(osc_t* o, struct pollfd *pfds, int npfds) +int osc_handle_revents(osc_t* o, struct pollfd *pfds, int npfds, mixer_t* x) { assert(npfds == 1); @@ -26,6 +26,8 @@ #include "lo/lo.h" #include <poll.h> +#include "mixer.h" + typedef struct { lo_server server_; } osc_t; @@ -33,6 +35,6 @@ typedef struct { int osc_init(osc_t* o, const char* port); int osc_get_poll_fd_count(osc_t* o); int osc_get_poll_fds(osc_t* o, struct pollfd *pfds, int npfds); -int osc_handle_revents(osc_t* o, struct pollfd *pfds, int npfds); +int osc_handle_revents(osc_t* o, struct pollfd *pfds, int npfds, mixer_t* x); #endif |