From 10777e22600f6cea8fba064ebbc50e6123f88c45 Mon Sep 17 00:00:00 2001 From: Alexandre Ratchov Date: Thu, 8 Nov 2018 11:25:39 +0100 Subject: [PATCH 1/6] Revert "midicat: Move midi write its own routine." This reverts commit ea55b2c67d511691eb4acd8b634633b4c515ae7a. --- midicat/midicat.c | 92 +++++++++++++++++++---------------------------- 1 file changed, 36 insertions(+), 56 deletions(-) diff --git a/midicat/midicat.c b/midicat/midicat.c index 8a053e0..2cc8bd7 100644 --- a/midicat/midicat.c +++ b/midicat/midicat.c @@ -21,59 +21,23 @@ #include #include "bsd-compat.h" -#define MIDI_BUFSZ 1024 - char usagestr[] = "usage: midicat [-d] [-i in-file] [-o out-file] " "[-q in-port] [-q out-port]\n"; -char *port0, *port1, *ifile, *ofile; -struct mio_hdl *ih, *oh; -unsigned char buf[MIDI_BUFSZ]; -int buf_used = 0; -int ifd = -1, ofd = -1; -int dump; - -static int -midi_flush(void) -{ - int i, n, sep; - - if (buf_used == 0) - return 1; - - if (ofile != NULL) { - n = write(ofd, buf, buf_used); - if (n != buf_used) { - fprintf(stderr, "%s: short write\n", ofile); - buf_used = 0; - return 0; - } - } else { - n = mio_write(oh, buf, buf_used); - if (n != buf_used) { - fprintf(stderr, "%s: port disconnected\n", - ih == oh ? port0 : port1); - buf_used = 0; - return 0; - } - } - - if (dump) { - for (i = 0; i < buf_used; i++) { - sep = (i % 16 == 15 || i == buf_used - 1) ? - '\n' : ' '; - fprintf(stderr, "%02x%c", buf[i], sep); - } - } - - buf_used = 0; - return 1; -} - int main(int argc, char **argv) { - int c, mode; +#define MIDI_BUFSZ 1024 + unsigned char buf[MIDI_BUFSZ]; + struct mio_hdl *ih, *oh; + char *port0, *port1, *ifile, *ofile; + int ifd, ofd; + int dump, c, i, len, n, sep, mode; + + dump = 0; + port0 = port1 = ifile = ofile = NULL; + ih = oh = NULL; + ifd = ofd = -1; while ((c = getopt(argc, argv, "di:o:q:")) != -1) { switch (c) { @@ -180,23 +144,39 @@ main(int argc, char **argv) /* transfer until end-of-file or error */ for (;;) { if (ifile != NULL) { - buf_used = read(ifd, buf, sizeof(buf)); - if (buf_used < 0) { + len = read(ifd, buf, sizeof(buf)); + if (len == 0) + break; + if (len < 0) { perror("stdin"); break; } - if (buf_used == 0) - break; - if (!midi_flush()) - break; } else { - buf_used = mio_read(ih, buf, sizeof(buf)); - if (buf_used == 0) { + len = mio_read(ih, buf, sizeof(buf)); + if (len == 0) { fprintf(stderr, "%s: disconnected\n", port0); break; } - if (!midi_flush()) + } + if (ofile != NULL) { + n = write(ofd, buf, len); + if (n != len) { + fprintf(stderr, "%s: short write\n", ofile); break; + } + } else { + n = mio_write(oh, buf, len); + if (n != len) { + fprintf(stderr, "%s: disconnected\n", port1); + break; + } + } + if (dump) { + for (i = 0; i < len; i++) { + sep = (i % 16 == 15 || i == len - 1) ? + '\n' : ' '; + fprintf(stderr, "%02x%c", buf[i], sep); + } } } From d9c44b2c2d374a13e79e13b47039677f83b1dafb Mon Sep 17 00:00:00 2001 From: Alexandre Ratchov Date: Thu, 21 Feb 2019 07:37:37 +0100 Subject: [PATCH 2/6] Remove guards for a zero length read or write requests. From miko@. --- libsndio/mio.c | 12 ------------ libsndio/sio.c | 8 -------- 2 files changed, 20 deletions(-) diff --git a/libsndio/mio.c b/libsndio/mio.c index 42f938c..95c89cc 100644 --- a/libsndio/mio.c +++ b/libsndio/mio.c @@ -141,10 +141,6 @@ mio_read(struct mio_hdl *hdl, void *buf, size_t len) hdl->eof = 1; return 0; } - if (len == 0) { - DPRINTF("mio_read: zero length read ignored\n"); - return 0; - } while (todo > 0) { n = hdl->ops->read(hdl, data, todo); if (n == 0 && hdl->eof) @@ -175,14 +171,6 @@ mio_write(struct mio_hdl *hdl, const void *buf, size_t len) hdl->eof = 1; return 0; } - if (len == 0) { - DPRINTF("mio_write: zero length write ignored\n"); - return 0; - } - if (todo == 0) { - DPRINTF("mio_write: zero length write ignored\n"); - return 0; - } while (todo > 0) { n = hdl->ops->write(hdl, data, todo); if (n == 0) { diff --git a/libsndio/sio.c b/libsndio/sio.c index 1f4c55c..b1e659c 100644 --- a/libsndio/sio.c +++ b/libsndio/sio.c @@ -311,10 +311,6 @@ sio_read(struct sio_hdl *hdl, void *buf, size_t len) hdl->eof = 1; return 0; } - if (todo == 0) { - DPRINTF("sio_read: zero length read ignored\n"); - return 0; - } while (todo > 0) { if (!sio_rdrop(hdl)) return 0; @@ -352,10 +348,6 @@ sio_write(struct sio_hdl *hdl, const void *buf, size_t len) hdl->eof = 1; return 0; } - if (todo == 0) { - DPRINTF("sio_write: zero length write ignored\n"); - return 0; - } while (todo > 0) { if (!sio_wsil(hdl)) return 0; From 16ae676f9e24612c80c8cf1291a3efa3506bc50d Mon Sep 17 00:00:00 2001 From: Alexandre Ratchov Date: Thu, 21 Feb 2019 07:39:56 +0100 Subject: [PATCH 3/6] Say that using sio_getcap() to negociate parameters is not recomended. From Paul Swanson , ok jmc --- libsndio/sio_open.3 | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/libsndio/sio_open.3 b/libsndio/sio_open.3 index b491e13..8c00880 100644 --- a/libsndio/sio_open.3 +++ b/libsndio/sio_open.3 @@ -284,6 +284,11 @@ Applications that need to have a set of working parameter combinations in advance can use the .Fn sio_getcap function. +However, for most new applications it's generally +not recommended to use +.Fn sio_getcap . +Instead, follow the recommendations for negotiating +device parameters (see above). .Pp The .Vt sio_cap @@ -367,6 +372,11 @@ structure, then the second element of the array of the .Vt sio_cap structure is valid for this configuration. +As such, when reading the array elements in the +.Vt sio_cap +structure, the corresponding +.Vt sio_conf +bitmasks should always be used. .El .Ss Starting and stopping the device The From d428027573a00b0c20a49ad2f8ae5d52904be0c6 Mon Sep 17 00:00:00 2001 From: Alexandre Ratchov Date: Thu, 21 Feb 2019 07:42:20 +0100 Subject: [PATCH 4/6] Tweak a space to reduce diff with OpenBSD. --- aucat/aucat.c | 1 + 1 file changed, 1 insertion(+) diff --git a/aucat/aucat.c b/aucat/aucat.c index bd3f59e..68293af 100644 --- a/aucat/aucat.c +++ b/aucat/aucat.c @@ -1165,6 +1165,7 @@ playrec(char *dev, int mode, int bufsz, char *port) if (dev_mh) n += mio_nfds(dev_mh); pfds = xmalloc(n * sizeof(struct pollfd)); + for (s = slot_list; s != NULL; s = s->next) slot_init(s); if (dev_mh == NULL) From 00910bf6fac242ca1b157f193947d70556a2447f Mon Sep 17 00:00:00 2001 From: Alexandre Ratchov Date: Thu, 21 Feb 2019 07:43:36 +0100 Subject: [PATCH 5/6] mio_open.3: "a" MIDI, not "an"; from jmc@ --- libsndio/mio_open.3 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsndio/mio_open.3 b/libsndio/mio_open.3 index 164560b..85870c2 100644 --- a/libsndio/mio_open.3 +++ b/libsndio/mio_open.3 @@ -53,7 +53,7 @@ library allows user processes to access hardware and .Xr sndiod 8 MIDI thru boxes and control ports in a uniform way. -.Ss Opening and closing an MIDI stream +.Ss Opening and closing a MIDI stream First the application must call the .Fn mio_open function to obtain a handle representing the newly created stream; From 2c97522b5a7d6749e963f63d51fa3a7ad2a29e41 Mon Sep 17 00:00:00 2001 From: Alexandre Ratchov Date: Thu, 21 Feb 2019 07:44:07 +0100 Subject: [PATCH 6/6] Sync midicat(1) manual to OpenBSD. --- midicat/midicat.1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/midicat/midicat.1 b/midicat/midicat.1 index bb95e1b..3725ebb 100644 --- a/midicat/midicat.1 +++ b/midicat/midicat.1 @@ -19,7 +19,7 @@ .Os .Sh NAME .Nm midicat -.Nd send to or receive from MIDI ports. +.Nd send to or receive from MIDI ports .Sh SYNOPSIS .Nm midicat .Bk -words @@ -75,7 +75,7 @@ $ midicat -d -q rmidi/0 -o /dev/null Send data from .Pa rmidi/0 to -.Pa midithru/0: +.Pa midithru/0 : .Bd -literal -offset indent $ midicat -q rmidi/0 -q midithru/0 .Ed