#!/usr/bin/env bash # # ------------------------------------------------------------------ # made by sputnick in da FreAkY lAb (c) 2010 # gilles.quenot gmail com # # This program is free software; you can redistribute it and/or # modify it under the terms of version 2 of the GNU General Public # License published by the Free Software Foundation. # (see http://www.gnu.org/licenses/gpl.html). # ------------------------------------------------------------------ # ,,_ # o" )@ # '''' # ------------------------------------------------------------------ # # $Date: 2010-07-14 20:12:46 +0200 (mer. 14 juil. 2010) $ # # -----8<-------------------------------------------------------- # see http://wiki.ekiga.org/index.php/Audio_setup#Audio_tricks # -----8<-------------------------------------------------------- # **PLEASE EDIT THIS VARIABLES TO FIT YOUR NEEDS** # volume controls to set ( see alsamixer ) EkigaControls="Master PCM Front" # volume control to mute when calling EkigaControlMute="Front" # the default volume level in % EkigaControlsVol=50 # the capture control EkigaControlCapture="Capture" # alsa hardware device EkigaHardwareDevice="hw:0" # the Ekiga binary path EkigaPath="/usr/bin/ekiga" # The sound applications to stops on incoming calls # mplayer will be really killed because it can't be "paused" # with a SITSTOP signal, so, don't put it in the list bellow EkigaSoundSoftKill="vlc nsplugin amarok kaffeine totem xmms" # -----8<-------------------------------------------------------- # MAIN CODE # Don't edit if you don't know what you are doing readlink -f /proc/$$/exe | grep &>/dev/null bash || { echo >&2 "Hey dude ! You must call $0 with bash ! WTF ?!" exit 2 } . ~/.bashrc || . /etc/profile rmdir &>/dev/null /tmp/z95ds8rm trap 'retval=$?; rmdir &>/dev/null /tmp/z95ds8rm; exit $retval' 0 1 2 3 15 Die() { tput setaf 1 echo >&2 "$@" tput sgr0 exit 1 } EkigaKilla() { # if there's another instance, don't make war [[ -d /tmp/z95ds8rm ]] && return 0 # simple lock mkdir /tmp/z95ds8rm if [[ $EkigaSoundToKillMplayer ]]; then commandPlayer=$(ps -o command $EkigaSoundToKillMplayer | tail -1) pkill mplayer fi # pause some sound applications [[ ${EkigaSoundToKill[@]} ]] && kill -SIGSTOP ${EkigaSoundToKill[@]} # prompt user to re-play sounds via zenity dialog box if LC_ALL=C zenity --question --title ekiga --text "Do you want sound application to continue ?\nYES to continue, NO to kill the processus"; then # unmute volume controls if reply is "yes" for control in $EkigaControls; do amixer &>/dev/null -D$EkigaHardwareDevice set "$control",0 ${EkigaControlsVol}%,${EkigaControlsVol}% unmute done # let's continue playing sounds [[ "$commandPlayer" ]] && eval "$commandPlayer &>/dev/null &" [[ $MyEkiPids ]] && kill -SIGCONT $MyEkiPids rmdir &>/dev/null /tmp/z95ds8rm else # "no" reply kill $MyEkiPids rmdir &>/dev/null /tmp/z95ds8rm fi } # various system checks (( $(printf "%s\n" /dev/snd/* | wc -l) > 2 )) || Die "You must use a working alsa configuration" [[ -x $EkigaPath ]] || Die "You must have ekiga installed and 'EkigaPath' variable set in $0" type &>/dev/null zenity || Die "You must install zenity" type &>/dev/null inotifywait || Die "You must install inotify" type &>/dev/null sox || Die "You must install sox" type &>/dev/null amixer || Die "You must install alsa-utils" # get the call sound file path from ekiga XML configuration EkigaSound=$(gconftool-2 -g /apps/ekiga/general/sound_events/incoming_call_sound) || Die "Can't read XML ekiga configuration !" # start ekiga in the background and stop the whole script when ekiga dies { $EkigaPath "$@"; pkill -f "inotifywait -q -r -m $EkigaSound"; kill $$; } & # how many seconds is required to play the ring file ? set +x; exec 3>&1 4>&2 EkigaSoundTime=$( { TIMEFORMAT='%E'; time play -q "$EkigaSound" vol 0 1>&3 2>&4; } 2>&1 ) exec 3>&- 4>&- grep "^[0-9]+$" <<< $EkigaSoundTime || EkigaSoundTime=1.8 # listening events on sound file with inotify to know when someone call us, then, # let's set volumes. inotifywait -q -r -m "$EkigaSound" | while read a; do if [[ $a == *OPEN* ]]; then EkigaSoundToKillMplayer="$(pgrep mplayer)" EkigaSoundToKill=( $(for i in $EkigaSoundSoftKill; do pgrep $i; done) ) [[ ${EkigaSoundToKill[@]} || $EkigaSoundToKillMplayer ]] && EkigaKilla & # makes alsa ringing in all desired volume controls for control in $EkigaControls; do amixer &>/dev/null -D$EkigaHardwareDevice set "$control",0 ${EkigaControlsVol}%,${EkigaControlsVol}% unmute done # sleeping while the sound is playing sleep $EkigaSoundTime amixer &>/dev/null -D$EkigaHardwareDevice set "$EkigaControlCapture" 85% cap amixer &>/dev/null -D$EkigaHardwareDevice set "$EkigaControlMute" mute fi done # vim:ts=4:sw=4