summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2015-10-12 01:33:49 +0200
committerChristian Pointner <equinox@spreadspace.org>2015-10-12 01:33:49 +0200
commit72aef56c3f9f3441d5cdabfed2b1eb1ba8743bbb (patch)
tree2dae4991f8a70636f0ab188fa92df2c6d097050b
parentrefactored mixer variable name (diff)
switch task insertion works now
-rw-r--r--apps/dolmetschctl.c6
-rw-r--r--apps/mixer.c70
-rw-r--r--apps/mixer.h16
3 files changed, 85 insertions, 7 deletions
diff --git a/apps/dolmetschctl.c b/apps/dolmetschctl.c
index 2cffff7..b704109 100644
--- a/apps/dolmetschctl.c
+++ b/apps/dolmetschctl.c
@@ -73,6 +73,12 @@ int main_loop(mixer_t* x, midi_t* m, osc_t* o)
mixer_print_langs(x);
+
+ mixer_switch_lang(x, "en", NULL, NULL);
+ mixer_switch_lang(x, "de", free, &npfds);
+
+ mixer_print_tasks(x);
+
printf("main_loop running with %d pollfds...\n", npfds);
for (;;) {
int err = poll(pfds, npfds, 200);
diff --git a/apps/mixer.c b/apps/mixer.c
index ef4f0fd..098a329 100644
--- a/apps/mixer.c
+++ b/apps/mixer.c
@@ -23,6 +23,7 @@
#include "config.h"
#include <stdio.h>
+#include <string.h>
#include <error.h>
#include <poll.h>
#include <assert.h>
@@ -40,6 +41,14 @@ static void free_lang_entry(void* ptr)
free(l);
}
+static void free_task_entry(void* ptr)
+{
+ task_t* t = ptr;
+ assert(t);
+ free(t->buf_);
+ free(t);
+}
+
static int mixer_read_config_file(mixer_t* x, int dirfd, const char* filename)
{
assert(dirfd > 0);
@@ -113,6 +122,7 @@ int mixer_init(mixer_t* x, const char* name, const char* device)
x->name_ = name;
x->output_ = NULL;
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);
if(ret < 0) {
error(0, 0, "MIXER: cannot open midi port '%s': %s", device, snd_strerror(ret));
@@ -139,7 +149,7 @@ void mixer_print_langs(mixer_t* x)
{
assert(x);
- printf("mixer:\n");
+ printf("languages:\n");
if(!slist_length(&(x->langs_)))
printf(" <no languages>\n");
else {
@@ -152,6 +162,64 @@ void mixer_print_langs(mixer_t* x)
}
}
+static u_int8_t* mixer_create_task_buf(slist_t cmds, int len)
+{
+ u_int8_t* buf = malloc(len);
+ slist_element_t* tmp;
+ int i;
+ for(tmp = cmds.first_, i=0; tmp; tmp = tmp->next_, i+=sizeof(midi_cmd_t)) {
+ midi_cmd_t* c = (midi_cmd_t*)(tmp->data_);
+ memcpy(&(buf[i]), (*c), sizeof(midi_cmd_t));
+ }
+ return buf;
+}
+
+int mixer_switch_lang(mixer_t* x, const char* lang, void (*done_cb)(void*), void* done_data)
+{
+ slist_element_t* tmp;
+ for(tmp = x->langs_.first_; tmp; tmp = tmp->next_) {
+ lang_t* l = (lang_t*)(tmp->data_);
+ if(!strcmp(lang, l->name_)) {
+ int len = slist_length(&(l->cmds_));
+ if(len > 0) {
+ task_t* task = malloc(sizeof(task_t));
+ assert(task);
+ task->len_ = sizeof(midi_cmd_t) * len;
+ assert((task->buf_ = mixer_create_task_buf(l->cmds_, task->len_)));
+ task->write_idx_ = 0;
+ task->done_cb = done_cb;
+ task->done_data = done_data;
+ assert(slist_add(&(x->tasks_), task));
+ }
+ return 0;
+ }
+ }
+ error(0, 0, "requested language '%s' not found ... ignoring switch", lang);
+ return -1;
+}
+
+
+void mixer_print_tasks(mixer_t* x)
+{
+ assert(x);
+
+ printf("tasks:\n");
+ if(!slist_length(&(x->tasks_)))
+ printf(" <no tasks>\n");
+ else {
+ slist_element_t* tmp;
+ for(tmp = x->tasks_.first_; tmp; tmp = tmp->next_) {
+ task_t* t = (task_t*)(tmp->data_);
+ int i;
+ printf(" buf(%d) = ", t->len_);
+ for(i = 0; i < t->len_; ++i) {
+ printf("0x%02X%s", t->buf_[i], (i && !((i+1) % 3)) ? ", " : " ");
+ }
+ printf("\n write_idx = %d\n done = %016lX ( %016lX )\n\n", t->write_idx_, (int64_t)(t->done_cb), (int64_t)(t->done_data));
+ }
+ }
+}
+
int mixer_get_poll_fd_count(mixer_t* x)
{
return snd_rawmidi_poll_descriptors_count(x->output_);
diff --git a/apps/mixer.h b/apps/mixer.h
index f041da5..17b3282 100644
--- a/apps/mixer.h
+++ b/apps/mixer.h
@@ -35,21 +35,25 @@ typedef struct {
slist_t cmds_;
} lang_t;
-// typedef struct {
-// u_int8_t* buf_;
-// (*done_cb)(void*);
-// void* done_data;
-// } task_t;
+typedef struct {
+ u_int8_t* buf_;
+ int len_;
+ int write_idx_;
+ void (*done_cb)(void*);
+ void* done_data;
+} task_t;
typedef struct {
const char* name_;
snd_rawmidi_t* output_;
slist_t langs_;
-// slist_t tasks_;
+ slist_t tasks_;
} mixer_t;
int mixer_init(mixer_t* x, const char* name, const char* device);
void mixer_print_langs(mixer_t* x);
+int mixer_switch_lang(mixer_t* x, const char* lang, void (*done_cb)(void*), void* done_data);
+void mixer_print_tasks(mixer_t* x);
int mixer_get_poll_fd_count(mixer_t* x);
int mixer_get_poll_fds(mixer_t* x, struct pollfd *pfds, int npfds);
int mixer_handle_revents(mixer_t* x, struct pollfd *pfds, int npfds);