| 1 |
#!/bin/bash |
| 2 |
# Support for amixer controls |
| 3 |
# Written by: Dominique Michel <[email protected]> |
| 4 |
# |
| 5 |
# Usage: |
| 6 |
# PipeRead "AmixerControl $[infostore.SoundCard] $[infostore.SoundDevice] |
| 7 |
|
| 8 |
# Variables |
| 9 |
MenuStepMax=15 |
| 10 |
|
| 11 |
# Initialisations |
| 12 |
# The control's name: |
| 13 |
CName=`amixer -c $1 cget numid="$2"|grep numid|sed -e "s:.*name='::" -e "s:'::"` |
| 14 |
# The hardware maximum step (and volume): |
| 15 |
CStepMax=`amixer -c $1 cget numid="$2"|grep type|sed -e "s:.*max=::" -e "s:,step.*::"` |
| 16 |
# The hardware minimum step: |
| 17 |
CStepMin=`amixer -c $1 cget numid="$2"|grep type|sed -e "s:.*min=::" -e "s:,max.*::"` |
| 18 |
# The minimum level of the volume: |
| 19 |
CVolMin=`amixer -c $1 cget numid="$2"|grep dBscale|sed -e "s:.*dBscale-min=::" -e "s:dB.*::"` |
| 20 |
# The hardware step level: |
| 21 |
CStepLevel=`amixer -c $1 cget numid="$2"|grep dBscale|sed -e "s:.*step=::" -e "s:dB.*::"` |
| 22 |
|
| 23 |
# Menu steps |
| 24 |
if [ ${CStepMax} -le $MenuStepMax ] |
| 25 |
then MenuStepMax="$((${CStepMax}+1))" |
| 26 |
fi |
| 27 |
|
| 28 |
# Initialise the menu |
| 29 |
CMenuStep=`echo $(( $CStepMax / $MenuStepMax ))` |
| 30 |
if [ ${CMenuStep} -lt 1 ] |
| 31 |
then CMenuStep="1" |
| 32 |
fi |
| 33 |
VolMax=`echo "${CVolMin} + (${CStepLevel} * ${CStepMax})"|bc -l` |
| 34 |
|
| 35 |
# Where is the 0dB |
| 36 |
AbsVolMin=`echo "a=$CVolMin/1;if(0>a)a*=-1;a"|bc -l` |
| 37 |
Step0dB=`echo "$AbsVolMin/$CStepLevel"|bc` |
| 38 |
|
| 39 |
# Mixer menu |
| 40 |
echo "+ '\$[gt.Sound Card] ${1} ${CName}' Nop" |
| 41 |
y=0 |
| 42 |
db=0 # 0dB test |
| 43 |
for (( x=${CStepMax} ; x >= ${CStepMin} ; x -= ${CMenuStep} )) ; do |
| 44 |
npas=`echo $(( ${CStepMax} - ${x} ))` |
| 45 |
ndB=`echo "${VolMax} - ( ${npas} * ${CStepLevel} )"|bc -l` |
| 46 |
# be sure to show the 0dB step |
| 47 |
if [ ${db} -eq 0 ] && [ ${x} -le ${Step0dB} ] |
| 48 |
then if [ ${x} -lt ${Step0dB} ] |
| 49 |
then echo "+ ' 0 dB' Exec exec amixer -c ${1} cset numid=${2} ${Step0dB}" |
| 50 |
fi |
| 51 |
db=1 |
| 52 |
fi |
| 53 |
# show other steps |
| 54 |
echo "+ '${ndB} dB' Exec exec amixer -c ${1} cset numid=${2} ${x}" |
| 55 |
# show the minimum value as last iteration |
| 56 |
if [ ${x} -le ${CMenuStep} ] |
| 57 |
then if [ ${y} -eq 1 ] |
| 58 |
then break |
| 59 |
fi |
| 60 |
x="${CMenuStep}" |
| 61 |
y=1 |
| 62 |
fi |
| 63 |
done |
| 64 |
|
| 65 |
# Send the control name to fvwm |
| 66 |
echo "InfoStoreAdd MixerControl \"${CName}\"" |