TheAtomicAss icon

audio-control.sh

TheAtomicAss | PRO | 03/07/16 06:23:47 AM UTC | 0 ⭐ | 401 👁️ | Never ⏰ | []
Bash |

3.12 KB

|

None

|

0 👍

/

0 👎

#!/bin/bash
set +x
#trap read debug
 
# v 1.0, built for yggdrasil-3
 
# This script handles a variety of different audio configurations, as requested by the window manager (Awesome)
 
 
# Interfaces
 
#     These functions should automatically adjust the interface variable if the interface changes.
#     This is especially a problem with SPK_FACE is it will change when the monitor is swapped.
 
MIC_VOL=6554  # This is 10%, also marked as base in Pavucontrol
MIC_FACE=alsa_input.pci-0000_00_1b.0.`pactl list cards|awk -F ":" '/alsa_card.pci-0000_00_1b.0/{while (!match($0,"Active Profile")) getline;print $4;exit;}'`
SPK_FACE=alsa_output.pci-0000_01_00.1.`pactl list cards|awk -F ":" '/alsa_card.pci-0000_01_00.1/{while (!match($0,"Active Profile")) getline;print $3;exit;}'`
B326HK=alsa_output.pci-0000_01_00.1.hdmi-stereo-extra2
B326HKS=output:hdmi-stereo-extra2
PG279Q=alsa_output.pci-0000_01_00.1.hdmi-stereo
PG279QS=output:hdmi-stereo
NVIDIA_CARD=alsa_card.pci-0000_01_00.1
 
# Functions
MUTE_MIC()
(
  pactl set-source-mute $MIC_FACE toggle;
  IS_MUTED_MIC=`pactl list sources|awk '/'$MIC_FACE'/{while (!match($0,"Mute")) getline;print $2;exit;}'`
  if [ $IS_MUTED_MIC = no ]
    then
      notify-send "Microphone" "Is Unmuted"
    else
      notify-send "Microphone" "Is Muted"
  fi
)
 
FIX_MIC()
(
  pactl set-source-volume $MIC_FACE $MIC_VOL;
  notify-send "Microphone" "Volume set to $(VOL_MIC)"
)
 
MON_WHICH()
(
  echo $SPK_FACE|awk -F "." '{print $4}'
)
 
SWAP_SPK()
(
  if [ $SPK_FACE == "$B326HK" ]
    then
      pactl set-card-profile $NVIDIA_CARD $PG279QS
      notify-send "Monitor Speakers" "Switched to PG279Q"
  elif [ $SPK_FACE == "$PG279Q" ]
    then
      pactl set-card-profile $NVIDIA_CARD $B326HKS
      notify-send "Monitor Speakers" "Switched to B326HK"
    else
      notify-send "Monitor Speakers" "Alternate output selected, ABORTING"
  fi
  #pactl # In progress
  notify-send "Monitor Speakers" "Switched output to: $SPK_FACE"
)
 
LOWR_SPK()
(
  pactl set-sink-volume $SPK_FACE -5%;
  notify-send "Monitor Speakers" "Volume set to $(VOL_SPK)"
)
 
RISE_SPK()
(
  pactl set-sink-volume $SPK_FACE +5%;
  notify-send "Monitor Speakers" "Volume set to $(VOL_SPK)"
)
 
MUTE_SPK()
(
  pactl set-sink-mute $SPK_FACE toggle;
  IS_MUTED_SPK=`pactl list sinks|awk '/'$SPK_FACE'/{while (!match($0,"Mute")) getline;print $2;exit;}'`
  if [ $IS_MUTED_SPK = no ]
    then
      notify-send "Monitor Speakers" "Is Unmuted"
    else
      notify-send "Monitor Speakers" "Is Muted"
  fi
)
 
# Volume tests
VOL_MIC()
(
  pactl list sources|awk '/'$MIC_FACE'/{while (!match($0,"Volume")) getline; print $5; exit; }'
)
 
VOL_SPK()
(
  pactl list sinks|awk '/'$SPK_FACE'/{while (!match($0,"Volume")) getline; print $5; exit; }'
)
 
# Process input commands
case $1 in
        micmute)MUTE_MIC;;
        miclkvl)FIX_MIC;;
        spkmute)MUTE_SPK;;
        spkvlup)RISE_SPK;;
        spkvldn)LOWR_SPK;;
        spkswap)SWAP_SPK;;
              *)echo "Audio Control: No valid command specified";
                notify-send "Audio Control: Error" "No valid command specified";;
esac

Comments