#!/bin/bash
# Alsa Mixer Gui version 2 by KuLuSz at 2019 12 27
dir="/tmp/AMG_v2" sw="$dir/sw" pof="$dir/play_gui" cof="$dir/rec_gui"
psof="$dir/play_gui_sw" csof="$dir/rec_gui_sw"
mkdir -p $dir
[ -e $sw ]&& rm $sw
[ -e $pof ]&& rm $pof
[ -e $cof ]&& rm $cof
[ -e $psof ]&& rm $psof
[ -e $csof ]&& rm $csof
amixer contents | tr -d '\n' | sed 's/num/\nnum/2g' | grep MIXER | grep "BOOLEAN\|ENUM" > $sw
amixer contents | tr -d '\n' | sed 's/num/\nnum/2g' | grep MIXER | grep INTEGER | while read i; do
ID=$(echo "$i" | cut -f1 -d',' | cut -f2 -d=)
N=$(echo "$i" | cut -f2 -d"'") # name
N2="$(echo "$N" | sed 's/Volume//')" # name2
N3="$(echo "$N" | sed 's/ /_/g ; s/-/_/g ; s:/:_:g ; s/[0-9]//g')"
if [ ! -z "$(echo "$N" | sed 's/ Capture// ; s/ Playback// ; s/Tone Control - // ; s/[ ]Volume//')" ];then
N4="$(echo "$N2" | sed 's/ Capture// ; s/ Playback// ; s/Tone Control - // ; s/[ ]Volume// ; s/- //')"
else
N4="$N"
fi
MAX_VAL=$(echo "$i" | grep -o "max=[0-9]*" | cut -f2 -d= | cut -f1 -d'|') # max value
VALS=$(echo "$i" | grep -o ":.*" | cut -f2 -d= | cut -f1 -d' ') # current value
STEP=$[$MAX_VAL/3]
if [ "$(echo "$i" | grep "mute=0")" ];then
MUTE_VAL="$(cat $sw | grep "${N2}" | cut -f2 -d':' | cut -f2 -d= | cut -f1 -d' ')"
MUTE_ID="$(cat $sw | grep "${N2}" | cut -f1 -d',' | cut -f2 -d'=')"
[ "$MUTE_VAL" == "on" ]&& SW="true" || SW="false"
M_VIS="true"
sed -i "/${N2}/d" $sw
else
SW="true" M_VIS="false"
fi
L="$(echo "$VALS" | cut -f1 -d',')"
if [ "$(echo "$VALS" | grep ',')" ];then
R="$(echo "$VALS" | cut -f2 -d',')"
[ "$L" == "$R" ]&& BOTH="true" || BOTH="false"
SLIDER='
'$L' L'$ID' echo $R'$ID'
refresh:R'$ID'
amixer cset numid='$ID' $L'$ID',$R'$ID'
'$R' R'$ID' echo $L'$ID'
refresh:L'$ID'
amixer cset numid='$ID' $L'$ID',$R'$ID'
C'$ID'
'
else
SLIDER='
'$L' L'$ID' amixer cset numid='$ID' $L'$ID'
'
fi
PANEL='
M'$ID' '$M_VIS'
if true amixer cset numid='$MUTE_ID' on
if false amixer cset numid='$MUTE_ID' off
'$SLIDER' '
if [ "$(echo "$N" | grep Playback)" ];then
echo "$PANEL" >> $pof
elif [ "$(echo "$N" | grep Capture)" ];then
echo "$PANEL" >> $cof
else
echo "$PANEL" >> $pof
echo "$PANEL" | sed "s/>M/>M2/ ; s/>L/>L2/ ; s/\$R/\$R2/
s/>R/>R2/ ; s/>C/>C2/ ; s/(C/(C2/ ; s/\$L/\$L2/ ; s/:L/:L2/ ; s/:R/:R2/" >> $cof
fi
done
cat $sw | while read i;do
ID=$(echo "$i" | cut -f1 -d',' | cut -f2 -d=)
N=$(echo "$i" | cut -f2 -d"'")
N2="$(echo "$N" | sed 's/ /_/g ; s/-/_/g ; s:/:_:g ; s/[0-9]//g ; s/[()]//g')"
if [ ! -z "$(echo "$N" | sed 's/ Capture// ; s/ Playback// ; s/ Switch// ; s/ - //')" ];then
N4="$(echo "$N" | sed 's/Capture// ; s/Playback// ; s/ Switch// ; s/ - //')"
else
N4="$N"
fi
if [ "$(echo $i | grep BOOLEAN)" ];then
VALS=$(echo "$i" | grep -o ":.*" | cut -f2 -d= | cut -f1 -d' ' | cut -f1 -d',')
[ "$VALS" == "on" ]&& SW='true' || SW='false'
PANEL='
MIA'$ID'
if true amixer cset numid='$ID' on
if false amixer cset numid='$ID' off
'
elif [ "$(echo $i | grep ENUME)" ];then
[ -e $dir/enum ]&& rm $dir/enum
DEF="$(echo "$i" | grep -o ":.*" | cut -f2 -d= | cut -f1 -d' ')"
DEF2="$(echo "$i" | cut -f3- -d';' | cut -f1 -d':' | sed 's/;/\n/g' | grep "#${DEF}" | cut -f2 -d"'")"
echo "$i" | cut -f3- -d';' | cut -f1 -d':' | sed 's/;/\n/g' | cut -f2 -d"'" | while read b;do
echo "- $b
" >> $dir/enum
done
PANEL='
MIA'$ID' "'$DEF2'"
'$(cat $dir/enum)' amixer cset numid='$ID' $MIA'$ID'
'
fi
if [ "$(echo "$N" | grep Playback)" ];then
echo "$PANEL" >> $psof
elif [ "$(echo "$N" | grep Capture)" ];then
echo "$PANEL" >> $csof
else
echo "$PANEL" >> $psof && echo "$PANEL" | sed "s/>MIA/>MIA2/ ; s/\$MIA/\$MIA2/" >> $csof
fi
done
PLAY_TAB="Playback|"
if [ -e $pof -a -e $psof ];then
PLAY_GUI='
'$(cat $pof)'
'$(cat $psof)''
elif [ -e $pof -a ! -e $psof ];then
PLAY_GUI='
'$(cat $pof)''
elif [ ! -e $pof -a -e $psof ];then
PLAY_GUI='
'$(cat $psof)''
else
PLAY_TAB="" PLAY_GUI=""
fi
REC_TAB="Record|"
if [ -e $cof -a -e $csof ];then
REC_GUI='
'$(cat $cof)'
'$(cat $csof)''
elif [ -e $cof -a ! -e $csof ];then
REC_GUI='
'$(cat $cof)''
elif [ ! -e $cof -a -e $csof ];then
REC_GUI='
'$(cat $csof)''
else
REC_TAB="" REC_GUI=""
fi
if [ ! -z "$(amixer info)" ];then
IT="info|" IG='amixer info'
else
IT='' IG=''
fi
export MD='
'$PLAY_GUI' '$REC_GUI' '$IG'
'
gtkdialog --program=MD --center
rm -r $dir