if no -f or -q are used, attach rsnd/[0-3] and rmidi/[0-7]

This commit is contained in:
Alexandre Ratchov 2015-10-20 15:25:54 +02:00
parent 56540a0d18
commit 8bb88f248f
5 changed files with 47 additions and 30 deletions

View File

@ -120,7 +120,7 @@ the character device minor number.
For audio devices or MIDI ports created with
.Xr sndiod 1
it corresponds to the number of the corresponding
.Fl fM
.Fl fq
option on the command line.
.It Pa option
Corresponds to the sub-device string registered using the

View File

@ -977,6 +977,7 @@ dev_new(char *path, struct aparams *par,
return NULL;
}
d = xmalloc(sizeof(struct dev));
d->path = xstrdup(path);
d->num = dev_sndnum++;
/*
@ -988,7 +989,6 @@ dev_new(char *path, struct aparams *par,
*/
d->midi = midi_new(&dev_midiops, d, MODE_MIDIIN | MODE_MIDIOUT);
midi_tag(d->midi, d->num);
d->path = path;
d->reqpar = *par;
d->reqmode = mode;
d->reqpchan = d->reqrchan = 0;
@ -1257,6 +1257,7 @@ dev_del(struct dev *d)
}
midi_del(d->midi);
*p = d->next;
xfree(d->path);
xfree(d);
}

View File

@ -430,7 +430,7 @@ port_new(char *path, unsigned int mode, int hold)
struct port *c, **pc;
c = xmalloc(sizeof(struct port));
c->path = path;
c->path = xstrdup(path);
c->state = PORT_CFG;
c->hold = hold;
c->midi = midi_new(&port_midiops, c, mode);
@ -462,6 +462,7 @@ port_del(struct port *c)
#endif
}
*p = c->next;
xfree(c->path);
xfree(c);
}

View File

@ -350,29 +350,22 @@ to which they are attached.
.Pp
If no audio devices
.Pq Fl f
are specified,
settings are applied as if
the default device is specified.
are specified, first 4 audio devices are added and
settings are applied to all of them.
Similarly, if no MIDI ports
.Pq Fl q
are specified, first 8 MIDI ports are added and
settings are applied to all of them.
If no sub-devices
.Pq Fl s
are specified for a device, a default sub-device is
created attached to it.
If a device
.Pq Fl f
If a device or MIDI port
.Pq Fl fq
is defined twice, both definitions are merged:
parameters of the first one are used but sub-devices
.Pq Fl s
of both definitions are created.
The default
.Xr sndio 7
device used by
.Nm
is
.Pa rsnd/0 ,
and the default sub-device exposed by
.Nm
is
.Pa snd/0 .
.Pp
If
.Nm

View File

@ -314,6 +314,21 @@ mkdev(char *path, struct aparams *par,
return d;
}
struct port *
mkport(char *path, int hold)
{
struct port *c;
for (c = port_list; c != NULL; c = c->next) {
if (strcmp(c->path, path) == 0)
return c;
}
c = port_new(path, MODE_MIDIMASK, hold);
if (c == NULL)
exit(1);
return c;
}
struct opt *
mkopt(char *path, struct dev *d,
int pmin, int pmax, int rmin, int rmax,
@ -335,7 +350,8 @@ main(int argc, char **argv)
int c, background, unit;
int pmin, pmax, rmin, rmax;
char base[SOCKPATH_MAX], path[SOCKPATH_MAX];
unsigned int mode, dup, mmc, vol;
char loc[32];
unsigned int mode, dup, mmc, vol, i;
unsigned int hold, autovol, bufsz, round, rate;
const char *str;
struct aparams par;
@ -414,16 +430,14 @@ main(int argc, char **argv)
break;
case 's':
if ((d = dev_list) == NULL) {
d = mkdev(DEFAULT_DEV, &par, 0, bufsz, round, rate,
hold, autovol);
d = mkdev(DEFAULT_DEV, &par, 0, bufsz, round,
rate, hold, autovol);
}
mkopt(optarg, d, pmin, pmax, rmin, rmax,
mode, vol, mmc, dup);
break;
case 'q':
p = port_new(optarg, MODE_MIDIMASK, hold);
if (!p)
errx(1, "%s: can't open port", optarg);
mkport(optarg, hold);
break;
case 'a':
hold = opt_onoff();
@ -442,10 +456,8 @@ main(int argc, char **argv)
errx(1, "%s: block size is %s", optarg, str);
break;
case 'f':
mkdev(optarg, &par, 0, bufsz, round, rate, hold, autovol);
break;
case 'M':
/* XXX: for compatibility with aucat, remove this */
mkdev(optarg, &par, 0, bufsz, round,
rate, hold, autovol);
break;
default:
fputs(usagestr, stderr);
@ -458,8 +470,18 @@ main(int argc, char **argv)
fputs(usagestr, stderr);
return 1;
}
if (dev_list == NULL)
mkdev(DEFAULT_DEV, &par, 0, bufsz, round, rate, hold, autovol);
if (dev_list == NULL) {
for (i = 0; i < 4; i++) {
snprintf(loc, sizeof(loc), "rsnd/%u", i);
mkdev(loc, &par, 0, bufsz, round, rate, hold, autovol);
}
}
if (port_list == NULL) {
for (i = 0; i < 8; i++) {
snprintf(loc, sizeof(loc), "rmidi/%u", i);
mkport(loc, hold);
}
}
for (d = dev_list; d != NULL; d = d->next) {
if (opt_byname("default", d->num))
continue;