mirror of https://github.com/ericonr/sndio.git
add midicat
This commit is contained in:
parent
4717cf976d
commit
dfa1d3dd8c
|
@ -5,6 +5,7 @@ all:
|
|||
cd sndiod && ${MAKE}
|
||||
cd sndioctl && ${MAKE}
|
||||
cd aucat && ${MAKE}
|
||||
cd midicat && ${MAKE}
|
||||
if [ ${XVOLKEYS} = yes ]; then cd xvolkeys && ${MAKE}; fi
|
||||
|
||||
install:
|
||||
|
@ -12,17 +13,20 @@ install:
|
|||
cd sndiod && ${MAKE} install
|
||||
cd sndioctl && ${MAKE} install
|
||||
cd aucat && ${MAKE} install
|
||||
cd midicat && ${MAKE} install
|
||||
if [ ${XVOLKEYS} = yes ]; then cd xvolkeys && ${MAKE} install; fi
|
||||
|
||||
uninstall:
|
||||
cd xvolkeys && ${MAKE} uninstall
|
||||
cd aucat && ${MAKE} uninstall
|
||||
cd midicat && ${MAKE} uninstall
|
||||
cd aucat && ${MAKE} uninstall
|
||||
cd sndioctl && ${MAKE} uninstall
|
||||
cd sndiod && ${MAKE} uninstall
|
||||
cd libsndio && ${MAKE} uninstall
|
||||
|
||||
clean:
|
||||
cd aucat && ${MAKE} clean
|
||||
cd midicat && ${MAKE} clean
|
||||
cd sndioctl && ${MAKE} clean
|
||||
cd sndiod && ${MAKE} clean
|
||||
cd libsndio && ${MAKE} clean
|
||||
|
@ -31,7 +35,7 @@ clean:
|
|||
|
||||
distclean: clean
|
||||
rm -f \
|
||||
Makefile aucat/Makefile sndiod/Makefile \
|
||||
Makefile aucat/Makefile midicat/Makefile sndiod/Makefile \
|
||||
libsndio/Makefile sndioctl/Makefile \
|
||||
xvolkeys/Makefile \
|
||||
examples/Makefile \
|
||||
|
|
|
@ -183,7 +183,7 @@ if [ $rmidi = yes ]; then
|
|||
defs="$defs -DUSE_RMIDI"
|
||||
fi
|
||||
|
||||
for f in Makefile aucat/Makefile sndiod/Makefile \
|
||||
for f in Makefile aucat/Makefile midicat/Makefile sndiod/Makefile \
|
||||
libsndio/Makefile sndioctl/Makefile xvolkeys/Makefile \
|
||||
examples/Makefile \
|
||||
contrib/init.d.sndiod
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
# extra includes paths (-I options)
|
||||
INCLUDE = -I../libsndio -I../bsd-compat
|
||||
|
||||
# extra libraries paths (-L options)
|
||||
LIB = -L../libsndio
|
||||
|
||||
# extra defines (-D options)
|
||||
DEFS = -DDEBUG @defs@
|
||||
|
||||
# extra libraries (-l options)
|
||||
LDADD = -lsndio @ldadd@
|
||||
|
||||
# variables defined on configure script command line (if any)
|
||||
@vars@
|
||||
|
||||
#
|
||||
# binaries, documentation, man pages and examples will be installed in
|
||||
# ${BIN_DIR}, ${MAN1_DIR}
|
||||
#
|
||||
BIN_DIR = @bindir@
|
||||
MAN1_DIR = @mandir@/man1
|
||||
|
||||
#
|
||||
# programs to build
|
||||
#
|
||||
PROG = midicat
|
||||
MAN1 = midicat.1
|
||||
|
||||
all: ${PROG} ${MAN1}
|
||||
|
||||
install:
|
||||
mkdir -p ${DESTDIR}${BIN_DIR} ${DESTDIR}${MAN1_DIR}
|
||||
cp midicat ${DESTDIR}${BIN_DIR}
|
||||
cp midicat.1 ${DESTDIR}${MAN1_DIR}
|
||||
|
||||
uninstall:
|
||||
cd ${DESTDIR}${BIN_DIR} && rm -f ${PROG}
|
||||
cd ${DESTDIR}${MAN1_DIR} && rm -f ${MAN1}
|
||||
|
||||
clean:
|
||||
rm -f -- *.o midicat
|
||||
|
||||
# ---------------------------------------------------------- dependencies ---
|
||||
|
||||
OBJS = midicat.o
|
||||
|
||||
midicat: ${OBJS}
|
||||
${CC} ${LDFLAGS} ${LIB} -o midicat ${OBJS} ${LDADD}
|
||||
|
||||
.c.o:
|
||||
${CC} ${CFLAGS} ${INCLUDE} ${DEFS} -c $<
|
||||
|
||||
midicat.o: midicat.c
|
|
@ -0,0 +1,65 @@
|
|||
.\" $OpenBSD$
|
||||
.\"
|
||||
.\" Copyright (c) 2015 Alexandre Ratchov <alex@caoua.org>
|
||||
.\"
|
||||
.\" Permission to use, copy, modify, and distribute this software for any
|
||||
.\" purpose with or without fee is hereby granted, provided that the above
|
||||
.\" copyright notice and this permission notice appear in all copies.
|
||||
.\"
|
||||
.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
.\"
|
||||
.Dd $Mdocdate$
|
||||
.Dt MIDICAT 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm midicat
|
||||
.Nd send to or receive from MIDI ports.
|
||||
.Sh SYNOPSIS
|
||||
.Nm midicat
|
||||
.Bk -words
|
||||
.Op Fl d
|
||||
.Op Fl i Ar port
|
||||
.Op Fl o Ar port
|
||||
.Ek
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm
|
||||
utility receives MIDI data from the given input MIDI port and/or
|
||||
sends it to the given output MIDI port.
|
||||
The options are as follows:
|
||||
.Bl -tag -width Ds
|
||||
.It Fl d
|
||||
Dump transferred data in hex on stderr.
|
||||
.It Fl i Ar port
|
||||
Use this
|
||||
.Xr sndio 7
|
||||
MIDI port as input instead of stdin.
|
||||
.It Fl o Ar port
|
||||
Use this
|
||||
.Xr sndio 7
|
||||
MIDI port as output instead of stdout.
|
||||
.El
|
||||
.Sh EXAMPLES
|
||||
Dump data received from
|
||||
.Pa rmidi/0
|
||||
to stderr:
|
||||
.Bd -literal -offset indent
|
||||
$ midicat -di rmidi/0
|
||||
.Ed
|
||||
.Pp
|
||||
Send data from
|
||||
.Pa rmidi/0
|
||||
to
|
||||
.Pa midithru/0:
|
||||
.Bd -literal -offset indent
|
||||
$ midicat -i rmidi/0 -o midithru/0
|
||||
.Ed
|
||||
.Sh SEE ALSO
|
||||
.Xr midi 4 ,
|
||||
.Xr sndio 7
|
|
@ -0,0 +1,118 @@
|
|||
/*
|
||||
* Copyright (c) 2008-2014 Alexandre Ratchov <alex@caoua.org>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <poll.h>
|
||||
#include <signal.h>
|
||||
#include <sndio.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include "bsd-compat.h"
|
||||
|
||||
char usagestr[] = "usage: midicat [-d] [-i port] [-o port]\n";
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
#define MIDI_BUFSZ 1024
|
||||
unsigned char buf[MIDI_BUFSZ];
|
||||
struct mio_hdl *ih, *oh;
|
||||
char *in, *out;
|
||||
int dump, conn, c, i, len, sep;
|
||||
|
||||
dump = 0;
|
||||
in = NULL;
|
||||
out = NULL;
|
||||
ih = NULL;
|
||||
oh = NULL;
|
||||
|
||||
while ((c = getopt(argc, argv, "di:o:")) != -1) {
|
||||
switch (c) {
|
||||
case 'd':
|
||||
dump = 1;
|
||||
break;
|
||||
case 'i':
|
||||
in = optarg;
|
||||
break;
|
||||
case 'o':
|
||||
out = optarg;
|
||||
break;
|
||||
default:
|
||||
goto bad_usage;
|
||||
}
|
||||
}
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
if (argc != 0) {
|
||||
bad_usage:
|
||||
fputs(usagestr, stderr);
|
||||
return 1;
|
||||
}
|
||||
if (in == NULL && out == NULL) {
|
||||
fputs("either -i or -o required\n", stderr);
|
||||
exit(1);
|
||||
}
|
||||
if (in) {
|
||||
ih = mio_open(in, MIO_IN, 0);
|
||||
if (ih == NULL) {
|
||||
fprintf(stderr, "%s: couldn't open MIDI in\n", in);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
if (out) {
|
||||
oh = mio_open(out, MIO_OUT, 0);
|
||||
if (oh == NULL) {
|
||||
fprintf(stderr, "%s: couldn't open MIDI out\n", out);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
for (;;) {
|
||||
if (in) {
|
||||
len = mio_read(ih, buf, sizeof(buf));
|
||||
if (len == 0) {
|
||||
fprintf(stderr, "%s: disconnected\n", in);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
len = read(STDIN_FILENO, buf, sizeof(buf));
|
||||
if (len == 0)
|
||||
break;
|
||||
if (len < 0) {
|
||||
perror("stdin");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
if (out)
|
||||
mio_write(oh, buf, len);
|
||||
else
|
||||
write(STDOUT_FILENO, buf, len);
|
||||
if (dump) {
|
||||
for (i = 0; i < len; i++) {
|
||||
sep = (i % 16 == 15 || i == len - 1) ?
|
||||
'\n' : ' ';
|
||||
fprintf(stderr, "%02x%c", buf[i], sep);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (in)
|
||||
mio_close(ih);
|
||||
if (out)
|
||||
mio_close(oh);
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue