From 6820631175868c277effa7cc05f9cb3197b72654 Mon Sep 17 00:00:00 2001 From: Aaron Marcher Date: Sun, 17 Sep 2017 16:18:17 +0200 Subject: Split into multiple files For multiple reasons the program is now split: - Make future porting to OpenBSD easier - Assign header includes to individiual functions - Make future program extensions easier - Recompile only changed parts --- volume.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 volume.c (limited to 'volume.c') diff --git a/volume.c b/volume.c new file mode 100644 index 0000000..a23c4f1 --- /dev/null +++ b/volume.c @@ -0,0 +1,42 @@ +#include +#include +#include +#include +#include +#include +#include + +#include "util.h" + +const char * +vol_perc(const char *card) +{ + unsigned int i; + int v, afd, devmask; + char *vnames[] = SOUND_DEVICE_NAMES; + + afd = open(card, O_RDONLY | O_NONBLOCK); + if (afd == -1) { + warn("Cannot open %s", card); + return NULL; + } + + if (ioctl(afd, SOUND_MIXER_READ_DEVMASK, &devmask) == -1) { + warn("Cannot get volume for %s", card); + close(afd); + return NULL; + } + for (i = 0; i < LEN(vnames); i++) { + if (devmask & (1 << i) && !strcmp("vol", vnames[i])) { + if (ioctl(afd, MIXER_READ(i), &v) == -1) { + warn("vol_perc: ioctl"); + close(afd); + return NULL; + } + } + } + + close(afd); + + return bprintf("%d", v & 0xff); +} -- cgit v1.2.3