%
% anyremote configuration file for MPD management. (Server-mode Bemused emulation)
% Prerequisites: Bemused client installed on cell phone
% tested with Jam SE 1.3 RC1
%

% STATUS stable
% XTEST no
% SOUND app
% ENV no

GuiAppName=MPD
GuiAppBinary=mpc
GuiAppRun=echo 'P=`ps -ef|grep mpd|grep -v grep|grep -v anyremote|grep -v nedit|grep -v mpd.cfg`; if [ "x$P" == "x" ]; then echo NOK; else echo OK; fi' | bash -f -s
GuiAppType=Application
GuiAppProtocols=Bemused
GuiAppDesc=Music Player Daemon (MPD) allows remote access for playing music.

[Protocol]=Bemused

(Init)=\
	Include($(CfgDir)/Utils/aliases-bemused.cfg);\
	Macro(BEMUSED_SETUP);\
	Macro(CheckMPC);\
	Macro(CheckMPD);\
	Macro(Check PL);

CheckMPC=Exec(echo 'P=`which mpc 2> /dev/null|grep mpc|grep -v no|wc -l|tr -d " "`; if [ "x$P" == "x0" ]; then $(CfgDir)/Utils/message.sh "ERROR: mpc client is not installed"; fi'|bash -f -s);
CheckMPD=Exec(echo 'P=`ps -ef|grep mpd|grep -v grep|grep -v mpd.cfg|wc -l|tr -d " "`; if [ "x$P" == "x0" ]; then $(CfgDir)/Utils/message.sh "ERROR: mpd is not run"; fi'|bash -f -s);
CheckPL =Exec(echo 'P=`mpc playlist 2> /dev/null|wc -l|tr -d " "`; if [ "x$P" == "x0" ]; then $(CfgDir)/Utils/message.sh "ERROR: mpd playlist is empty"; fi'|bash -f -s);

EXIT=Exec(mpd --kill)
FADE=Exec(mpc volume 0)
FFWD=Exec(mpc seek +00:00:05)
INF2=Send(string,INF2ACK);Send(bytes,128,0,0,0,128,0,0,0,1,0,0);ExecAndSend(string,mpc|head -1|sed "s/.*\///;s/(/-/g;s/)/-/g");Send(bytes,0,0)
INFO=Send(string,INFOACK);Send(bytes,128,0,0,0,128,0,0,0,1,0,0);ExecAndSend(string,mpc|head -1|sed "s/.*\///;s/(/-/g;s/)/-/g")
NEXT=Exec(mpc next)
PAUS=Exec(mpc toggle)
PLAY=Exec(mpc play)
PREV=Exec(mpc prev)
RWND=Exec(mpc seek -00:00:05)
STOP=Exec(mpc stop)
VOLM($$)=Exec(mpc volume $(Param))

GVOL=Send(string,GVOLACK);Make(var,mpd_volume,echo 'V=`mpc volume|tr -s " "|cut -f 2 -d " "|sed "s/%//"`;echo "$V*255/100"|bc'|bash -f -s);Send(bytes,$(mpd_volume))
%GVOL=Send(string,GVOLNAK);

%REPT
%SHFL
%SEEK=

PLEN=ExecAndSend(bytes,mpc playlist|wc -l|awk '{if($0>255) {b=int($0/256);a=$0-b;} else {b=$0;a=0};s=sprintf("%s,%s",a,b);print s; }');
PLST=Send(string,PLSTACK);\
	ExecAndSend(bytes,mpc playlist|grep '^>'|cut -f 1 -d "`echo -e '\0051'`"|sed 's/>//'|awk '{if($0>255) {b=int($0/256);a=$0-b;} else {b=$0;a=0};s=sprintf("%s,%s",a,b);print s; }');\
	ExecAndSend(string,mpc playlist);\
	Send(bytes,0);
SLCT($$)=Exec(mpc play `echo "$(Param)+1"|bc`);

[End]
