Browse Source

adding text2osc, need more cleanup

tth 1 year ago
parent
commit
517b381360
5 changed files with 160 additions and 0 deletions
  1. 1
    0
      .gitignore
  2. 3
    0
      Makefile
  3. 2
    0
      doc/gadgets-osc.tex
  4. 2
    0
      functions/Makefile
  5. 152
    0
      text2osc.c

+ 1
- 0
.gitignore View File

@@ -4,6 +4,7 @@ tarball
4 4
 
5 5
 osc2cursor
6 6
 osc-joy
7
+text2osc
7 8
 
8 9
 doc/*.toc
9 10
 doc/*.log

+ 3
- 0
Makefile View File

@@ -12,4 +12,7 @@ osc2cursor:        osc2cursor.c ${DEPS} functions/libpocosc.a
12 12
 osc-joy:        osc-joy.c ${DEPS} functions/libpocosc.a 
13 13
 	gcc ${OPTS} $< functions/libpocosc.a -llo -o $@
14 14
 
15
+text2osc:        text2osc.c ${DEPS} functions/libpocosc.a
16
+	gcc ${OPTS} $< functions/libpocosc.a -llo -o $@
17
+
15 18
 # ----------------------------------------------------

+ 2
- 0
doc/gadgets-osc.tex View File

@@ -24,10 +24,12 @@
24 24
 \section{Open Sound Control}
25 25
 
26 26
 De quoi parle-t-on exactement ?
27
+\vspace{1em}
27 28
 
28 29
 % -------------------------------------------------------------------
29 30
 \section{Example}
30 31
 
32
+TODO\index{TODO}
31 33
 
32 34
 % -------------------------------------------------------------------
33 35
 

+ 2
- 0
functions/Makefile View File

@@ -4,6 +4,8 @@
4 4
 #
5 5
 #----------------------------------------------------
6 6
 
7
+all:	libpocosc.a
8
+
7 9
 OPTS = -Wall -g -DDEBUG_LEVEL=1
8 10
 
9 11
 senders.o:	senders.c senders.h Makefile

+ 152
- 0
text2osc.c View File

@@ -0,0 +1,152 @@
1
+/*
2
+ *		WARNING, THIS IS JUST A WIP !
3
+ */
4
+
5
+#include  <stdio.h>
6
+#include  <stdlib.h>
7
+#include  <unistd.h>
8
+#include  <ctype.h>
9
+
10
+#include  <lo/lo.h>
11
+#include  "functions/senders.h"
12
+
13
+#define REMOTE_HOST	"localhost"			/* just loling */
14
+#define REMOTE_PORT	"9000"
15
+#define MY_TEXT_ID	"<@TROLL>"
16
+/* ----------------------------------------------------------------- */
17
+
18
+int		verbosity = 0;
19
+char		*my_id = MY_TEXT_ID;
20
+int		wait_time = 100;		/* in milliseconds */
21
+
22
+/* ----------------------------------------------------------------- */
23
+int megaloop(FILE *fp, lo_address loa)
24
+{
25
+int		caractere, note;
26
+short		x_val, y_val;
27
+int		must_send_xy;
28
+int		char_count;
29
+
30
+x_val = y_val = 0;
31
+must_send_xy = 1;
32
+char_count = 0;
33
+
34
+rewind(fp);		/* so we can run this code again and again
35
+			   on the same fopened file */
36
+
37
+while (EOF != (caractere=getc(fp))) {
38
+
39
+	char_count++;
40
+	
41
+	if (verbosity) fprintf(stderr, "car = %d\n", caractere);
42
+	
43
+	if (isalpha(caractere)) {
44
+		/* Play a sound */
45
+		note=toupper(caractere) - 'A';
46
+		// fprintf(stderr, "%c -> %3d\n", caractere, note);
47
+		send_data_button(loa, note, 1);
48
+		usleep(40*1000);
49
+		send_data_button(loa, note, 0);
50
+		usleep(80*1000);
51
+		}
52
+	else if (isblank(caractere)) {
53
+		usleep(300*1000);
54
+		}
55
+	else if (caractere == '!') {
56
+		send_data_id(loa, my_id);
57
+		}
58
+
59
+	/* imagine : we are a XY joystick */
60
+	else if (caractere == '+') {
61
+		x_val++;
62
+		if (x_val > 32000)	x_val = 0;
63
+		must_send_xy = 1;		
64
+		}
65
+	else if (caractere == '-') {
66
+		x_val--;
67
+		if (x_val < -32000)	x_val = 0;
68
+		must_send_xy = 1;		
69
+		}
70
+	else if (caractere == '^') {
71
+		y_val++;
72
+		if (y_val > 32000)	y_val = 0;
73
+		must_send_xy = 1;		
74
+		}
75
+	else if (caractere == '$') {
76
+		y_val--;
77
+		if (y_val < -32000)	y_val = 0;
78
+		must_send_xy = 1;		
79
+		}
80
+				
81
+	/* default case */
82
+	else 	{	
83
+		usleep(wait_time*1000);
84
+		}
85
+	
86
+	if (must_send_xy) {
87
+		fprintf(stderr, "...     X %6d   Y %6d\n",
88
+					x_val, y_val);
89
+		send_data_xy(loa, x_val, y_val);		
90
+		must_send_xy = 0;
91
+		}
92
+	}
93
+
94
+return 0;
95
+}
96
+/* ----------------------------------------------------------------- */
97
+static void help(int k)
98
+{
99
+puts("\t * text -> osc       "__DATE__" *");
100
+puts("\t-r\tremote host ("REMOTE_HOST")");
101
+puts("\t-p\tremote UDP port ("REMOTE_PORT")");
102
+puts("\t-v\tincrease verbosity");
103
+puts("\t-w\twait time unit in ms.");
104
+puts("\t-I\tchange text id (\""MY_TEXT_ID"\")");
105
+exit(0);
106
+}
107
+/* ----------------------------------------------------------------- */
108
+
109
+int main(int argc, char *argv[])
110
+{
111
+int		opt;
112
+char		*remote_host = REMOTE_HOST;
113
+char		*remote_port = REMOTE_PORT;
114
+lo_address	loaddr;
115
+FILE		*fp;
116
+
117
+/* parsing command line options */
118
+while ((opt = getopt(argc, argv, "hp:r:vI:")) != -1) {
119
+	switch (opt) {
120
+		case 'h':	help(0);		break;
121
+		case 'r':	remote_host = optarg;	break;
122
+		case 'p':	remote_port = optarg;	break;
123
+		case 'v':	verbosity++;		break;
124
+		case 'I':	my_id = optarg;		break;
125
+		default:	exit(1);
126
+		}
127
+	}
128
+
129
+if (optind >= argc) {
130
+	fprintf(stderr, "Expected a filename after options\n");
131
+	exit(EXIT_FAILURE);
132
+	}
133
+	
134
+loaddr =  lo_address_new(remote_host, remote_port);
135
+if (verbosity) {
136
+	fprintf(stderr, "%s (%s) is sending to %s:%s\n",
137
+			argv[0], my_id, remote_host, remote_port);
138
+	} 
139
+
140
+if (NULL==(fp=fopen(argv[optind], "r"))) {
141
+	perror (argv[optind]);
142
+	exit(1);
143
+	}
144
+
145
+if (verbosity) fprintf(stderr, "now playing %s\n", argv[optind]);
146
+
147
+megaloop(fp, loaddr);
148
+
149
+
150
+return 0;
151
+}
152
+/* ----------------------------------------------------------------- */

Loading…
Cancel
Save