summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rw-r--r--apps/dolmetschctl.c4
-rw-r--r--apps/midi.c29
-rw-r--r--apps/midi.h6
-rw-r--r--apps/mixer.c2
-rw-r--r--apps/osc.c2
-rw-r--r--apps/osc.h4
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) {
diff --git a/apps/osc.c b/apps/osc.c
index 887684d..5d656b9 100644
--- a/apps/osc.c
+++ b/apps/osc.c
@@ -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);
diff --git a/apps/osc.h b/apps/osc.h
index ddef73e..b4a496e 100644
--- a/apps/osc.h
+++ b/apps/osc.h
@@ -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