| 1 |
# Support for mixer controls in FVWM-Crystal |
| 2 |
# Written by: Dominique Michel <[email protected]> |
| 3 |
# |
| 4 |
# This file contain code for all the mixers. |
| 5 |
# |
| 6 |
# The original mixers are ALSA mixer (alsamixer, alsamixergui and |
| 7 |
# alsamixerguis (a script part of bmpdj)), |
| 8 |
# audacious, aumix, cdcd, cmus, mpd, quodlibet and xmms2. |
| 9 |
# |
| 10 |
# The original controls was written by Maciej Delmanowski <[email protected]> |
| 11 |
# at the exception of alsamixer, bindings for multimadia keys |
| 12 |
# and dB support by Dominique Michel, |
| 13 |
# audacious control by Rafael Antonio Porras Samaniego <[email protected]> |
| 14 |
# and xmms2 control by Michal Gorny <[email protected]> |
| 15 |
# |
| 16 |
# Only alsamixer do have direct dB control. This is a must have feature for a professional audio mixer. |
| 17 |
# It will be approximated for the other mixers. |
| 18 |
# Update: The alsamixer control use now the alsamixer native steps, it was tested |
| 19 |
# with card using dB. It should hopefully work for cards without dB support, at the exception of the |
| 20 |
# volume tooltip. |
| 21 |
# |
| 22 |
# Alsamixer support up to eight sound cards. You can choose the one and the volume control in the prefs. |
| 23 |
# |
| 24 |
# To call the functions, in the menus, it is part of "Popup /Music" |
| 25 |
# Button 1: Mouse 4 "Change-Volume-Up"; Mouse 5 "Change-Volume-Down" |
| 26 |
# Button 2: Mouse 3 "Menu /Mixer" |
| 27 |
# |
| 28 |
# Amixer do have tooltip support now; it show the current volume. |
| 29 |
|
| 30 |
# Preferences {{{1 |
| 31 |
# If there is no selected mixer, load the default |
| 32 |
LoadPreferences DefaultMixer |
| 33 |
CheckPreferences DefaultMixer "InfoStoreAdd Mixer amixer" |
| 34 |
# If there is no selected sound card and device, load the default |
| 35 |
LoadPreferences DefaultSoundCard |
| 36 |
CheckPreferences DefaultSoundCard "InfoStoreAdd SoundCard 0" |
| 37 |
LoadPreferences DefaultSoundDevice |
| 38 |
CheckPreferences DefaultSoundDevice "InfoStoreAdd SoundDevice 1" |
| 39 |
|
| 40 |
# AlsaMixer: value for volume steps in dB. It is hardware dependant. With the other |
| 41 |
# mixers, the result will vary. Use only decimal . as separator or bc will bail: |
| 42 |
PipeRead 'if [ $[infostore.Mixer] = amixer ] ; then \\ |
| 43 |
echo "InfoStoreAdd Vol_Step `amixer -c$[infostore.SoundCard] cget numid=$[infostore.SoundDevice]|grep dB|sed -e \\"s:\\(.*step=\\)\\(.*dB\\)\\(.*\\):\\2:\\" -e \\"s:dB::\\"`"; \\ |
| 44 |
else echo "InfoStoreAdd Vol_Step 1.5"; fi' |
| 45 |
PipeRead 'if [ $[infostore.Mixer] = amixer ] ; then \\ |
| 46 |
echo "InfoStoreAdd Vol_StepMax `amixer -c$[infostore.SoundCard] cget numid=$[infostore.SoundDevice]|grep type|sed -e \\"s:\\(.*max=\\)\\(.*,step\\)\\(.*\\):\\2:\\" -e \\"s:,step::\\"`"; fi' |
| 47 |
|
| 48 |
# Initialisations {{{1 |
| 49 |
# aumix {{{2 |
| 50 |
# Set VolControl: Test if MASTER mixer exist, fallback to PCM |
| 51 |
PipeRead "if [ $[infostore.Mixer] = aumix ] ; then NVolControl=`aumix -d /dev/mixer$[infostore.SoundCard] -q | grep \'master\\|vol\' -c` ; echo InfoStoreAdd VolControl `if [ $NVolControl = 0 ]; then echo w; else echo v ; fi` ; fi" |
| 52 |
|
| 53 |
# amixer: Memorize the volume {{{2 |
| 54 |
DestroyFunc AmixerCurrentVolume |
| 55 |
AddToFunc AmixerCurrentVolume |
| 56 |
+ I PipeRead 'if [ $[infostore.Mixer] = amixer ] ; then \\ |
| 57 |
echo "InfoStoreAdd CurrentVolume `amixer -c $[infostore.SoundCard] cget numid=$[infostore.SoundDevice] | grep \": values\" | sed -e \"s:.*values=::\" -e \"s:,.*::\"`"; \\ |
| 58 |
fi' |
| 59 |
PipeRead 'if [ $[infostore.Mixer] = amixer ] ; then \\ |
| 60 |
echo AmixerCurrentVolume; fi' |
| 61 |
|
| 62 |
# Mute = off {{{2 |
| 63 |
InfoStoreAdd MixerMute 0 |
| 64 |
InfoStoreAdd MixerMuteAP 0 |
| 65 |
InfoStoreAdd MixerMuteCdcd 0 |
| 66 |
InfoStoreAdd MixerMuteMP 0 |
| 67 |
InfoStoreAdd MixerMuteMP2 0 |
| 68 |
|
| 69 |
# Basics functions {{{1 |
| 70 |
# Mixer-Volume <value> {{{2 |
| 71 |
# 0 <= value <= 100; used by the menu |
| 72 |
# amixer use the native amixer steps |
| 73 |
DestroyFunc Mixer-Volume |
| 74 |
AddToFunc Mixer-Volume |
| 75 |
+ I PipeRead 'case $[infostore.Mixer] in \\ |
| 76 |
amixer) exec amixer -c $[infostore.SoundCard] cset numid=$[infostore.SoundDevice] `echo \"(87-(($[0]*(100/$[infostore.Vol_StepMax]))*$[infostore.Vol_Step]))\"|bc -l` > /dev/null ; \\ |
| 77 |
echo AmixerCurrentVolume ;; \\ |
| 78 |
aumix) exec aumix -d /dev/mixer$[infostore.SoundCard] -\'$[infostore.VolControl]\' $[0] ;; \\ |
| 79 |
audacious) exec audtool set-volume $[0] ;; \\ |
| 80 |
cdcd) exec cdcd setvol $[0] > /dev/null ;; \\ |
| 81 |
cmus) exec cmus-remote --volume $[0]% > /dev/null ;; \\ |
| 82 |
mpd) exec mpc volume $[0] > /dev/null ;; \\ |
| 83 |
quodlibet) exec quodlibet --volume $[0] > /dev/null ;; \\ |
| 84 |
xmms2) exec xmms2 config output.volume $[0]/$[0] ;; \\ |
| 85 |
*) exec amixer -c $[infostore.SoundCard] set '$[infostore.VolControl]' $[0] > /dev/null ;; \\ |
| 86 |
esac' |
| 87 |
|
| 88 |
# Change-Volume-Up <step> {{{2 |
| 89 |
DestroyFunc Change-Volume-Up |
| 90 |
AddToFunc Change-Volume-Up |
| 91 |
+ I PipeRead 'case $[infostore.Mixer] in \\ |
| 92 |
amixer) tmpval=`amixer -c $[infostore.SoundCard] cget numid=$[infostore.SoundDevice] | grep \": values\" | sed -e \"s:.*values=::\" -e \"s:,.*::\"`; \\ |
| 93 |
echo "InfoStoreAdd CurrentVolume $((${tmpval}+1))" ; \\ |
| 94 |
if [ $0 != 10 ]; then \\ |
| 95 |
exec amixer -c $[infostore.SoundCard] cset numid=$[infostore.SoundDevice] $((${tmpval}+1)) > /dev/null; \\ |
| 96 |
else exec amixer -c $[infostore.SoundCard] cset numid=$[infostore.SoundDevice] $((${tmpval}+2)) > /dev/null; fi ;; \\ |
| 97 |
aumix) step=$(echo $[infostore.Vol_Step]*2|bc -l) ; exec aumix -d /dev/mixer$[infostore.SoundCard] -'$[infostore.VolControl]' +${step} ;; \\ |
| 98 |
audacious) exec audtool set-volume +$[0] ;; \\ |
| 99 |
cdcd) echo Nop ;; \\ |
| 100 |
cmus) exec cmus-remote --volume +$[0]% > /dev/null ;; \\ |
| 101 |
mpd) exec mpc volume +`echo "($[0]*2+0.5)/1" | bc` > /dev/null ;; \\ |
| 102 |
quodlibet) exec quodlibet --volume-up > /dev/null ;; \\ |
| 103 |
xmms2) echo Nop ;; \\ |
| 104 |
*) echo Nop ;; \\ |
| 105 |
esac' |
| 106 |
+ I PipeRead 'if [ $[infostore.Mixer] = amixer ]; then \\ |
| 107 |
echo Volume-Tooltip; echo Deschedule $[schedule.last]; echo Schedule 1500 Kill-FvwmTooltip Volume; fi' |
| 108 |
|
| 109 |
# Change-Volume-Down <value> {{{2 |
| 110 |
DestroyFunc Change-Volume-Down |
| 111 |
AddToFunc Change-Volume-Down |
| 112 |
+ I PipeRead 'case $[infostore.Mixer] in \\ |
| 113 |
amixer) tmpval=`amixer -c $[infostore.SoundCard] cget numid=$[infostore.SoundDevice] | grep \": values\" | sed -e \"s:.*values=::\" -e \"s:,.*::\"`; \\ |
| 114 |
echo "InfoStoreAdd CurrentVolume $((${tmpval}-1))" ; \\ |
| 115 |
if [ $0 != 10 ]; then \\ |
| 116 |
exec amixer -c $[infostore.SoundCard] cset numid=$[infostore.SoundDevice] $((${tmpval}-1)) > /dev/null ; \\ |
| 117 |
else exec amixer -c $[infostore.SoundCard] cset numid=$[infostore.SoundDevice] $((${tmpval}-2)) > /dev/null; fi ;; \\ |
| 118 |
aumix) step=$(echo $[infostore.Vol_Step]*2|bc -l) ; exec aumix -d /dev/mixer$[infostore.SoundCard] -'$[infostore.VolControl]' -"${step}" ;; \\ |
| 119 |
audacious) exec audtool set-volume -$[0] ;; \\ |
| 120 |
cdcd) echo Nop ;; \\ |
| 121 |
cmus) exec cmus-remote --volume -$[0]% > /dev/null ;; \\ |
| 122 |
mpd) exec mpc volume -`echo "($[0]*2+0.5)/1" | bc` > /dev/null ;; \\ |
| 123 |
quodlibet) exec quodlibet --volume-down > /dev/null ;; \\ |
| 124 |
xmms2) echo Nop ;; \\ |
| 125 |
*) echo Nop ;; \\ |
| 126 |
esac' |
| 127 |
+ I PipeRead 'if [ $[infostore.Mixer] = amixer ]; then \\ |
| 128 |
echo Volume-Tooltip; echo Deschedule $[schedule.last]; echo Schedule 1500 Kill-FvwmTooltip Volume; fi' |
| 129 |
|
| 130 |
# Mixer volume toggle mute {{{2 |
| 131 |
# Selected player will toggle the pause. |
| 132 |
# If alsamixer or aumix is selected, it will mute toggle too. |
| 133 |
DestroyFunc Mixer-Volume-Toggle |
| 134 |
AddToFunc Mixer-Volume-Toggle |
| 135 |
+ I PipeRead 'if [ $[infostore.Mixer] = amixer ]; then \\ |
| 136 |
if [ $[infostore.MixerMute] = 0 ]; then \\ |
| 137 |
amixer -c $[infostore.SoundCard] cset numid=$[infostore.SoundDevice] 0 > /dev/null; echo "InfoStoreAdd MixerMute 1"; \\ |
| 138 |
else amixer -c $[infostore.Soundcard] cset numid=$[infostore.SoundDevice] $[infostore.CurrentVolume] > /dev/null; echo "InfoStoreAdd MixerMute 0"; fi; fi' |
| 139 |
+ I PipeRead 'if [ $[infostore.Mixer] = aumix ]; then \\ |
| 140 |
if [ $[infostore.MixerMute] = 0 ]; then echo "InfoStoreAdd MixerMute 1"; tmpval=`aumix -d /dev/mixer$[infostore.SoundCard] -'$[infostore.VolControl]'q | sed -e "s:.*, ::"`; echo "InfoStoreAdd CurrentVolume $tmpval"; exec aumix -d /dev/mixer$[infostore.SoundCard] -'$[infostore.VolControl]' 0 > /dev/null; else echo "InfoStoreAdd MixerMute 0"; exec aumix -d /dev/mixer$[infostore.SoundCard] -'$[infostore.VolControl]' $[infostore.CurrentVolume] > /dev/null; fi; fi' |
| 141 |
+ I PipeRead 'if [ $[infostore.MusicPlayer] = audacious ]; then \\ |
| 142 |
exec audtool playback-playpause > /dev/null; fi' |
| 143 |
+ I PipeRead 'if [ $[infostore.MusicPlayer] = cdcd ]; then \\ |
| 144 |
if [ $[infostore.MixerMuteCdcd] = 0 ]; then echo "InfoStoreAdd MixerMuteCdcd 1"; exec cdcd pause > /dev/null; else echo "InfoStoreAdd MixerMuteCdcd 0"; cdcd resume > /dev/null; fi; fi' |
| 145 |
+ I PipeRead 'if [ $[infostore.Musicplayer] = cmus ]; then \\ |
| 146 |
exec cmus-remote --pause > /dev/null; fi' |
| 147 |
+ I PipeRead 'if [ $[infostore.MusicPlayer] = mpd ]; then \\ |
| 148 |
exec mpc toggle > /dev/null; fi' |
| 149 |
+ I PipeRead 'if [ $[infostore.MusicPlayer] = quodlibet ]; then \\ |
| 150 |
exec quodlibet --play-pause > /dev/null; fi' |
| 151 |
+ I PipeRead 'if [ $[infostore.MusicPlayer] = xmms2 ]; then \\ |
| 152 |
exec xmms2 toggle > /dev/null; fi' |
| 153 |
# the other players |
| 154 |
+ I PipeRead 'if [ $[infostore.MusicPlayer] = alsaplayer ] || [ $[infostore.MusicPlayer] = alsaplayerdaemon ]; then \\ |
| 155 |
if [ $[infostore.MixerMuteAP] = 0 ]; then echo "InfoStoreAdd MixerMuteAP 1"; exec alsaplayer --speed 0; else echo "InfoStoreAdd MixerMuteAP 0"; exec alsaplayer --speed $[infostore.speed]; fi; fi' |
| 156 |
+ I PipeRead 'if [ $[infostore.MusicPlayer] = mocp ]; then \\ |
| 157 |
exec mocp --sync --toggle-pause; fi' |
| 158 |
+ I PipeRead 'if [ $[infostore.MusicPlayer] = mplayer ]; then \\ |
| 159 |
if [ $[infostore.MixerMuteMP] = 0 ]; then echo "InfoStoreAdd MixerMuteMP 1"; echo "Exec exec echo pause > /home/$[infostore.USERDIR]/.mplayer/pipe"; else echo "InfoStoreAdd MixerMuteMP 0"; echo "Exec exec echo pause > /home/$[infostore.USERDIR]/.mplayer/pipe"; fi; fi' |
| 160 |
+ I PipeRead 'if [ $[infostore.MusicPlayer] = mplayer2 ]; then \\ |
| 161 |
if [ $[infostore.MixerMuteMP2] = 0 ]; then echo "InfoStoreAdd MixerMuteMP2 1"; echo "Exec exec echo pause > /home/$[infostore.USERDIR]/.mplayer/pipe"; else echo "InfoStoreAdd MixerMuteMP2 0"; echo "Exec exec echo pause > /home/$[infostore.USERDIR]/.mplayer/pipe"; fi; fi' |
| 162 |
|
| 163 |
# Mixer volume mute toggle mute {{{2 |
| 164 |
# Toggle only alsamixer or aumix if selected. |
| 165 |
DestroyFunc Mixer-Mute-Toggle |
| 166 |
AddToFunc Mixer-Mute-Toggle |
| 167 |
+ I PipeRead 'if [ $[infostore.Mixer] = amixer ]; then \\ |
| 168 |
if [ $[infostore.MixerMute] = 0 ]; then \\ |
| 169 |
amixer -c $[infostore.SoundCard] cset numid=$[infostore.SoundDevice] 0 > /dev/null; echo "InfoStoreAdd MixerMute 1"; \\ |
| 170 |
else amixer -c $[infostore.Soundcard] cset numid=$[infostore.SoundDevice] $[infostore.CurrentVolume] > /dev/null; echo "InfoStoreAdd MixerMute 0"; fi; fi' |
| 171 |
+ I PipeRead 'if [ $[infostore.Mixer] = aumix ]; then \\ |
| 172 |
if [ $[infostore.MixerMute] = 0 ]; then echo "InfoStoreAdd MixerMute 1"; tmpval=`aumix -d /dev/mixer$[infostore.SoundCard] -'$[infostore.VolControl]'q | sed -e "s:.*, ::"`; echo "InfoStoreAdd CurrentVolume $tmpval"; exec aumix -d /dev/mixer$[infostore.SoundCard] -'$[infostore.VolControl]' 0 > /dev/null; else echo "InfoStoreAdd MixerMute 0"; exec aumix -d /dev/mixer$[infostore.SoundCard] -'$[infostore.VolControl]' $[infostore.CurrentVolume] > /dev/null; fi; fi' |
| 173 |
|
| 174 |
# Show/Hide the GUI {{{2 |
| 175 |
DestroyFunc Mixer-GUI |
| 176 |
AddToFunc Mixer-GUI |
| 177 |
PipeRead 'case $[infostore.Mixer] in \\ |
| 178 |
amixer) echo "+ I All (\\\"ALSA Mixer\\\") Close" ; \\ |
| 179 |
echo "+ I TestRc (Match) Break" ; \\ |
| 180 |
echo "+ I TestRc (NoMatch) None (\\\"ALSA Mixer\\\") Test (x alsamixerguis) X alsamixerguis" ; \\ |
| 181 |
echo "+ I TestRc (Match) None (\\\'ALSA Mixer\\\') AT \\\"ALSA Mixer\\\" \\\"alsamixer -c $[infostore.SoundCard]\\\"" ;; \\ |
| 182 |
aumix) echo "+ I All (aumix) Close" ; \\ |
| 183 |
echo "+ I TestRc (NoMatch) X aumix -d /dev/mixer$[infostore.SoundCard] -I" ;; \\ |
| 184 |
audacious) echo "+ I Nop" ;; \\ |
| 185 |
cdcd) echo "+ I Nop" ;; \\ |
| 186 |
cmus) echo "+ I Nop" ;; \\ |
| 187 |
mpd) echo "+ I Nop" ;; \\ |
| 188 |
quodlibet) echo "+ I Nop" ;; \\ |
| 189 |
xmms2) echo "+ I Nop" ;; \\ |
| 190 |
*) echo "+ I Nop" ;; \\ |
| 191 |
esac' |
| 192 |
|
| 193 |
# Menus {{{1 |
| 194 |
# Mixer menu {{{2 |
| 195 |
DestroyMenu /Mixer |
| 196 |
AddToMenu /Mixer |
| 197 |
+ '%22x22/fvwm-crystal/mixer-2.png%$[gt.Show main mixer]' Mixer-GUI |
| 198 |
+ '%22x22/fvwm-crystal/mixer.png%$[gt.Audio mixer]' Popup /Preferences/Mixer |
| 199 |
+ '' Nop |
| 200 |
PipeRead 'if [ $[infostore.Mixer] = amixer ] ; \\ |
| 201 |
then $[FVWM_SYSTEMDIR]/scripts/AmixerControl $[infostore.SoundCard] $[infostore.SoundDevice]; \\ |
| 202 |
else echo \"+ \\\"$[infostore.Mixer]\\\" Nop\"; \\ |
| 203 |
for i in 0 -3 -6 -9 -12 -15 -18 -24 -30 -36 -42 -48 -54 -60 -100 ; \\ |
| 204 |
do case $i in \\ |
| 205 |
0) vol=100;; \\ |
| 206 |
-3) vol=95;; \\ |
| 207 |
-6) vol=91;; \\ |
| 208 |
-9) vol=86;; \\ |
| 209 |
-12) vol=81;; \\ |
| 210 |
-15) vol=76;; \\ |
| 211 |
-18) vol=72;; \\ |
| 212 |
-24) vol=62;; \\ |
| 213 |
-30) vol=53;; \\ |
| 214 |
-36) vol=43;; \\ |
| 215 |
-42) vol=34;; \\ |
| 216 |
-48) vol=24;; \\ |
| 217 |
-54) vol=15;; \\ |
| 218 |
-60) vol=6;; \\ |
| 219 |
-100) vol=0;; \\ |
| 220 |
*) vol=50;; \\ |
| 221 |
esac; \\ |
| 222 |
echo \"+ \\\"${i} dB\\\" Mixer-Volume ${vol}\" ; \\ |
| 223 |
done; fi' |
| 224 |
|
| 225 |
# Volume tooltip {{{1 |
| 226 |
# amixer: Show the volume tooltip in dB |
| 227 |
DestroyFunc Volume-Tooltip |
| 228 |
AddToFunc Volume-Tooltip |
| 229 |
+ I PipeRead '$[FVWM_SYSTEMDIR]/scripts/AmixerCurrentdBVolume $[infostore.SoundCard] $[infostore.SoundDevice]' |
| 230 |
+ I PipeRead 'echo "Fvwm-Tooltip Volume \\"$[infostore.MixerControl]\\" \\"$[infostore.CurrentdBVolume] dB\\" +$(($[vp.width]/2))-$(($[vp.height]/2)) 20 750"' |
| 231 |
#+ I PipeRead 'echo "Fvwm-Tooltip Volume \\"$[gt.Sound Card] $[infostore.SoundCard] $[infostore.MixerControl]\\" \\"$[infostore.CurrentdBVolume] dB\\" +$(($[vp.width]/2))-$(($[vp.height]/2)) 20 750"' |
| 232 |
|
| 233 |
# vim:ft=fvwm |