%
% anyremote configuration file for Juk/KDE4 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=Juk/KDE4
GuiAppBinary=juk
GuiAppVersion= V=`juk -v|grep KDE|tr -d " "|cut -f 2 -d ":"|cut -f 1 -d "."`; if [ "x$V" = "x4" ]; then echo OK; else echo NOK; fi
GuiAppRun= A=`pgrep juk`; if [ "x$A" = "x" ]; then echo NOK; else echo OK; fi
GuiAppIcon=juk.png
GuiAppType=Application
GuiAppProtocols=iViewer
GuiAppDesc=JuK is a free software audio player for KDE, part of the kdemultimedia package. JuK supports collections of MP3, Ogg Vorbis, and FLAC audio files. This configuration file is for Juk/KDE4.

[Protocol]=iViewer

(Init)=\
	Make(var,IViewer,by_value,true);\
	Exec(V=`juk -v|grep KDE|tr -d " "|cut -f 2 -d ":"|cut -f 1 -d "."`;if [ "x$V" = "x3" ]; then $(CfgDir)/Utils/message.sh "ERROR: this configuration file is for KDE4"; 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)=Exec(qdbus org.kde.juk /Player org.kde.juk.player.play);

% stop
d30(1)=Exec(qdbus org.kde.juk /Player org.kde.juk.player.stop);

% pause
d31(1)=Exec(qdbus org.kde.juk /Player org.kde.juk.player.pause);

% next
d5(1)=Exec(qdbus org.kde.juk /Player org.kde.juk.player.forward);\
	Macro(TITLE);

% prev
d6(1)=Exec(qdbus org.kde.juk /Player org.kde.juk.player.back);\
	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)/65535"|bc -l);\
	Exec(qdbus org.kde.juk /Player setVolume $(change_vol));\
	Macro(VOLUME);

% seek >> and <<
a2($$)=\
	Make(var,seek_command,if [ $(Index) \> 32750 ]; then echo "seekForward"; else echo "seekBack"; fi);\
	Exec(qdbus org.kde.juk /Player $(seek_command));\
	Macro(PLAYBACK);

% Feedback
PLAYBACK=\
	Make(var,song_pos,qdbus org.kde.juk /Player currentTime);\
	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,qdbus org.kde.juk /Player totalTime);\
	Make(var,playback_pos,echo "65535*$(song_pos)/$(song_len)"|bc|cut -f 1 -d '.');\
	Send(string,a2=$(playback_pos));Send(bytes,3);

% get volume: 0 - 65535
VOLUME=\
	Make(var,juk_vol,qdbus org.kde.juk /Player volume);\
	Make(var,vol_value,echo "65535*$(juk_vol)"|bc|cut -f 1 -d '.');\
	Send(string,a1=$(vol_value));Send(bytes,3);

% Artist name
ARTIST=\
	Make(var,album,qdbus org.kde.juk /Player trackProperty Album);\
	Make(var,artist,qdbus org.kde.juk /Player trackProperty Artist);\
	Send(string,$(artist) - $(album));

% Track
TRACK=\
	ExecAndSend(string,qdbus org.kde.juk /Player trackProperty Title);

% Song length mm:ss
SONG_LEN=\
	Make(var,song_len,qdbus org.kde.juk /Player totalTime);\
	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);

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(A=`pgrep juk`; if [ "x$A" = "x" ]; then juk; fi);\
	Timer(DISC,10,1);\
	Timer(PLAYBACK,3,0);\
	Timer(VOLUME,10,0);\
	Timer(TITLE,5,0);

(Disconnect)=\
	Macro(STOP_TIMERS);

[End]

