importing basic functions

This commit is contained in:
Tonton Th 2019-08-02 14:34:15 +02:00
parent 36d38c2a00
commit a817966104
11 changed files with 289 additions and 2 deletions

4
.gitignore vendored
View File

@ -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]

View File

@ -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 $@
# ----------------------------------------------------

View File

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

22
functions/Makefile Normal file
View File

@ -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 $@ $?

101
functions/alsaseq.c Normal file
View File

@ -0,0 +1,101 @@
/*
*
* code semi-grabed from the original asedump.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <alsa/asoundlib.h>
#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));
}
}
}
/* ----------------------------------------------------------------- */
/* ----------------------------------------------------------------- */
/* ----------------------------------------------------------------- */

13
functions/alsaseq.h Normal file
View File

@ -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);
/* ----------------------------------------------------------------- */

48
functions/senders.c Normal file
View File

@ -0,0 +1,48 @@
/*
* some functions for sending various data over the wire
*/
#include <stdio.h>
#include <lo/lo.h>
#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;
}
/* ----------------------------------------------------------------- */

13
functions/senders.h Normal file
View File

@ -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);
/* ------------------------------------------------------- */
/* ------------------------------------------------------- */

75
functions/serial.c Normal file
View File

@ -0,0 +1,75 @@
#include <stdio.h>
#include <stdlib.h>
#include <termios.h> /* serial things */
#include <unistd.h>
#include <fcntl.h>
#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;
}
/* ----------------------------------------------------------------- */
/* ----------------------------------------------------------------- */
/* ----------------------------------------------------------------- */

7
functions/serial.h Normal file
View File

@ -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);

View File

@ -14,7 +14,7 @@
#include <getopt.h>
#include <lo/lo.h>
#include "ncursefuncs.h"
#include "functions/ncursefuncs.h"
/* ----------------------------------------------------------------- */