From 7a39a18686727157d4bbb92348a9eae2ca42ca35 Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Thu, 7 May 2020 18:34:30 +0900 Subject: [PATCH] Fixed detection of alsa channels capabilities. This resolves bug 2994 and issue #16. The code is partially based on previous work from TCH . Signed-off-by: Michele Calgaro --- kmix/mixer_alsa9.cpp | 109 ++++++++++++++++++++++++------------------- 1 file changed, 61 insertions(+), 48 deletions(-) diff --git a/kmix/mixer_alsa9.cpp b/kmix/mixer_alsa9.cpp index 46d98d41..22303b43 100644 --- a/kmix/mixer_alsa9.cpp +++ b/kmix/mixer_alsa9.cpp @@ -199,9 +199,10 @@ Mixer_ALSA::open() sid = (snd_mixer_selem_id_t*)malloc(snd_mixer_selem_id_sizeof()); // I believe *we* must malloc it for ourself snd_mixer_selem_get_id( elem, sid ); - bool canRecord = false; - bool canMute = false; + bool canPlay = false; bool canCapture = false; + bool hasPlaySwitch = false; + bool hasCaptureSwitch = false; long maxVolumePlay= 0, minVolumePlay= 0; long maxVolumeRec = 0, minVolumeRec = 0; validDevice = true; @@ -261,6 +262,7 @@ Mixer_ALSA::open() ? Volume::MLEFT : (Volume::ChannelMask)(Volume::MLEFT | Volume::MRIGHT); chn = (Volume::ChannelMask) (chn | chnTmp); cc = MixDevice::SLIDER; + canPlay = true; volPlay = new Volume( chn, maxVolumePlay, minVolumePlay ); } else { volPlay = new Volume(); @@ -283,72 +285,83 @@ Mixer_ALSA::open() mixer_sid_list.append( sid ); if ( snd_mixer_selem_has_playback_switch ( elem ) ) { - //kdDebug(67100) << "has_playback_switch()" << endl; - canMute = true; + //kdDebug(67100) << "has_playback_switch()" << endl; + hasPlaySwitch = true; } if ( snd_mixer_selem_has_capture_switch ( elem ) ) { - //kdDebug(67100) << "has_capture_switch()" << endl; - canRecord = true; + //kdDebug(67100) << "has_capture_switch()" << endl; + hasCaptureSwitch = true; } if ( snd_mixer_selem_has_common_switch ( elem ) ) { - //kdDebug(67100) << "has_common_switch()" << endl; - canMute = true; - canRecord = true; + //kdDebug(67100) << "has_common_switch()" << endl; + hasPlaySwitch = true; + hasCaptureSwitch = true; } - if ( /*snd_mixer_selem_has_common_switch ( elem ) || */ - cc == MixDevice::UNDEFINED ) + if (cc == MixDevice::UNDEFINED ) { // Everything unknown is handled as switch cc = MixDevice::SWITCH; } } // is ordinary mixer element (NOT an enum) + if (canPlay || cc == MixDevice::SWITCH || cc == MixDevice::ENUM) + { MixDevice* md = new MixDevice( mixerIdx, - canCapture ? *volCapture : *volPlay, - canCapture ? true : canRecord, - canMute, - snd_mixer_selem_id_get_name( sid ), - ct, - cc ); - - m_mixDevices.append( md ); - + *volPlay, + false, + hasPlaySwitch, + snd_mixer_selem_id_get_name( sid ), + ct, + cc ); + m_mixDevices.append( md ); if (!masterChosen && ct==MixDevice::VOLUME) { - // Determine a nicer MasterVolume - m_recommendedMaster = md; - masterChosen = true; + // Determine a nicer MasterVolume + m_recommendedMaster = md; + masterChosen = true; } if ( enumList.count() > 0 ) { - int maxEnumId= enumList.count(); - TQPtrList& enumValuesRef = md->enumValues(); // retrieve a ref - for (int i=0; i& enumValuesRef = md->enumValues(); // retrieve a ref + for (int i=0; i