diff options
author | Alexandre Ratchov <ratchov@cvs.openbsd.org> | 2009-07-25 08:44:28 +0000 |
---|---|---|
committer | Alexandre Ratchov <ratchov@cvs.openbsd.org> | 2009-07-25 08:44:28 +0000 |
commit | 0844fac57a53bca70c73354af3517b8bea149328 (patch) | |
tree | 38194a88aaef0f05f48c3bc6df1dec993ead1163 /lib/libsndio/sndio.c | |
parent | 8c4eca591954bdaedc99cf39f7f3f83fdc5ae579 (diff) |
Currently midi capable programs can control midi hardware, but
cannot cooperate with other programs. The aim of this change is
to allow any program to send midi data to other programs as they
were midi hardware. For instance, this change should solve the
longstanding problem of using a midi sequencer with software
synthesizers. More precisely:
- new midicat(1) utility (actually hardlink to aucat(1)).
it creates software midi thru boxes, allowing programs
to send midi messages to other programs as they were
midi(4) hardware.
- new midi api in libsndio (see mio_open(3)), to access
midi(4) devices and midicat(1) sockets in a uniform way.
- new device naming scheme <service>:<unit>[.<option>],
common to audio and midi.
- new sndio(7) manual describing concepts and naming
The current audio device naming still works, but people having
scripts or configuration files containing device names could read
the sndio(7) man page and slowly start updating device names.
discussed with jakemsr@ and deraadt@, help form jmc@
Diffstat (limited to 'lib/libsndio/sndio.c')
-rw-r--r-- | lib/libsndio/sndio.c | 46 |
1 files changed, 38 insertions, 8 deletions
diff --git a/lib/libsndio/sndio.c b/lib/libsndio/sndio.c index 6656cc67bb1..c7ab3750c81 100644 --- a/lib/libsndio/sndio.c +++ b/lib/libsndio/sndio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sndio.c,v 1.15 2009/05/15 13:04:52 ratchov Exp $ */ +/* $OpenBSD: sndio.c,v 1.16 2009/07/25 08:44:27 ratchov Exp $ */ /* * Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org> * @@ -17,6 +17,7 @@ #include <sys/param.h> #include <sys/types.h> #include <sys/time.h> +#include <sys/stat.h> #include <errno.h> #include <fcntl.h> #include <poll.h> @@ -163,11 +164,15 @@ done: return p - istr; } - struct sio_hdl * sio_open(char *str, unsigned mode, int nbio) { + static char prefix_aucat[] = "aucat"; + static char prefix_sun[] = "sun"; struct sio_hdl *hdl; + struct stat sb; + char *sep, buf[NAME_MAX]; + int len; #ifdef DEBUG char *dbg; @@ -181,12 +186,37 @@ sio_open(char *str, unsigned mode, int nbio) return NULL; if (str == NULL && !issetugid()) str = getenv("AUDIODEVICE"); - hdl = sio_open_aucat(str, mode, nbio); - if (hdl != NULL) - return hdl; - hdl = sio_open_sun(str, mode, nbio); - if (hdl != NULL) - return hdl; + if (str == NULL) { + hdl = sio_open_aucat("0", mode, nbio); + if (hdl != NULL) + return hdl; + if (stat("/dev/audio", &sb) == 0 && S_ISCHR(sb.st_mode)) { + snprintf(buf, sizeof(buf), "%u", + minor(sb.st_rdev) & 0xf); + } else + strlcpy(buf, "0", sizeof(buf)); + return sio_open_sun(buf, mode, nbio); + } + sep = strchr(str, ':'); + if (sep == NULL) { + /* + * try legacy "/dev/audioxxx" or ``socket'' device name + */ + if (stat(str, &sb) < 0 || !S_ISCHR(sb.st_mode)) { + snprintf(buf, sizeof(buf), "0.%s", str); + return sio_open_aucat(buf, mode, nbio); + } + snprintf(buf, sizeof(buf), "%u", minor(sb.st_rdev) & 0xf); + return sio_open_sun(buf, mode, nbio); + } + len = sep - str; + if (len == strlen(prefix_aucat) && + memcmp(str, prefix_aucat, len) == 0) + return sio_open_aucat(sep + 1, mode, nbio); + if (len == strlen(prefix_sun) && + memcmp(str, prefix_sun, len) == 0) + return sio_open_sun(sep + 1, mode, nbio); + DPRINTF("sio_open: %s: unknown device type\n", str); return NULL; } |