Use device unit number for index.
The index number was too confusing such as 0: [ ] audio1 @ wss0 1: [*] audio0 @ yds0 in my PC for example. Here is new format: [*] audio0 @ yds0 [ ] audio1 @ wss0 In this style, devices are always listed in order of unit number and 0 always means audio0, 1 always means audio1.
This commit is contained in:
parent
ab49aa4fd6
commit
cb1e8d26ed
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: audiodev.c,v 1.9 2019/08/24 04:04:10 isaki Exp $ */
|
||||
/* $NetBSD: audiodev.c,v 1.10 2019/08/24 05:45:24 isaki Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010 Jared D. McNeill <jmcneill@invisible.ca>
|
||||
@ -48,6 +48,7 @@ static int audiodev_test_chmask(struct audiodev *, unsigned int,
|
||||
|
||||
static TAILQ_HEAD(audiodevhead, audiodev) audiodevlist =
|
||||
TAILQ_HEAD_INITIALIZER(audiodevlist);
|
||||
static unsigned int maxunit;
|
||||
|
||||
#define AUDIODEV_SAMPLE_RATE 44100
|
||||
|
||||
@ -138,6 +139,9 @@ audiodev_add(const char *pdev, const char *dev, unsigned int unit)
|
||||
|
||||
TAILQ_INSERT_TAIL(&audiodevlist, adev, next);
|
||||
|
||||
if (unit > maxunit)
|
||||
maxunit = unit;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -179,29 +183,22 @@ audiodev_refresh(void)
|
||||
}
|
||||
|
||||
unsigned int
|
||||
audiodev_count(void)
|
||||
audiodev_maxunit(void)
|
||||
{
|
||||
struct audiodev *adev;
|
||||
unsigned int n;
|
||||
|
||||
n = 0;
|
||||
TAILQ_FOREACH(adev, &audiodevlist, next)
|
||||
++n;
|
||||
|
||||
return n;
|
||||
return maxunit;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get audiodev corresponding to audio<i> device.
|
||||
*/
|
||||
struct audiodev *
|
||||
audiodev_get(unsigned int i)
|
||||
{
|
||||
struct audiodev *adev;
|
||||
unsigned int n;
|
||||
|
||||
n = 0;
|
||||
TAILQ_FOREACH(adev, &audiodevlist, next) {
|
||||
if (n == i)
|
||||
if (i == adev->unit)
|
||||
return adev;
|
||||
++n;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: audiodev.h,v 1.7 2019/08/24 04:04:10 isaki Exp $ */
|
||||
/* $NetBSD: audiodev.h,v 1.8 2019/08/24 05:45:25 isaki Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010 Jared D. McNeill <jmcneill@invisible.ca>
|
||||
@ -60,7 +60,7 @@ struct audiodev {
|
||||
};
|
||||
|
||||
int audiodev_refresh(void);
|
||||
unsigned int audiodev_count(void);
|
||||
unsigned int audiodev_maxunit(void);
|
||||
struct audiodev * audiodev_get(unsigned int);
|
||||
int audiodev_set_default(struct audiodev *);
|
||||
int audiodev_set_param(struct audiodev *, int,
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: main.c,v 1.11 2019/08/24 04:04:10 isaki Exp $ */
|
||||
/* $NetBSD: main.c,v 1.12 2019/08/24 05:45:25 isaki Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010 Jared D. McNeill <jmcneill@invisible.ca>
|
||||
@ -72,15 +72,15 @@ const char *encoding_names[] = {
|
||||
u_int encoding_max = __arraycount(encoding_names);
|
||||
|
||||
static void
|
||||
print_audiodev(struct audiodev *adev, int i)
|
||||
print_audiodev(struct audiodev *adev)
|
||||
{
|
||||
struct audiofmt *f;
|
||||
int j;
|
||||
|
||||
assert(adev != NULL);
|
||||
|
||||
printf("%u: [%c] %s @ %s: ",
|
||||
i, adev->defaultdev ? '*' : ' ',
|
||||
printf("[%c] %s @ %s: ",
|
||||
adev->defaultdev ? '*' : ' ',
|
||||
adev->xname, adev->pxname);
|
||||
printf("%s", adev->audio_device.name);
|
||||
if (strlen(adev->audio_device.version) > 0)
|
||||
@ -159,9 +159,12 @@ main(int argc, char *argv[])
|
||||
/* NOTREACHED */
|
||||
|
||||
if (strcmp(argv[1], "list") == 0 && argc == 2) {
|
||||
n = audiodev_count();
|
||||
for (i = 0; i < n; i++)
|
||||
print_audiodev(audiodev_get(i), i);
|
||||
n = audiodev_maxunit();
|
||||
for (i = 0; i <= n; i++) {
|
||||
adev = audiodev_get(i);
|
||||
if (adev)
|
||||
print_audiodev(adev);
|
||||
}
|
||||
} else if (strcmp(argv[1], "list") == 0 && argc == 3) {
|
||||
errno = 0;
|
||||
i = strtoul(argv[2], NULL, 10);
|
||||
@ -173,7 +176,7 @@ main(int argc, char *argv[])
|
||||
fprintf(stderr, "no such device\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
print_audiodev(adev, i);
|
||||
print_audiodev(adev);
|
||||
} else if (strcmp(argv[1], "default") == 0 && argc == 3) {
|
||||
if (*argv[2] < '0' || *argv[2] > '9')
|
||||
usage(argv[0]);
|
||||
@ -252,7 +255,7 @@ main(int argc, char *argv[])
|
||||
fprintf(stderr, "no such device\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
print_audiodev(adev, i);
|
||||
print_audiodev(adev);
|
||||
if (audiodev_test(adev) == -1)
|
||||
return EXIT_FAILURE;
|
||||
} else
|
||||
|
Loading…
Reference in New Issue
Block a user