[wiki] [sites] dwmstatus alsa volume || blut

From: <git_AT_suckless.org>
Date: Sun, 08 Jun 2014 20:10:20 +0200

commit e1d1fdaba95c6241a1ed8d738e477ce58f45b4ec
Author: blut <CXblut_AT_gmail.com>
Date: Sun Jun 8 18:09:00 2014 +0000

    dwmstatus alsa volume

diff --git a/dwm.suckless.org/dwmstatus/getvol.c b/dwm.suckless.org/dwmstatus/getvol.c
new file mode 100644
index 0000000..d170075
--- /dev/null
+++ b/dwm.suckless.org/dwmstatus/getvol.c
_AT_@ -0,0 +1,32 @@
+#include <alsa/asoundlib.h>
+#include <alsa/control.h>
+
+int
+get_vol(void)
+{
+ long int vol;
+ snd_hctl_t *hctl;
+ snd_ctl_elem_id_t *id;
+ snd_ctl_elem_value_t *control;
+
+// To find card and subdevice: /proc/asound/, aplay -L, amixer controls
+ snd_hctl_open(&hctl, "hw:0", 0);
+ snd_hctl_load(hctl);
+
+ snd_ctl_elem_id_alloca(&id);
+ snd_ctl_elem_id_set_interface(id, SND_CTL_ELEM_IFACE_MIXER);
+
+// amixer controls
+ snd_ctl_elem_id_set_name(id, "Master Playback Volume");
+
+ snd_hctl_elem_t *elem = snd_hctl_find_elem(hctl, id);
+
+ snd_ctl_elem_value_alloca(&control);
+ snd_ctl_elem_value_set_id(control, id);
+
+ snd_hctl_elem_read(elem, control);
+ vol = snd_ctl_elem_value_get_integer(control,0);
+
+ snd_hctl_close(hctl);
+ return (int)vol;
+}
diff --git a/dwm.suckless.org/dwmstatus/index.md b/dwm.suckless.org/dwmstatus/index.md
index bb58789..91a2e4c 100644
--- a/dwm.suckless.org/dwmstatus/index.md
+++ b/dwm.suckless.org/dwmstatus/index.md
_AT_@ -46,6 +46,7 @@ add them here as file or as code example.
   dynamic_info.
 * [Battery function](batterystatus.c) : Battery percentage and status. + if
   charging, - if discharging, = if full.
+* [Alsa Volume API](getvol.c) : Alsa Volume via the Alsa API
 
 Questions
 ---------
Received on Sun Jun 08 2014 - 20:10:20 CEST

This archive was generated by hypermail 2.3.0 : Thu Jun 18 2015 - 17:39:00 CEST