17 #ifndef MIXERELEMENT_H_ 18 #define MIXERELEMENT_H_ 45 double toDB(
long v)
const {
46 return (
double)v/100.;
50 return (
long)(d*100.);
54 os<<
"{\"channel\": "<<channel<<
", "<<
"\"level\":"<<vol<<
", \"dB\":"<<dB<<
"}";
58 os<<
"{\"channel\": "<<channel<<
", "<<
"\"switch\":"<<sw<<
"}";
62 os<<
"{\"channel\": "<<channel<<
", "<<
"\"level\":"<<vol<<
", \"dB\":"<<dB
63 <<
", "<<
"\"switch\":"<<sw<<
"}";
81 if ((err=snd_mixer_selem_get_playback_volume(elem,
channel, &
vol))<0)
83 if ((err=snd_mixer_selem_get_playback_dB(elem,
channel, &
volDB))<0)
95 if ((err=snd_mixer_selem_get_playback_switch(elem,
channel, &
sw))<0)
114 if ((err=snd_mixer_selem_get_capture_volume(elem,
channel, &
vol))<0)
116 if ((err=snd_mixer_selem_get_capture_dB(elem,
channel, &
volDB))<0)
128 if ((err=snd_mixer_selem_get_capture_switch(elem,
channel, &
sw))<0)
169 playbackVolMax=playbackVolMin=0;
170 playbackVolMaxDB=playbackVolMinDB=0.;
171 captureVolMax=captureVolMin=0;
172 captureVolMaxDB=captureVolMinDB=0.;
173 hasCommonVolume=
false;
174 hasPlaybackVolume=
false;
175 hasPlaybackVolumeJoined=
false;
176 hasCaptureVolume=
false;
177 hasCaptureVolumeJoined=
false;
178 hasCommonSwitch=
false;
179 hasPlaybackSwitch=
false;
180 hasPlaybackSwitchJoined=
false;
181 hasCaptureSwitch=
false;
182 hasCaptureSwitchJoined=
false;
183 hasCaptureSwitchExclusive=
false;
188 name=snd_mixer_selem_get_name(elem);
189 index=snd_mixer_selem_get_index(elem);
191 playbackVolMax=playbackVolMin=0;
192 playbackVolMaxDB=playbackVolMinDB=0.;
193 captureVolMax=captureVolMin=0;
194 captureVolMaxDB=captureVolMinDB=0.;
196 hasCommonVolume=snd_mixer_selem_has_common_volume(elem);
197 hasPlaybackVolume=snd_mixer_selem_has_playback_volume(elem);
198 hasPlaybackVolumeJoined=snd_mixer_selem_has_playback_volume_joined(elem);
199 hasCaptureVolume=snd_mixer_selem_has_capture_volume(elem);
200 hasCaptureVolumeJoined=snd_mixer_selem_has_capture_volume_joined(elem);
201 hasCommonSwitch=snd_mixer_selem_has_common_switch(elem);
202 hasPlaybackSwitch=snd_mixer_selem_has_playback_switch(elem);
203 hasPlaybackSwitchJoined=snd_mixer_selem_has_playback_switch_joined(elem);
204 hasCaptureSwitch=snd_mixer_selem_has_capture_switch(elem);
205 hasCaptureSwitchJoined=snd_mixer_selem_has_capture_switch_joined(elem);
206 hasCaptureSwitchExclusive=snd_mixer_selem_has_capture_switch_exclusive(elem);
208 unsigned long chMask=1;
209 for (
int i=0; i<SND_MIXER_SCHN_LAST; i++){
210 if (snd_mixer_selem_has_playback_channel(elem, (snd_mixer_selem_channel_id_t)i)>0){
212 if (hasPlaybackVolume || hasPlaybackVolumeJoined)
213 playbackVolumes[playbackVolumes.size()-1].getLevels(elem);
214 if (hasCommonSwitch || hasPlaybackSwitch || hasPlaybackSwitchJoined)
215 playbackVolumes[playbackVolumes.size()-1].getSwitch(elem);
219 for (
int i=0; i<SND_MIXER_SCHN_LAST; i++)
220 if (snd_mixer_selem_has_capture_channel(elem, (snd_mixer_selem_channel_id_t)i)>0){
222 if (hasCaptureVolume || hasCaptureVolumeJoined)
223 captureVolumes[captureVolumes.size()-1].getLevels(elem);
224 if (hasCommonSwitch || hasCaptureSwitch || hasCaptureSwitchJoined)
225 captureVolumes[captureVolumes.size()-1].getSwitch(elem);
228 if (hasPlaybackVolume || hasPlaybackVolumeJoined){
229 if (snd_mixer_selem_get_playback_volume_range(elem, &playbackVolMin, &playbackVolMax))
232 if (snd_mixer_selem_get_playback_dB_range(elem, &min, &max))
234 playbackVolMinDB=
ChannelElement((snd_mixer_selem_channel_id_t)0).toDB(min);
235 playbackVolMaxDB=
ChannelElement((snd_mixer_selem_channel_id_t)0).toDB(max);
238 if (hasCaptureVolume || hasCaptureVolumeJoined){
239 if (snd_mixer_selem_get_capture_volume_range(elem, &captureVolMin, &captureVolMax))
242 if (snd_mixer_selem_get_capture_dB_range(elem, &min, &max))
244 captureVolMinDB=
ChannelElement((snd_mixer_selem_channel_id_t)0).toDB(min);
245 captureVolMaxDB=
ChannelElement((snd_mixer_selem_channel_id_t)0).toDB(max);
258 if (!hasCommonSwitch && !hasPlaybackSwitch && !hasPlaybackSwitchJoined)
260 for (
int i=0; i<playbackVolumes.size(); i++){
261 if ((err=snd_mixer_selem_set_playback_switch(elem, playbackVolumes[i].
channel, v))<0)
263 if ((err=playbackVolumes[i].getSwitch(elem))<0)
266 return playbackVolumes[0].sw;
275 if (!hasPlaybackVolume && !hasPlaybackVolumeJoined)
277 for (
int i=0; i<playbackVolumes.size(); i++){
278 if ((err=snd_mixer_selem_set_playback_volume(elem, playbackVolumes[i].
channel, v))<0)
280 if ((err=playbackVolumes[i].getLevels(elem))<0)
283 return playbackVolumes[0].vol;
293 if (!hasPlaybackVolume && !hasPlaybackVolumeJoined)
295 for (
int i=0; i<playbackVolumes.size(); i++)
296 if (channel==playbackVolumes[i].channel){
297 if ((err=snd_mixer_selem_set_playback_volume (elem, playbackVolumes[i].channel, v))<0)
299 if ((err=playbackVolumes[i].getLevels(elem))<0)
301 return playbackVolumes[i].vol;
312 if (!hasPlaybackVolume && !hasPlaybackVolumeJoined)
314 for (
int i=0; i<playbackVolumes.size(); i++){
315 if ((err=snd_mixer_selem_set_playback_dB(elem, playbackVolumes[i].
channel,
ChannelElement((snd_mixer_selem_channel_id_t)0).
fromDB(dB), 1))<0)
317 if ((err=playbackVolumes[i].getLevels(elem))<0)
319 dB=playbackVolumes[i].dB;
331 if (!hasPlaybackVolume && !hasPlaybackVolumeJoined)
333 for (
int i=0; i<playbackVolumes.size(); i++)
334 if (channel==playbackVolumes[i].channel){
335 if ((err=snd_mixer_selem_set_playback_dB(elem, playbackVolumes[i].channel,
ChannelElement((snd_mixer_selem_channel_id_t)0).
fromDB(dB),1))<0)
337 if ((err=playbackVolumes[i].getLevels(elem))<0)
339 dB=playbackVolumes[i].dB;
351 if (!hasCommonSwitch && !hasCaptureSwitch && !hasCaptureSwitchJoined)
353 for (
int i=0; i<captureVolumes.size(); i++){
354 if ((err=snd_mixer_selem_set_capture_switch(elem, captureVolumes[i].
channel, v))<0)
356 if ((err=captureVolumes[i].getSwitch(elem))<0)
359 return captureVolumes[0].sw;
368 if (!hasCaptureVolume && !hasCaptureVolumeJoined)
370 for (
int i=0; i<captureVolumes.size(); i++){
371 if ((err=snd_mixer_selem_set_capture_volume(elem, captureVolumes[i].
channel, v))<0)
373 if ((err=captureVolumes[i].getLevels(elem))<0)
376 return captureVolumes[0].vol;
386 if (!hasCaptureVolume && !hasCaptureVolumeJoined)
388 for (
int i=0; i<captureVolumes.size(); i++)
389 if (channel==captureVolumes[i].channel){
390 if ((err=snd_mixer_selem_set_capture_volume (elem, captureVolumes[i].channel, v))<0)
392 if ((err=captureVolumes[i].getLevels(elem))<0)
394 return captureVolumes[i].vol;
405 if (!hasCaptureVolume && !hasCaptureVolumeJoined)
407 for (
int i=0; i<captureVolumes.size(); i++){
408 if ((err=snd_mixer_selem_set_capture_dB(elem, captureVolumes[i].
channel,
ChannelElement((snd_mixer_selem_channel_id_t)0).
fromDB(dB), 1))<0)
410 if ((err=captureVolumes[i].getLevels(elem))<0)
412 dB=captureVolumes[i].dB;
424 if (!hasCaptureVolume && !hasCaptureVolumeJoined)
426 for (
int i=0; i<captureVolumes.size(); i++)
427 if (channel==captureVolumes[i].channel){
428 if ((err=snd_mixer_selem_set_capture_dB(elem, captureVolumes[i].channel,
ChannelElement((snd_mixer_selem_channel_id_t)0).
fromDB(dB),1))<0)
430 if ((err=captureVolumes[i].getLevels(elem))<0)
432 dB=captureVolumes[i].dB;
440 os<<
"\"name\":\""<<me.
name<<
"\",\n";
441 os<<
"\"index\":"<<me.
index<<
",\n";
469 os<<
",\"playbackVolumes\":[\n";
477 os<<
",\"playbackVolumes\":[\n";
485 os<<
",\"playbackVolumes\":[\n";
494 os<<
",\"captureVolumes\":[\n";
502 os<<
",\"captureVolumes\":[\n";
510 os<<
",\"captureVolumes\":[\n";
522 #endif // MIXERELEMENT_H_ long setPlaybackVolDB(snd_mixer_selem_channel_id_t channel, double &dB)
ChannelPlaybackElement(snd_mixer_selem_channel_id_t ch)
bool hasPlaybackSwitch
0 if no control is present, 1 if it's present
virtual ~ChannelElement()
snd_mixer_elem_t * elem
The pointer to the element.
ChannelCaptureElement(snd_mixer_selem_channel_id_t ch)
long setCaptureVol(long v)
double toDB(long v) const
bool hasCaptureVolume
0 if no control is present, 1 if it's present
long setPlaybackVol(long v)
void outputSwitch(std::ostream &os)
int getLevels(snd_mixer_elem_t *elem)
void outputLevelAndSwitch(std::ostream &os)
friend std::ostream & operator<<(std::ostream &os, MixerElement &me)
#define ALSA_MIXER_NO_CHANNEL_ERROR
error when we can't find the prescribed channel
long setCaptureVol(snd_mixer_selem_channel_id_t channel, long v)
bool hasPlaybackVolume
0 if no control is present, 1 if it's present
int getSwitch(snd_mixer_elem_t *elem)
virtual int evaluateError(int errorNum)
ChannelElement(snd_mixer_selem_channel_id_t ch)
bool hasPlaybackVolumeJoined
0 if control is separated per channel, 1 if control acts on all channels together ...
bool hasCaptureSwitchExclusive
0 if control is separated per element, 1 if control acts on other elements too (i.e. only one active at a time inside a group)
#define ALSA_MIXER_QUERY_ERROR
error when attempting to query the mixer
bool hasCaptureSwitchJoined
0 if control is separated per channel, 1 if control acts on all channels together ...
long setPlaybackVol(snd_mixer_selem_channel_id_t channel, long v)
long setCaptureVolDB(snd_mixer_selem_channel_id_t channel, double &dB)
virtual ~ChannelPlaybackElement()
long vol
If the channel has a volume, this holds its state.
int setCaptureSwitch(int v)
int getSwitch(snd_mixer_elem_t *elem)
long fromDB(double d) const
snd_mixer_selem_channel_id_t channel
void outputLevel(std::ostream &os)
bool hasCaptureSwitch
0 if no control is present, 1 if it's present
bool hasPlaybackSwitchJoined
0 if control is separated per channel, 1 if control acts on all channels together ...
#define ALSA_MIXER_NO_PLAYBACK_VOL_ERROR
error this mixer element is not a playback element
bool hasCaptureVolumeJoined
0 if control is separated per channel, 1 if control acts on all channels together ...
long volDB
If the channel has a volume, this holds its state in 100*dB.
virtual ~ChannelCaptureElement()
int setPlaybackSwitch(int v)
std::vector< ChannelCaptureElement > captureVolumes
Volume setting for each capture channel in this mixer element.
std::vector< ChannelPlaybackElement > playbackVolumes
Volume setting for each playback channel in this mixer element.
double dB
If the channel has a volume, this holds its state in dB.
int setPlaybackVolDB(double &dB)
bool hasCommonVolume
element has only one volume control for both playback and capture
bool hasCommonSwitch
0 separated control, 1 common control
std::string name
The mixer element name.
int getLevels(snd_mixer_elem_t *elem)
MixerElement(snd_mixer_elem_t *e)
int setCaptureVolDB(double &dB)
unsigned int index
The mixer element index.
int sw
If the channel has a switch, this holds its state.