summaryrefslogtreecommitdiff
path: root/apps/mixer.c
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 /apps/mixer.c
parentrefactored mixer variable name (diff)
switch task insertion works now
Diffstat (limited to 'apps/mixer.c')
-rw-r--r--apps/mixer.c70
1 files changed, 69 insertions, 1 deletions
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_);