list_devices takes arguments to override backend

This commit is contained in:
Andrew Kelley 2015-07-20 00:00:43 -07:00
parent 13e6aba370
commit 24f466a0a0
2 changed files with 16 additions and 6 deletions

View file

@ -14,7 +14,7 @@
// list or keep a watch on audio devices // list or keep a watch on audio devices
static int usage(char *exe) { static int usage(char *exe) {
fprintf(stderr, "Usage: %s [--watch]\n", exe); fprintf(stderr, "Usage: %s [--watch] [--dummy] [--alsa] [--pulseaudio]\n", exe);
return 1; return 1;
} }
@ -108,11 +108,18 @@ static void on_devices_change(struct SoundIo *soundio) {
int main(int argc, char **argv) { int main(int argc, char **argv) {
char *exe = argv[0]; char *exe = argv[0];
bool watch = false; bool watch = false;
enum SoundIoBackend backend = SoundIoBackendNone;
for (int i = 1; i < argc; i += 1) { for (int i = 1; i < argc; i += 1) {
char *arg = argv[i]; char *arg = argv[i];
if (strcmp("--watch", arg) == 0) { if (strcmp("--watch", arg) == 0) {
watch = true; watch = true;
} else if (strcmp("--dummy", arg) == 0) {
backend = SoundIoBackendDummy;
} else if (strcmp("--alsa", arg) == 0) {
backend = SoundIoBackendAlsa;
} else if (strcmp("--pulseaudio", arg) == 0) {
backend = SoundIoBackendPulseAudio;
} else { } else {
return usage(exe); return usage(exe);
} }
@ -124,8 +131,10 @@ int main(int argc, char **argv) {
return 1; return 1;
} }
int err; int err = (backend == SoundIoBackendNone) ?
if ((err = soundio_connect(soundio))) { soundio_connect(soundio) : soundio_connect_backend(soundio, backend);
if (err) {
fprintf(stderr, "%s\n", soundio_strerror(err)); fprintf(stderr, "%s\n", soundio_strerror(err));
return err; return err;
} }

View file

@ -479,12 +479,13 @@ enum SoundIoDevicePurpose soundio_device_purpose(const struct SoundIoDevice *dev
// Sorts channel layouts by channel count, descending. // Sorts channel layouts by channel count, descending.
void soundio_device_sort_channel_layouts(struct SoundIoDevice *device); void soundio_device_sort_channel_layouts(struct SoundIoDevice *device);
// Returns whether `format` is included in the devices supported formats. // Convenience function. Returns whether `format` is included in the device's
// supported formats.
bool soundio_device_supports_format(struct SoundIoDevice *device, bool soundio_device_supports_format(struct SoundIoDevice *device,
enum SoundIoFormat format); enum SoundIoFormat format);
// Returns whether `layout` is included in the devices supported channel // Convenience function. Returns whether `layout` is included in the device's
// layouts. // supported channel layouts.
bool soundio_device_supports_layout(struct SoundIoDevice *device, bool soundio_device_supports_layout(struct SoundIoDevice *device,
const struct SoundIoChannelLayout *layout); const struct SoundIoChannelLayout *layout);