%
% anyremote configuration file for Banshee management. (Server-mode Command Fusion iViewer)
% prerequisites: Iviewer client installed on Ipod touch/Iphone 2.x and Iviewer free winamp GUI
%

% STATUS stable
% XTEST no
% SOUND mixer
% ENV no

GuiAppName=Banshee
GuiAppBinary=echo 'B=`which banshee 2> /dev/null`;if [ "x$B" == "x" ]; then echo banshee-1; else echo banshee; fi'|bash -f -s
GuiAppRun=echo 'P=`ps -ef|grep banshee|grep -v grep|grep -v anyremote|grep -v edit`; if [ "x$P" == "x" ]; then echo NOK; else echo OK; fi'|bash -f -s
GuiAppIcon=media-player-banshee.png
GuiAppType=Application
GuiAppProtocols=iViewer
GuiAppDesc=Music management and playback for Gnome

[Protocol]=iViewer

(Init)=\
	Include($(CfgDir)/Utils/aliases-iviewer.cfg);\
	Macro(SETUP_DEFAULT_MIXER);\
	Make(var,IViewer,by_value,true);\
	Make(var, banshee_exec, which banshee 2> /dev/null);\
	Make(var, banshee_exec, if [ "x$(banshee_exec)" = "x" ]; then which banshee-1; else echo $(banshee_exec); fi);\

BANSHEE_CMD=\
	Exec(P=`ps -ef|grep banshee|grep -v grep|grep -v anyremote|grep -v edit`; if [ "x$P" != "x" ]; then $(banshee_cmd); fi);

%a1 = volume
%a2 = needs a constent update to. its the seek bar

%s1 = artist
%s2 = track
%s5 = current playback in min:sec
%s6 = song length min:sec.

% play
d1(1)=\
	Make(var,banshee_cmd,by_value,$(banshee_exec) --toggle-playing);\
	Macro(BANSHEE_CMD);

% stop
d30(1)=\
	Make(var,banshee_cmd,by_value,$(banshee_exec) --pause);\
	Macro(BANSHEE_CMD);

% pause
d31(1)=\
	Make(var,banshee_cmd,by_value,$(banshee_exec) --pause);\
	Macro(BANSHEE_CMD);

% next
d5(1)=\
	Make(var,banshee_cmd,by_value,$(banshee_exec) --next);\
	Macro(BANSHEE_CMD);\
	Macro(TITLE);

% prev
d6(1)=\
	Make(var,banshee_cmd,by_value,$(banshee_exec) --previous);\
	Macro(BANSHEE_CMD);\
	Macro(TITLE);

% toggle repeat
d12(1)=\
	Exec(echo "Toggle repeat")

% toggle shuffle
d9(1)=\
	Exec(echo "Toggle shuffle")

% volume contol
a1($$)=\
	Make(var,default_mixer_value,by_value,$(Index));\
	Macro(DEFAULT_VOLUME_SET);\
	Macro(VOLUME);

% seek >> and <<
a2($$)=\
	Make(var,song_len,P=`$(banshee_exec) --query-duration|cut -f 2 -d ":"|cut -f 1 -d ","|tr -d " "`;if [ "x$P" = "x" ]; then echo 1; else echo $P; fi);\
 	Make(var,song_pos,$(Index)*$(song_len)/65535"|bc);\
 	Exec($(banshee_exec) --set-position=$(song_pos));\
	Macro(PLAYBACK);

% Feedback
PLAYBACK=\
	Make(var,song_pos,P=`$(banshee_exec) --query-position|cut -f 2 -d ":"|cut -f 1 -d ","|tr -d " "`;if [ "x$P" = "x" ]; then echo 1; else echo $P; fi);\
	Make(var,pos_mm,echo "$(song_pos)/60"|bc);\
	Make(var,pos_ss,echo "$(song_pos)-$(pos_mm)*60"|bc);\
	Send(string,s5=$(pos_mm):$(pos_ss));Send(bytes,3);\
	Make(var,song_len,P=`$(banshee_exec) --query-duration|cut -f 2 -d ":"|cut -f 1 -d ","|tr -d " "`;if [ "x$P" = "x" ]; then echo 1; else echo $P; fi);\
	Make(var,playback_pos,echo "65535*$(song_pos)/$(song_len)"|bc);\
	Send(string,a2=$(playback_pos));Send(bytes,3);

%Send(string,s5=);ExecAndSend(string,echo "01:00");Send(bytes,3);\
%        Make(var,playback_persent,echo "65535*"`echo 50`"/100"|bc);\
%        Send(string,a2=$(playback_persent));Send(bytes,3);

% get volume: 0 - 65535
VOLUME=\
	Macro(DEFAULT_VOLUME_GET);\
	Send(string,a1=$(default_mixer_value));Send(bytes,3);

% Artist name
ARTIST=\
	ExecAndSend(string,P=`ps -ef|grep banshee|grep -v grep|grep -v anyremote|grep -v edit`; if [ "x$P" != "x" ]; then $(banshee_exec) --query-artist|cut -f 2 -d ":"|sed "s/%20/ /g"; fi);

% Track
TRACK=\
	ExecAndSend(string,P=`ps -ef|grep banshee|grep -v grep|grep -v anyremote|grep -v edit`; if [ "x$P" != "x" ]; then $(banshee_exec) --query-title|cut -f 2 -d ":"|sed "s/%20/ /g"; fi;);

% Song length mm:ss
SONG_LEN=\
	Make(var,song_len,P=`$(banshee_exec) --query-duration|cut -f 2 -d ":"|cut -f 1 -d ","|tr -d " "`;if [ "x$P" = "x" ]; then echo 1; else echo $P; fi);\
	Make(var,song_mm,echo "$(song_len)/60"|bc);\
	Make(var,song_ss,echo "$(song_len)-$(song_mm)*60"|bc);\
	Send(string,$(song_mm):$(song_ss));

%
% The following is a common part. In general, it should not be changed.
%

TITLE=\
	Send(string,s1=);Macro(ARTIST);Send(bytes,3);\
	Send(string,s2=);Macro(TRACK);Send(bytes,3);\
	Send(string,s6=);Macro(SONG_LEN);Send(bytes,3);\
	Send(string,s4=img_coverart-300.png);Send(bytes,3);

d5(0)=Macro(TITLE);
d6(0)=Macro(TITLE);

% Init
i(1)=Macro(TITLE);

% Password p(PASSWORD)"
p($$)=Send(string,p=ok);Send(bytes,3);

% Heartbeat
DISC=Macro(STOP_TIMERS);Make(disconnect);

h(0)=Timer(DISC,reset);

% no needs to send "h=1\03" replay directly because this will be done 
% automatically - that controlled by $(IViewer) variable
% If $(IViewer) variable is not set it needs to use the following command:
% h(0)=Send(bytes,104,61,49,3);Timer(DISC,reset);

STOP_TIMERS=\
	Timer(PLAYBACK,cancel);\
	Timer(VOLUME,cancel);\
	Timer(TITLE,cancel);
	
% Event timers
(Connect)=\
	Exec(P=`ps -ef|grep banshee|grep -v grep|grep -v anyremote|grep -v edit`; if [ "x$P" = "x" ]; then $(banshee_exec)& fi);\
	Timer(DISC,10,1);\
	Timer(PLAYBACK,3,0);\
	Timer(VOLUME,10,0);\
	Timer(TITLE,5,0);

(Disconnect)=\
	Macro(STOP_TIMERS);

[End]

