%
% anyremote configuration file for quodlibet. (Server-mode)
% 
% Thanks to Van Wout Heeswijk for initial version this configuration file
%

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

GuiAppName=Quodlibet
GuiAppBinary=quodlibet
GuiAppRun= A=`ps -ef|grep quodlibet|grep -v grep`; if [ "x$A" = "x" ]; then echo NOK; else echo OK; fi
GuiAppIcon=quodlibet.png
GuiAppType=Application
GuiAppProtocols=Server
GuiAppDesc=Quod Libet is a GTK+-based audio player written in Python. It's designed around the idea that you know how to organize your music better than we do.

[Protocol]=Server

(Init)=\
	Include($(CfgDir)/Utils/aliases-server.cfg);\
	Make(var,player_name,by_value,Quodlibet);\
	Include($(CfgDir)/Utils/aliases-server-player.cfg);\
        Include($(CfgDir)/Utils/aliases-server-fbrowser-v3i.cfg);\
	Macro(FBROWSER_IC_INIT);\
	Make(var,quodlibet_layout,\
	     V=`$(CfgDir)/Utils/registry.sh $(TmpDir) get quodlibet_layout`;\
	     if [ "x$V" = "x" ]; then echo "5x1"; else echo $V; fi);
	
(Exit)=\
	Macro(FBROWSER_IC_EXIT);\
	Exec($(CfgDir)/Utils/registry.sh $(TmpDir) set quodlibet_layout $(quodlibet_layout));

(Connect)=\
	Make(mode,quodlibet_$(quodlibet_layout));

[Mode]=quodlibet_general

QUODLIBET_VOL-=\
	Exec(quodlibet --volume-down);

QUODLIBET_MUTE=\
	Make(var,quodlibet_volume,\
           if [ "x$(quodlibet_volume)" = "x-1" ]; then \
          	V=`quodlibet --status|cut -f 3 -d ' '|grep '.'`;echo "$V * 100"|bc|cut -f 1 -d '.';quodlibet --volume=0; \
	   else \
	  	quodlibet --volume=$(quodlibet_volume);echo "-1"; \
	   fi);

QUODLIBET_VOL+=\
	Exec(quodlibet --volume-up)

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

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

% 0-9,*,# assignments by Utils/aliases-server-player.cfg
PLAY_ONLY=\
	Exec(quodlibet --play);

PLAY=\
	Macro(PLAY_ONLY);\
	Macro(QUODLIBET_TIMER_START);

RWD=\
	Exec(quodlibet --seek=-10)

FF=\
	Exec(quodlibet --seek=+10);

PREV=\
	Exec(quodlibet --previous);\
	Macro(QUODLIBET_TITLE);

NEXT=\
	Exec(quodlibet --next);\
	Macro(QUODLIBET_TITLE);

STOP=\
	Exec(quodlibet --play-pause);

PAUSE=\
	Exec(quodlibet --play-pause);

QUODLIBET_CHECK_TIMER=\
	Make(var,quodlibet_status,quodlibet --status|cut -f 1 -d ' ');\
	Make(var,timer_action,if [ "x$(quodlibet_status)" = "xplaying" ]; \
	                      then echo QUODLIBET_TIMER_START; else echo QUODLIBET_TIMER_CANCEL; fi);\
	Macro($(timer_action));

QUODLIBET_TITLE_GENERAL=\
	Make(var,alb_tit,quodlibet  --print-playing '<album> - <title>');\
	Make(var,art,quodlibet  --print-playing '<artist>');\
	Set(title,$(alb_tit));\
	Set(status,$(art));

% QUODLIBET_TITLE should be defined in child mode
QUODLIBET_TIMER_START=\
	Macro(QUODLIBET_TITLE);\
	Timer(QUODLIBET_TITLE,$(UpdateTimeout),0);
	
QUODLIBET_TIMER_CANCEL=\
	Timer(QUODLIBET_TITLE,cancel);\
	Set(title,);\
	Set(status,);

RUN_IF_NEED=\
	Exec($(CfgDir)/Utils/run-or-switch-to.sh quodlibet);

RUN_OR_QUIT=\
	Timer(QUODLIBET_TITLE,cancel);\
	Exec(P=`ps -ef|grep quodlibet|grep -v grep|grep -v quodlibet.cfg`; \
	     if [ "x$P" = "x" ]; then quodlibet & else quodlibet --quit; fi);

APP_QUIT=\
	Macro(QUODLIBET_TIMER_CANCEL);\
	Exec(quodlibet --quit);

APP_PLAY_STATUS=\
	Make(var,quodlibet_status,quodlibet --status|cut -f 1 -d " ");\
	Make(var,app_status,if [ "x$(quodlibet_status)" = "xplaying" ]; then echo playing; else echo paused; fi);

Repeat=\
	Make(mode,quodlibet_repeat);

Shuffle=\
	Make(mode,quodlibet_shuffle);

Files=\
	Make(mode,quodlibet_filebrowser);
	
Layout 3x4=\
	Make(mode,quodlibet_3x4);

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

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

[ModeEnd]

[Mode]=quodlibet_3x4 : quodlibet_general, default_player

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

APP_PRE_SETUP=\
	Make(var,quodlibet_volume,echo "-1");

APP_POST_SETUP=\
	Make(var,quodlibet_layout,by_value,3x4);\
	Macro(QUODLIBET_CHECK_TIMER);

% PowerMgmt by Utils/aliases-server.cfg
APP_MENU=\
	Set(menu,replace,Files,Repeat,Shuffle,Layout 5x1,Layout 7x1,PowerMgmt);\
	Macro(ALLIN1MENU);\
	Macro(MEDIACENTER_MENU);
	
QUODLIBET_TITLE=\
	Macro(QUODLIBET_TITLE_GENERAL);

1=Macro(QUODLIBET_VOL-);
2=Macro(QUODLIBET_MUTE);
3=Macro(QUODLIBET_VOL+);

[ModeEnd]

[Mode]=quodlibet_cover

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

APP_COVER=\
	Make(var,media_file,quodlibet  --print-playing '<~dirname>');\
	Macro(DEFAULT_COVER);

VOL-=\
	Macro(QUODLIBET_VOL-);

Mute=\
	Macro(QUODLIBET_MUTE);

VOL+=\
	Macro(QUODLIBET_VOL+);

[ModeEnd]

[Mode]=quodlibet_7x1 : quodlibet_general, quodlibet_cover, default_player_7x1

APP_MENU=\
	Set(menu,replace,Mute,Files,Repeat,Shuffle,Next Cover,Previous Cover,Update Cover,Layout 3x4,Layout 5x1,Help,PowerMgmt);\
	Macro(ALLIN1MENU);\
	Macro(MEDIACENTER_MENU);

APP_POST_SETUP=\
	Make(var,quodlibet_layout,by_value,7x1);

[ModeEnd]

[Mode]=quodlibet_5x1 : quodlibet_general, quodlibet_cover, default_player_5x1

APP_MENU=\
	Set(menu,replace,Mute,Files,Repeat,Shuffle,Next Cover,Previous Cover,Update Cover,Layout 3x4,Layout 7x1,Help,PowerMgmt);\
	Macro(ALLIN1MENU);\
	Macro(MEDIACENTER_MENU);

APP_POST_SETUP=\
	Make(var,quodlibet_layout,by_value,5x1);

APP_TITLE=\
	Macro(QUODLIBET_TITLE);

PLAY=\
	Macro(PLAY_ONLY);

[ModeEnd]

% rely on $(quodlibet_layout) variable
[Mode]=quodlibet_repeat

(EnterMode)=\
	Set(list,replace,Repeat,Yes,No);\
	Set(menu,replace,Choose);

Back($$)=\
	Set(list,close);\
	Make(mode,quodlibet_$(quodlibet_layout));
	
Push($$)=\
	Macro(Choose($$));
	
Choose($$)=\
	Exec(quodlibet --repeat=`echo $(Param)|sed 's/Yes/1/;s/No/0/'`);\
	Set(list,close);\
	Make(mode,quodlibet_$(quodlibet_layout));

[ModeEnd]

% rely on $(quodlibet_layout) variable
[Mode]=quodlibet_shuffle

(EnterMode)=\
	Set(list,replace,Shuffle,Yes,No);\
	Set(menu,replace,Choose);

Back($$)=\
	Set(list,close);\
	Make(mode,quodlibet_$(quodlibet_layout));
	
Push($$)=\
	Macro(Choose($$));
	
Choose($$)=\
	Exec(quodlibet --order=`echo $(Param)|sed 's/Yes/1/;s/No/0/'`);\
	Set(list,close);\
	Make(mode,quodlibet_$(quodlibet_layout));

[ModeEnd]

% rely on $(quodlibet_layout) variable
[Mode]=quodlibet_filebrowser

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

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(quodlibet --enqueue="$(fbrowser_dir)"/$(Param));

Back($$)=\
	Set(list,close);\
	Make(mode,quodlibet_$(quodlibet_layout));

[ModeEnd]

[End]
