@ -0,0 +1,11 @@ | |||
MANIFEST | |||
tarball | |||
doc/*.toc | |||
doc/*.log | |||
doc/*.aux | |||
doc/*.pdf | |||
doc/*.idx | |||
doc/*.ilg | |||
doc/*.ind |
@ -0,0 +1,8 @@ | |||
# ---------------------------------------------------- | |||
# umpf... | |||
OPTS = -Wall -g -DDEBUG_LEVEL=1 | |||
# ---------------------------------------------------- | |||
@ -0,0 +1,38 @@ | |||
\documentclass[a4paper,11pt]{article} | |||
% \listfiles % pour le debug | |||
\usepackage[french]{babel} | |||
\usepackage[utf8]{inputenc} | |||
\usepackage[T1]{fontenc} | |||
% XXX \usepackage{lipsum} | |||
\usepackage{makeidx} | |||
\usepackage{listings} | |||
% \usepackage{color} | |||
% \usepackage{url} | |||
\usepackage{xspace} | |||
\usepackage[verbose]{layout} | |||
\makeindex | |||
% ------------------------------------------------------------------- | |||
\title{Floating images processing} | |||
\author{tTh} | |||
\begin{document} | |||
\maketitle | |||
\section{Open Sound Control} | |||
De quoi parle-t-on exactement ? | |||
% ------------------------------------------------------------------- | |||
\section{Example} | |||
% ------------------------------------------------------------------- | |||
\pagebreak | |||
\tableofcontents | |||
\printindex | |||
\end{document} |
@ -0,0 +1,9 @@ | |||
#!/bin/bash | |||
DOC=gadgets-osc | |||
pdflatex $DOC.tex | |||
makeindex $DOC | |||
pdflatex $DOC |
@ -0,0 +1,127 @@ | |||
/* | |||
* ncurses widgets for poc-osc | |||
*/ | |||
#include <stdio.h> | |||
#include <stdlib.h> | |||
#include <curses.h> | |||
#include <signal.h> | |||
#include <locale.h> | |||
#include "ncursefuncs.h" | |||
extern int verbosity; /* to be declared public near main() */ | |||
/* ----------------------------------------------------------------- */ | |||
void endcurses(int p) | |||
{ | |||
endwin(); | |||
fprintf(stderr, "%s : p=%d, bye...\n", __func__, p); | |||
exit(0); | |||
} | |||
static void atexit_endcurses(void) | |||
{ | |||
#if DEBUG_LEVEL | |||
fprintf(stderr, "--> %s ( )\n", __func__); | |||
#endif | |||
endcurses(0); | |||
} | |||
/* ----------------------------------------------------------------- */ | |||
int initcurses(void) | |||
{ | |||
setlocale(LC_ALL, ""); /* pourquoi ? */ | |||
/* get character-at-a-time input without echoing */ | |||
initscr(); cbreak(); noecho(); | |||
/* hide the cursor */ | |||
curs_set(0); | |||
atexit(atexit_endcurses); | |||
// signal(SIGINT, endcurses); | |||
return 0; /* this is not a magic number */ | |||
} | |||
/* ----------------------------------------------------------------- */ | |||
int draw_main_screen(char *title, int unused) | |||
{ | |||
char ligne[81]; | |||
int foo; | |||
#if DEBUG_LEVEL | |||
fprintf(stderr, "--> %s ( '%s' %d )\n", __func__, title, unused); | |||
#endif | |||
if (verbosity) { | |||
sprintf(ligne, "screen : %d x %d", LINES, COLS); | |||
mvaddstr(1, 0, ligne); | |||
} | |||
standout(); | |||
for (foo=0; foo<COLS; foo++) mvaddch(0, foo, '|'); | |||
mvaddstr(0, 0, title); | |||
standend(); | |||
refresh(); | |||
return 0; /* this is not a magic number */ | |||
} | |||
/* ----------------------------------------------------------------- */ | |||
int blast_error_message(char *txt, int violence, int unused) | |||
{ | |||
int line, foo; | |||
char buff[60]; | |||
#if DEBUG_LEVEL | |||
fprintf(stderr, "--> %s ( '%s' %d %d )\n", __func__, | |||
txt, violence, unused); | |||
#endif | |||
line = LINES - 1; | |||
if (verbosity > 3) { | |||
sprintf(buff, "%s : line is %d ", __func__, line); | |||
mvaddstr(1, 0, buff); refresh(); | |||
} | |||
standout(); | |||
// clear our part of screen | |||
for (foo=0; foo<COLS; foo++) { | |||
mvaddch(line, foo, '_'); | |||
} | |||
mvaddstr(line, 0, "SYS$MSG_ "); | |||
mvaddstr(line, 9, txt); | |||
standend(); | |||
return 0; | |||
} | |||
/* ----------------------------------------------------------------- */ | |||
/* warning: only use the bit 0 of the 'state' arg */ | |||
int draw_a_button(WINDOW *w, int lig, int col, char *txt, int state) | |||
{ | |||
#if DEBUG_LEVEL > 1 | |||
fprintf(stderr, "--> %s ( %3d %3d '%s' %d )\n", __func__, | |||
lig, col, txt, state); | |||
#endif | |||
if (state) { | |||
standout(); | |||
mvaddstr(lig, col, "*****"); | |||
mvaddstr(lig+1, col, "*"); | |||
mvaddstr(lig+1, col+1, txt); | |||
mvaddstr(lig+1, col+4, "*"); | |||
mvaddstr(lig+2, col, "*****"); | |||
standend(); | |||
} | |||
else { | |||
mvaddstr(lig, col, "+---+"); | |||
mvaddstr(lig+1, col, "| |"); | |||
mvaddstr(lig+2, col, "+---+"); | |||
} | |||
refresh(); | |||
return 0; | |||
} | |||
/* ----------------------------------------------------------------- */ | |||
/* ----------------------------------------------------------------- */ |
@ -0,0 +1,14 @@ | |||
/* | |||
* ncurse funcs | |||
*/ | |||
#include <curses.h> | |||
int initcurses(void); | |||
void endcurses(int p); | |||
int draw_main_screen(char *title, int unused); | |||
int blast_error_message(char *txt, int violence, int unused); | |||
/* warning: only use the bit 0 of the 'state' arg */ | |||
int draw_a_button(WINDOW *w, int lig, int col, char *txt, int state); |
@ -0,0 +1,189 @@ | |||
/* | |||
* dessiner avec OSC et la manette de jeu | |||
*/ | |||
#include <stdio.h> | |||
#include <stdlib.h> | |||
#include <unistd.h> | |||
#include <limits.h> /* for SHRT_MIN */ | |||
#include <time.h> | |||
#include <curses.h> | |||
#include <signal.h> | |||
#include <locale.h> | |||
#include <getopt.h> | |||
#include <lo/lo.h> | |||
#include "ncursefuncs.h" | |||
/* ----------------------------------------------------------------- */ | |||
#define LOCAL_PORT "9000" | |||
int verbosity = 0; | |||
unsigned long hits = 0L; | |||
int erase_button = -1; | |||
int current_char = '%'; | |||
volatile int must_erase = 0; | |||
/* ----------------------------------------------------------------- */ | |||
void error(int num, const char *msg, const char *path) | |||
{ | |||
fprintf(stderr, "liblo server error %d in path %s : %s\n", num, path, msg); | |||
exit(1); | |||
} | |||
/* ----------------------------------------------------------------- */ | |||
int button_handler(const char *path, const char *types, lo_arg ** argv, | |||
int argc, void *data, void *user_data) | |||
{ | |||
char ligne[80]; | |||
#if DEBUG_LEVEL > 1 | |||
printf(stderr, "%s : %s %s %d\n", __func__, path, types, argc); | |||
#endif | |||
if (verbosity) { | |||
sprintf(ligne, "%s %s %s %d\n", __func__, path, types, argc); | |||
mvaddstr(2, 2, ligne); | |||
refresh(); | |||
} | |||
if (-1 == erase_button) return 0; | |||
if ( (argv[0]->i == erase_button) && | |||
(argv[1]->i == 0) ) { | |||
must_erase = 1; | |||
} | |||
return 0; | |||
} | |||
/* ----------------------------------------------------------------- */ | |||
static int old_c = 0, old_l = 0; | |||
int xy_handler(const char *path, const char *types, lo_arg ** argv, | |||
int argc, void *data, void *user_data) | |||
{ | |||
char ligne[80]; | |||
int val_x, val_y; | |||
int cur_l, cur_c; | |||
float kx, ky; | |||
if (verbosity>1) fprintf(stderr, "%s : %s %s %d\n", __func__, | |||
path, types, argc); | |||
if (must_erase) { | |||
move(1, 0); | |||
clrtobot(); | |||
must_erase = 0; | |||
} | |||
standout(); | |||
val_x = argv[0]->i; val_y = argv[1]->i; | |||
if (verbosity) { | |||
sprintf(ligne, " xy %6d %6d ", val_x, val_y); | |||
mvaddstr(0, 30, ligne); | |||
hits++; | |||
sprintf(ligne, " %7lu ", hits); | |||
mvaddstr(0, COLS-12, ligne); | |||
} | |||
standend(); | |||
/* boundary checking */ | |||
if (val_x < SHRT_MIN) val_x = SHRT_MIN; | |||
if (val_y < SHRT_MIN) val_y = SHRT_MIN; | |||
if (val_x > SHRT_MAX) val_x = SHRT_MAX; | |||
if (val_y > SHRT_MAX) val_y = SHRT_MAX; | |||
/* make values positives */ | |||
val_x += -SHRT_MIN; | |||
val_y += -SHRT_MIN; | |||
/* compute position of the new spot */ | |||
kx = (float)COLS / 65535.0; | |||
ky = (float)(LINES-1) / 65535.0; | |||
cur_c = (int)((float)val_x * kx); | |||
cur_l = 1 + (int)((float)val_y * ky); | |||
if (verbosity) { | |||
fprintf(stderr, "%7d %7d -> %7d %7d\n", | |||
val_x, val_y, cur_l, cur_c); | |||
} | |||
/* erase the old spot */ | |||
if (old_l) mvaddch(old_l, old_c, current_char); | |||
standout(); | |||
mvaddch(cur_l, cur_c, '#'); | |||
standend(); | |||
old_l = cur_l, old_c = cur_c; | |||
refresh(); | |||
return 0; | |||
} | |||
/* ----------------------------------------------------------------- */ | |||
/* ----------------------------------------------------------------- */ | |||
static int help(int notused) | |||
{ | |||
fprintf(stderr, "\t * osc2cursor %s\n", __DATE__" *"); | |||
puts("\t-p\tlistening UDP port ("LOCAL_PORT")"); | |||
puts("\t-v\tincrease verbosity"); | |||
puts("\t-E\terasing button number (0)"); | |||
puts("\t-C\tdrawing character (NA)"); | |||
return -1; | |||
} | |||
/* ----------------------------------------------------------------- */ | |||
int main(int argc, char *argv[]) | |||
{ | |||
int foo; | |||
lo_server_thread st; | |||
char *local_port = LOCAL_PORT; | |||
int opt; | |||
char ligne[81]; | |||
/* parsing command line options */ | |||
while ((opt = getopt(argc, argv, "hp:vE:C:")) != -1) { | |||
switch (opt) { | |||
case 'h': if (help(0)) exit(1); break; | |||
case 'p': local_port = optarg; break; | |||
case 'v': verbosity++; break; | |||
case 'E': erase_button = atoi(optarg); | |||
break; | |||
case 'C': current_char = *optarg; break; | |||
default: exit(1); | |||
} | |||
} | |||
fprintf(stderr, "erase %d\n", erase_button); | |||
st = lo_server_thread_new(local_port, error); | |||
foo = initcurses(); | |||
sprintf(ligne, ":%s ", local_port); | |||
foo = draw_main_screen(ligne, 0); | |||
if (verbosity) fprintf(stderr, "dms %d\n", foo); | |||
lo_server_thread_add_method(st, "/joystick/xy", "ii", xy_handler, NULL); | |||
lo_server_thread_add_method(st, "/joystick/b", "ii", button_handler, NULL); | |||
lo_server_thread_start(st); | |||
for (;;) { | |||
if (verbosity) | |||
fprintf(stderr, "t = %ld\n", time(NULL)); | |||
sleep(100); | |||
} | |||
return 0; | |||
} | |||
/* ----------------------------------------------------------------- */ |