From 517b381360fcc5d05877133fd52a03b83b1ca0ac Mon Sep 17 00:00:00 2001 From: tth Date: Sun, 25 Aug 2019 16:51:36 +0200 Subject: [PATCH] adding text2osc, need more cleanup --- .gitignore | 1 + Makefile | 3 + doc/gadgets-osc.tex | 2 + functions/Makefile | 2 + text2osc.c | 152 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 160 insertions(+) create mode 100644 text2osc.c diff --git a/.gitignore b/.gitignore index 1744ede..69f2256 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ tarball osc2cursor osc-joy +text2osc doc/*.toc doc/*.log diff --git a/Makefile b/Makefile index 9ec3ca2..80db751 100644 --- a/Makefile +++ b/Makefile @@ -12,4 +12,7 @@ osc2cursor: osc2cursor.c ${DEPS} functions/libpocosc.a osc-joy: osc-joy.c ${DEPS} functions/libpocosc.a gcc ${OPTS} $< functions/libpocosc.a -llo -o $@ +text2osc: text2osc.c ${DEPS} functions/libpocosc.a + gcc ${OPTS} $< functions/libpocosc.a -llo -o $@ + # ---------------------------------------------------- diff --git a/doc/gadgets-osc.tex b/doc/gadgets-osc.tex index 0e08d2c..b9b2228 100644 --- a/doc/gadgets-osc.tex +++ b/doc/gadgets-osc.tex @@ -24,10 +24,12 @@ \section{Open Sound Control} De quoi parle-t-on exactement ? +\vspace{1em} % ------------------------------------------------------------------- \section{Example} +TODO\index{TODO} % ------------------------------------------------------------------- diff --git a/functions/Makefile b/functions/Makefile index 5cc02e1..41be22a 100644 --- a/functions/Makefile +++ b/functions/Makefile @@ -4,6 +4,8 @@ # #---------------------------------------------------- +all: libpocosc.a + OPTS = -Wall -g -DDEBUG_LEVEL=1 senders.o: senders.c senders.h Makefile diff --git a/text2osc.c b/text2osc.c new file mode 100644 index 0000000..c31c056 --- /dev/null +++ b/text2osc.c @@ -0,0 +1,152 @@ +/* + * WARNING, THIS IS JUST A WIP ! + */ + +#include +#include +#include +#include + +#include +#include "functions/senders.h" + +#define REMOTE_HOST "localhost" /* just loling */ +#define REMOTE_PORT "9000" +#define MY_TEXT_ID "<@TROLL>" +/* ----------------------------------------------------------------- */ + +int verbosity = 0; +char *my_id = MY_TEXT_ID; +int wait_time = 100; /* in milliseconds */ + +/* ----------------------------------------------------------------- */ +int megaloop(FILE *fp, lo_address loa) +{ +int caractere, note; +short x_val, y_val; +int must_send_xy; +int char_count; + +x_val = y_val = 0; +must_send_xy = 1; +char_count = 0; + +rewind(fp); /* so we can run this code again and again + on the same fopened file */ + +while (EOF != (caractere=getc(fp))) { + + char_count++; + + if (verbosity) fprintf(stderr, "car = %d\n", caractere); + + if (isalpha(caractere)) { + /* Play a sound */ + note=toupper(caractere) - 'A'; + // fprintf(stderr, "%c -> %3d\n", caractere, note); + send_data_button(loa, note, 1); + usleep(40*1000); + send_data_button(loa, note, 0); + usleep(80*1000); + } + else if (isblank(caractere)) { + usleep(300*1000); + } + else if (caractere == '!') { + send_data_id(loa, my_id); + } + + /* imagine : we are a XY joystick */ + else if (caractere == '+') { + x_val++; + if (x_val > 32000) x_val = 0; + must_send_xy = 1; + } + else if (caractere == '-') { + x_val--; + if (x_val < -32000) x_val = 0; + must_send_xy = 1; + } + else if (caractere == '^') { + y_val++; + if (y_val > 32000) y_val = 0; + must_send_xy = 1; + } + else if (caractere == '$') { + y_val--; + if (y_val < -32000) y_val = 0; + must_send_xy = 1; + } + + /* default case */ + else { + usleep(wait_time*1000); + } + + if (must_send_xy) { + fprintf(stderr, "... X %6d Y %6d\n", + x_val, y_val); + send_data_xy(loa, x_val, y_val); + must_send_xy = 0; + } + } + +return 0; +} +/* ----------------------------------------------------------------- */ +static void help(int k) +{ +puts("\t * text -> osc "__DATE__" *"); +puts("\t-r\tremote host ("REMOTE_HOST")"); +puts("\t-p\tremote UDP port ("REMOTE_PORT")"); +puts("\t-v\tincrease verbosity"); +puts("\t-w\twait time unit in ms."); +puts("\t-I\tchange text id (\""MY_TEXT_ID"\")"); +exit(0); +} +/* ----------------------------------------------------------------- */ + +int main(int argc, char *argv[]) +{ +int opt; +char *remote_host = REMOTE_HOST; +char *remote_port = REMOTE_PORT; +lo_address loaddr; +FILE *fp; + +/* parsing command line options */ +while ((opt = getopt(argc, argv, "hp:r:vI:")) != -1) { + switch (opt) { + case 'h': help(0); break; + case 'r': remote_host = optarg; break; + case 'p': remote_port = optarg; break; + case 'v': verbosity++; break; + case 'I': my_id = optarg; break; + default: exit(1); + } + } + +if (optind >= argc) { + fprintf(stderr, "Expected a filename after options\n"); + exit(EXIT_FAILURE); + } + +loaddr = lo_address_new(remote_host, remote_port); +if (verbosity) { + fprintf(stderr, "%s (%s) is sending to %s:%s\n", + argv[0], my_id, remote_host, remote_port); + } + +if (NULL==(fp=fopen(argv[optind], "r"))) { + perror (argv[optind]); + exit(1); + } + +if (verbosity) fprintf(stderr, "now playing %s\n", argv[optind]); + +megaloop(fp, loaddr); + + +return 0; +} +/* ----------------------------------------------------------------- */