#!/bin/bash
IFS=$'\n'
TMP="`ps -eo pid,command`"

case $1 in
-mixer) #not in use
#	for I in `echo "$TMP" | grep -F 'func_mixer' | awk '{print $1}'`; do kill -9 $I 2> /dev/null; done
#	killall amixer 2> /dev/null
	echo
	;;
-trackinfo) #user is writing in a id3tag <entry>, and we want to avoid a refresh that would reset content of <entry>
	for I in `echo "$TMP" | grep -F 'func_trackinfo' | awk '{print $1}'`; do kill -9 $I 2> /dev/null; done
echo
	;;
-audio) #interupt playing (ie. when moving progressbar or jump to time) - we don't want to save rating
	echo true > $WORKDIR/NO_RATING
	for I in `echo "$TMP" | grep -F "aplay" | awk '{print $1}'`; do kill -9 $I 2> /dev/null; done
	for I in `echo "$TMP" | grep -F "ffmpeg" | grep -F grep -F '-f au -' | awk '{print $1}'`; do kill -9 $I 2> /dev/null; done
	for I in `echo "$TMP" | grep -F 'func_player -playing' | awk '{print $1}'`; do kill -9 $I 2> /dev/null; done
	for I in `echo "$TMP" | grep -F "streamripper" | grep -F "A -k 0 -u WinampMPEG/5.0 -r 8002" | awk '{print $1}'`; do kill -9 $I 2> /dev/null; done
	killall cdda2wav 2> /dev/null
	;;
*)
	for I in `echo "$TMP" | grep -F 'func_trackinfo' | awk '{print $1}'`; do kill -9 $I 2> /dev/null; done
	for I in `echo "$TMP" | grep -F "func -read_cd" | awk '{print $1}'`; do kill -9 $I 2> /dev/null; done
	for I in `echo "$TMP" | grep -F "aplay" | awk '{print $1}'`; do kill -9 $I 2> /dev/null; done
	for I in `echo "$TMP" | grep -F "ffmpeg" | grep -F 'f au ' | awk '{print $1}'`; do kill -9 $I 2> /dev/null; done
	for I in `echo "$TMP" | grep -F 'func_player -playing' | awk '{print $1}'`; do kill -9 $I 2> /dev/null; done
	for I in `echo "$TMP" | grep -F "streamripper" | grep -F "A -k 0 -u WinampMPEG/5.0 -r 8002" | awk '{print $1}'`; do kill -9 $I 2> /dev/null; done
	killall cdda2wav 2> /dev/null
	;;
esac

