2 * Advanced Linux Sound Architecture Control Program
3 * Copyright (c) by Takashi Iwai <tiwai@suse.de>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <alsa/asoundlib.h>
25 static int open_ctl(const char *name, snd_ctl_t **ctlp)
30 err = snd_ctl_open(&ctl, name, SND_CTL_READONLY);
32 fprintf(stderr, "Cannot open ctl %s\n", name);
35 err = snd_ctl_subscribe_events(ctl, 1);
37 fprintf(stderr, "Cannot open subscribe events to ctl %s\n", name);
45 static int print_event(int card, snd_ctl_t *ctl)
47 snd_ctl_event_t *event;
51 snd_ctl_event_alloca(&event);
52 err = snd_ctl_read(ctl, event);
56 if (snd_ctl_event_get_type(event) != SND_CTL_EVENT_ELEM)
60 printf("card %d, ", card);
61 printf("#%d (%i,%i,%i,%s,%i)",
62 snd_ctl_event_elem_get_numid(event),
63 snd_ctl_event_elem_get_interface(event),
64 snd_ctl_event_elem_get_device(event),
65 snd_ctl_event_elem_get_subdevice(event),
66 snd_ctl_event_elem_get_name(event),
67 snd_ctl_event_elem_get_index(event));
69 mask = snd_ctl_event_elem_get_mask(event);
70 if (mask == SND_CTL_EVENT_MASK_REMOVE) {
75 if (mask & SND_CTL_EVENT_MASK_VALUE)
77 if (mask & SND_CTL_EVENT_MASK_INFO)
79 if (mask & SND_CTL_EVENT_MASK_ADD)
81 if (mask & SND_CTL_EVENT_MASK_TLV)
89 int monitor(const char *name)
91 snd_ctl_t *ctls[MAX_CARDS];
98 while (snd_card_next(&card) >= 0 && card >= 0) {
100 if (ncards >= MAX_CARDS) {
101 fprintf(stderr, "alsactl: too many cards\n");
105 sprintf(cardname, "hw:%d", card);
106 err = open_ctl(cardname, &ctls[ncards]);
113 err = open_ctl(name, &ctls[0]);
121 struct pollfd fds[ncards];
123 for (i = 0; i < ncards; i++)
124 snd_ctl_poll_descriptors(ctls[i], &fds[i], 1);
126 err = poll(fds, ncards, -1);
132 for (i = 0; i < ncards; i++) {
133 unsigned short revents;
134 snd_ctl_poll_descriptors_revents(ctls[i], &fds[i], 1,
136 if (revents & POLLIN)
137 print_event(show_cards ? i : -1, ctls[i]);
142 for (i = 0; i < ncards; i++)
143 snd_ctl_close(ctls[i]);