1 #include <alsa/asoundlib.h>
2 #include "volume_alsa.h"
4 int status_volume_alsa(char *cardname, char *mixername, snd_mixer_selem_channel_id_t channel)
6 snd_mixer_t *handle = NULL;
7 snd_mixer_elem_t *elem;
8 snd_mixer_selem_id_t *sid;
10 long min = 0, max = 0;
15 snd_mixer_selem_id_alloca(&sid);
17 if (snd_mixer_open(&handle, 0) < 0) {
21 if (snd_mixer_attach(handle, cardname) < 0) {
25 snd_mixer_selem_id_set_name(sid, mixername);
27 if (snd_mixer_selem_register(handle, NULL, NULL) < 0) {
31 if (snd_mixer_load(handle) < 0) {
35 elem = snd_mixer_find_selem(handle, sid);
40 if (snd_mixer_selem_has_playback_volume(elem)
41 && snd_mixer_selem_has_playback_channel(elem, channel)) {
42 snd_mixer_selem_get_playback_switch(elem, channel, &on_off);
44 fputs("^fg(#22FF22)", stdout);
46 fputs("^fg(red)", stdout);
49 snd_mixer_selem_get_playback_volume_range(elem, &min, &max);
51 snd_mixer_selem_get_playback_volume(elem, channel, &volume);
52 fputs("^ca(1, amixer sset Master toggle)", stdout);
53 fputs("^ca(4, amixer sset Master 2+ unmute)", stdout);
54 fputs("^ca(5, amixer sset Master 2- unmute)", stdout);
55 printf(" Vol: %d ", (int)volume);
56 fputs("^ca()", stdout);
57 fputs("^ca()", stdout);
58 fputs("^ca()", stdout);
61 snd_mixer_close(handle);
67 snd_mixer_close(handle);