From d4a4d3309165bbdd97f6334e1166be00fb5413cb Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Fri, 14 Sep 2012 18:41:23 +0200 Subject: integrated liblo --- Makefile | 7 +++++-- main.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 64 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index c0f4a92..19a0221 100644 --- a/Makefile +++ b/Makefile @@ -12,11 +12,14 @@ SDL_GFX_LDFLAGS := $(shell pkg-config SDL_gfx --libs) LIBVLC_CFLAGS := $(shell pkg-config libvlc --cflags) LIBVLC_LDFLAGS := $(shell pkg-config libvlc --libs) +LIBLO_CFLAGS := $(shell pkg-config liblo --cflags) +LIBLO_LDFLAGS := $(shell pkg-config liblo --libs) + CFLAGS := -std=c99 -Wall -g -O0 \ $(SDL_CFLAGS) $(SDL_IMAGE_CFLAGS) $(SDL_GFX_CFLAGS) \ - $(LIBVLC_CFLAGS) + $(LIBVLC_CFLAGS) $(LIBLO_CFLAGS) LDFLAGS := $(SDL_LDFLAGS) $(SDL_IMAGE_LDFLAGS) $(SDL_GFX_LDFLAGS) \ - $(LIBVLC_LDFLAGS) + $(LIBVLC_LDFLAGS) $(LIBLO_LDFLAGS) all : osc-graphics diff --git a/main.c b/main.c index 1300b35..97b374e 100644 --- a/main.c +++ b/main.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -11,6 +12,8 @@ #include +#include + #define NARRAY(ARRAY) \ (sizeof(ARRAY) / sizeof((ARRAY)[0])) @@ -38,8 +41,60 @@ #define SCREEN_HEIGHT 480 #define FRAMERATE 20 /* Hz */ +static inline void effect_bg_change(SDL_Color color); + static SDL_Surface *screen; +static void +osc_error(int num, const char *msg, const char *path) +{ + printf("liblo server error %d in path %s: %s\n", num, path, msg); +} + +/* catch any incoming messages and display them. returning 1 means that the + * message has not been fully handled and the server should try other methods */ +static int +osc_generic_handler(const char *path, const char *types, lo_arg **argv, + int argc, void *data, + void *user_data __attribute__((unused))) +{ + int i; + + printf("path: <%s>\n", path); + for (i=0; ii, (Uint8)argv[1]->i, (Uint8)argv[2]->i}); + return 0; +} + +static inline int +osc_init(const char *port) +{ + lo_server_thread st = lo_server_thread_new(port, osc_error); + + lo_server_thread_add_method(st, NULL, NULL, osc_generic_handler, NULL); + + lo_server_thread_add_method(st, "/background/color", "iii", + osc_bg_change, NULL); + + lo_server_thread_start(st); + + return 0; +} + static SDL_Surface *image_surface = NULL; static void @@ -250,7 +305,10 @@ process_events(void) int main(int argc, char **argv) { - FPSmanager fpsm; + FPSmanager fpsm; + + if (osc_init("7770")) + return EXIT_FAILURE; if (SDL_Init(SDL_INIT_VIDEO)) { SDL_ERROR("SDL_Init"); -- cgit v1.2.3