diff options
author | Alexandre Ratchov <ratchov@cvs.openbsd.org> | 2020-04-25 05:03:55 +0000 |
---|---|---|
committer | Alexandre Ratchov <ratchov@cvs.openbsd.org> | 2020-04-25 05:03:55 +0000 |
commit | 39ce76c140bacee0a2d8db3f229dc75d60721293 (patch) | |
tree | 06a2723c87c764dd5a338f45a9a14f7f9fa72e1d /usr.bin | |
parent | 49573da5e8072105aced00f1486dbbf42f093c68 (diff) |
Get a reference to the device when "snd/N" MIDI ports are opened
As the master output level control is not in software any longer the
device needs to opened for adjustments to work.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/sndiod/midi.c | 21 | ||||
-rw-r--r-- | usr.bin/sndiod/midi.h | 3 | ||||
-rw-r--r-- | usr.bin/sndiod/sock.c | 11 |
3 files changed, 32 insertions, 3 deletions
diff --git a/usr.bin/sndiod/midi.c b/usr.bin/sndiod/midi.c index d84bd3aa971..d3bd018de32 100644 --- a/usr.bin/sndiod/midi.c +++ b/usr.bin/sndiod/midi.c @@ -1,4 +1,4 @@ -/* $OpenBSD: midi.c,v 1.23 2020/01/23 05:27:17 ratchov Exp $ */ +/* $OpenBSD: midi.c,v 1.24 2020/04/25 05:03:54 ratchov Exp $ */ /* * Copyright (c) 2008-2012 Alexandre Ratchov <alex@caoua.org> * @@ -190,6 +190,25 @@ midi_tag(struct midi *ep, unsigned int tag) } /* + * return the list of tags + */ +unsigned int +midi_tags(struct midi *ep) +{ + int i; + struct midithru *t; + unsigned int tags; + + tags = 0; + for (i = 0; i < MIDITHRU_NMAX; i++) { + t = midithru + i; + if ((t->txmask | t->rxmask) & ep->self) + tags |= 1 << i; + } + return tags; +} + +/* * broadcast the given message to other endpoints */ void diff --git a/usr.bin/sndiod/midi.h b/usr.bin/sndiod/midi.h index 15d293597f4..bdcc2b7d7e0 100644 --- a/usr.bin/sndiod/midi.h +++ b/usr.bin/sndiod/midi.h @@ -1,4 +1,4 @@ -/* $OpenBSD: midi.h,v 1.11 2020/01/23 05:27:17 ratchov Exp $ */ +/* $OpenBSD: midi.h,v 1.12 2020/04/25 05:03:54 ratchov Exp $ */ /* * Copyright (c) 2008-2012 Alexandre Ratchov <alex@caoua.org> * @@ -110,6 +110,7 @@ void midi_out(struct midi *, unsigned char *, int); void midi_send(struct midi *, unsigned char *, int); void midi_fill(struct midi *); void midi_tag(struct midi *, unsigned int); +unsigned int midi_tags(struct midi *); void midi_link(struct midi *, struct midi *); void port_log(struct port *); diff --git a/usr.bin/sndiod/sock.c b/usr.bin/sndiod/sock.c index b4a3abe92d2..be38edaa71f 100644 --- a/usr.bin/sndiod/sock.c +++ b/usr.bin/sndiod/sock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sock.c,v 1.33 2020/03/08 14:52:20 ratchov Exp $ */ +/* $OpenBSD: sock.c,v 1.34 2020/04/25 05:03:54 ratchov Exp $ */ /* * Copyright (c) 2008-2012 Alexandre Ratchov <alex@caoua.org> * @@ -129,7 +129,9 @@ sock_log(struct sock *f) void sock_close(struct sock *f) { + struct dev *d; struct sock **pf; + unsigned int tags, i; for (pf = &sock_list; *pf != f; pf = &(*pf)->next) { #ifdef DEBUG @@ -154,6 +156,11 @@ sock_close(struct sock *f) f->slot = NULL; } if (f->midi) { + tags = midi_tags(f->midi); + for (i = 0; i < DEV_NMAX; i++) { + if ((tags & (1 << i)) && (d = dev_bynum(i)) != NULL) + dev_unref(d); + } midi_del(f->midi); f->midi = NULL; } @@ -860,6 +867,8 @@ sock_hello(struct sock *f) d = dev_bynum(p->devnum); if (d == NULL) return 0; + if (!dev_ref(d)) + return 0; midi_tag(f->midi, p->devnum); } else if (p->devnum < 32) { midi_tag(f->midi, p->devnum); |