As aucat was simplified, base system lost the ability to move midi
data from one port to another; for instance to connect a midi
keyboard to a synth.
The diff below adds the midicat utility which I used last few
months to test/debug my midi setup and to connect my keyboard to a
my synth. Example:
midicat -i rmidi/0 -o rmidi/1
I could provide a diff to add this to the ports tree, if it's a
more appropriate place for it.
Thoughts? Other ideas? OKs?
--- usr.bin/Makefile.orig Sat Jul 18 04:01:36 2015
+++ usr.bin/Makefile Sun Aug 30 20:12:02 2015
@@ -13,7 +13,7 @@ SUBDIR= apply arch at aucat audioctl awk banner \
join jot kdump keynote ktrace lam last lastcomm leave less lex \
libtool lndir \
locale locate lock logger login logname look lorder \
- m4 mail make mandoc mesg mg \
+ m4 mail make mandoc mesg mg midicat \
midiplay mixerctl mkdep mklocale mktemp nc netstat \
newsyslog \
nfsstat nice nm nl nohup openssl pagesize passwd paste patch pctr \
--- /dev/null Sun Aug 30 20:18:05 2015
+++ usr.bin/midicat/midicat.1 Sun Aug 30 20:15:12 2015
@@ -0,0 +1,65 @@
+.\" $OpenBSD$
+.\"
+.\" Copyright (c) 2015 Alexandre Ratchov <[email protected]>
+.\"
+.\" 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 >/dev/null
+.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
--- /dev/null Sun Aug 30 20:18:05 2015
+++ usr.bin/midicat/midicat.c Sun Aug 30 20:09:37 2015
@@ -0,0 +1,112 @@
+/*
+ * Copyright (c) 2015 Alexandre Ratchov <[email protected]>
+ *
+ * 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 <sndio.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.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, 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;
+}
--- /dev/null Sun Aug 30 20:18:05 2015
+++ usr.bin/midicat/Makefile Sun Aug 30 20:18:02 2015
@@ -0,0 +1,6 @@
+# $OpenBSD$
+
+PROG= midicat
+MAN= midicat.1
+LDADD+= -lsndio
+.include <bsd.prog.mk>