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 For audio devices or MIDI ports created with
.Xr sndiod 1 .Xr sndiod 1
it corresponds to the number of the corresponding it corresponds to the number of the corresponding
.Fl fM .Fl fq
option on the command line. option on the command line.
.It Pa option .It Pa option
Corresponds to the sub-device string registered using the Corresponds to the sub-device string registered using the

View File

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

View File

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

View File

@ -350,29 +350,22 @@ to which they are attached.
.Pp .Pp
If no audio devices If no audio devices
.Pq Fl f .Pq Fl f
are specified, are specified, first 4 audio devices are added and
settings are applied as if settings are applied to all of them.
the default device is specified. 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 If no sub-devices
.Pq Fl s .Pq Fl s
are specified for a device, a default sub-device is are specified for a device, a default sub-device is
created attached to it. created attached to it.
If a device If a device or MIDI port
.Pq Fl f .Pq Fl fq
is defined twice, both definitions are merged: is defined twice, both definitions are merged:
parameters of the first one are used but sub-devices parameters of the first one are used but sub-devices
.Pq Fl s .Pq Fl s
of both definitions are created. 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 .Pp
If If
.Nm .Nm

View File

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