Permalink
Browse files

support for osc over zeromq

  • Loading branch information...
yaxu committed Sep 1, 2013
1 parent ed481ba commit 9ab660b0404be8a352446d8fbec2fbac1d1edba4
Showing with 56 additions and 1 deletion.
  1. +2 −0 jack.h
  2. +54 −1 server.c
View
2 jack.h
@@ -1,6 +1,8 @@
#include <jack/jack.h>
#ifndef CHANNELS
#define CHANNELS 2
#endif
typedef int (*t_callback)(int, float *, float **);
View
@@ -6,10 +6,16 @@
#include <sys/types.h>
#include <math.h>
#include <sys/time.h>
#include <assert.h>
#include "server.h"
#include "audio.h"
#ifdef ZEROMQ
#include <zmq.h>
#define MAXOSCSZ 1024
#endif
void error(int num, const char *m, const char *path);
int trigger_handler(const char *path, const char *types, lo_arg **argv,
@@ -110,9 +116,49 @@ int play_handler(const char *path, const char *types, lo_arg **argv,
/**/
#ifdef ZEROMQ
void *zmqthread(void *data){
void *context = zmq_ctx_new ();
void *subscriber = zmq_socket (context, ZMQ_SUB);
void *buffer = (void *) malloc(MAXOSCSZ);
int rc = zmq_connect (subscriber, ZEROMQ);
lo_server s = lo_server_new("7772", error);
lo_server_add_method(s, "/play", "iisffffffsffffi",
play_handler,
NULL
);
lo_server_add_method(s, "/kriole", "iifff",
kriole_handler,
NULL
);
lo_server_add_method(s, NULL, NULL, generic_handler, NULL);
assert(rc == 0);
// Subscribe to all
rc = zmq_setsockopt(subscriber, ZMQ_SUBSCRIBE,
NULL, 0);
assert (rc == 0);
while(1) {
int size = zmq_recv(subscriber, buffer, MAXOSCSZ, 0);
if (size > 0) {
lo_server_dispatch_data(s, buffer, size);
}
else {
printf("oops.\n");
}
}
return(NULL);
}
#endif
/**/
extern int server_init(void) {
lo_server_thread st = lo_server_thread_new("7771", error);
lo_server_thread st = lo_server_thread_new("7771", error);
lo_server_thread_add_method(st, "/play", "iisffffffsffffi",
play_handler,
NULL
@@ -122,8 +168,15 @@ extern int server_init(void) {
kriole_handler,
NULL
);
lo_server_thread_add_method(st, NULL, NULL, generic_handler, NULL);
lo_server_thread_start(st);
#ifdef ZEROMQ
pthread_t t;
pthread_create(&t, NULL, (void *(*)(void *)) zmqthread, NULL);
#endif
return(1);
}

0 comments on commit 9ab660b

Please sign in to comment.