summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2015-10-13 00:52:54 +0200
committerChristian Pointner <equinox@spreadspace.org>2015-10-13 00:52:54 +0200
commitfe2f19dcba0002d8eeaf8d05ce544a659308422c (patch)
tree6afd0b824e91b43bdadd7714f68b083a2c377510 /client
parentadded inital osc support (diff)
sending switching commands over osc works now...ansers to be done.
Diffstat (limited to 'client')
-rw-r--r--client/midi.c11
-rw-r--r--client/osc.c72
-rw-r--r--client/osc.h10
3 files changed, 35 insertions, 58 deletions
diff --git a/client/midi.c b/client/midi.c
index 46a4687..25ec551 100644
--- a/client/midi.c
+++ b/client/midi.c
@@ -45,7 +45,6 @@ int midi_init(midi_t* m, const char* device)
slist_init(&(m->done_data_), free);
-
int ret = snd_rawmidi_open(&(m->input_), &(m->output_), device, SND_RAWMIDI_NONBLOCK);
if(ret < 0) {
error(0, 0, "MIDI: cannot open port '%s': %s", device, snd_strerror(ret));
@@ -106,7 +105,7 @@ static int midi_enqueue_lang_switch(midi_t* m, osc_t* o, const char* lang, const
done_data->write_idx_ = 0;
assert(slist_add(&(m->done_data_), done_data));
- return 0; // mixer_switch_lang(x, lang, &midi_lang_switch_done, done_data);
+ return osc_switch_lang(o, lang, &midi_lang_switch_done, done_data);
}
static int midi_handle_note_on(midi_t* m, osc_t* o)
@@ -127,10 +126,10 @@ static int midi_handle_note_off(midi_t* m, osc_t* o)
static int midi_handle_message(midi_t* m, osc_t* o)
{
- int i;
- printf("MIDI: ");
- for (i = 0; i < sizeof(m->buf_); ++i)
- printf("%02X%c", m->buf_[i], (i >= (sizeof(m->buf_)-1)) ? '\n' : ' ');
+ /* int i; */
+ /* printf("MIDI: "); */
+ /* for (i = 0; i < sizeof(m->buf_); ++i) */
+ /* printf("%02X%c", m->buf_[i], (i >= (sizeof(m->buf_)-1)) ? '\n' : ' '); */
int ret = 0;
switch(m->buf_[0]) {
diff --git a/client/osc.c b/client/osc.c
index 4ecc28a..79bfd76 100644
--- a/client/osc.c
+++ b/client/osc.c
@@ -39,52 +39,32 @@ static void print_error(int num, const char *msg, const char *path)
static int lang_handler(const char *path, const char *types, lo_arg ** argv,
int argc, lo_message msg, void *user_data)
{
+ osc_t* o = (osc_t*)user_data;
+ assert(o);
+
if(argc != 1 || !lo_is_string_type((lo_type)types[0]))
return 1;
- lo_address from = lo_message_get_source(msg);
- const char* host = lo_address_get_hostname(from);
- const char* port = lo_address_get_port(from);
- assert(host && port);
+ printf("got ack for: lang '%s'\n", &(argv[0]->s));
- osc_t* o = (osc_t*)user_data;
- assert(o);
- osc_task_t* task = malloc(sizeof(osc_task_t));
- assert(task);
+ /* search for right task ... */
+ /* if(task->done_cb_) */
+ /* task->done_cb_(task->done_data_); */
- task->self_ = o;
- task->state_ = 0;
- assert((task->lang_ = strdup(&(argv[0]->s))));
- task->addr_ = lo_address_new(host, port);
- assert(task->addr_);
- task->msg_ = lo_message_new();
- assert(task->msg_);
- assert(!lo_message_add(task->msg_, "s", task->lang_));
-
- assert(slist_add(&(o->tasks_), task));
+ /* slist_remove(&(o->tasks_), task); */
return 0;
}
void free_osc_task(void* ptr)
{
- osc_task_t* task = (osc_task_t*)ptr;
+ task_t* task = (task_t*)ptr;
+ assert(task);
- lo_message_free(task->msg_);
- lo_address_free(task->addr_);
free(task->lang_);
free(task);
}
-void osc_lang_switch_task(void* data)
-{
- assert(data);
- osc_task_t* d = data;
-
- lo_send_message_from(d->addr_, d->self_->server_, "/lang/switch", d->msg_);
- slist_remove(&(d->self_->tasks_), d);
-}
-
int osc_init(osc_t* o, const char* host, const char* port)
{
assert(o != NULL);
@@ -106,6 +86,21 @@ int osc_init(osc_t* o, const char* host, const char* port)
return 0;
}
+int osc_switch_lang(osc_t* o, const char* lang, void (*done_cb)(void*), void* done_data)
+{
+ task_t* task = malloc(sizeof(task_t));
+ assert(task);
+ task->state_ = 0;
+ assert((task->lang_ = strdup(lang)));
+ task->done_cb_ = done_cb;
+ task->done_data_ = done_data;
+ assert(slist_add(&(o->tasks_), task));
+
+ if(lo_send_from(o->target_, o->server_, LO_TT_IMMEDIATE, "/lang/switch", "s", task->lang_) > 0)
+ task->state_ = 1;
+
+ return 0;
+}
int osc_get_poll_fd_count(osc_t* o)
{
@@ -131,7 +126,6 @@ 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, midi_t* m)
int osc_handle_revents(osc_t* o, struct pollfd *pfds, int npfds)
{
assert(o);
@@ -148,19 +142,5 @@ int osc_handle_revents(osc_t* o, struct pollfd *pfds, int npfds)
lo_server_recv_noblock(o->server_, 0);
- int ret = 0;
- slist_element_t* tmp;
- for(tmp = o->tasks_.first_; tmp; tmp = tmp->next_) {
- osc_task_t* d = (osc_task_t*)(tmp->data_);
- if(d->state_ == 0) {
-// ret = midi_switch_lang(x, d->lang_, &osc_lang_switch_task, d);
- if(ret)
- break;
-
- d->state_ = 1;
- }
- }
-
-
- return ret;
+ return 0;
}
diff --git a/client/osc.h b/client/osc.h
index f6ac83d..a5b6454 100644
--- a/client/osc.h
+++ b/client/osc.h
@@ -27,7 +27,6 @@
#include <poll.h>
#include "slist.h"
-//#include "midi.h"
typedef struct {
lo_server server_;
@@ -36,17 +35,16 @@ typedef struct {
} osc_t;
typedef struct {
- osc_t* self_;
int state_;
char* lang_;
- lo_address addr_;
- lo_message msg_;
-} osc_task_t;
+ void (*done_cb_)(void*);
+ void* done_data_;
+} task_t;
int osc_init(osc_t* o, const char* host, const char* port);
+int osc_switch_lang(osc_t* o, const char* lang, void (*done_cb)(void*), void* done_data);
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, midi_t* m);
int osc_handle_revents(osc_t* o, struct pollfd *pfds, int npfds);
#endif