%
% anyremote configuration file for Audacious management (Server-mode)
% 
% Thanks to Eugeny Tereshkov for corrections and advices
%

% STATUS stable
% XTEST no
% SOUND app
% ENV no
% DEF_PLAYER   
% ALL_IN_ONE 

GuiAppName=Audacious
GuiAppBinary=audacious
GuiAppRun=echo 'P=`ps -ef|grep audacious|grep -v grep|grep -v anyremote|grep -v edit`; if [ "x$P" = "x" ]; then echo NOK; else echo OK; fi'|sh -s
GuiAppIcon=audacious.png
GuiAppType=Application
GuiAppProtocols=Server
GuiAppDesc=Audacious is a fork of Beep Media Player (BMP) 0.9.7.1, which in itself was based on XMMS1.

[Protocol]=Server

(Init)=\
	Include($(CfgDir)/Utils/aliases-server.cfg);\
	Exec(P=`which audtool 2> /dev/null|grep audtool|grep -v no|wc -l|tr -d " "`;if [ "x$P" = "x1" ]; then true; else $(CfgDir)/Utils/message.sh "ERROR: audtool package is not installed"; fi);\
	Make(var,player_name,by_value,Audacious);\
	Include($(CfgDir)/Utils/aliases-server-player.cfg);

(Connect)=Make(mode,audacious);

[Mode]=audacious : default_player

% (EnterMode) by Utils/aliases-server-player.cfg
	
APP_POST_SETUP=\
	Make(var,au_volume,by_value,-1);

APP_MENU=\
	Set(menu,replace,Playlist,Toggle Shuffle,Toggle Repeat,Power Off,Suspend);\
	Macro(ALLIN1MENU);
	
AUDACIOUS_TITLE_SET=\
	Macro(AUDACIOUS_TITLE);\
	Timer(AUDACIOUS_TITLE,5,0)
	
AUDACIOUS_TITLE_CANCEL=\
	Timer(AUDACIOUS_TITLE,cancel);
	
AUDACIOUS_TITLE=\
	ExecAndSet(title,audtool current-song|sed 's/%20/ /g')

(ExitMode)=Macro(AUDACIOUS_TITLE_CANCEL)

Toggle Shuffle=Exec(audtool playlist-shuffle-toggle);
Toggle Repeat=Exec(audtool playlist-repeat-toggle);
Playlist=Make(mode,audacious_playlist)

% custom volume control
1=Exec(V=`audtool get-volume`;audtool set-volume `expr $V - 5`)
2=Make(var,au_volume,if [ "x$(au_volume)" = "x-1" ]; then audtool get-volume;audtool set-volume 0; else audtool set-volume $(au_volume); echo "-1"; fi)
3=Exec(V=`audtool get-volume`;audtool set-volume `expr $V + 5`)

% Android support
VOL-=Exec(V=`audtool get-volume`;audtool set-volume `expr $V - 5`)
VOL+=Exec(V=`audtool get-volume`;audtool set-volume `expr $V + 5`)

% 0,4-9,*,# assignments by Utils/aliases-server-player.cfg
PLAY =Exec(audacious -t);Macro(AUDACIOUS_TITLE_SET)
RWD  =Exec(audtool playback-seek-relative -5)
FF   =Exec(audtool playback-seek-relative 5)
PREV =ExecAndSet(title,audacious -r;audtool current-song|sed 's/%20/ /g')
STOP =Exec(audacious -s);Macro(AUDACIOUS_TITLE_CANCEL);
NEXT =ExecAndSet(title,audacious -f;audtool current-song|sed 's/%20/ /g')
PAUSE=Exec(audacious -t);Macro(AUDACIOUS_TITLE_CANCEL);

RUN_IF_NEED=\
	Exec(P=`ps auxc|grep audacious`; if [ "x$P" = "x" ]; then audacious -e& fi);\
	Exec($(CfgDir)/Utils/run-or-switch-to.sh -switch audacious);
RUN_OR_QUIT=Exec(P=`ps auxc|grep audacious`; if [ "x$P" = "x" ]; then audacious -e& else audtool shutdown; fi);
QUIT=Exec(audtool shutdown);Macro(AUDACIOUS_TITLE_CANCEL);

[ModeEnd]

[Mode]=audacious_playlist

(EnterMode)=\
	ExecAndSet(list,replace,Playlist,audtool playlist-display|tr -s  ' '|cut -f 2 -d "|"|grep -v " tracks."|grep -v "Total length"|sed 's/%20/ /g;s/,/\r/g;s/$/,/;s/(/-/g;s/)/-/g');\
	Set(menu,replace,Choose);

(ExitMode)=Set(list,close);\
	Macro(AUDACIOUS_TITLE_SET);

Back($$)=Make(mode,audacious);
Choose($$)=Exec(audtool playlist-jump $(Index));
Push($$)=Macro(Choose($$));

[ModeEnd]

[End]
