File: AmixerControl

package info (click to toggle)
fvwm-crystal 3.4.1%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 21,708 kB
  • sloc: sh: 3,265; cs: 1,335; python: 875; makefile: 214
file content (66 lines) | stat: -rwxr-xr-x 2,031 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
# Support for amixer controls
# Written by: Dominique Michel <dominique_libre@sourceforge.net>
#
# Usage:
# PipeRead "AmixerControl $[infostore.SoundCard] $[infostore.SoundDevice]

# Variables
MenuStepMax=15

# Initialisations
# The control's name:
CName=`amixer -c $1 cget numid="$2"|grep numid|sed -e "s:.*name='::" -e "s:'::"`
# The hardware maximum step (and volume):
CStepMax=`amixer -c $1 cget numid="$2"|grep type|sed -e "s:.*max=::" -e "s:,step.*::"`
# The hardware minimum step:
CStepMin=`amixer -c $1 cget numid="$2"|grep type|sed -e "s:.*min=::" -e "s:,max.*::"`
# The minimum level of the volume:
CVolMin=`amixer -c $1 cget numid="$2"|grep dBscale|sed -e "s:.*dBscale-min=::" -e "s:dB.*::"`
# The hardware step level:
CStepLevel=`amixer -c $1 cget numid="$2"|grep dBscale|sed -e "s:.*step=::" -e "s:dB.*::"`

# Menu steps
if [ ${CStepMax} -le $MenuStepMax ]
then MenuStepMax="$((${CStepMax}+1))"
fi

# Initialise the menu
CMenuStep=`echo $(( $CStepMax / $MenuStepMax ))`
if [ ${CMenuStep} -lt 1 ]
then CMenuStep="1"
fi
VolMax=`echo "${CVolMin} + (${CStepLevel} * ${CStepMax})"|bc -l`

# Where is the 0dB
AbsVolMin=`echo "a=$CVolMin/1;if(0>a)a*=-1;a"|bc -l`
Step0dB=`echo "$AbsVolMin/$CStepLevel"|bc`

# Mixer menu
echo "+ '\$[gt.Sound Card] ${1} ${CName}' Nop"
y=0
db=0 # 0dB test
for (( x=${CStepMax} ; x >= ${CStepMin} ; x -= ${CMenuStep} )) ; do
    npas=`echo $(( ${CStepMax} - ${x} ))`
    ndB=`echo "${VolMax} - ( ${npas} * ${CStepLevel} )"|bc -l`
    # be sure to show the 0dB step
    if [ ${db} -eq 0 ] && [ ${x} -le ${Step0dB} ]
    then if [ ${x} -lt ${Step0dB} ]
	 then echo "+ ' 0 dB' Exec exec amixer -c ${1} cset numid=${2} ${Step0dB}"
	 fi
    db=1
    fi
    # show other steps
    echo "+ '${ndB} dB' Exec exec amixer -c ${1} cset numid=${2} ${x}"
    # show the minimum value as last iteration
    if [ ${x} -le ${CMenuStep} ]
    then if [ ${y} -eq 1 ]
	 then break
	 fi
	 x="${CMenuStep}"
	 y=1
    fi
done

# Send the control name to fvwm
echo "InfoStoreAdd MixerControl \"${CName}\""