%
% anyremote configuration file for AlsaPlayer (http://www.alsaplayer.org/) (Server-mode)
% 

% STATUS stable
% XTEST no
% SOUND mixer
% ENV no
% DEF_PLAYER   
% ALL_IN_ONE 
% FBROWSER v.4i
% MEDIACENTER audio

GuiAppName=AlsaPlayer
GuiAppBinary=alsaplayer
GuiAppRun=echo 'A=`pgrep alsaplayer`; if [ "x$A" = "x" ]; then echo NOK; else echo OK; fi'|sh -s
GuiAppIcon=alsaplayer.png
GuiAppType=Application
GuiAppProtocols=Server
GuiAppDesc=AlsaPlayer is a new type of PCM player. It has some very interesting features unique to Linux/Unix players. The goal is to create a fully pluggable framework for playback of all sorts of media with the focus on PCM audio data. 

[Protocol]=Server

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

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

(Connect)=\
	Make(mode,alsaplayer_$(alsaplayer_layout));

[Mode]=alsaplayer_general

PLAY=\
	Exec(alsaplayer --start);\
	Macro(APLAYER_TITLE);\
	Timer(APLAYER_TITLE,$(UpdateTimeout),0);
	
RWD=\
	Exec(alsaplayer --relative -5)
	
FF=\
	Exec(alsaplayer --relative 5)

PREV=\
	Exec(alsaplayer --prev);\
	Macro(APLAYER_TITLE);

STOP=\
	Timer(APLAYER_TITLE,cancel);\
	Exec(alsaplayer --stop);\
	Set(title,);\
	Set(status,);
	
NEXT=\
	Exec(alsaplayer --next);\
	Macro(APLAYER_TITLE);
	
PAUSE=\
	Exec(alsaplayer --pause);

RUN_IF_NEED=\
	Exec($(CfgDir)/Utils/run-or-switch-to.sh alsaplayer);
	
RUN_OR_QUIT=\
	Make(var,aplayer_cmd,\
	     P=`pgrep alsaplayer`;\
	     if [ "x$P" = "x" ]; then echo RUN_IF_NEED else echo APP_QUIT; fi);\
	Macro($(aplayer_cmd));

APP_QUIT=\
	Timer(APLAYER_TITLE,cancel);\
	Exec(alsaplayer --quit);

% Repeat commands does not works
Repeat 1=\
	Exec(alsaplayer --loopsong);
	
Repeat List=\
	Exec(alsaplayer --looplist);

Files=\
	Make(mode,alsaplayer_filebrowser);

Playlist=\
	Make(mode,alsaplayer_playlist);

Play reversely=\
	Exec(alsaplayer --speed -1.0);

Play normal=\
	Exec(alsaplayer --speed 1.0);

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

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

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

[ModeEnd]

[Mode]=alsaplayer_3x4 : alsaplayer_general,default_player

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

APP_MENU=\
	Set(menu,replace,Files,Playlist,Layout 7x1,Layout 5x1,PowerMgmt);\
	Macro(ALLIN1MENU);\
	Macro(MEDIACENTER_MENU);

APP_POST_SETUP=\
	Make(var,alsaplayer_layout,by_value,3x4);
	
%APLAYER_GETVOL=\
%	Make(var,aplayer_volume,alsaplayer --status|grep 'volume:'|sed 's/^volume: //');

APLAYER_TITLE=\
	ExecAndSet(title,alsaplayer --status|grep 'path:'|sed "s/^path: //");

* 4=Exec(alsaplayer --speed -1.0);
* 6=Exec(alsaplayer --speed 1.0);
* *=Set(text,replace,Help,1 Vol-\n2 Mute\n3 Vol+\n4 RWD\n5 Play\n6 Next\n7 FF\n8 Stop\n9 Next\n* 4 Play reversely\n * 6 Play normal speed\n ** Help\n0 Pause\n# Quit\n* # - Run/Quit)

[ModeEnd]

[Mode]=alsaplayer_cover

APLAYER_TITLE=\
	ExecAndSet(title,alsaplayer --status|grep 'path:'|sed "s/^path: //");\
	Macro(APP_COVER, if [ "x$(cover_size)" = "x" ]; then echo 1; else echo 0; fi);

APP_COVER=\
	Make(var,media_file,alsaplayer --status|grep 'path:'|sed "s/^path: //;s/'/'\\\''/g;s/\//\'\/\'/g;s/$/\'/g;s/^'\//\//");\
	Macro(DEFAULT_COVER);

[ModeEnd]

[Mode]=alsaplayer_7x1 : alsaplayer_general,default_player_7x1,alsaplayer_cover

% (EnterMode) by Utils/aliases-server-player.cfg
APP_MENU=\
	Set(menu,replace,Files,Playlist,Mute,Next Cover,Previous Cover,Update Cover,Play reversely,Play normal,Layout 3x4,Layout 5x1,Help,PowerMgmt);\
	Macro(ALLIN1MENU);\
	Macro(MEDIACENTER_MENU);

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

% Mute, Next Cover,Previous Cover,Update Cover by Utils/aliases-server-player.cfg
% PowerMgmt by Utils/aliases-server.cfg

[ModeEnd]

[Mode]=alsaplayer_5x1 : alsaplayer_general,default_player_5x1,alsaplayer_cover

% no timer
PLAY=\
	Exec(alsaplayer --start);\
	Macro(APLAYER_TITLE);

% (EnterMode) by Utils/aliases-server-player.cfg
APP_MENU=\
	Set(menu,replace,Files,Playlist,Mute,Next Cover,Previous Cover,Update Cover,Play reversely,Play normal,Layout 3x4,Layout 7x1,Help,PowerMgmt);\
	Macro(ALLIN1MENU);\
	Macro(MEDIACENTER_MENU);

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

% Mute, Next Cover,Previous Cover,Update Cover by Utils/aliases-server-player.cfg
% PowerMgmt by Utils/aliases-server.cfg
	
APP_PLAY_STATUS=\
	Make(var,app_status,\
	     OUT=`alsaplayer --status|grep "speed: 0%\|^length:"`;\
	     L0=`echo $OUT|grep 'length: 0 seconds'|wc -l`;\
	     if [ "x$L0" = "x1" ]; then echo stopped;\
	     else \
	       S0=`echo $OUT|grep speed|wc -l`;\
	       if [ "x$S0" = "x1" ]; then echo paused;\
	       else echo playing; fi;\
	     fi);

APP_TITLE=\
	Macro(APLAYER_TITLE);

[ModeEnd]

[Mode]=alsaplayer_nobutton

% bug-prone :)
1=Make(mode,alsaplayer_$(alsaplayer_layout));	
2=Make(mode,alsaplayer_$(alsaplayer_layout));	
3=Make(mode,alsaplayer_$(alsaplayer_layout));	
4=Make(mode,alsaplayer_$(alsaplayer_layout));	
5=Make(mode,alsaplayer_$(alsaplayer_layout));	
6=Make(mode,alsaplayer_$(alsaplayer_layout));	
7=Make(mode,alsaplayer_$(alsaplayer_layout));	
8=Make(mode,alsaplayer_$(alsaplayer_layout));	
9=Make(mode,alsaplayer_$(alsaplayer_layout));	
*=Make(mode,alsaplayer_$(alsaplayer_layout));	
0=Make(mode,alsaplayer_$(alsaplayer_layout));	
#=Make(mode,alsaplayer_$(alsaplayer_layout));	

[ModeEnd]

% rely on $(alsaplayer_layout) variable
[Mode]=alsaplayer_playlist : alsaplayer_nobutton

(EnterMode)=\
	ExecAndSet(list,replace,Playlist,\
	           cd;cat .alsaplayer/alsaplayer.m3u|sed "s/'//g"|xargs -i basename {}|sed 's/\*//;s/@//;s/,/ /g;s/$/,/');\
	Set(menu,replace,Jump,Clear);

Push($$)=\
	Macro(JUMP);
	
Jump($$)=\
        Macro(JUMP);
	
JUMP=\
	Set(list,close);\
	Exec(alsaplayer --jump $(Index));\
	Make(mode,alsaplayer_$(alsaplayer_layout);

Clear($$)=\
	Set(list,clear);\
    Exec(alsaplayer --clear);\
	Exec(rm -f $(Home)/.alsaplayer/alsaplayer.m3u; touch $(Home)/.alsaplayer/alsaplayer.m3u);

Back($$)=\
	Set(list,close);\
	Make(mode,alsaplayer_$(alsaplayer_layout));

[ModeEnd]

% rely on $(alsaplayer_layout) variable
[Mode]=alsaplayer_filebrowser : alsaplayer_nobutton

(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-v4i.cfg

Add($$)=\
	Exec(alsaplayer -e "$(fbrowser_dir)"/$(Param));\
	Exec(echo "$(fbrowser_dir)"/$(Param) >> $(Home)/.alsaplayer/alsaplayer.m3u);

Back($$)=\
	Set(list,close);\
	Make(mode,alsaplayer_$(alsaplayer_layout));

[ModeEnd]

[End]
