Index | Thread | Search

From:
Alexandre Ratchov <alex@caoua.org>
Subject:
sndiod: Unify "midithru/N" and "midi/N" ports
To:
tech@openbsd.org
Date:
Wed, 12 Aug 2026 14:31:33 +0200

Download raw body.

Thread
  • Alexandre Ratchov:

    sndiod: Unify "midithru/N" and "midi/N" ports

This diff adds the new -p option, which is the same as -s, but for
MIDI: Basically, "-p foo" will register a MIDI port that programs can
access as "midi/foo"; it has the same functionnality as the
"midithru/N" ports. The new default MIDI port becomes "midi/default",
which is automatically created (similarly to the default audio
device).

This is simpler and reduces the differences between audio and MIDI
handling.

The "midithru/N" ports are left as an useless complication that can go
away, so we can drop support for them. To make upgrades smoother,
device names like "midithru/0" will continue to work during the next
few releases.

OK?

Index: lib/libsndio/mio.c
===================================================================
RCS file: /cvs/src/lib/libsndio/mio.c,v
diff -u -p -r1.23 mio.c
--- lib/libsndio/mio.c	29 Jun 2019 06:05:26 -0000	1.23
+++ lib/libsndio/mio.c	12 Aug 2026 11:55:46 -0000
@@ -48,7 +48,7 @@ mio_open(const char *str, unsigned int m
 			str = portany;
 	}
 	if (strcmp(str, portany) == 0) {
-		hdl = _mio_aucat_open("midithru/0", mode, nbio);
+		hdl = _mio_aucat_open("midi/default", mode, nbio);
 		if (hdl != NULL)
 			return hdl;
 		return _mio_rmidi_open("rmidi/0", mode, nbio);
Index: lib/libsndio/sndio.7
===================================================================
RCS file: /cvs/src/lib/libsndio/sndio.7,v
diff -u -p -r1.27 sndio.7
--- lib/libsndio/sndio.7	1 Nov 2021 14:43:24 -0000	1.27
+++ lib/libsndio/sndio.7	12 Aug 2026 11:55:46 -0000
@@ -77,13 +77,10 @@ how to access the audio device or MIDI p
 The type of the audio device or MIDI port.
 Possible values are:
 .Pp
-.Bl -tag -width "midithru" -offset 3n -compact
+.Bl -tag -width "rmidi" -offset 3n -compact
 .It Cm snd
 Audio device exposed by
 .Xr sndiod 8 .
-.It Cm midithru
-MIDI thru port created with
-.Xr sndiod 8 .
 .It Cm midi
 MIDI port exposed by
 .Xr sndiod 8 .
@@ -112,8 +109,10 @@ option on the
 .Xr sndiod 8
 command line.
 .It Ar option
-Corresponds to the sub-device string registered using the
+Corresponds to the string registered using the
 .Fl s
+or
+.Fl p
 option of
 .Xr sndiod 8 .
 .El
@@ -159,7 +158,7 @@ the program uses the one specified in th
 .Ev MIDIDEVICE
 environment variable.
 If it is not set, the program first tries to connect to
-.Li midithru/0 .
+.Li midi/default .
 If that fails, it then tries to use
 .Li rmidi/0 .
 As long as
@@ -215,7 +214,7 @@ Raw audio devices.
 Raw MIDI ports.
 .El
 .Sh EXAMPLES
-.Bl -tag -width "midithru/0" -compact
+.Bl -tag -width "midi/synth" -compact
 .It Li snd/0
 Audio device referred to by the first
 .Fl f
@@ -224,9 +223,9 @@ option of
 .It Li snd/rear
 Sub-device registered with
 .Dq -s rear .
-.It Li midithru/0
-First MIDI thru port created with
-.Xr sndiod 8 .
+.It Li midi/synth
+MIDI thru port registered with
+.Dq -p synth .
 .It Li default
 Default audio or MIDI device.
 .It Li rsnd/0
Index: usr.bin/sndiod/sndiod.8
===================================================================
RCS file: /cvs/src/usr.bin/sndiod/sndiod.8,v
diff -u -p -r1.22 sndiod.8
--- usr.bin/sndiod/sndiod.8	22 Jun 2026 14:15:26 -0000	1.22
+++ usr.bin/sndiod/sndiod.8	12 Aug 2026 11:55:46 -0000
@@ -34,6 +34,7 @@
 .Op Fl j Ar flag
 .Op Fl L Ar addr
 .Op Fl m Ar mode
+.Op Fl p Ar name
 .Op Fl q Ar port
 .Op Fl r Ar rate
 .Op Fl s Ar name
@@ -262,6 +263,19 @@ Multiple modes can be specified, separat
 The default is
 .Ar play , Ns Ar rec
 (i.e. full-duplex).
+.It Fl p Ar name
+Add
+.Ar name
+to the list of MIDI thru ports to expose.
+This allows clients to send MIDI messages to each other or to
+hardware MIDI ports.
+The given
+.Ar name
+corresponds to the
+.Dq option
+part of the
+.Xr sndio 7
+MIDI port name string.
 .It Fl q Ar port
 Expose the given MIDI port.
 This allows multiple programs to share the port.
Index: usr.bin/sndiod/sndiod.c
===================================================================
RCS file: /cvs/src/usr.bin/sndiod/sndiod.c,v
diff -u -p -r1.61 sndiod.c
--- usr.bin/sndiod/sndiod.c	12 Aug 2026 11:01:26 -0000	1.61
+++ usr.bin/sndiod/sndiod.c	12 Aug 2026 11:55:46 -0000
@@ -522,7 +522,7 @@ main(int argc, char **argv)
 	p = NULL;
 
 	while ((c = getopt(argc, argv,
-	    "a:b:c:C:de:F:f:j:L:m:Q:q:r:s:t:U:v:w:x:z:")) != -1) {
+	    "a:b:c:C:de:F:f:j:L:m:Q:p:q:r:s:t:U:v:w:x:z:")) != -1) {
 		switch (c) {
 		case 'd':
 			log_level++;
@@ -578,6 +578,11 @@ main(int argc, char **argv)
 				mode, vol, mmc, dup) == NULL)
 				return 1;
 			break;
+		case 'p':
+			if (!ckname(optarg))
+				return 1;
+			midithru_new(optarg);
+			break;
 		case 'q':
 		case 'Q':
 			p = mkport(optarg, hold);
@@ -666,6 +671,9 @@ main(int argc, char **argv)
 		if (o == NULL)
 			return 1;
 	}
+
+	if (!midithru_byname("default"))
+		midithru_new("default");
 
 	/*
 	 * For each device create an anonymous sub-device using
Index: usr.bin/sndiod/sock.c
===================================================================
RCS file: /cvs/src/usr.bin/sndiod/sock.c,v
diff -u -p -r1.69 sock.c
--- usr.bin/sndiod/sock.c	12 Aug 2026 10:58:19 -0000	1.69
+++ usr.bin/sndiod/sock.c	12 Aug 2026 11:55:46 -0000
@@ -759,6 +759,12 @@ sock_hello(struct sock *f)
 			return 0;
 		break;
 	case AMSG_TYPE_MIDITHRU:
+		/*
+		 * Make legacy "midithru/0" an alias to "midi/default"
+		 */
+		if (strcmp("default-0", name) == 0)
+			strlcpy(name, "default", sizeof(name));
+		/* FALLTHROUGH */
 	case AMSG_TYPE_MIDI:
 		midithru = midithru_byname(name);
 		if (midithru == NULL)