1 // AItem.cc, Petr Hlavka, 2004
6 #include <alsa/asoundlib.h>
9 #define ROUND_POS(x) (long ((long (x) + 0.5 > (x)) ? (x) : (x) + 1))
12 // load only playback channels, don't care about common items
13 AItem::AItem(AMixer
*m
, snd_mixer_elem_t
*e
) {
17 name
= snd_mixer_selem_get_name(aElem
);
19 hPVolume
= snd_mixer_selem_has_playback_volume(aElem
);
20 hPSwitch
= snd_mixer_selem_has_playback_switch(aElem
);
23 snd_mixer_selem_get_playback_volume_range(aElem
, &minPVolume
, &maxPVolume
);
25 minPVolume
= maxPVolume
= 0;
27 for (int channel
= 0; channel
<= (int) SND_MIXER_SCHN_LAST
; channel
++) {
28 if (snd_mixer_selem_has_playback_channel(aElem
, (SNDCHID_T
) channel
)) {
29 AChannel
*ch
= new AChannel(this, (SNDCHID_T
) channel
);
30 pbChannels
.push_back(ch
);
37 for (unsigned int i
= 0; i
< pbChannels
.size(); i
++)
42 // set same volume for all channels in this item in percent
43 void AItem::setVolumePerc(unsigned int percent
) {
47 snd_mixer_selem_set_playback_volume_all(aElem
, (long) ROUND_POS((minPVolume
+ (maxPVolume
- minPVolume
) * percent
/ 100.0)));
51 // get max channel volume of all channels in this item in percent
52 unsigned int AItem::getVolumePerc() {
53 long max_vol
= 0, act_vol
;
55 // find the max volume
56 for (unsigned int i
= 0; i
< pbChannels
.size(); i
++)
57 if ((act_vol
= pbChannels
[i
]->getVolume()) > max_vol
)
60 // convert it into percent
61 if (minPVolume
!= maxPVolume
)
62 return ((unsigned int) ROUND_POS((max_vol
- minPVolume
) * 100.0 / (maxPVolume
- minPVolume
)));
68 // in this app side of view, item is muted if all channels is muted
69 bool AItem::isMuted() {
70 for (unsigned int i
= 0; i
< pbChannels
.size(); i
++)
71 if (!pbChannels
[i
]->isMuted())
80 snd_mixer_selem_set_playback_switch_all(aElem
, false);
84 // unmute all channels
85 void AItem::unmute() {
86 snd_mixer_selem_set_playback_switch_all(aElem
, true);