Browse Source

premiere version du translateur Joystick -> Laser

tth 1 month ago
parent
commit
a2e28adcd9
7 changed files with 330 additions and 0 deletions
  1. 4
    0
      .gitignore
  2. 63
    0
      generators/moresinus.pl
  3. 12
    0
      specific/Makefile
  4. 4
    0
      specific/README.md
  5. 131
    0
      specific/joy2laser.c
  6. 104
    0
      specific/laserblast.c
  7. 12
    0
      specific/laserblast.h

+ 4
- 0
.gitignore View File

@@ -17,4 +17,8 @@ doc/*.ind
17 17
 functions/*.[oa]
18 18
 
19 19
 tools/udp-dumper
20
+tools/*.o
21
+
22
+specific/joy2laser
23
+specific/*.o
20 24
 

+ 63
- 0
generators/moresinus.pl View File

@@ -0,0 +1,63 @@
1
+#!/usr/bin/perl -w
2
+
3
+
4
+use Net::OpenSoundControl::Client;
5
+use Data::Dumper qw(Dumper);
6
+use Getopt::Std;
7
+
8
+my $client;
9
+my $verbose = 0;
10
+my $dhost = "localhost";
11
+my $dport = 9000;
12
+
13
+# ----------------------------------------------------------
14
+
15
+sub AskErase($)
16
+{
17
+my $b = shift;
18
+$client->send(['/joystick/b', 'i', $b, 'i', 1]);
19
+$client->send(['/joystick/b', 'i', $b, 'i', 0]);
20
+}
21
+
22
+# ----------------------------------------------------------
23
+print "--- Moresinus $$ ---\n";
24
+
25
+getopts('d:v', \%options);
26
+
27
+if (defined $options{"d"}) {
28
+	# print Dumper $options{"d"};
29
+	($dhost, $dport) = split /:/, $options{"d"};
30
+	}
31
+$verbose = 1 if (defined $options{"v"});
32
+print "trashing ", $dhost, " on port ", $dport, "\n";
33
+
34
+$client =  Net::OpenSoundControl::Client->new(
35
+		Host => $dhost, Port => $dport)
36
+		or die "Could not start client: $@\n";
37
+
38
+print Dumper $client if $verbose;
39
+
40
+# ----------------------------------------------------------
41
+
42
+AskErase(50);
43
+srand($$);
44
+print "   ", rand(1000), "\n";
45
+
46
+my ($t, $v, $r1, $r2, $phi);
47
+
48
+$r1 = rand(100) + 1600;
49
+$r2 = rand(100) + 3200;
50
+$phi = rand(3124) / 1000.0;
51
+print "     $r1 $r2   $phi\n" if $verbose;
52
+
53
+for ($t = -32000; $t < 32000; $t+=150) {
54
+
55
+	$v = 15000 * (sin($t / $r1) + cos($phi + ($t / $r2)));
56
+
57
+	# print $t, "   -->  ", $v, "\n";
58
+	
59
+	$client->send(['/joystick/xy', 'i', $t, 'i', $v]);
60
+
61
+	sleep 1 if (($t % 16) == 0);	
62
+	}
63
+

+ 12
- 0
specific/Makefile View File

@@ -0,0 +1,12 @@
1
+
2
+
3
+OPTS = -Wall -g -DDEBUG_LEVEL=0
4
+
5
+
6
+laserblast.o:	laserblast.c Makefile
7
+	gcc -c ${OPTS} $< 
8
+
9
+joy2laser:	joy2laser.c Makefile laserblast.o
10
+	gcc ${OPTS} $< laserblast.o ../functions/libpocosc.a -llo -o $@
11
+
12
+

+ 4
- 0
specific/README.md View File

@@ -0,0 +1,4 @@
1
+# joy2laser
2
+
3
+Kluge intuité pendant [Sonoptic 2020](https://sonoptic.net).
4
+

+ 131
- 0
specific/joy2laser.c View File

@@ -0,0 +1,131 @@
1
+/*
2
+ *		Joystick to Laser
3
+ *
4
+ *		Sonoptic 2020
5
+ */
6
+
7
+
8
+#include  <stdio.h>
9
+#include  <unistd.h>
10
+#include  <stdlib.h>
11
+#include  <getopt.h>
12
+#include  <time.h>
13
+
14
+#include  <lo/lo.h>			/* OSC library */
15
+
16
+#include  "laserblast.h"
17
+
18
+/* ------------------------------------------------------------------- */
19
+
20
+#define	LOCAL_PORT	"9000"
21
+#define REMOTE_HOST	"localhost"			/* just loling */
22
+#define REMOTE_PORT	"9999"
23
+
24
+int		verbosity = 0;
25
+
26
+int		scenenumber = 1,
27
+		lasernumber = 1;
28
+/* ------------------------------------------------------------------- */
29
+int draw_this_point(int x, int y)
30
+{
31
+float		fx, fy;
32
+
33
+fx = (32768.0 + (float)x) / 94.7;
34
+fy = (32768.0 + (float)y) / 94.7;
35
+
36
+#define SZ 10.0
37
+
38
+blast_rewind();
39
+blast_addpoint(fx-SZ, fy-SZ, 0xffffff);
40
+blast_addpoint(fx-SZ, fy+SZ, 0xffffff);
41
+blast_addpoint(fx+SZ, fy+SZ, 0xffffff);
42
+blast_addpoint(fx+SZ, fy-SZ, 0xffffff);
43
+blast_addpoint(fx-SZ, fy-SZ, 0);
44
+
45
+blast_flush(0);
46
+
47
+return -1;
48
+}
49
+/* ------------------------------------------------------------------- */
50
+int xy_handler(const char *path, const char *types, lo_arg ** argv,
51
+                int argc, void *data, void *user_data)
52
+{
53
+int		val_x, val_y;
54
+int		foo;
55
+
56
+#if DEBUG_LEVEL
57
+fprintf(stderr, "%s ( %s %s %d )\n", __func__, path, types, argc);
58
+#endif
59
+
60
+val_x = argv[0]->i;	val_y = argv[1]->i;
61
+
62
+if (verbosity)		fprintf(stderr, "%6d  %6d\n", val_x, val_y);
63
+
64
+foo = draw_this_point(val_x, val_y);
65
+
66
+return 0;
67
+}
68
+/* ------------------------------------------------------------------- */
69
+void error(int num, const char *msg, const char *path)
70
+{
71
+fprintf(stderr, "liblo server error %d in path %s : %s\n", num, path, msg);
72
+exit(1);
73
+}
74
+/* ------------------------------------------------------------------- */
75
+int help(int k)
76
+{
77
+puts("HELP ME !");
78
+return 0;
79
+}
80
+/* ------------------------------------------------------------------- */
81
+int main(int argc, char *argv[])
82
+{
83
+char			*local_port = LOCAL_PORT;
84
+char			*remote_host = REMOTE_HOST;
85
+char			*remote_port = REMOTE_PORT;
86
+
87
+int			opt, foo;
88
+lo_server_thread	st;
89
+long			starttime;
90
+
91
+/* parsing command line options */
92
+while ((opt = getopt(argc, argv, "hp:vL:S:")) != -1) {
93
+	switch (opt) {
94
+		case 'h':	if (help(0)) exit(1);		break;
95
+		case 'p':	local_port = optarg;		break;
96
+		case 'R':	remote_host = optarg;		break;
97
+		case 'P':	remote_port = optarg;		break;
98
+		case 'L':	lasernumber = atoi(optarg);	break;
99
+		case 'S':	scenenumber = atoi(optarg);	break;
100
+		case 'v':	verbosity++;			break;
101
+		}
102
+	}
103
+
104
+if (verbosity) {
105
+	fprintf(stderr, "-----------: %s\n", argv[0]);
106
+	fprintf(stderr, "pid        : %d\n", getpid());
107
+	fprintf(stderr, "local port : %s\n", local_port);
108
+	fprintf(stderr, "scene      : %d\n", scenenumber);
109
+	fprintf(stderr, "laser      : %d\n", lasernumber);
110
+	}
111
+
112
+foo = blast_init(remote_host, remote_port, scenenumber, lasernumber);
113
+
114
+
115
+st = lo_server_thread_new(local_port, error);
116
+lo_server_thread_add_method(st, "/joystick/xy", "ii", xy_handler, NULL);
117
+
118
+lo_server_thread_start(st);
119
+
120
+starttime = time(NULL) / 60;
121
+
122
+for (;;) {
123
+	if (verbosity)
124
+		fprintf(stderr, "\tt = %ld min.\n",
125
+					(time(NULL)/60L) - starttime);
126
+	sleep(60);
127
+	}
128
+
129
+return 8;
130
+}
131
+/* ------------------------------------------------------------------- */

+ 104
- 0
specific/laserblast.c View File

@@ -0,0 +1,104 @@
1
+/*
2
+ *		laserblsat over OSC
3
+ *
4
+ *		Sonoptic 2020
5
+ */
6
+
7
+#include  <stdio.h>
8
+#include  <unistd.h>
9
+#include  <stdlib.h>
10
+#include  <string.h>
11
+
12
+#include  <lo/lo.h>			/* OSC library */
13
+
14
+/* ------------------------------------------------------------------- */
15
+
16
+#define		BUFF_SIZE	8000
17
+
18
+static char		big_buffer[BUFF_SIZE+2];
19
+static int		curpos;
20
+static int		la_scene, le_laser;
21
+static lo_address	lo_addr;
22
+
23
+extern int		verbosity;
24
+
25
+/* ------------------------------------------------------------------- */
26
+int	blast_init(char *host, char *port, int scene, int laser)
27
+{
28
+
29
+/* prepare OSC transmission */
30
+lo_addr =  lo_address_new(host, port);
31
+if (verbosity) {
32
+	fprintf(stderr, "%s is sending to %s:%s\n", __FILE__, host, port);
33
+	} 
34
+
35
+la_scene = scene, le_laser = laser;
36
+
37
+/* manage our internals memories */
38
+big_buffer[0] = '\0';			/* clear buffer */
39
+curpos = 0;				/* index in buffer */
40
+
41
+return -1;
42
+}
43
+/* ------------------------------------------------------------------- */
44
+int blast_rewind(void)
45
+{
46
+
47
+if (verbosity)		fprintf(stderr, "Blast rewind\n");
48
+
49
+big_buffer[0] = '\0';			/* clear buffer */
50
+curpos = 0;				/* index in buffer */
51
+
52
+strcat(big_buffer, "[");	curpos++;
53
+
54
+return -1;
55
+}
56
+/* ------------------------------------------------------------------- */
57
+int	blast_addpoint(float x, float y, long col)
58
+{
59
+char		buff[100];
60
+int		foo, sz;
61
+
62
+sz = sprintf(buff, "(%f, %f, %ld),", x, y, col);
63
+
64
+if (verbosity)
65
+	fprintf(stderr, "%s --> %s\n", __func__, buff);
66
+
67
+/* check free space in bigbuffer */
68
+if ( (curpos+sz) > BUFF_SIZE ) {
69
+	fprintf(stderr, "buffer overflow in %s\n", __func__);
70
+	exit(1);
71
+	}
72
+
73
+strcat(big_buffer, buff);		curpos += sz;
74
+
75
+return -1;
76
+}
77
+/* ------------------------------------------------------------------- */
78
+int	blast_flush(void)
79
+{
80
+int		foo;
81
+char		buffer[100];
82
+
83
+big_buffer[curpos-1] = ']'; big_buffer[curpos] = '\0';
84
+
85
+if (verbosity)
86
+	fprintf(stderr, "BLAST  %s\n", big_buffer);
87
+
88
+sprintf(buffer, "/pl/%d/%d", la_scene, le_laser);
89
+
90
+foo = lo_send(lo_addr, buffer, "s", big_buffer);
91
+if (-1==foo) {
92
+	fprintf(stderr, "%s : error %d\n", __func__, foo);
93
+	return -1;
94
+	}
95
+
96
+return 0;
97
+}
98
+/* ------------------------------------------------------------------- */
99
+/* ------------------------------------------------------------------- */
100
+/* ------------------------------------------------------------------- */
101
+
102
+	
103
+
104
+

+ 12
- 0
specific/laserblast.h View File

@@ -0,0 +1,12 @@
1
+/*
2
+ *				laserblast.h
3
+ *
4
+ *		sonoptic 2020
5
+ */
6
+
7
+int	blast_init(char *host, char *port, int scene, int laser);
8
+int	blast_rewind(void);
9
+
10
+int	blast_addpoint(float fx, float fy, long col);
11
+int	blast_flush(int notused);
12
+

Loading…
Cancel
Save