%
% anyremote configuration file for moc (http://moc.daper.net) management. (Server-mode)
%

% STATUS nonstable
% TODO work with playlists
% XTEST no
% SOUND mixer
% ENV no
% FBROWSER v.3
% DEF_PLAYER   
% ALL_IN_ONE 

GuiAppName=MOC
GuiAppBinary=mocp
GuiAppRun= P=`ps -ef|grep mocp|grep -v grep|grep -v anyremote|grep -v nedit`; if [ "x$P" = "x" ]; then echo NOK; else echo OK; fi
GuiAppType=Application
GuiAppProtocols=Server
GuiAppDesc=Console audio player for Linux/UNIX

[Protocol]=Server

(Init)=\
	Include($(CfgDir)/Utils/aliases-server.cfg);\
	Macro(SETUP_DEFAULT_MIXER);\
        Include($(CfgDir)/Utils/aliases-server-fbrowser-v3.cfg);\
	Macro(FBROWSER_INIT);\
	Make(var,player_name,by_value,MOC);\
	Include($(CfgDir)/Utils/aliases-server-player.cfg);\
	Make(var,cover_size,by_value,);\
	Make(var,moc_layout,\
	     V=`$(CfgDir)/Utils/registry.sh $(TmpDir) get moc_layout`;\
	     if [ "x$V" = "x" ]; then echo "5x1"; else echo $V; fi);

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

(Connect)=\
	Make(mode,moc_$(moc_layout));


[Mode]=moc_general

(Disconnect)=\
	Macro(MOC_TIMER_CANCEL);

MOC_TITLE_GENERAL=\
	ExecAndSet(title,mocp -Q "%album - %song");\
	ExecAndSet(status,mocp -Q "%artist");

MOC_CHECK_TIMER=\
	Make(var,moc_status,mocp -Q "%state");\
	Make(var,timer_action,if [ "x$(moc_status)" = "xPLAY" ]; \
	                      then echo MOC_TIMER_START; else echo MOC_TIMER_CANCEL; fi);\
	Macro($(timer_action));

% MOC_TITLE should be defined on child modes

MOC_TIMER_START=\
	Macro(MOC_TITLE);\
	Timer(MOC_TITLE,$(UpdateTimeout),0);

MOC_TIMER_CANCEL=\
	Timer(MOC_TITLE,cancel);\
	Set(title,);\
	Set(status,);

File Browser=\
	Make(mode,moc_file_browser)

Play Dir=\
	Make(mode,moc_play_dir)

PLAY_ONLY=\
	Exec(mocp -p);

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

RWD=\
	Exec(mocp -k -10);

FF=\
	Exec(mocp -k 10) ;

PREV=\
	Exec(mocp -r);\
	Macro(MOC_TITLE);

NEXT=\
	Exec(mocp -f);\
	Macro(MOC_TITLE);

STOP=\
	Macro(MOC_TIMER_CANCEL);\
	Exec(mocp -s);

PAUSE=\
	Exec(mocp -G);

RUN_IF_NEED=\
	Exec(ID=`id -u`;P=`ps -fu $ID|grep mocp|grep -v grep|grep -v anyremote|grep -v edit`; \
	     if [ "x$P" = "x" ]; then mocp -S; fi);

RUN_OR_QUIT=\
	Exec(ID=`id -u`;P=`ps -fu $ID|grep mocp|grep -v grep|grep -v anyremote|grep -v edit`; \
	     if [ "x$P" = "x" ]; then mocp -S; else mocp -x; fi);

APP_QUIT=\
	Macro(MOC_TIMER_CANCEL);\
	Exec(mocp -x);

APP_PLAY_STATUS=\
	Make(var,moc_status,mocp -i|grep State|tr -d " "|cut -f 2 -d ":");\
	Make(var,app_status,if [ "x$(moc_status)" = "xPLAY" ]; then echo playing; else if [ "x$(moc_status)" = "xSTOP" ]; then echo stopped; else echo paused; fi; fi);

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

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

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

[ModeEnd]


[Mode]=moc_3x4 : moc_general, default_player

APP_POST_SETUP=\
	Make(var,moc_layout,by_value,3x4);\
	Macro(MOC_CHECK_TIMER);

% PowerMgmt by Utils/aliases-server.cfg
APP_MENU=\
	Set(menu,replace,File Browser,Play Dir,Shuffle,Repeat,Layout 5x1,Layout 7x1,PowerMgmt);\
	Macro(ALLIN1MENU);

MOC_TITLE=\
	Macro(MOC_TITLE_GENERAL);

[ModeEnd]

[Mode]=moc_cover

MOC_TITLE=\
	Macro(MOC_TITLE_GENERAL);\
	Macro(APP_COVER);
 
APP_COVER=\
	Make(var,media_file,mocp -i|grep File:|sed "s/File: //;s/'/'\\\''/g;s/\//\'\/\'/g;s/$/\'/g;s/^'\//\//;s/%20/ /g");\
	Macro(DEFAULT_COVER);

[ModeEnd]

[Mode]=moc_7x1 : moc_general, default_player_7x1, moc_cover

APP_POST_SETUP=\
	Make(var,moc_layout,by_value,7x1);\
	Macro(MOC_CHECK_TIMER);

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

[ModeEnd]

[Mode]=moc_5x1 : moc_general, default_player_5x1, moc_cover

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

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

APP_TITLE=\
	Macro(MOC_TITLE);

PLAY=\
	Macro(APP_PLAY_STATUS);\
	Make(var,moc_play_action,if [ "x$(app_status)" = "xstopped" ]; \
	                      then echo PLAY_ONLY; else echo PAUSE; fi);\
	Macro($(moc_play_action));

[ModeEnd]

[Mode]=moc_file_browser

(EnterMode)=\
	Timer(MOC_TITLE,cancel);\
	Set(list,font,small);\
	Macro(FBROWSER_FILL_LIST);\
	Macro(UPDATEMENU);
	
(ExitMode)=\
	Set(list,close);\
	Macro(MOC_TITLE);\
	Macro(MOC_TIMER);

UPDATEMENU=\
	Set(menu,replace,Go To,Go Home,Play it,Enqueue);

Go To($$)=\
	Macro(FBROWSER_GO_TO);

Go Home($$)=\
	Macro(FBROWSER_GO_HOME);

Back($$)=\
	Make(mode,moc_$(moc_layout));

Play it($$)=\
	Exec(mocp -l "$(fbrowser_dir)"/"$(Param)");

Enqueue($$)=\
	Exec(mocp -q "$(fbrowser_dir)"/"$(Param)");

%Push($$) use from aliases-server-fbrowser-v3.cfg

[ModeEnd]

[Mode]=moc_play_dir : moc_general

(EnterMode)=\
	Timer(MOC_TITLE,cancel);\
	Set(list,font,small);\
	Macro(FBROWSER_FILL_LIST);\
	Macro(UPDATEMENU);
	
(ExitMode)=\
	Set(list,close);

UPDATEMENU=\
	Set(menu,replace,Go To,Go Home,Play Dir);

Go To($$)=\
	Macro(FBROWSER_GO_TO);

Go Home($$)=\
	Macro(FBROWSER_GO_HOME);
	
Back($$)=\
	Make(mode,moc_$(moc_layout));

Play Dir($$)=\
	Exec(mocp -c;\
	     if [ -d "$(fbrowser_dir)"/"$(Param)" ]; then \
		 mocp -a "$(fbrowser_dir)"/"$(Param)"; \
	     else \
	         mocp -a "$(fbrowser_dir)"; \
	     fi; \
	     mocp -p);\
	Make(mode,moc_$(moc_layout));

%Push($$) use from aliases-server-fbrowser-v3.cfg

[ModeEnd]

[Mode]=moc_repeat

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

Back($$)=\
	Set(list,close);\
	Make(mode,moc_$(moc_layout));
	
Push($$)=\
	Macro(Choose($$));
	
Choose($$)=\
	Exec(moc `echo $(Param)|sed 's/Yes/-o/;s/No/-u/' repeat`);\
	Set(list,close);\
	Make(mode,moc_$(moc_layout));

[ModeEnd]

[Mode]=moc_shuffle

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

Back($$)=\
	Set(list,close);\
	Make(mode,moc_$(moc_layout));
	
Push($$)=\
	Macro(Choose($$));
	
Choose($$)=\
	Exec(moc `echo $(Param)|sed 's/Yes/-o/;s/No/-u/' shuffle`);\
	Set(list,close);\
	Make(mode,moc_$(moc_layout));

[ModeEnd]

[End]
