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

% STATUS nonstable
% XTEST yes
% SOUND mixer
% ENV no

GuiAppName=VLC
GuiAppBinary=vlc
GuiAppRun= P=`ps -ef|grep vlc|grep -v grep|grep -v anyremote|grep -v nedit`; if [ "x$P" = "x" ]; then echo NOK; else echo OK; fi
GuiAppIcon=vlc.png
GuiAppType=Application
GuiAppProtocols=iViewer
GuiAppDesc=VLC media player is a highly portable multimedia player for various audio and video formats (MPEG-1, MPEG-2, MPEG-4, DivX, mp3, ogg, ...) as well as DVDs, VCDs, and various streaming protocols.

[Protocol]=iViewer

% Init update
%T current title
%M song len mm:ss
%m playback time mm:ss
%p playback time in persents
%S song len sec

%s1 = artist
%s2 = track

%s6 = song length min:sec.
%s5 = current playback in min:sec
%a2 = needs a constent update to. its the seek bar
%a1 = volume

% play/pause
d1(1)=Exec($(vlc_dbus) org.mpris.MediaPlayer2.Player.Play);

% next
d5(1)=Exec($(vlc_dbus) org.mpris.MediaPlayer2.Player.Next);

% prev
d6(1)=Exec($(vlc_dbus) org.mpris.MediaPlayer2.Player.Previous);

% toggle repeat
d12(1)=Make(none);

% toggle shuffle
d9(1)=Make(none);

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

% seek >> and <<
a2($$)=\
	Make(var,seek_command,if [ $(Index) \> 32750 ]; then echo VLC_SEEK_FWD; else echo VLC_SEEK_RW; fi);\
	Macro($(seek_command));\
	Macro(PLAYBACK);

% Feedback
PLAYBACK=\
	Make(none)

VLC_SEEK_FWD=\
	Emulate(keydown,Alt_L,key,Right,keyup,Alt_L);

VLC_SEEK_RW=\
	Emulate(keydown,Alt_L,key,Left,keyup,Alt_L);
	
% get volume: 0 - 65535
VOLUME=\
	Macro(DEFAULT_VOLUME_GET);\
        Send(string,a1=$(default_mixer_value));\
	Send(bytes,3);

% Artist name
ARTIST=\
	ExecAndSend(string,echo "");

% Track
TRACK=\
	ExecAndSend(string,echo "");

% Song length sec
SONG_LEN=\
	ExecAndSend(string,echo "");

%
% 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);\
	Macro(VOLUME);

% 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)=\
	Include($(CfgDir)/Utils/aliases-iviewer.cfg);\
	Macro(SETUP_DEFAULT_MIXER);\
	Make(var,IViewer,by_value,true);

(Connect)= \
	Exec(P=`ps -ef|grep vlc|grep -v grep|grep -v anyremote|grep -v nedit`; if [ "x$P" = "x" ]; then vlc& fi);\
	Make(var,vlc_dbus,by_value,qdbus org.mpris.MediaPlayer2.vlc /org/mpris/MediaPlayer2);\
	Timer(DISC,10,1);\
	Timer(PLAYBACK,3,0);\
	Timer(VOLUME,10,0);\
	Timer(TITLE,5,0);
	

(Disconnect)=\
	Macro(STOP_TIMERS);

[End]

