make -a per-device, it doesn't make sense to be per-midi-port since

if one port is open, then all ports must be opened.
This commit is contained in:
Alexandre Ratchov 2011-06-20 18:17:11 +02:00
parent 007a5ce2e1
commit 96eb11eaf9
5 changed files with 29 additions and 57 deletions

View File

@ -74,18 +74,16 @@ The options are as follows:
.It Fl a Ar flag
Control whether
.Nm
opens the audio device
.Pq Fl f
or the MIDI port
.Pq Fl q
only when needed or keeps it open all the time.
opens the audio device only when needed or keeps it open all the time.
This applies to MIDI ports controlling the device as well.
If the flag is
.Va on
then it is kept open all the time, ensuring no other program can steal it.
then the device is kept open all the time, ensuring no other program can
steal it.
If the flag is
.Va off ,
then it's automatically closed, allowing other programs to have direct
access to it, or corresponding audio or MIDI hardware to be disconnected.
access to the device, or the device to be disconnected.
The default is
.Va on .
.It Fl b Ar nframes
@ -322,7 +320,7 @@ On the command line,
per-device parameters
.Pq Fl abwz
must precede the device definition
.Pq Fl fq ,
.Pq Fl f ,
and per-stream parameters
.Pq Fl Ccehjmrtvx
must precede the stream definition

View File

@ -235,7 +235,6 @@ SLIST_HEAD(cfstrlist, cfstr);
struct cfmid {
SLIST_ENTRY(cfmid) entry;
char *path; /* static path (no need to copy it) */
int hold;
};
SLIST_HEAD(cfmidlist, cfmid);
@ -339,8 +338,8 @@ cfstr_add(struct cfstrlist *list, struct cfstr *cs, char *path)
SLIST_INSERT_HEAD(list, cs, entry);
}
struct cfmid *
cfmid_new(struct cfmid *templ)
void
cfmid_add(struct cfmidlist *list, char *path)
{
struct cfmid *cm;
@ -349,18 +348,6 @@ cfmid_new(struct cfmid *templ)
perror("malloc");
abort();
}
if (templ)
memcpy(cm, templ, sizeof(struct cfmid));
else {
cm->hold = 1;
}
cm->path = NULL;
return cm;
}
void
cfmid_add(struct cfmidlist *list, struct cfmid *cm, char *path)
{
cm->path = path;
SLIST_INSERT_HEAD(list, cm, entry);
}
@ -519,7 +506,6 @@ aucat_main(int argc, char **argv)
*/
cd = cfdev_new(NULL);
cs = cfstr_new(NULL);
cm = cfmid_new(NULL);
while ((c = getopt(argc, argv, "a:w:dnb:c:C:e:r:h:x:v:i:o:f:m:luq:s:U:L:t:j:z:")) != -1) {
switch (c) {
@ -601,14 +587,13 @@ aucat_main(int argc, char **argv)
nsock++;
break;
case 'a':
cm->hold = cd->hold = opt_onoff();
cd->hold = opt_onoff();
break;
case 'w':
cd->autovol = opt_onoff();
break;
case 'q':
cfmid_add(&cd->mids, cm, optarg);
cm = cfmid_new(cm);
cfmid_add(&cd->mids, optarg);
break;
case 'b':
cd->bufsz = strtonum(optarg, 1, RATE_MAX * 5, &str);
@ -688,7 +673,6 @@ aucat_main(int argc, char **argv)
free(cs);
free(cd);
}
free(cm);
/*
* Check modes and calculate "best" device parameters. Iterate over all
@ -768,7 +752,7 @@ aucat_main(int argc, char **argv)
while (!SLIST_EMPTY(&cd->mids)) {
cm = SLIST_FIRST(&cd->mids);
SLIST_REMOVE_HEAD(&cd->mids, entry);
if (!devctl_add(d, cm->path, cm->hold, MODE_MIDIMASK))
if (!devctl_add(d, cm->path, MODE_MIDIMASK))
errx(1, "%s: can't open port", cm->path);
free(cm);
}
@ -925,7 +909,6 @@ midicat_main(int argc, char **argv)
*/
cs = cfstr_new(NULL);
cd = cfdev_new(NULL);
cm = cfmid_new(NULL);
while ((c = getopt(argc, argv, "di:o:ls:a:q:U:L:")) != -1) {
switch (c) {
@ -945,11 +928,10 @@ midicat_main(int argc, char **argv)
cs = cfstr_new(cs);
break;
case 'a':
cm->hold = opt_onoff();
cd->hold = opt_onoff();
break;
case 'q':
cfmid_add(&cd->mids, cm, optarg);
cm = cfmid_new(cm);
cfmid_add(&cd->mids, optarg);
break;
case 's':
cfstr_add(&cd->opts, cs, optarg);
@ -1000,19 +982,15 @@ midicat_main(int argc, char **argv)
if (SLIST_EMPTY(&cd->mids)) {
if (SLIST_EMPTY(&cd->ins) && SLIST_EMPTY(&cd->outs)) {
cfstr_add(&cd->opts, cs, DEFAULT_OPT);
free(cm);
nsock++;
} else {
cfmid_add(&cd->mids, cm, "default");
cfmid_add(&cd->mids, "default");
free(cs);
}
} else {
free(cm);
} else
free(cs);
}
cfdev_add(&cfdevs, cd, "default");
} else {
free(cm);
free(cs);
free(cd);
}
@ -1028,7 +1006,7 @@ midicat_main(int argc, char **argv)
cd = SLIST_FIRST(&cfdevs);
SLIST_REMOVE_HEAD(&cfdevs, entry);
d = dev_new_thru();
d = dev_new_thru(cd->hold);
if (d == NULL)
errx(1, "%s: can't open device", cd->path);
if (SLIST_EMPTY(&cd->opts) && APROC_OK(d->midi))
@ -1040,7 +1018,7 @@ midicat_main(int argc, char **argv)
while (!SLIST_EMPTY(&cd->mids)) {
cm = SLIST_FIRST(&cd->mids);
SLIST_REMOVE_HEAD(&cd->mids, entry);
if (!devctl_add(d, cm->path, cm->hold, MODE_MIDIMASK))
if (!devctl_add(d, cm->path, MODE_MIDIMASK))
errx(1, "%s: can't open port", cm->path);
free(cm);
}

View File

@ -183,7 +183,7 @@ dev_new_loop(struct aparams *dipar, struct aparams *dopar, unsigned bufsz)
* Create a MIDI thru box device
*/
struct dev *
dev_new_thru(void)
dev_new_thru(int hold)
{
struct dev *d;
@ -195,7 +195,7 @@ dev_new_thru(void)
d->ctl_list = NULL;
d->reqmode = MODE_MIDIMASK;
d->pstate = DEV_CLOSED;
d->hold = 0;
d->hold = hold;
d->path = "midithru";
d->next = dev_list;
dev_list = d;
@ -206,21 +206,16 @@ dev_new_thru(void)
* Add a MIDI port to the device
*/
int
devctl_add(struct dev *d, char *name, int hold, unsigned mode)
devctl_add(struct dev *d, char *name, unsigned mode)
{
struct devctl *c;
if (hold) {
if (!dev_ref(d))
return 0;
}
c = malloc(sizeof(struct devctl));
if (c == NULL) {
perror("malloc");
exit(1);
}
c->path = name;
c->hold = hold;
c->mode = mode;
c->next = d->ctl_list;
d->ctl_list = c;

View File

@ -54,9 +54,8 @@ struct dev {
struct aproc *midi;
struct devctl {
struct devctl *next;
char *path;
unsigned mode;
int hold;
char *path;
} *ctl_list;
};
@ -68,12 +67,12 @@ void dev_unref(struct dev *);
void dev_del(struct dev *);
void dev_wakeup(struct dev *);
void dev_drain(struct dev *);
struct dev *dev_new_thru(void);
struct dev *dev_new_thru(int);
struct dev *dev_new_loop(struct aparams *, struct aparams *, unsigned);
struct dev *dev_new_sio(char *, unsigned,
struct aparams *, struct aparams *,
unsigned, unsigned, unsigned, unsigned);
int devctl_add(struct dev *, char *, int, unsigned);
int devctl_add(struct dev *, char *, unsigned);
void dev_midiattach(struct dev *, struct abuf *, struct abuf *);
unsigned dev_roundof(struct dev *, unsigned);
int dev_getpos(struct dev *);

View File

@ -51,14 +51,16 @@ The options are as follows:
.It Fl a Ar flag
Control whether
.Nm
opens the MIDI port only when needed or keeps it open all the time.
opens all MIDI ports connected to the thru box only when needed
or keeps them open all the time.
If the flag is
.Va on
then it is kept open all the time, ensuring no other program can steal it.
then MIDI ports are are kept open all the time, ensuring no other program can
steal any of them.
If the flag is
.Va off ,
then it's automatically closed, allowing other programs to have direct
access to it, or the corresponding MIDI hardware to be disconnected.
then they are automatically closed, allowing other programs to have direct
access to MIDI ports, or the corresponding hardware to be disconnected.
The default is
.Va on .
.It Fl d