wmail: added breaks and explicit fall-through comments to switches.
[dockapps.git] / wmmixer-alsa / mixer.c
blobd454b50146de8b7a7ece6df618002061cc7deb38
1 #include "wmmixer-alsa.h"
3 void init_mixer(void)
5 int err;
6 if((err=snd_mixer_open(&mixer_handle,CARD_NUM,MIXER_NUM))<0)
8 fprintf(stderr,"Mixer open failed: %s\n",snd_strerror(err));
9 return;
11 init_elements();
12 return;
15 void init_elements(void)
17 int err,i;
18 count=0;
19 memset(&elements,0,sizeof(elements));
20 if((err=snd_mixer_elements(mixer_handle,&elements))<0)
22 fprintf(stderr,"Elements error: %s\n",snd_strerror(err));
23 return;
25 elements.pelements=(snd_mixer_eid_t *)malloc(elements.elements_over*sizeof(snd_mixer_eid_t));
26 if(!elements.pelements)
28 fprintf(stderr,"Elements error: Not enough memory\n");
29 return;
31 elements.elements_size=elements.elements_over;
32 elements.elements_over=elements.elements=0;
33 if((err=snd_mixer_elements(mixer_handle,&elements))<0)
35 fprintf(stderr,"Elements error: %s\n",snd_strerror(err));
36 return;
38 for(i=0;i<elements.elements;i++)
40 elementinfo *e;
41 if(elements.pelements[i].type!=SND_MIXER_ETYPE_VOLUME1)
42 continue;
43 if(snd_mixer_element_has_control(&elements.pelements[i])!=1)
44 continue;
45 if(snd_mixer_element_has_info(&elements.pelements[i])!=1)
46 continue;
47 e=add_element();
48 e->element.eid=elements.pelements[i];
49 if((err=snd_mixer_element_build(mixer_handle,&e->element))<0)
51 fprintf(stderr,"Element error: %s\n",snd_strerror(err));
52 return;
54 e->info.eid=elements.pelements[i];
55 if((err=snd_mixer_element_info_build(mixer_handle,&e->info))<0)
57 fprintf(stderr,"Element info error: %s\n",snd_strerror(err));
58 return;
60 count++;
62 free((void *)elements.pelements);
63 return;
66 elementinfo *add_element(void)
68 if(!element)
70 element=(elementinfo *)malloc(sizeof(elementinfo));
71 element->next=NULL;
72 element->prev=NULL;
73 memset(&element->info,0,sizeof(element->info));
74 memset(&element->element,0,sizeof(element->element));
75 return element;
77 else
79 elementinfo *e;
80 e=element;
81 while(e->next)
82 e=e->next;
83 e->next=(elementinfo *)malloc(sizeof(elementinfo));
84 e->next->prev=e;
85 e=e->next;
86 e->next=NULL;
87 memset(&e->info,0,sizeof(e->info));
88 memset(&e->element,0,sizeof(e->element));
89 return e;