Browse Source

importing basic functions

tth 1 month ago
parent
commit
a817966104
11 changed files with 289 additions and 2 deletions
  1. 4
    0
      .gitignore
  2. 4
    0
      Makefile
  3. 1
    1
      README.md
  4. 22
    0
      functions/Makefile
  5. 101
    0
      functions/alsaseq.c
  6. 13
    0
      functions/alsaseq.h
  7. 48
    0
      functions/senders.c
  8. 13
    0
      functions/senders.h
  9. 75
    0
      functions/serial.c
  10. 7
    0
      functions/serial.h
  11. 1
    1
      osc2cursor.c

+ 4
- 0
.gitignore View File

@@ -2,6 +2,8 @@
2 2
 MANIFEST
3 3
 tarball
4 4
 
5
+osc2cursor
6
+
5 7
 doc/*.toc
6 8
 doc/*.log
7 9
 doc/*.aux
@@ -9,3 +11,5 @@ doc/*.pdf
9 11
 doc/*.idx
10 12
 doc/*.ilg
11 13
 doc/*.ind
14
+
15
+functions/*.[oa]

+ 4
- 0
Makefile View File

@@ -6,3 +6,7 @@ OPTS = -Wall -g -DDEBUG_LEVEL=1
6 6
 
7 7
 # ----------------------------------------------------
8 8
 
9
+osc2cursor:        osc2cursor.c ${DEPS} functions/libpocosc.a 
10
+	gcc ${OPTS} $< functions/libpocosc.a -llo -lcurses -o $@
11
+
12
+# ----------------------------------------------------

+ 1
- 1
README.md View File

@@ -1 +1 @@
1
-wtf ?
1
+# Gadgets autou du protocole OSC

+ 22
- 0
functions/Makefile View File

@@ -0,0 +1,22 @@
1
+#----------------------------------------------------
2
+#
3
+#		functions
4
+#
5
+#----------------------------------------------------
6
+
7
+OPTS = -Wall -g -DDEBUG_LEVEL=1
8
+
9
+senders.o:	senders.c senders.h Makefile
10
+	gcc ${OPTS} -c $<
11
+	
12
+alsaseq.o:	alsaseq.c alsaseq.h Makefile
13
+	gcc ${OPTS} -c $<
14
+
15
+serial.o:	serial.c serial.h Makefile
16
+	gcc ${OPTS} -c $<
17
+
18
+ncursefuncs.o:	ncursefuncs.c ncursefuncs.h Makefile
19
+	gcc ${OPTS} -c $<
20
+
21
+libpocosc.a:	senders.o alsaseq.o serial.o ncursefuncs.o
22
+	ar r $@ $?

+ 101
- 0
functions/alsaseq.c View File

@@ -0,0 +1,101 @@
1
+/*
2
+ *
3
+ *  code semi-grabed from the original asedump.
4
+ *
5
+ */ 
6
+ 
7
+#include  <stdio.h>
8
+#include  <stdlib.h>
9
+
10
+#include <alsa/asoundlib.h>
11
+
12
+#include  "alsaseq.h"
13
+
14
+extern int	verbosity;
15
+
16
+/* ----------------------------------------------------------------- */
17
+snd_seq_t * create_sequencer(char *name)
18
+{
19
+snd_seq_t 	*p_seq;
20
+int		err;
21
+
22
+#if DEBUG_LEVEL
23
+fprintf(stderr, "---> %s ( '%s' )\n", __func__, name);
24
+#endif
25
+
26
+/* open sequencer */
27
+err = snd_seq_open(&p_seq, "default", SND_SEQ_OPEN_DUPLEX, 0);
28
+// fprintf(stderr, " seq_open --> %d\n", err);
29
+if (err) {
30
+	fprintf(stderr, "%s : open sequencer -% d", __func__, err);
31
+	exit(1);
32
+	}
33
+
34
+/* set our client's name */
35
+err = snd_seq_set_client_name(p_seq, name);
36
+if (err) {
37
+	fprintf(stderr, "%s : set client name -% d", __func__, err);
38
+	exit(1);
39
+	}
40
+
41
+return p_seq;
42
+}
43
+/* ----------------------------------------------------------------- */
44
+/* ----------------------------------------------------------------- */
45
+int create_port(snd_seq_t *seq)
46
+{
47
+int err;
48
+
49
+#if DEBUG_LEVEL
50
+fprintf(stderr, "---> %s (%p)\n", __func__, seq);
51
+#endif
52
+
53
+err = snd_seq_create_simple_port(seq, "kontrol2osc",
54
+			 SND_SEQ_PORT_CAP_WRITE 	|
55
+			 SND_SEQ_PORT_CAP_SUBS_WRITE	,
56
+			 SND_SEQ_PORT_TYPE_MIDI_GENERIC |
57
+			 SND_SEQ_PORT_TYPE_APPLICATION	);
58
+if (err) {			 
59
+	fprintf(stderr, "%s:%s snd_seq_create_simple_port : err %d\n",
60
+		__FILE__, __func__, err);
61
+	}
62
+
63
+return err;
64
+}
65
+/* ----------------------------------------------------------------- */
66
+
67
+void list_ports(snd_seq_t *seq)
68
+{
69
+snd_seq_client_info_t	*cinfo;
70
+snd_seq_port_info_t	*pinfo;
71
+int			client;
72
+
73
+snd_seq_client_info_alloca(&cinfo);
74
+snd_seq_port_info_alloca(&pinfo);
75
+
76
+puts(" Port    Client name                      Port name");
77
+
78
+snd_seq_client_info_set_client(cinfo, -1);
79
+
80
+while (snd_seq_query_next_client(seq, cinfo) >= 0) {
81
+	client = snd_seq_client_info_get_client(cinfo);
82
+
83
+	snd_seq_port_info_set_client(pinfo, client);
84
+	snd_seq_port_info_set_port(pinfo, -1);
85
+	while (snd_seq_query_next_port(seq, pinfo) >= 0) {
86
+		/* we need both READ and SUBS_READ */
87
+		if ((snd_seq_port_info_get_capability(pinfo)
88
+		     & (SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_READ))
89
+		    != (SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_READ))
90
+			continue;
91
+		printf("%3d:%-3d  %-32.32s %s\n",
92
+		       snd_seq_port_info_get_client(pinfo),
93
+		       snd_seq_port_info_get_port(pinfo),
94
+		       snd_seq_client_info_get_name(cinfo),
95
+		       snd_seq_port_info_get_name(pinfo));
96
+		}
97
+	}
98
+}
99
+/* ----------------------------------------------------------------- */
100
+/* ----------------------------------------------------------------- */
101
+/* ----------------------------------------------------------------- */

+ 13
- 0
functions/alsaseq.h View File

@@ -0,0 +1,13 @@
1
+/*
2
+ *   alsaseq.h
3
+ */
4
+
5
+/* ----------------------------------------------------------------- */
6
+
7
+snd_seq_t * create_sequencer(char *name);
8
+
9
+int create_port(snd_seq_t *seq);
10
+
11
+void list_ports(snd_seq_t *seq);
12
+
13
+/* ----------------------------------------------------------------- */

+ 48
- 0
functions/senders.c View File

@@ -0,0 +1,48 @@
1
+/*
2
+ * some functions for sending various data over the wire
3
+ */
4
+ 
5
+#include  <stdio.h>
6
+#include  <lo/lo.h>
7
+
8
+#include  "senders.h"
9
+
10
+extern int verbosity;			/* not so ugly hack */
11
+
12
+/* ----------------------------------------------------------------- */
13
+int	send_data_xy(lo_address dst, int x, int y)
14
+{
15
+int		foo;
16
+
17
+if (verbosity) fprintf(stderr, "sending x y    %7d  %7d\n", x, y);
18
+foo = lo_send(dst, "/joystick/xy", "ii", x, y);
19
+if (verbosity > 2) {
20
+	fprintf(stderr, "lo_send -> %d\n", foo);
21
+	}
22
+return foo;
23
+}
24
+/* ----------------------------------------------------------------- */
25
+int	send_data_button(lo_address dst, int n, int v)
26
+{
27
+int		foo;
28
+
29
+if (verbosity) fprintf(stderr, "sending button %d %d\n", n, v);
30
+foo = lo_send(dst, "/joystick/b", "ii", n, v);
31
+if (verbosity > 2) {
32
+	fprintf(stderr, "lo_send -> %d\n", foo);
33
+	}
34
+return foo;
35
+}
36
+/* ----------------------------------------------------------------- */
37
+int	send_data_id(lo_address dst, char *s)
38
+{
39
+int		foo;
40
+
41
+if (verbosity) fprintf(stderr, "sending my id '%s'\n", s);
42
+foo = lo_send(dst, "/joystick/id", "s", s);
43
+if (verbosity > 2) {
44
+	fprintf(stderr, "lo_send -> %d\n", foo);
45
+	}
46
+return foo;
47
+}
48
+/* ----------------------------------------------------------------- */

+ 13
- 0
functions/senders.h View File

@@ -0,0 +1,13 @@
1
+/*
2
+ *	senders.h    *   part of poc-osc
3
+ */
4
+
5
+/* ------------------------------------------------------- */
6
+
7
+int	send_data_xy(lo_address dst, int x, int y);
8
+int	send_data_button(lo_address dst, int n, int v);
9
+int	send_data_id(lo_address dst, char *s);
10
+
11
+/* ------------------------------------------------------- */
12
+/* ------------------------------------------------------- */
13
+

+ 75
- 0
functions/serial.c View File

@@ -0,0 +1,75 @@
1
+#include  <stdio.h>
2
+#include  <stdlib.h>
3
+#include  <termios.h>		/* serial things */
4
+#include  <unistd.h>
5
+#include  <fcntl.h>
6
+
7
+#include  "serial.h"
8
+
9
+/* ----------------------------------------------------------------- */
10
+/*
11
+ *	this variable must be declared/initialised in your
12
+ *	main program.
13
+ */
14
+ 
15
+extern int verbosity;
16
+
17
+/* ----------------------------------------------------------------- */
18
+/* values for 'bauds' can be found in /usr/include/bits/termios.h
19
+ */
20
+int open_serial(char *dev, int bauds, int unused)
21
+{
22
+int		fd;
23
+
24
+#if DEBUG_LEVEL
25
+fprintf(stderr, "opening %s (b/s code : 0%06o)\n", dev, bauds);
26
+#endif
27
+
28
+fd = open(dev, O_RDWR, O_NOCTTY);
29
+if (fd < 0) {
30
+	perror(dev);
31
+	return -1;
32
+	}
33
+
34
+return fd;
35
+}
36
+/* ----------------------------------------------------------------- */
37
+/*
38
+ *		from the manpage
39
+ The  zero baud rate, B0, is used to terminate the connection. If B0 is
40
+ specified, the modem control lines shall no longer be asserted. Normally,  
41
+ this will disconnect the line.  
42
+ */
43
+
44
+int bauds_str_to_B(char *strb, int unused)
45
+{
46
+long		value;
47
+
48
+#if DEBUG_LEVEL
49
+fprintf(stderr, "--> %s ( '%s' 0x%x )\n", __func__, strb, unused);
50
+#endif
51
+
52
+if (1 != sscanf(strb, "%ld", &value)) {
53
+	return B0;
54
+	}
55
+#if DEBUG_LEVEL
56
+fprintf(stderr, "    computed baudrate = %ld\n", value);
57
+#endif
58
+
59
+switch (value) {
60
+	case	50:		return B50;
61
+	case	75:		return B75;
62
+	case	110:		return B110;
63
+	case	300:		return B300;
64
+	case	1200:		return B1200;
65
+	case	2400:		return B2400;
66
+	case	4800:		return B4800;
67
+	case	9600:		return B9600;
68
+	case	19200:		return B19200;
69
+	}
70
+
71
+return B0;
72
+}
73
+/* ----------------------------------------------------------------- */
74
+/* ----------------------------------------------------------------- */
75
+/* ----------------------------------------------------------------- */

+ 7
- 0
functions/serial.h View File

@@ -0,0 +1,7 @@
1
+/*
2
+ *	basic functions for frienly use of various
3
+ *	serial interfaces.
4
+ */
5
+
6
+int open_serial(char *dev, int bauds, int unused);
7
+int bauds_str_to_B(char *strb, int unused);

+ 1
- 1
osc2cursor.c View File

@@ -14,7 +14,7 @@
14 14
 #include  <getopt.h>
15 15
 #include  <lo/lo.h>
16 16
 
17
-#include  "ncursefuncs.h"
17
+#include  "functions/ncursefuncs.h"
18 18
 
19 19
 /* ----------------------------------------------------------------- */
20 20
 

Loading…
Cancel
Save