Skip to content
Newer
Older
100644 84 lines (61 sloc) 1.91 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,
6356ffd @yaxu more
yaxu authored
44 int argc, void *data, void *user_data) {
ab0fe60 @yaxu there
yaxu authored
45
f4296e1 @yaxu foo
yaxu authored
46 /* lo_timetag ts = lo_message_get_timestamp(data); */
ab0fe60 @yaxu there
yaxu authored
47
fb689a4 @yaxu panning and sample interpellation
yaxu authored
48 double when = (double) argv[0]->i + ((double) argv[1]->i / 1000000.0);
82f4f04 @yaxu works better
yaxu authored
49
cf3bb79 @yaxu working and broken again
yaxu authored
50 char *sample_name = strdup((char *) argv[2]);
82f4f04 @yaxu works better
yaxu authored
51
52 float offset = argv[3]->f;
53 float duration = argv[4]->f;
54 float speed = argv[5]->f;
fb689a4 @yaxu panning and sample interpellation
yaxu authored
55 float pan = argv[6]->f;
56 float velocity = argv[7]->f;
82f4f04 @yaxu works better
yaxu authored
57
cf3bb79 @yaxu working and broken again
yaxu authored
58 audio_play(when,
82f4f04 @yaxu works better
yaxu authored
59 sample_name,
60 offset,
61 duration,
fb689a4 @yaxu panning and sample interpellation
yaxu authored
62 speed,
63 pan,
64 velocity
f4296e1 @yaxu foo
yaxu authored
65 );
ab0fe60 @yaxu there
yaxu authored
66 return 0;
67 }
68
f4296e1 @yaxu foo
yaxu authored
69 /**/
70
71 extern int server_init(void) {
72 lo_server_thread st = lo_server_thread_new("7771", error);
73
cf3bb79 @yaxu working and broken again
yaxu authored
74 //lo_server_thread_add_method(st, NULL, NULL, generic_handler, NULL);
f4296e1 @yaxu foo
yaxu authored
75
fb689a4 @yaxu panning and sample interpellation
yaxu authored
76 lo_server_thread_add_method(st, "/play", "iisfffff",
f4296e1 @yaxu foo
yaxu authored
77 play_handler,
78 NULL
79 );
80 lo_server_thread_start(st);
81
82 return(1);
83 }
Something went wrong with that request. Please try again.