%
% anyremote configuration file for Rhythmbox 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 app
% ENV no

GuiAppName=Rhythmbox
GuiAppBinary=rhythmbox
GuiAppRun=echo 'A=`ps -ef|grep rhythmbox|grep -v grep|grep -v anyremote|grep -v edit`; if [ "x$A" == "x" ]; then echo NOK; else echo OK; fi' | bash -f -s
GuiAppIcon=rhythmbox.png
GuiAppType=Application
GuiAppProtocols=iViewer
GuiAppDesc=Rhythmbox - The music management application for GNOME

[Protocol]=iViewer

%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)=Exec(rhythmbox-client --no-start --play-pause);

% stop
d30(1)=Exec(rhythmbox-client --no-start  --play-pause)

% pause
d31(1)=Exec(rhythmbox-client --no-start  --play-pause)

% next
d5(1)=Exec(rhythmbox-client --no-start --next);\
	Macro(TITLE);

% prev
d6(1)=Exec(rhythmbox-client --no-start --previous);\
	Macro(TITLE);

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

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

% volume contol
a1($$)=Make(var,change_vol,echo "$(Index)*100/65535"|bc);\
	Exec(rhythmbox-client --no-start --set-volume .$(change_vol));\
	Macro(VOLUME);

% seek >> and <<
a2($$)=\
	Make(var,seek_command,echo 'if [ $(Index) \> 32750 ]; then echo "+10"; else echo "-10"; fi'|bash -f -s);\
	Macro(SEEK);\
	Macro(PLAYBACK);

SEEK=\
	Exec(python -c "import dbus;import sys;import os;session_bus = dbus.SessionBus();pp = session_bus.get_object('org.gnome.Rhythmbox', '/org/gnome/Rhythmbox/Player');player = dbus.Interface(pp, 'org.gnome.Rhythmbox.Player');ts=player.getElapsed()$(seek_command);player.setElapsed(ts)")

% Feedback
PLAYBACK=\
	Send(string,s5=);\
	ExecAndSend(string,rhythmbox-client --no-start --print-playing-format %te);\
	Send(bytes,3);\
	Send(string,a2=0);\
	Send(bytes,3);

% get volume: 0 - 65535
VOLUME=\
	Make(var,rh_vol,LANG=C;rhythmbox-client --no-start --print-volume|cut -f 4 -d " "|cut -f1 -d '.'|sed 's/,/./g');\
	Make(var,rh_vol,if [ "x$(rh_vol)" = "x" ]; then echo 1; else echo $(rh_vol); fi);\
	Make(var,vol_value,echo "65535*$(rh_vol)"|bc|cut -f 1 -d '.');\
	Send(string,a1=$(vol_value));Send(bytes,3);

% Artist name
ARTIST=\
	ExecAndSend(string,rhythmbox-client --no-start --print-playing-format %ta);

% Track
TRACK=\
	ExecAndSend(string,rhythmbox-client --no-start --print-playing-format "%at - %tt");

% Song length mm:ss
SONG_LEN=\
	ExecAndSend(string,rhythmbox-client --no-start --print-playing-format %td);

%
% 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);

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
(Init)=\
	Make(var,IViewer,by_value,true);

(Connect)=\
	Timer(DISC,10,1);\
	Timer(PLAYBACK,3,0);\
	Timer(VOLUME,10,0);\
	Timer(TITLE,5,0);

(Disconnect)=Macro(STOP_TIMERS);

[End]

