%
% cmus configuration file for cmus (Server-mode)
%
% cfg by Arthus Belliqueux
%

% STATUS nonstable
% XTEST no
% ENV no
% SOUND mixer
% FBROWSER v.4i
% DEF_PLAYER   
% ALL_IN_ONE 
%

GuiAppName=cmus
GuiAppBinary=cmus-remote
GuiAppRun=echo 'A=`ps -ef|grep cmus|grep -v grep|grep -v anyremote|grep -v edit`; if [ "x$A" = "x" ]; then echo NOK; else echo OK; fi'|sh -s
GuiAppIcon=gnome-mime-audio.png
GuiAppType=Application
GuiAppProtocols=Server
GuiAppDesc=C* Music Player. Note: this configuration file is not stable.

[Protocol]=Server

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

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

(Connect)=\
	Make(mode,cmus_$(cmus_layout));

TEST_XTERM=\
	Exec(P=`which xterm|grep xterm|grep -v no|wc -l|tr -d " "`; \
	     if [ "x$P" != "x1" ]; then \
	         $(CfgDir)/Utils/message.sh "ERROR: xterm not found"; \
	     fi);

[Mode]=cmus_general

% Do not work on Fedora 14, use defaults
%1=Exec(cmus-remote -v -10%);
%2=Exec(cmus-remote -v -100%);
%3=Exec(cmus-remote -v +10%);

PLAY=\
	Exec(cmus-remote -p);\
	Macro(CMUS_SETTITLE);\
	Timer(CMUS_SETTITLE,$(UpdateTimeout),0);
	
FF=\
	Exec(cmus-remote -k +10);
	
RWD=\
	Exec(cmus-remote -k -10);
	
PREV=\
	Exec(cmus-remote -r);\
	Macro(CMUS_SETTITLE);

STOP=\
	Exec(cmus-remote -s);\
	Macro(CMUS_DELTIMER);

NEXT=\
	Exec(cmus-remote -n);\
	Macro(CMUS_SETTITLE);

PAUSE=\
	Exec(cmus-remote -u);

CMUS_DELTIMER=\
	Set(title, );\
	Set(status, );\
	Timer(CMUS_SETTITLE,cancel);

CMUS_SETTITLE_GENERAL=\
	Make(var,cmus_title,cmus-remote -Q|grep "tag title"|sed "s/tag title //");\
	Make(var,cmus_album,cmus-remote -Q|grep "tag album"|grep -v albumartist|sed "s/tag album //");\
	Make(var,cmus_artist,cmus-remote -Q|grep "tag albumartist"|sed "s/tag albumartist //");\
	Set(title,$(cmus_album) - $(cmus_title));\
	Set(status,$(cmus_artist));\

RUN_IF_NEED=\
	Exec(P=`ps -ef|grep cmus|grep -v grep|grep -v anyremote|grep -v edit`;\
	     if [ "x$P" = "x" ]; then xterm -e cmus& fi);

RUN_OR_QUIT=\
	Exec(P=`ps -ef|grep cmus|grep -v grep|grep -v anyremote|grep -v edit`;\
	     if [ "x$P" = "x" ]; then  xterm -e cmus; else cmus-remote -C quit; fi);\
	Macro(CMUS_DELTIMER);

APP_QUIT=\
	Exec(P=`ps -ef|grep cmus|grep -v grep|grep -v anyremote|grep -v edit`;\
	     if [ "x$P" = "x" ]; then true; else cmus-remote -C quit; fi);\
	Macro(CMUS_DELTIMER);

% PowerMgmt by Utils/aliases-server.cfg

Shuffle=\
	Exec(cmus-remote -S);
	
Repeat=\
	Exec(cmus-remote -R);

File Browser=\
	Make(mode,cmus_filebrowser);

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

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

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

APP_PLAY_STATUS=\
	Make(var,cmus_status,cmus-remote -Q|grep status|grep playing|wc -l);\
	Make(var,app_status,if [ "x$(cmus_status)" = "x0" ]; then echo paused; else echo playing; fi);

[ModeEnd]
	
[Mode]=cmus_3x4 : cmus_general , default_player

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

APP_POST_SETUP=\
	Make(var,cmus_layout,by_value,3x4);

APP_MENU=\
	Set(menu,replace,File Browser,Shuffle,Repeat,Layout 5x1,Layout 7x1,PowerMgmt);\
	Macro(ALLIN1MENU);

% Volume control and 0-9,*,# assignments by Utils/aliases-server-player.cfg

% Do not work on Fedora 14, use defaults
%1=Exec(cmus-remote -v -10%);
%2=Exec(cmus-remote -v -100%);
%3=Exec(cmus-remote -v +10%);

CMUS_SETTITLE=\
	Macro(CMUS_SETTITLE_GENERAL);

[ModeEnd]

[Mode]=cmus_cover

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

% Will fail if file name is relative path
APP_COVER=\
	Make(var,media_file,cmus-remote -Q|grep file|sed "s/^file //");\
	Macro(DEFAULT_COVER);

[ModeEnd]

[Mode]=cmus_7x1 : cmus_general , default_player_7x1, cmus_cover

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

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

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


% Volume control and 0-9,*,# assignments by Utils/aliases-server-player.cfg

[ModeEnd]

[Mode]=cmus_5x1 : cmus_general , default_player_5x1, cmus_cover

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

PLAY=\
	Exec(cmus-remote -p);\
	Macro(CMUS_SETTITLE);

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

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


% Volume control and 0-9,*,# assignments by Utils/aliases-server-player.cfg
APP_TITLE=\
	Macro(CMUS_SETTITLE);

[ModeEnd]
	
[Mode]=cmus_nobutton
% bug-prone :)
1=Make(mode,cmus_$(cmus_layout));	
2=Make(mode,cmus_$(cmus_layout));	
3=Make(mode,cmus_$(cmus_layout));	
4=Make(mode,cmus_$(cmus_layout));	
5=Make(mode,cmus_$(cmus_layout));	
6=Make(mode,cmus_$(cmus_layout));	
7=Make(mode,cmus_$(cmus_layout));	
8=Make(mode,cmus_$(cmus_layout));	
9=Make(mode,cmus_$(cmus_layout));	
*=Make(mode,cmus_$(cmus_layout));	
0=Make(mode,cmus_$(cmus_layout));	
#=Make(mode,cmus_$(cmus_layout));	

[ModeEnd]

[Mode]=cmus_filebrowser : cmus_nobutton

(EnterMode)=\
	Macro(FBROWSER_IC_FILL_LIST);\
	Set(menu,replace,GoTo,Queue,Go Home);

GoTo($$)=\
	Macro(FBROWSER_IC_GO_TO);
	
Go Home($$)=\
	Macro(FBROWSER_IC_GO_HOME);
	
%Push($$) use from aliases-server-fbrowser-v4i.cfg
	
Queue($$)=\
	Exec(cd "$(fbrowser_dir)";cmus-remote -q "$(Param)" > /dev/null);

Back($$)=\
	Set(list,close);\
	Make(mode,cmus_$(cmus_layout));

[ModeEnd]

[End]
