%
% anyremote configuration file for Xmms2 management (Server-mode)
%
% prerequisites: xmms2-client-cli package
%
% Thanks to Gyuris Szabolcs for original version of this configuration file
%

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

GuiAppName=Xmms2
GuiAppBinary=xmms2
GuiAppRun= P=`ps -ef|grep xmms2d|grep -v grep|grep -v anyremote|grep -v edit`; if [ "x$P" = "x" ]; then echo NOK; else echo OK; fi
GuiAppIcon=xmms.png
GuiAppType=Application
GuiAppProtocols=Server
GuiAppDesc=XMMS2 is definitely an audio player. But it is  not a general multimedia player - it will not play videos. It has a modular framework and plugin architecture for audio processing, visualisation and output, but this framework has not been designed to support video.

[Protocol]=Server

(Init)=\
	Include($(CfgDir)/Utils/aliases-server.cfg);\
	Make(var,player_name,by_value,Xmms2);\
	Include($(CfgDir)/Utils/aliases-server-player.cfg);\
	Make(var,cover_size,by_value,);\
	Make(var,xmms2_layout,\
	     V=`$(CfgDir)/Utils/registry.sh $(TmpDir) get xmms2_layout`;\
	     if [ "x$V" = "x" ]; then echo "3x4"; else echo $V; fi);

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

(Connect)=\
	Make(mode,xmms2_$(xmms2_layout));

[Mode]=xmms2_general

XMMS2_VOL-=\
	Exec(xmms2 server volume -5);
	
XMMS2_MUTE=\
	Make(var,x2_volume,\
	         if [ "x$(x2_volume)" = "x-1" ]; then \
		     xmms2 server volume|tail -1|tr -d " "|cut -f 2 -d "=";xmms2 server volume 0; \
		 else \
		     xmms2 server volume $(x2_volume); echo "-1";\
		 fi);

XMMS2_VOL+=\
	Exec(xmms2 server volume +5)

% Android support
VOL-=Macro(XMMS2_VOL-);
VOL+=Macro(XMMS2_VOL+);

% Gestures support
SlideDown=Macro(XMMS2_VOL-);
SlideUp  =Macro(XMMS2_VOL+);

RWD=\
	Exec(xmms2 seek -10);

PLAY=\
	Exec(xmms2 play);\
	Macro(XMMS2_TIMER_START);

FF=\
	Exec(xmms2 seek +10)

PREV=\
	Exec(xmms2 prev);\
	Macro(XMMS2_TITLE_DELAYED);

STOP=\
	Macro(XMMS2_TIMER_CANCEL);\
	Exec(xmms2 stop);

NEXT=\
	Exec(xmms2 next);\
	Macro(XMMS2_TITLE_DELAYED);

PAUSE=\
	Exec(xmms2 pause);\
	Macro(XMMS2_CHECK_TIMER);

APP_QUIT=\
	Macro(XMMS2_TIMER_CANCEL);\
	Exec(xmms2 quit);

RUN_IF_NEED=\
	Exec(P=`ps -ef|grep -v grep|grep -v anyremote|grep xmms2d`; \
	     if [ "x$P" = "x" ]; then \
	     	xmms2-launcher; \
	     fi);
	
RUN_OR_QUIT=\
	Exec(P=`ps -ef|grep -v grep|grep -v anyremote|grep xmms2d`; \
	     if [ "x$P" = "x" ]; then \
	     	xmms2-launcher; \
	     else \
	     	xmms2 quit; \
	     fi);

% XMMS2_TITLE should be defined in child modes

XMMS2_TIMER_START=\
	Macro(XMMS2_TITLE);\
	Timer(XMMS2_TITLE,$(UpdateTimeout),0);

XMMS2_TIMER_CANCEL=\
	Timer(XMMS2_TITLE,cancel);\
	Set(title,);\
	Set(status,);

% Too simple :-)
%	ExecAndSet(title,xmms2 current|cut -f 2 -d":");
XMMS2_TITLE_GENERAL=\
	Make(var,alb,xmms2 info|grep 'album ='|cut -f 2 -d "=");\
	Make(var,tit,xmms2 info|grep 'title ='|cut -f 2 -d "=");\
	Make(var,art,xmms2 info|grep 'artist ='|cut -f 2 -d "=");\
	Set(title,$(alb) - $(tit));\
	Set(status,$(art));

XMMS2_TITLE_DELAYED=\
	Make(var,dummy,sleep 1;echo 0);\
	Macro(XMMS2_TITLE);
	
XMMS2_CHECK_TIMER=\
	Make(var,xmms2_status,xmms2 current|cut -f 1 -d ":");\
	Make(var,timer_action,if [ "x$(xmms2_status)" = "xPlaying" ]; \
	                      then echo XMMS2_TIMER_START; else echo XMMS2_TIMER_CANCEL; fi);\
	Macro($(timer_action));

Shuffle=\
	Exec(xmms2 playlist shuffle);

% there isn't any repeat in xmms2 cli now 
% Repeat=Exec(xmms2 repeat);

Playlist=\
	Make(mode,xmms2_playlist);

Audio Device=\
	Timer(XMMS2_TITLE,cancel);\
	Make(mode,xmms2_audio);

Xmms2 cmd=\
	Make(mode,xmms2_clicmd)

[ModeEnd]

[Mode]=xmms2_3x4 : xmms2_general,default_player

% (EnterMode) by Utils/aliases-server-player.cfg

APP_PRE_SETUP=\
	Make(var,x2_volume,by_value,-1);

APP_POST_SETUP=\
	Make(var,xmms2_layout,by_value,3x4);\
	Macro(XMMS2_CHECK_TIMER);

% PowerMgmt by Utils/aliases-server.cfg
APP_MENU=\
	Set(menu,replace,Playlist,Shuffle,Layout 7x1,Audio Device,Xmms2 cmd,PowerMgmt);\
	Macro(ALLIN1MENU)

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

% Override
1=Macro(XMMS2_VOL-);
2=Macro(XMMS2_MUTE);
3=Macro(XMMS2_VOL+);

XMMS2_TITLE=\
	Macro(XMMS2_TITLE_GENERAL);

[ModeEnd]

[Mode]=xmms2_7x1 : xmms2_general,default_player_7x1

% (EnterMode) by Utils/aliases-server-player.cfg

% Next Cover, Previous Cover,Update Cover, Help, PowerMgmt by Utils/aliases-server-player.cfg
APP_MENU=\
	Set(menu,replace,Playlist,Shuffle,Mute,Next Cover,Previous Cover,Update Cover,Layout 3x4,Help,Audio Device,Xmms2 cmd,PowerMgmt);\
	Macro(ALLIN1MENU);

APP_POST_SETUP=\
	Make(var,xmms2_layout,by_value,7x1);\
	Macro(XMMS2_CHECK_TIMER);

Mute=\
	Macro(XMMS2_MUTE);

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

APP_COVER=\
	Make(var,media_file,xmms2 info|grep 'url = file'|sed "s/.*\/\/\//\//;s/'/'\\\''/g;s/\//\'\/\'/g;s/$/\'/g;s/^'\//\//");\
	Macro(DEFAULT_COVER);

Mute=\
	Macro(TOGGLE_MUTE_MPRIS);

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

[ModeEnd]

[Mode]=xmms2_playlist

(EnterMode)=\
	Set(list,font,small);\
	ExecAndSet(list,replace,Playlist,\
	           L=`xmms2 list| grep "\["|tr -d ','|sed 's/$/,/'`; if [ -z "$L" ]; then echo "<empty>"; else echo "$L"; fi);\
	ExecAndSet(list,select,L=`xmms2 list|grep -n '[>]'|cut -d: -f1`; if [ -z "$L" ]; then echo "1"; else echo "$L"; fi);\
	Set(menu,replace,Choose);

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

Back($$)=\
	Make(mode,xmms2_$(xmms2_layout))

Choose($$)=\
	Exec(xmms2 jump $(Index));

Push($$)=\
	Macro(Choose($$));

[ModeEnd]

% Choose Audio Device
[Mode]=xmms2_audio

% Alsa devices: default, bluetooth
%% asoundrc:
%% pcm.bluetooth {
%%   type bluetooth
%%   device <MAC>
%%   profile "auto"
%% }

(EnterMode)=\
	Set(list,font,small);\
	Set(list,replace,Audio Devices,default,bluetooth);\
	Set(menu,replace,Choose);

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

Back($$)=\
	Make(mode,xmms2_$(xmms2_layout));

Push($$)=\
	Macro(Choose($$));

Choose($$)=\
	Make(var,xmms2_status,xmms2 current|cut -f 1 -d ":");\
	Exec(if [ "x$(xmms2_status)" = "xPlaying"; then \
	         xmms2 stop;xmms2 config alsa.device $(Param); sleep 1; xmms2 play; sleep 1; \
	     else \
	         xmms2 config alsa.device $(Param); \
	      fi);\
	Make(mode,xmms2_$(xmms2_layout));

[ModeEnd]

[Mode]=xmms2_clicmd

(EnterMode)=\
	Set(editfield,Xmms2 Cli,Param,add);

Ok($$)=\
	Set(text,close);\
	ExecAndSet(text,replace,Xmms2 Cli,xmms2 $(Param);echo -e \"---\\nExit code:<$?>\")

Back($$)=\
	Make(mode,xmms2_$(xmms2_layout))

Back=\
	Make(mode,xmms2_$(xmms2_layout))
	
[ModeEnd]

[End]
