%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Key aliases for default player handling in server mode
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

[Protocol]=Server

% Funny aliases
%>=Macro(PLAY);
%>>=Macro(FF);
%<<=Macro(RWD);
%||=Macro(PAUSE)
%>|=Macro(NEXT)
%|<=Macro(PREV)
%[]=Macro(STOP)
%{}=Macro(PLAYLIST)

%
% Screen setup
%
% It needs to define $(player_name) variable before, like this:
% ...
% Make(var, player_name, by_value, Amarok);\
% Macro(SETUP_DEFAULT_PLAYER);\
% ...
% It is good ides to define $(player_name) variable in (Init)
%

[Mode]=default_player_base

(EnterMode)=\
	Macro(APP_PRE_SETUP);\
	Macro(SETUP_DEFAULT_POWER_MANAGEMENT);\
	Macro(RUN_IF_NEED);\
	Macro(SETUP_DEFAULT_PLAYER);\
	Macro(APP_MENU);\
	Macro(APP_POST_SETUP);

VOL-=Macro(DEFAULT_VOLUME_DOWN);
VOL+=Macro(DEFAULT_VOLUME_UP);

SlideLeft =Macro(NEXT);
SlideRight=Macro(PREV);
SlideDown =Macro(DEFAULT_VOLUME_DOWN);
SlideUp   =Macro(DEFAULT_VOLUME_UP);
COVER     =Macro(PLAY);

InCall($$)=Macro(PAUSE);
EndCall($$)=Macro(PLAY);

% Default action on text screen closing
Back=\
	Set(text,close);\
	Macro(APP_MENU);

% Default action on list screen closing
Back($$)=\
	Set(list,close);\
	Macro(APP_MENU);
    
% Rarely used
Cancel=\
    Macro(APP_QUIT);\
    Make(exit);

[ModeEnd]

[Mode]=default_player : default_player_base

SETUP_DEFAULT_PLAYER=\
    Set(layout,default);\
	Set(status,);\
	Set(title,);\
	Set(icons,$(player_name),\
		1,vol_down,\
		2,mute,\
		3,vol_up,\
		4,rewind,\
		5,play,\
		6,forward,\
		7,prev,\
		8,stop,\
		9,next,\
		*,question,\
		0,pause,\
		#,no)

% Some players does not supports FF/RWD
SETUP_DEFAULT_PLAYER_NO_FF_FWD=\
    Set(layout,default);\
	Set(status,);\
	Set(title,);\
	Set(icons,$(player_name),\
		1,vol_down,\
		2,mute,\
		3,vol_up,\
		4,none,\
		5,play,\
		6,none,\
		7,prev,\
		8,stop,\
		9,next,\
		*,question,\
		0,pause,\
		#,no);

1=Macro(DEFAULT_VOLUME_DOWN);
2=Macro(DEFAULT_TOGGLE_MUTE);
3=Macro(DEFAULT_VOLUME_UP);

4=Macro(RWD);
5=Macro(PLAY);
6=Macro(FF);

7=Macro(PREV);
8=Macro(STOP);
9=Macro(NEXT);

% Default menu
APP_MENU=\
	Set(menu,replace,PowerMgmt);\
	Macro(ALLIN1MENU);\
	Macro(MEDIACENTER_MENU);

DEFAULT_HELP=Set(text,replace,Help,1 Vol-\n2 Mute\n3 Vol+\n4 Rwd\n5 Play\n6 FF\n7 Prew\n8 Stop\n9 Next\n* * Help\n* # Run/Quit $(player_name)\n0 Pause\n# Quit $(player_name))

% Some players does not supports FF/RWD
DEFAULT_HELP_NO_FF_FWD=Set(text,replace,Help,1 Vol-\n2 Mute\n3 Vol+\n5 Play\n7 Prew\n8 Stop\n9 Next\n* * Help\n* # Run/Quit $(player_name)\n0 Pause\n# Quit $(player_name))

* *=Macro(DEFAULT_HELP);
* #=Macro(RUN_OR_QUIT);
0=Macro(PAUSE);
#=Macro(APP_QUIT);

SETUP_DEFAULT_CALL_HANDLER=\
	Make(var,incoming_call_handler,by_value,);\
	Make(var,end_call_handler,by_value,);

% Must set variables:
%     incoming_call_handler to PAUSE or empty value
%     end_call_handler:     to PLAY or empty value
DEFAULT_INCOMING_CALL=\
	Macro(CHECK_PLAY_STATUS);\
	Macro($(incoming_call_handler));

DEFAULT_END_CALL=\
	Macro($(end_call_handler));

[ModeEnd]

[Mode]=default_cover_player

CoverSize($$)=\
	Make(var,cover_size,by_value,$(Index));

%
% Rely on $(media_file) variable
% APP_COVER must be defined in child modes (and it must set $(media_file) variable)
%
Next Cover=\
	Make(var,cover_index, expr $(cover_index) + 1);\
	Macro(APP_COVER);

Previous Cover=\
	Make(var,cover_index, I=`expr $(cover_index) - 1`;if [ "x$I" = "x0" ]; then echo 1; else echo $I; fi);\
	Macro(APP_COVER);

Update Cover=\
	Make(var,cover_force,by_value,-force);\
	Macro(APP_COVER);\
	Make(var,cover_force,by_value, );

DEFAULT_METADATA_COVER=\
	Make(var,coverfile,echo "$(media_file)"|md5sum|cut -f 1 -d ' ');\
	Make(var,dummy,\
	     if  [ "x$(media_file)" != "x" ] && [ -f "$(media_file)" ]; then \
	         convert -resize $(cover_size)x$(cover_size) -depth 8 -background transparent \
		        "$(media_file)" $(TmpDir)/album_covers/$(coverfile)-$(cover_size).png;\
		 echo "$(TmpDir)/album_covers/$(coverfile)-$(cover_size).png";\
	     fi);\
	Set(cover,noname,$(TmpDir)/album_covers/$(coverfile)-$(cover_size).png);

DEFAULT_COVER=\
	Make(var,coverconverted,$(CfgDir)/Utils/generate_cover.sh "$(media_file)" $(TmpDir)/album_covers $(cover_index) $(cover_size) $(cover_force));\
	Set(cover,noname,$(coverconverted));

Help=\
	Macro(DEFAULT_HELP);

Run/Quit=\
	Macro(RUN_OR_QUIT);

Mute=\
	Macro(DEFAULT_TOGGLE_MUTE);

[ModeEnd]


[Mode]=default_player_7x1 : default_player_base, default_cover_player

SETUP_DEFAULT_PLAYER=\
	Macro(TEST_IMAGEMAGIC);\
	Set(layout,7x1,choose,3,ticker,up,VOL+,down,VOL-);\
	Set(status,);\
	Set(title,);\
	Set(icons,$(player_name),\
		1,prev,\
		2,rewind,\
		3,play,\
		4,pause,\
		5,stop,\
		6,forward,\
		7,next,\
		8,none,9,none,*,none,0,none,#,none);\
	Exec(if [ ! -d $(TmpDir)/album_covers ]; then mkdir $(TmpDir)/album_covers; fi);\
	Make(var,cover_force,by_value,);\
	Make(var,cover_index,by_value,1);\
	Get(cover_size);

1=Macro(PREV);
2=Macro(RWD);
3=Macro(PLAY);
4=Macro(PAUSE);
5=Macro(STOP);
6=Macro(FF);
7=Macro(NEXT);

% Default menu
APP_MENU=\
	Set(menu,replace,Help,Mute,Run/Quit,PowerMgmt);\
	Macro(ALLIN1MENU);

DEFAULT_HELP=\
	Set(text,replace,Help,Joystick Down Vol-\nJoystick Up Vol+\n1 Prew\n2 Rwd\n3 Play\n4 Pause\n5 Stop\n6 FF\n7 Next);

% Some players does not supports FF/RWD
DEFAULT_HELP_NO_FF_FWD=\
	Set(text,replace,Help,1 Prew\n2 Play\n3 Pause\n4 Stop\n5 Next);

[ModeEnd]

[Mode]=default_status_player

%APP_PLAY_STATUS must update $(app_status) to playing/paused/stopped
PLAY_STATUS=\
	Macro(APP_PLAY_STATUS);\
	Make(var,app_play_icon_new,if [ "x$(app_status)" = "xplaying" ]; \
	                      then echo pause; else echo play; fi);\
	Macro(PLAY_PAUSE_ICON,if [ "x$(app_play_icon)" = "x$(app_play_icon_new)" ]; \
	                      then echo 1; else echo 0; fi);\
	Make(var,status_action,if [ "x$(app_status)" = "xplaying" ]; \
	                      then echo PLAYING; else echo PAUSED; fi);\
	Macro($(status_action));

COVER=\
    Macro(PLAY_PAUSE);

PLAYING=\
	Macro(APP_TITLE);

PAUSED=\
	Set(title,);\
	Set(status,);

PLAY_PAUSE=\
	Make(var,play_action,if [ "x$(app_play_icon)" = "xplay" ]; \
	                      then echo PLAY; else echo PAUSE; fi);\
	Macro($(play_action));\
	Make(var,app_play_icon_new,if [ "x$(app_play_icon)" = "xplay" ]; \
	                      then echo pause; else echo play; fi);\
	Macro(PLAY_PAUSE_ICON);\

PLAY_PAUSE_ICON=\
	Make(var,app_play_icon,by_value,$(app_play_icon_new));\
	Set(icons,$(player_name),3,$(app_play_icon));

[ModeEnd]

[Mode]=default_player_6x1 : default_player_base, default_cover_player, default_status_player

SETUP_DEFAULT_PLAYER=\
	Macro(TEST_IMAGEMAGIC);\
	Set(layout,7x1,choose,3,ticker,up,VOL+,down,VOL-);\
	Set(status,);\
	Set(title,);\
	Make(var,app_play_icon,by_value,play);\
	Set(icons,$(player_name),\
		1,prev,\
		2,rewind,\
		3,$(app_play_icon),\
		4,stop,\
		5,forward,\
		6,next,\
		7,none,8,none,9,none,*,none,0,none,#,none);\
	Exec(if [ ! -d $(TmpDir)/album_covers ]; then mkdir $(TmpDir)/album_covers; fi);\
	Make(var,cover_force,by_value,);\
	Make(var,cover_index,by_value,1);\
	Make(var,app_status,by_value,playing);\
	Get(cover_size);\
	Macro(PLAY_STATUS);\
	Timer(PLAY_STATUS,$(UpdateTimeout),0);\

1=Macro(PREV);
2=Macro(RWD);
3=Macro(PLAY_PAUSE);
4=Macro(STOP_6x1);
5=Macro(FF);
6=Macro(NEXT);
7=Make(none);

STOP_6x1=\
	Macro(STOP);\
	Make(var,app_play_icon_new,by_value,play);\
	Macro(PLAY_PAUSE_ICON);

% Default menu
APP_MENU=\
	Set(menu,replace,Help,Mute,Run/Quit,PowerMgmt);\
	Macro(ALLIN1MENU);

DEFAULT_HELP=\
	Set(text,replace,Help,Joystick Down Vol-\nJoystick Up Vol+\n1 Prew\n2 Rwd\n3 Play/Pause\n4 Stop\n5 FF\n6 Next);

[ModeEnd]

[Mode]=default_player_5x1 : default_player_base, default_cover_player, default_status_player

SETUP_DEFAULT_PLAYER=\
	Macro(TEST_IMAGEMAGIC);\
	Set(layout,7x1,choose,3,ticker,up,VOL+,down,VOL-);\
	Set(status,);\
	Set(title,);\
	Make(var,app_play_icon,by_value,play);\
	Set(icons,$(player_name),\
		1,prev,\
		2,rewind,\
		3,$(app_play_icon),\
		4,forward,\
		5,next,\
		6,none,7,none,8,none,9,none,*,none,0,none,#,none);\
	Exec(if [ ! -d $(TmpDir)/album_covers ]; then mkdir $(TmpDir)/album_covers; fi);\
	Make(var,cover_force,by_value,);\
	Make(var,cover_index,by_value,1);\
	Make(var,app_status,by_value,playing);\
	Get(cover_size);\
	Macro(PLAY_STATUS);\
	Timer(PLAY_STATUS,$(UpdateTimeout),0);\

1=Macro(PREV);
2=Macro(RWD);
3=Macro(PLAY_PAUSE);
4=Macro(FF);
5=Macro(NEXT);
6=Make(none);
7=Make(none);

% Default menu
APP_MENU=\
	Set(menu,replace,Help,Mute,Run/Quit,PowerMgmt);\
	Macro(ALLIN1MENU);

DEFAULT_HELP=\
	Set(text,replace,Help,Joystick Down Vol-\nJoystick Up Vol+\n1 Prew\n2 Rwd\n3 Play/Pause\n4 FF\n5 Next);

[ModeEnd]

[End]
