%
% 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 
% MEDIACENTER audio

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.

%audtool current-song-filename

[Protocol]=Server

(Init)=\
	Include($(CfgDir)/Utils/aliases-server.cfg);\
        Include($(CfgDir)/Utils/aliases-server-fbrowser-v3i.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);\
	Make(var,cover_size,by_value,);\
	Macro(FBROWSER_IC_INIT);\
	Include($(CfgDir)/Utils/aliases-server-player.cfg);\
	Make(var,audacious_layout,\
	     V=`$(CfgDir)/Utils/registry.sh $(TmpDir) get audacious_layout`;\
	     if [ "x$V" = "x" ]; then echo "5x1"; else echo $V; fi);

(Exit)=\
	Macro(FBROWSER_IC_EXIT);\
	Exec($(CfgDir)/Utils/registry.sh $(TmpDir) set audacious_layout $(audacious_layout));

(Connect)=\
	Make(mode,audacious_$(audacious_layout));

[Mode]=audacious_general

PLAY_ONLY=\
	ExecAndSet(title,audacious -t;audtool current-song|sed 's/%20/ /g');
	
PLAY=\
	Macro(PLAY_ONLY);\
	Timer(AUDACIOUS_TITLE,$(UpdateTimeout),0)
	
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');\
	Macro(AUDACIOUS_TITLE);

STOP=\
	Macro(AUDACIOUS_TITLE_CANCEL);\
	Exec(audacious -s);\
	Set(title,);\
	Set(status,);

NEXT=\
	ExecAndSet(title,audacious -f;audtool current-song|sed 's/%20/ /g');\
	Macro(AUDACIOUS_TITLE);

PAUSE=\
	Exec(audacious -t);

APP_QUIT=\
	Macro(AUDACIOUS_TITLE_CANCEL);\
	Exec(audtool shutdown);

(ExitMode)=\
	Macro(AUDACIOUS_TITLE_CANCEL);

% custom volume control
AUDACIOUS_VOL-=\
	Exec(V=`audtool get-volume`;audtool set-volume `expr $V - 5`)

AUDACIOUS_MUTE=\
	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);

AUDACIOUS_VOL+=\
	Exec(V=`audtool get-volume`;audtool set-volume `expr $V + 5`)

VOL-=Macro(AUDACIOUS_VOL-)
VOL+=Macro(AUDACIOUS_VOL+)

Shuffle=\
	Exec(audtool playlist-shuffle-toggle);
	
Repeat=\
	Exec(audtool playlist-repeat-toggle);
	
Files=\
	Make(mode,audacious_filebrowser);

Playlist=\
	Make(mode,audacious_playlist);

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);\
	Macro(AUDACIOUS_TITLE_CHECK);

RUN_OR_QUIT=\
	Exec(P=`ps auxc|grep audacious`;if [ "x$P" = "x" ]; then audacious -e& else audtool shutdown; fi);

AUDACIOUS_TITLE_GENERAL=\
	ExecAndSet(title,audtool current-song|sed 's/%20/ /g');

AUDACIOUS_TITLE_CHECK=\
	Macro(AUDACIOUS_START_TIMER,audtool playback-playing;echo $?);\

% AUDACIOUS_TITLE must be defined in child modes
AUDACIOUS_START_TIMER=\
	Timer(AUDACIOUS_TITLE,$(UpdateTimeout),0)
	
AUDACIOUS_TITLE_CANCEL=\
	Timer(AUDACIOUS_TITLE,cancel);

APP_PLAY_STATUS=\
	Make(var,audacious_status,audtool playback-status);\
	Make(var,app_status,if [ "x$(audacious_status)" = "xplaying" ]; then echo playing; else echo paused; fi);

Layout 3x4=\
	Make(mode,audacious_3x4);

Layout 7x1=\
	Make(mode,audacious_7x1);

Layout 5x1=\
	Make(mode,audacious_5x1);

[ModeEnd]

[Mode]=audacious_3x4 : audacious_general,default_player

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

APP_MENU=\
	Set(menu,replace,Files,Playlist,Shuffle,Repeat,Layout 7x1,Layout 5x1,Run/Quit,PowerMgmt);\
	Macro(ALLIN1MENU);\
	Macro(MEDIACENTER_MENU);
	
% custom volume control
1=Macro(AUDACIOUS_VOL-)
2=Macro(AUDACIOUS_MUTE)
3=Macro(AUDACIOUS_VOL+)

AUDACIOUS_TITLE=\
	Macro(AUDACIOUS_TITLE_GENERAL);

[ModeEnd]

[Mode]=audacious_cover

% Next Cover,Previous Cover,Update Cover by Utils/aliases-server-player.cfg
% PowerMgmt by Utils/aliases-server.cfg

Mute=\
	Macro(AUDACIOUS_MUTE);

AUDACIOUS_TITLE=\
	Macro(AUDACIOUS_TITLE_GENERAL);\
	Macro(APP_COVER, if [ "x$(cover_size)" = "x" ]; then echo 1; else echo 0; fi);

APP_COVER=\
	Make(var,media_file,\
	     audtool current-song-tuple-data file-path|\
	     sed "s/file:\/\///;s/'/'\\\''/g;s/\//\'\/\'/g;s/\/'$/\//g;s/^'\//\//");\
	Macro(DEFAULT_COVER);
	
Help=\
	Macro(DEFAULT_HELP);

[ModeEnd]

[Mode]=audacious_7x1 : audacious_general,default_player_7x1,audacious_cover

% (EnterMode) by Utils/aliases-server-player.cfg
APP_MENU=\
	Set(menu,replace,Files,Playlist,Mute,Next Cover,Previous Cover,Update Cover,Layout 3x4,Layout 5x1,Help,PowerMgmt);\
	Macro(ALLIN1MENU);\
	Macro(MEDIACENTER_MENU);

APP_POST_SETUP=\
	Make(var,au_volume,by_value,-1);\
	Make(var,audacious_layout,by_value,7x1);

[ModeEnd]

[Mode]=audacious_5x1 : audacious_general,default_player_5x1,audacious_cover

PLAY=\
	Macro(PLAY_ONLY);
	
% (EnterMode) by Utils/aliases-server-player.cfg
APP_MENU=\
	Set(menu,replace,Files,Playlist,Mute,Next Cover,Previous Cover,Update Cover,Layout 3x4,Layout 7x1,Help,PowerMgmt);\
	Macro(ALLIN1MENU);\
	Macro(MEDIACENTER_MENU);

APP_POST_SETUP=\
	Make(var,au_volume,by_value,-1);\
	Make(var,audacious_layout,by_value,5x1);

APP_TITLE=\
	Macro(AUDACIOUS_TITLE);

[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,Remove,Remove All);

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

Back($$)=\
	Make(mode,audacious_$(audacious_layout));
	
Choose($$)=\
	Exec(audtool playlist-jump $(Index));
	
Push($$)=\
	Macro(Choose($$));
	
Remove($$)=\
	Exec(audtool playlist-delete $(Index));\
	ExecAndSet(list,replace,Playlist,\
	           sleep 1;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');\

Remove All($$)=\
	ExecAndSet(list,clear);\
	Exec(audtool playlist-clear);

[ModeEnd]

[Mode]=audacious_nobutton

% bug-prone :)
1=Make(mode,audacious_$(audacious_layout));	
2=Make(mode,audacious_$(audacious_layout));	
3=Make(mode,audacious_$(audacious_layout));	
4=Make(mode,audacious_$(audacious_layout));	
5=Make(mode,audacious_$(audacious_layout));	
6=Make(mode,audacious_$(audacious_layout));	
7=Make(mode,audacious_$(audacious_layout));	
8=Make(mode,audacious_$(audacious_layout));	
9=Make(mode,audacious_$(audacious_layout));	
*=Make(mode,audacious_$(audacious_layout));	
0=Make(mode,audacious_$(audacious_layout));	
#=Make(mode,audacious_$(audacious_layout));	

[ModeEnd]

% rely on $(audacious_layout) variable
[Mode]=audacious_filebrowser:audacious_nobutton

(EnterMode)=\
	Macro(FBROWSER_IC_FILL_LIST);\
	Macro(UpdateMenu);

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

UpdateMenu=\
	Set(menu,replace,GoTo,Add,Go Home);

GoTo($$)=\
	Macro(FBROWSER_IC_GO_TO);
	
Go Home($$)=\
	Macro(FBROWSER_IC_GO_HOME);
	
%Push($$) use from aliases-server-fbrowser-v3i.cfg

Add($$)=\
	Exec(audtool playlist-addurl "$(fbrowser_dir)"/$(Param));

Back($$)=\
	Make(mode,audacious_$(audacious_layout));

[ModeEnd]

[End]
