%
% anyremote configuration file for decibel-audio-player (http://decibel.silent-blade.org/) (Server-mode)
% 

% STATUS nonstable
% TODO shuffle works strange;repeat do not works,RWD&FF works badly,playlist-add do not works,choose item from playlist do not works (seems these are decibel bugs)
% XTEST no
% SOUND mixer
% ENV no
% DEF_PLAYER   
% ALL_IN_ONE 
% MEDIACENTER audio

GuiAppName=Decibel
GuiAppBinary=decibel-audio-player
GuiAppRun=echo 'A=`ps -ef|grep decibel-audio-player|grep -v grep`; if [ "x$A" = "x" ]; then echo NOK; else echo OK; fi'|sh -s
GuiAppIcon=decibel-audio-player.png
GuiAppType=Application
GuiAppProtocols=Server
GuiAppDesc=Decibel Audio Player is a GTK+ open-source (GPL license) audio player designed for GNU/Linux, which aims at being very straightforward to use by mean of a very clean and user friendly interface.

[Protocol]=Server

(Init)=\
	Include($(CfgDir)/Utils/aliases-server.cfg);\
	Macro(TEST_DBUS_SEND);\
	Macro(SETUP_DEFAULT_MIXER);\
	Macro(FBROWSER_IC_INIT);\
	Make(var,player_name,by_value,Decibel);\
	Make(var,decibel_get,by_value,\
	     dbus-send --type=method_call --print-reply --dest=org.mpris.dap /Player);\
	Make(var,decibel_metadata,by_value,\
	     $(decibel_get) org.freedesktop.MediaPlayer.GetMetadata);\
	Include($(CfgDir)/Utils/aliases-server-player.cfg);\
	Make(var,cover_size,by_value,);\
	Make(var,decibel_layout,\
	     V=`$(CfgDir)/Utils/registry.sh $(TmpDir) get decibel_layout`;\
	     if [ "x$V" = "x" ]; then echo "5x1"; else echo $V; fi);

(Exit)=\
	Macro(FBROWSER_IC_EXIT);\
	Exec($(CfgDir)/Utils/registry.sh $(TmpDir) set decibel_layout $(decibel_layout));

(Connect)=\
	Make(mode,decibel_$(decibel_layout));

[Mode]=decibel_general

% Volume control and 0-9,*,# assignments by Utils/aliases-server-player.cfg
%decibel-audio-player-remote volume 100

GETPOS=\
        Make(var,dap_pos,$(decibel_get) org.freedesktop.MediaPlayer.PositionGet|tail -1|grep int|tr -s ' '|cut -f 3 -d ' ');

SETPOS=\
	Exec(dbus-send --type=method_call --dest=org.mpris.dap /Player org.freedesktop.MediaPlayer.PositionSet uint32:$(dap_pos_set));

% 'decibel-audio-player-remote play' does not resume playing after pause
PLAY=\
	Exec(decibel-audio-player-remote pause);\
	Macro(DECIBEL_TITLE);\
	Timer(DECIBEL_TITLE,$(UpdateTimeout),0);

%RWD=Emulate(key,Left);
%FF=Emulate(key,Right);

RWD=\
	Macro(GETPOS);\
	Make(var,dap_pos_set,expr $(dap_pos) - 5000);\
	Macro(SETPOS);
	
FF=\
	Macro(GETPOS);\
	Make(var,dap_pos_set,expr $(dap_pos) + 5000);\
	Macro(SETPOS);
	
PREV=\
	Exec(decibel-audio-player-remote prev);\
	Macro(DECIBEL_TITLE);

STOP=\
	Timer(DECIBEL_TITLE,cancel);\
	Exec(decibel-audio-player-remote stop);

NEXT=\
	Exec(decibel-audio-player-remote next);\
	Macro(DECIBEL_TITLE);

PAUSE=\
	Exec(decibel-audio-player-remote pause);

RUN_IF_NEED=\
	Exec(P=`ps -ef|grep decibel-audio-player|grep -v grep`;\
	     if [ "x$P" = "x" ]; then decibel-audio-player 2> /dev/null & fi);

RUN_OR_QUIT=\
	Exec(P=`ps -ef|grep decibel-audio-player|grep -v grep`; \
	     if [ "x$P" = "x" ]; then \
	         decibel-audio-player 2> /dev/null & \
	     else \
	         pkill -f "python.*decibel-audio-player"; \
	     fi);

APP_QUIT=\
	Timer(APLAYER_TITLE,cancel);\
	Exec(pkill -f "python.*decibel-audio-player");

DECIBEL_TITLE_GENERAL=\
        Make(var,dap_artist,$(decibel_metadata)|awk '/.*string "artist".*/{getline;print}'|grep string|cut -f 2 -d '"');\
        Make(var,dap_album,$(decibel_metadata)|awk '/.*string "album".*/{getline;print}'|grep string|cut -f 2 -d '"');\
        Make(var,dap_title,$(decibel_metadata)|awk '/.*string "title".*/{getline;print}'|grep string|cut -f 2 -d '"');\
	Set(title,$(dap_artist) - $(dap_album));\
	Set(status,$(dap_title));

Shuffle=\
	Exec(decibel-audio-player-remote shuffle);

Repeat=\
	Exec(P=`$(decibel_get) org.freedesktop.MediaPlayer.GetStatus|awk '/.*struct.*/{getline;getline;getline;getline;print}'|grep int|tr -s ' '|cut -f 3 -d ' '`; \
		if [ "x$P" != "x1" ]; \
		then \
		    dbus-send --type=method_call --dest=org.mpris.dap /TrackList org.freedesktop.MediaPlayer.SetLoop boolean:true & \
		else \
		    dbus-send --type=method_call --dest=org.mpris.dap /TrackList org.freedesktop.MediaPlayer.SetLoop boolean:false & \
		fi);

Playlist=\
	Make(mode,decibel_playlist);

APP_PLAY_STATUS=\
	Make(var,decibel_status,$(decibel_get) org.freedesktop.MediaPlayer.GetStatus|awk '/.*struct.*/{getline;print}'|grep int|tr -s ' '|cut -f 3 -d ' ');\
	Make(var,app_status,if [ "x$(decibel_status)" = "x0" ]; then echo playing; else echo paused; fi);

Layout 3x4=\
	Make(mode,decibel_3x4);

Layout 7x1=\
	Make(mode,decibel_7x1);

Layout 5x1=\
	Make(mode,decibel_5x1);

[ModeEnd]

[Mode]=decibel_3x4 : decibel_general, default_player

% (EnterMode) by Utils/aliases-server-player.cfg

APP_MENU=\
	Set(menu,replace,Playlist,Shuffle,Repeat,Layout 5x1,Layout 7x1,PowerMgmt);\
	Macro(ALLIN1MENU);\
	Macro(MEDIACENTER_MENU);

APP_POST_SETUP=\
	Make(var,decibel_layout,by_value,3x4);

DECIBEL_TITLE=\
	Macro(DECIBEL_TITLE_GENERAL);

[ModeEnd]

[Mode]=decibel_cover

DECIBEL_TITLE=\
	Macro(DECIBEL_TITLE_GENERAL);\
	Macro(APP_COVER, if [ "x$(cover_size)" = "x" ]; then echo 1; else echo 0; fi);

APP_COVER=\
	Make(var,media_file,\
	     $(decibel_metadata)|awk '/.*string "location".*/{getline;print}'|grep string|cut -f 2 -d '"'|cut -f 2 -d ':'|sed 's/"$//;s/^\/\/\//\//');\
	Macro(DEFAULT_COVER);

[ModeEnd]

[Mode]=decibel_7x1 : decibel_general, default_player_7x1, decibel_cover

% (EnterMode) by Utils/aliases-server-player.cfg

% Mute, Next Cover,Previous Cover,Update Cover, PowerMgmt by Utils/aliases-server-player.cfg
APP_MENU=\
	Set(menu,replace,Playlist,Shuffle,Repeat,Mute,Next Cover,Previous Cover,Update Cover,Layout 3x4,Layout 5x1,Help,PowerMgmt);\
	Macro(ALLIN1MENU);\
	Macro(MEDIACENTER_MENU);

APP_POST_SETUP=\
	Make(var,decibel_layout,by_value,7x1);

[ModeEnd]

[Mode]=decibel_5x1 : decibel_general, default_player_5x1, decibel_cover

% (EnterMode) by Utils/aliases-server-player.cfg

% Mute, Next Cover,Previous Cover,Update Cover, PowerMgmt by Utils/aliases-server-player.cfg
APP_MENU=\
	Set(menu,replace,Playlist,Shuffle,Repeat,Mute,Next Cover,Previous Cover,Update Cover,Layout 3x4,Layout 7x1,Help,PowerMgmt);\
	Macro(ALLIN1MENU);\
	Macro(MEDIACENTER_MENU);

APP_POST_SETUP=\
	Make(var,decibel_layout,by_value,5x1);

% not timer	
PLAY=\
	Exec(decibel-audio-player-remote pause);\
	Macro(DECIBEL_TITLE);

APP_TITLE=\
	Macro(DECIBEL_TITLE);

[ModeEnd]

[Mode]=decibel_nobutton

% bug-prone :)
1=Make(mode,decibel_$(decibel_layout));	
2=Make(mode,decibel_$(decibel_layout));	
3=Make(mode,decibel_$(decibel_layout));	
4=Make(mode,decibel_$(decibel_layout));	
5=Make(mode,decibel_$(decibel_layout));	
6=Make(mode,decibel_$(decibel_layout));	
7=Make(mode,decibel_$(decibel_layout));	
8=Make(mode,decibel_$(decibel_layout));	
9=Make(mode,decibel_$(decibel_layout));	
*=Make(mode,decibel_$(decibel_layout));	
0=Make(mode,decibel_$(decibel_layout));	
#=Make(mode,decibel_$(decibel_layout));	

[ModeEnd]

[Mode]=decibel_playlist : decibel_nobutton

%playlist-add do not works in Decibel v0.09	

(EnterMode)=\
	ExecAndSet(list,replace,Playlist,$(CfgDir)/Utils/getPlayList.sh org.mpris.dap);\
  	ExecAndSet(list,select,expr 1 + `dbus-send --type=method_call --print-reply --dest=org.mpris.dap /TrackList org.freedesktop.MediaPlayer.GetCurrentTrack|tail -1|grep int|tr -s ' '|cut -f 3 -d ' '`);\
	Set(menu,replace,Choose,Delete);
	
Push($$)=\
	Macro(Choose($$))
	
% no such method	
%Choose($$)=\
%	Exec();

Delete($$)=\
	Exec(dbus-send --type=method_call --dest=org.mpris.dap /TrackList org.freedesktop.MediaPlayer.DelTrack `expr $(Index) - 1`);

Back($$)=\
	Set(list,close);\
	Make(mode,decibel_$(decibel_layout));

[ModeEnd]

%UpdateMenu=Set(menu,replace,GoTo,Add,Go Home);
%Add to playlist=Macro(FBROWSER_IC_FILL_LIST);Macro(UpdateMenu);
%GoTo    =Macro(FBROWSER_IC_GO_TO);
%Go Home =Macro(FBROWSER_IC_GO_HOME);
%Push($$) use from aliases-server-fbrowser-v3i.cfg

%Add($$)=Set(list,close);\
%	Exec(decibel-audio-player-remote pl-add "$(fbrowser_dir)/$(Param)");\
%	Macro(APP_MENU);

[End]
