From a8179661045f4a8f19bf6de7058620c4cb4411db Mon Sep 17 00:00:00 2001 From: tth Date: Fri, 2 Aug 2019 14:34:15 +0200 Subject: [PATCH] importing basic functions --- .gitignore | 4 ++ Makefile | 4 ++ README.md | 2 +- functions/Makefile | 22 ++++++++++ functions/alsaseq.c | 101 ++++++++++++++++++++++++++++++++++++++++++++ functions/alsaseq.h | 13 ++++++ functions/senders.c | 48 +++++++++++++++++++++ functions/senders.h | 13 ++++++ functions/serial.c | 75 ++++++++++++++++++++++++++++++++ functions/serial.h | 7 +++ osc2cursor.c | 2 +- 11 files changed, 289 insertions(+), 2 deletions(-) create mode 100644 functions/Makefile create mode 100644 functions/alsaseq.c create mode 100644 functions/alsaseq.h create mode 100644 functions/senders.c create mode 100644 functions/senders.h create mode 100644 functions/serial.c create mode 100644 functions/serial.h diff --git a/.gitignore b/.gitignore index 9f60c29..8bec7c0 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,8 @@ MANIFEST tarball +osc2cursor + doc/*.toc doc/*.log doc/*.aux @@ -9,3 +11,5 @@ doc/*.pdf doc/*.idx doc/*.ilg doc/*.ind + +functions/*.[oa] diff --git a/Makefile b/Makefile index 48dba61..bde1dcd 100644 --- a/Makefile +++ b/Makefile @@ -6,3 +6,7 @@ OPTS = -Wall -g -DDEBUG_LEVEL=1 # ---------------------------------------------------- +osc2cursor: osc2cursor.c ${DEPS} functions/libpocosc.a + gcc ${OPTS} $< functions/libpocosc.a -llo -lcurses -o $@ + +# ---------------------------------------------------- diff --git a/README.md b/README.md index f5a0eba..ea47709 100644 --- a/README.md +++ b/README.md @@ -1 +1 @@ -wtf ? +# Gadgets autou du protocole OSC \ No newline at end of file diff --git a/functions/Makefile b/functions/Makefile new file mode 100644 index 0000000..5cc02e1 --- /dev/null +++ b/functions/Makefile @@ -0,0 +1,22 @@ +#---------------------------------------------------- +# +# functions +# +#---------------------------------------------------- + +OPTS = -Wall -g -DDEBUG_LEVEL=1 + +senders.o: senders.c senders.h Makefile + gcc ${OPTS} -c $< + +alsaseq.o: alsaseq.c alsaseq.h Makefile + gcc ${OPTS} -c $< + +serial.o: serial.c serial.h Makefile + gcc ${OPTS} -c $< + +ncursefuncs.o: ncursefuncs.c ncursefuncs.h Makefile + gcc ${OPTS} -c $< + +libpocosc.a: senders.o alsaseq.o serial.o ncursefuncs.o + ar r $@ $? diff --git a/functions/alsaseq.c b/functions/alsaseq.c new file mode 100644 index 0000000..38f6ffd --- /dev/null +++ b/functions/alsaseq.c @@ -0,0 +1,101 @@ +/* + * + * code semi-grabed from the original asedump. + * + */ + +#include +#include + +#include + +#include "alsaseq.h" + +extern int verbosity; + +/* ----------------------------------------------------------------- */ +snd_seq_t * create_sequencer(char *name) +{ +snd_seq_t *p_seq; +int err; + +#if DEBUG_LEVEL +fprintf(stderr, "---> %s ( '%s' )\n", __func__, name); +#endif + +/* open sequencer */ +err = snd_seq_open(&p_seq, "default", SND_SEQ_OPEN_DUPLEX, 0); +// fprintf(stderr, " seq_open --> %d\n", err); +if (err) { + fprintf(stderr, "%s : open sequencer -% d", __func__, err); + exit(1); + } + +/* set our client's name */ +err = snd_seq_set_client_name(p_seq, name); +if (err) { + fprintf(stderr, "%s : set client name -% d", __func__, err); + exit(1); + } + +return p_seq; +} +/* ----------------------------------------------------------------- */ +/* ----------------------------------------------------------------- */ +int create_port(snd_seq_t *seq) +{ +int err; + +#if DEBUG_LEVEL +fprintf(stderr, "---> %s (%p)\n", __func__, seq); +#endif + +err = snd_seq_create_simple_port(seq, "kontrol2osc", + SND_SEQ_PORT_CAP_WRITE | + SND_SEQ_PORT_CAP_SUBS_WRITE , + SND_SEQ_PORT_TYPE_MIDI_GENERIC | + SND_SEQ_PORT_TYPE_APPLICATION ); +if (err) { + fprintf(stderr, "%s:%s snd_seq_create_simple_port : err %d\n", + __FILE__, __func__, err); + } + +return err; +} +/* ----------------------------------------------------------------- */ + +void list_ports(snd_seq_t *seq) +{ +snd_seq_client_info_t *cinfo; +snd_seq_port_info_t *pinfo; +int client; + +snd_seq_client_info_alloca(&cinfo); +snd_seq_port_info_alloca(&pinfo); + +puts(" Port Client name Port name"); + +snd_seq_client_info_set_client(cinfo, -1); + +while (snd_seq_query_next_client(seq, cinfo) >= 0) { + client = snd_seq_client_info_get_client(cinfo); + + snd_seq_port_info_set_client(pinfo, client); + snd_seq_port_info_set_port(pinfo, -1); + while (snd_seq_query_next_port(seq, pinfo) >= 0) { + /* we need both READ and SUBS_READ */ + if ((snd_seq_port_info_get_capability(pinfo) + & (SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_READ)) + != (SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_READ)) + continue; + printf("%3d:%-3d %-32.32s %s\n", + snd_seq_port_info_get_client(pinfo), + snd_seq_port_info_get_port(pinfo), + snd_seq_client_info_get_name(cinfo), + snd_seq_port_info_get_name(pinfo)); + } + } +} +/* ----------------------------------------------------------------- */ +/* ----------------------------------------------------------------- */ +/* ----------------------------------------------------------------- */ diff --git a/functions/alsaseq.h b/functions/alsaseq.h new file mode 100644 index 0000000..c732338 --- /dev/null +++ b/functions/alsaseq.h @@ -0,0 +1,13 @@ +/* + * alsaseq.h + */ + +/* ----------------------------------------------------------------- */ + +snd_seq_t * create_sequencer(char *name); + +int create_port(snd_seq_t *seq); + +void list_ports(snd_seq_t *seq); + +/* ----------------------------------------------------------------- */ diff --git a/functions/senders.c b/functions/senders.c new file mode 100644 index 0000000..e4294f9 --- /dev/null +++ b/functions/senders.c @@ -0,0 +1,48 @@ +/* + * some functions for sending various data over the wire + */ + +#include +#include + +#include "senders.h" + +extern int verbosity; /* not so ugly hack */ + +/* ----------------------------------------------------------------- */ +int send_data_xy(lo_address dst, int x, int y) +{ +int foo; + +if (verbosity) fprintf(stderr, "sending x y %7d %7d\n", x, y); +foo = lo_send(dst, "/joystick/xy", "ii", x, y); +if (verbosity > 2) { + fprintf(stderr, "lo_send -> %d\n", foo); + } +return foo; +} +/* ----------------------------------------------------------------- */ +int send_data_button(lo_address dst, int n, int v) +{ +int foo; + +if (verbosity) fprintf(stderr, "sending button %d %d\n", n, v); +foo = lo_send(dst, "/joystick/b", "ii", n, v); +if (verbosity > 2) { + fprintf(stderr, "lo_send -> %d\n", foo); + } +return foo; +} +/* ----------------------------------------------------------------- */ +int send_data_id(lo_address dst, char *s) +{ +int foo; + +if (verbosity) fprintf(stderr, "sending my id '%s'\n", s); +foo = lo_send(dst, "/joystick/id", "s", s); +if (verbosity > 2) { + fprintf(stderr, "lo_send -> %d\n", foo); + } +return foo; +} +/* ----------------------------------------------------------------- */ diff --git a/functions/senders.h b/functions/senders.h new file mode 100644 index 0000000..8db19fe --- /dev/null +++ b/functions/senders.h @@ -0,0 +1,13 @@ +/* + * senders.h * part of poc-osc + */ + +/* ------------------------------------------------------- */ + +int send_data_xy(lo_address dst, int x, int y); +int send_data_button(lo_address dst, int n, int v); +int send_data_id(lo_address dst, char *s); + +/* ------------------------------------------------------- */ +/* ------------------------------------------------------- */ + diff --git a/functions/serial.c b/functions/serial.c new file mode 100644 index 0000000..180c6cf --- /dev/null +++ b/functions/serial.c @@ -0,0 +1,75 @@ +#include +#include +#include /* serial things */ +#include +#include + +#include "serial.h" + +/* ----------------------------------------------------------------- */ +/* + * this variable must be declared/initialised in your + * main program. + */ + +extern int verbosity; + +/* ----------------------------------------------------------------- */ +/* values for 'bauds' can be found in /usr/include/bits/termios.h + */ +int open_serial(char *dev, int bauds, int unused) +{ +int fd; + +#if DEBUG_LEVEL +fprintf(stderr, "opening %s (b/s code : 0%06o)\n", dev, bauds); +#endif + +fd = open(dev, O_RDWR, O_NOCTTY); +if (fd < 0) { + perror(dev); + return -1; + } + +return fd; +} +/* ----------------------------------------------------------------- */ +/* + * from the manpage + The zero baud rate, B0, is used to terminate the connection. If B0 is + specified, the modem control lines shall no longer be asserted. Normally, + this will disconnect the line. + */ + +int bauds_str_to_B(char *strb, int unused) +{ +long value; + +#if DEBUG_LEVEL +fprintf(stderr, "--> %s ( '%s' 0x%x )\n", __func__, strb, unused); +#endif + +if (1 != sscanf(strb, "%ld", &value)) { + return B0; + } +#if DEBUG_LEVEL +fprintf(stderr, " computed baudrate = %ld\n", value); +#endif + +switch (value) { + case 50: return B50; + case 75: return B75; + case 110: return B110; + case 300: return B300; + case 1200: return B1200; + case 2400: return B2400; + case 4800: return B4800; + case 9600: return B9600; + case 19200: return B19200; + } + +return B0; +} +/* ----------------------------------------------------------------- */ +/* ----------------------------------------------------------------- */ +/* ----------------------------------------------------------------- */ diff --git a/functions/serial.h b/functions/serial.h new file mode 100644 index 0000000..98e22b2 --- /dev/null +++ b/functions/serial.h @@ -0,0 +1,7 @@ +/* + * basic functions for frienly use of various + * serial interfaces. + */ + +int open_serial(char *dev, int bauds, int unused); +int bauds_str_to_B(char *strb, int unused); diff --git a/osc2cursor.c b/osc2cursor.c index 7f72d7d..39f57b8 100644 --- a/osc2cursor.c +++ b/osc2cursor.c @@ -14,7 +14,7 @@ #include #include -#include "ncursefuncs.h" +#include "functions/ncursefuncs.h" /* ----------------------------------------------------------------- */