@ -0,0 +1,63 @@ | |||
#!/usr/bin/perl -w | |||
use Net::OpenSoundControl::Client; | |||
use Data::Dumper qw(Dumper); | |||
use Getopt::Std; | |||
my $client; | |||
my $verbose = 0; | |||
my $dhost = "localhost"; | |||
my $dport = 9000; | |||
# ---------------------------------------------------------- | |||
sub AskErase($) | |||
{ | |||
my $b = shift; | |||
$client->send(['/joystick/b', 'i', $b, 'i', 1]); | |||
$client->send(['/joystick/b', 'i', $b, 'i', 0]); | |||
} | |||
# ---------------------------------------------------------- | |||
print "--- Moresinus $$ ---\n"; | |||
getopts('d:v', \%options); | |||
if (defined $options{"d"}) { | |||
# print Dumper $options{"d"}; | |||
($dhost, $dport) = split /:/, $options{"d"}; | |||
} | |||
$verbose = 1 if (defined $options{"v"}); | |||
print "trashing ", $dhost, " on port ", $dport, "\n"; | |||
$client = Net::OpenSoundControl::Client->new( | |||
Host => $dhost, Port => $dport) | |||
or die "Could not start client: $@\n"; | |||
print Dumper $client if $verbose; | |||
# ---------------------------------------------------------- | |||
AskErase(50); | |||
srand($$); | |||
print " ", rand(1000), "\n"; | |||
my ($t, $v, $r1, $r2, $phi); | |||
$r1 = rand(100) + 1600; | |||
$r2 = rand(100) + 3200; | |||
$phi = rand(3124) / 1000.0; | |||
print " $r1 $r2 $phi\n" if $verbose; | |||
for ($t = -32000; $t < 32000; $t+=150) { | |||
$v = 15000 * (sin($t / $r1) + cos($phi + ($t / $r2))); | |||
# print $t, " --> ", $v, "\n"; | |||
$client->send(['/joystick/xy', 'i', $t, 'i', $v]); | |||
sleep 1 if (($t % 16) == 0); | |||
} | |||
@ -0,0 +1,12 @@ | |||
OPTS = -Wall -g -DDEBUG_LEVEL=0 | |||
laserblast.o: laserblast.c Makefile | |||
gcc -c ${OPTS} $< | |||
joy2laser: joy2laser.c Makefile laserblast.o | |||
gcc ${OPTS} $< laserblast.o ../functions/libpocosc.a -llo -o $@ | |||
@ -0,0 +1,4 @@ | |||
# joy2laser | |||
Kluge intuité pendant [Sonoptic 2020](https://sonoptic.net). | |||
@ -0,0 +1,131 @@ | |||
/* | |||
* Joystick to Laser | |||
* | |||
* Sonoptic 2020 | |||
*/ | |||
#include <stdio.h> | |||
#include <unistd.h> | |||
#include <stdlib.h> | |||
#include <getopt.h> | |||
#include <time.h> | |||
#include <lo/lo.h> /* OSC library */ | |||
#include "laserblast.h" | |||
/* ------------------------------------------------------------------- */ | |||
#define LOCAL_PORT "9000" | |||
#define REMOTE_HOST "localhost" /* just loling */ | |||
#define REMOTE_PORT "9999" | |||
int verbosity = 0; | |||
int scenenumber = 1, | |||
lasernumber = 1; | |||
/* ------------------------------------------------------------------- */ | |||
int draw_this_point(int x, int y) | |||
{ | |||
float fx, fy; | |||
fx = (32768.0 + (float)x) / 94.7; | |||
fy = (32768.0 + (float)y) / 94.7; | |||
#define SZ 10.0 | |||
blast_rewind(); | |||
blast_addpoint(fx-SZ, fy-SZ, 0xffffff); | |||
blast_addpoint(fx-SZ, fy+SZ, 0xffffff); | |||
blast_addpoint(fx+SZ, fy+SZ, 0xffffff); | |||
blast_addpoint(fx+SZ, fy-SZ, 0xffffff); | |||
blast_addpoint(fx-SZ, fy-SZ, 0); | |||
blast_flush(0); | |||
return -1; | |||
} | |||
/* ------------------------------------------------------------------- */ | |||
int xy_handler(const char *path, const char *types, lo_arg ** argv, | |||
int argc, void *data, void *user_data) | |||
{ | |||
int val_x, val_y; | |||
int foo; | |||
#if DEBUG_LEVEL | |||
fprintf(stderr, "%s ( %s %s %d )\n", __func__, path, types, argc); | |||
#endif | |||
val_x = argv[0]->i; val_y = argv[1]->i; | |||
if (verbosity) fprintf(stderr, "%6d %6d\n", val_x, val_y); | |||
foo = draw_this_point(val_x, val_y); | |||
return 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 help(int k) | |||
{ | |||
puts("HELP ME !"); | |||
return 0; | |||
} | |||
/* ------------------------------------------------------------------- */ | |||
int main(int argc, char *argv[]) | |||
{ | |||
char *local_port = LOCAL_PORT; | |||
char *remote_host = REMOTE_HOST; | |||
char *remote_port = REMOTE_PORT; | |||
int opt, foo; | |||
lo_server_thread st; | |||
long starttime; | |||
/* parsing command line options */ | |||
while ((opt = getopt(argc, argv, "hp:vL:S:")) != -1) { | |||
switch (opt) { | |||
case 'h': if (help(0)) exit(1); break; | |||
case 'p': local_port = optarg; break; | |||
case 'R': remote_host = optarg; break; | |||
case 'P': remote_port = optarg; break; | |||
case 'L': lasernumber = atoi(optarg); break; | |||
case 'S': scenenumber = atoi(optarg); break; | |||
case 'v': verbosity++; break; | |||
} | |||
} | |||
if (verbosity) { | |||
fprintf(stderr, "-----------: %s\n", argv[0]); | |||
fprintf(stderr, "pid : %d\n", getpid()); | |||
fprintf(stderr, "local port : %s\n", local_port); | |||
fprintf(stderr, "scene : %d\n", scenenumber); | |||
fprintf(stderr, "laser : %d\n", lasernumber); | |||
} | |||
foo = blast_init(remote_host, remote_port, scenenumber, lasernumber); | |||
st = lo_server_thread_new(local_port, error); | |||
lo_server_thread_add_method(st, "/joystick/xy", "ii", xy_handler, NULL); | |||
lo_server_thread_start(st); | |||
starttime = time(NULL) / 60; | |||
for (;;) { | |||
if (verbosity) | |||
fprintf(stderr, "\tt = %ld min.\n", | |||
(time(NULL)/60L) - starttime); | |||
sleep(60); | |||
} | |||
return 8; | |||
} | |||
/* ------------------------------------------------------------------- */ |
@ -0,0 +1,104 @@ | |||
/* | |||
* laserblsat over OSC | |||
* | |||
* Sonoptic 2020 | |||
*/ | |||
#include <stdio.h> | |||
#include <unistd.h> | |||
#include <stdlib.h> | |||
#include <string.h> | |||
#include <lo/lo.h> /* OSC library */ | |||
/* ------------------------------------------------------------------- */ | |||
#define BUFF_SIZE 8000 | |||
static char big_buffer[BUFF_SIZE+2]; | |||
static int curpos; | |||
static int la_scene, le_laser; | |||
static lo_address lo_addr; | |||
extern int verbosity; | |||
/* ------------------------------------------------------------------- */ | |||
int blast_init(char *host, char *port, int scene, int laser) | |||
{ | |||
/* prepare OSC transmission */ | |||
lo_addr = lo_address_new(host, port); | |||
if (verbosity) { | |||
fprintf(stderr, "%s is sending to %s:%s\n", __FILE__, host, port); | |||
} | |||
la_scene = scene, le_laser = laser; | |||
/* manage our internals memories */ | |||
big_buffer[0] = '\0'; /* clear buffer */ | |||
curpos = 0; /* index in buffer */ | |||
return -1; | |||
} | |||
/* ------------------------------------------------------------------- */ | |||
int blast_rewind(void) | |||
{ | |||
if (verbosity) fprintf(stderr, "Blast rewind\n"); | |||
big_buffer[0] = '\0'; /* clear buffer */ | |||
curpos = 0; /* index in buffer */ | |||
strcat(big_buffer, "["); curpos++; | |||
return -1; | |||
} | |||
/* ------------------------------------------------------------------- */ | |||
int blast_addpoint(float x, float y, long col) | |||
{ | |||
char buff[100]; | |||
int foo, sz; | |||
sz = sprintf(buff, "(%f, %f, %ld),", x, y, col); | |||
if (verbosity) | |||
fprintf(stderr, "%s --> %s\n", __func__, buff); | |||
/* check free space in bigbuffer */ | |||
if ( (curpos+sz) > BUFF_SIZE ) { | |||
fprintf(stderr, "buffer overflow in %s\n", __func__); | |||
exit(1); | |||
} | |||
strcat(big_buffer, buff); curpos += sz; | |||
return -1; | |||
} | |||
/* ------------------------------------------------------------------- */ | |||
int blast_flush(void) | |||
{ | |||
int foo; | |||
char buffer[100]; | |||
big_buffer[curpos-1] = ']'; big_buffer[curpos] = '\0'; | |||
if (verbosity) | |||
fprintf(stderr, "BLAST %s\n", big_buffer); | |||
sprintf(buffer, "/pl/%d/%d", la_scene, le_laser); | |||
foo = lo_send(lo_addr, buffer, "s", big_buffer); | |||
if (-1==foo) { | |||
fprintf(stderr, "%s : error %d\n", __func__, foo); | |||
return -1; | |||
} | |||
return 0; | |||
} | |||
/* ------------------------------------------------------------------- */ | |||
/* ------------------------------------------------------------------- */ | |||
/* ------------------------------------------------------------------- */ | |||
@ -0,0 +1,12 @@ | |||
/* | |||
* laserblast.h | |||
* | |||
* sonoptic 2020 | |||
*/ | |||
int blast_init(char *host, char *port, int scene, int laser); | |||
int blast_rewind(void); | |||
int blast_addpoint(float fx, float fy, long col); | |||
int blast_flush(int notused); | |||