1 #include <alsa/asoundlib.h>
6 int status_volume_alsa(GlobalData *g,
9 snd_mixer_selem_channel_id_t channel)
12 char text[16] = { 0 };
14 snd_mixer_t *handle = NULL;
15 snd_mixer_elem_t *elem;
16 snd_mixer_selem_id_t *sid;
18 long min = 0, max = 0;
26 snd_mixer_selem_id_alloca(&sid);
28 if (snd_mixer_open(&handle, 0) < 0) {
32 if (snd_mixer_attach(handle, cardname) < 0) {
36 snd_mixer_selem_id_set_name(sid, mixername);
38 if (snd_mixer_selem_register(handle, NULL, NULL) < 0) {
42 if (snd_mixer_load(handle) < 0) {
46 elem = snd_mixer_find_selem(handle, sid);
51 if (snd_mixer_selem_has_playback_volume(elem)
52 && snd_mixer_selem_has_playback_channel(elem, channel)) {
53 snd_mixer_selem_get_playback_switch(elem, channel, &on_off);
54 snd_mixer_selem_get_playback_volume_range(elem, &min, &max);
55 snd_mixer_selem_get_playback_volume(elem, channel, &volume);
57 s.color = on_off ? "#22FF22" : "#FF0000"; // green/red
58 snprintf(text, sizeof(text), "Vol: %d", (int)volume);
61 snd_mixer_close(handle);
63 line_append_item(g, &s);
69 snd_mixer_close(handle);