adding text2osc, need more cleanup

This commit is contained in:
tth 2019-08-25 16:51:36 +02:00
parent 03bdd5ab88
commit 517b381360
5 changed files with 160 additions and 0 deletions

1
.gitignore vendored
View File

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

View File

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

View File

@ -24,10 +24,12 @@
\section{Open Sound Control} \section{Open Sound Control}
De quoi parle-t-on exactement ? De quoi parle-t-on exactement ?
\vspace{1em}
% ------------------------------------------------------------------- % -------------------------------------------------------------------
\section{Example} \section{Example}
TODO\index{TODO}
% ------------------------------------------------------------------- % -------------------------------------------------------------------

View File

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

152
text2osc.c Normal file
View File

@ -0,0 +1,152 @@
/*
* WARNING, THIS IS JUST A WIP !
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <ctype.h>
#include <lo/lo.h>
#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;
}
/* ----------------------------------------------------------------- */