Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 72 lines (51 sloc) 1.704 kB
ab0fe60 @yaxu there
yaxu authored
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include <string.h>
5 #include <lo/lo.h>
6
7 #include "server.h"
f4296e1 @yaxu foo
yaxu authored
8 #include "audio.h"
ab0fe60 @yaxu there
yaxu authored
9
10 void error(int num, const char *m, const char *path);
11
12 int trigger_handler(const char *path, const char *types, lo_arg **argv,
13 int argc, void *data, void *user_data);
14
15 int generic_handler(const char *path, const char *types, lo_arg **argv,
16 int argc, void *data, void *user_data);
17
18 /**/
19
20 void error(int num, const char *msg, const char *path) {
21 printf("liblo server error %d in path %s: %s\n", num, path, msg);
22 }
23
24 /**/
25
26 int generic_handler(const char *path, const char *types, lo_arg **argv,
f4296e1 @yaxu foo
yaxu authored
27 int argc, void *data, void *user_data) {
ab0fe60 @yaxu there
yaxu authored
28 int i;
29
30 printf("path: <%s>\n", path);
31 for (i=0; i<argc; i++) {
32 printf("arg %d '%c' ", i, types[i]);
33 lo_arg_pp(types[i], argv[i]);
34 printf("\n");
35 }
36 printf("\n");
37
38 return 1;
39 }
40
41 /**/
42
f4296e1 @yaxu foo
yaxu authored
43 int play_handler(const char *path, const char *types, lo_arg **argv,
ab0fe60 @yaxu there
yaxu authored
44 int argc, void *data, void *user_data) {
45
f4296e1 @yaxu foo
yaxu authored
46 /* lo_timetag ts = lo_message_get_timestamp(data); */
ab0fe60 @yaxu there
yaxu authored
47
cf3bb79 @yaxu working and broken again
yaxu authored
48 double when = (double) argv[0]->d + ((double) argv[1]->d / 1000000.0);
49 char *sample_name = strdup((char *) argv[2]);
ab0fe60 @yaxu there
yaxu authored
50
cf3bb79 @yaxu working and broken again
yaxu authored
51 audio_play(when,
f4296e1 @yaxu foo
yaxu authored
52 sample_name
53 );
ab0fe60 @yaxu there
yaxu authored
54 return 0;
55 }
56
f4296e1 @yaxu foo
yaxu authored
57 /**/
58
59 extern int server_init(void) {
60 lo_server_thread st = lo_server_thread_new("7771", error);
61
cf3bb79 @yaxu working and broken again
yaxu authored
62 //lo_server_thread_add_method(st, NULL, NULL, generic_handler, NULL);
f4296e1 @yaxu foo
yaxu authored
63
cf3bb79 @yaxu working and broken again
yaxu authored
64 lo_server_thread_add_method(st, "/play", "dds",
f4296e1 @yaxu foo
yaxu authored
65 play_handler,
66 NULL
67 );
68 lo_server_thread_start(st);
69
70 return(1);
71 }
Something went wrong with that request. Please try again.