summaryrefslogtreecommitdiff
path: root/plugins/Watrack_MPD/src/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/Watrack_MPD/src/main.cpp')
-rwxr-xr-xplugins/Watrack_MPD/src/main.cpp350
1 files changed, 175 insertions, 175 deletions
diff --git a/plugins/Watrack_MPD/src/main.cpp b/plugins/Watrack_MPD/src/main.cpp
index 17a8c29d64..eec0a6b1af 100755
--- a/plugins/Watrack_MPD/src/main.cpp
+++ b/plugins/Watrack_MPD/src/main.cpp
@@ -14,169 +14,38 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
-
-
#include "commonheaders.h"
-
-//maybe add mutex ?
-void Start(void *param);
-int Parser();
-
-LPINITPROC Init()
-{
- mir_forkthread(&Start, 0);
- return 0;
-}
-void Stop();
-LPDEINITPROC DeInit()
-{
- Stop();
- return 0;
-}
-LPCHECKPROC CheckPlayer(HWND wnd, int flags)
-{
- if(!ghConnection)
- {
- mir_forkthread(&Start, 0);
- return 0;
- }
- if(Parser())
- return (LPCHECKPROC)WAT_MES_STOPPED;
- if(Connected)
- return (LPCHECKPROC)WAT_MES_PLAYING;
- return 0;
-}
-LPGETSTATUSPROC GetStatus()
-{
- if(!ghConnection)
- {
- mir_forkthread(&Start, 0);
- return 0;
- }
- if(Parser())
- return (LPGETSTATUSPROC)-1;
- return (LPGETSTATUSPROC)(gbState);
-}
-LPNAMEPROC GetFileName(HWND wnd, int flags)
-{
- if(!ghConnection)
- {
- mir_forkthread(&Start, 0);
- return 0;
- }
- return 0;
-}
+HANDLE ghConnection;
+HANDLE ghPacketReciever;
+BOOL Connected;
+int gbState;
SONGINFO SongInfo = {0};
-LPINFOPROC GetPlayerInfo(LPSONGINFO info, int flags)
-{
- if(!ghConnection)
- {
- mir_forkthread(&Start, 0);
- return 0;
- }
- if(Parser())
- return (LPINFOPROC)-1;
-/*
-
- info->channels = SongInfo.channels;
- info->codec = SongInfo.codec;
- info->comment = SongInfo.comment;
- info->cover = SongInfo.cover;
- info->date = SongInfo.date;
- info->fps = SongInfo.fps;
- info->fsize = SongInfo.fsize;
-
- info->icon = SongInfo.icon;
- info->kbps = SongInfo.kbps;
- info->khz = SongInfo.khz;
- info->lyric = SongInfo.lyric;
- info->mfile = SongInfo.mfile;
- info->player = SongInfo.player;
- info->plyver = SongInfo.plyver;
- info->status = SongInfo.status;
- info->time = SongInfo.time;
- info->title = SongInfo.title;
- info->total = SongInfo.total;
- info->track = SongInfo.track;*/
- info->total = SongInfo.total;
- info->time = SongInfo.time;
- info->mfile = SongInfo.mfile;
- info->txtver = SongInfo.txtver;
- info->title = SongInfo.title;
- info->artist = SongInfo.artist;
- info->genre = SongInfo.genre;
- info->album = SongInfo.album;
- info->year = SongInfo.year;
- info->kbps = SongInfo.kbps;
- info->track = SongInfo.track;
- info->khz = SongInfo.khz;
- info->volume = SongInfo.volume;
-/* info->url = SongInfo.url; //??
- info->vbr = SongInfo.vbr;
- info->volume = SongInfo.volume;
- */
- return 0;
-}
-LPCOMMANDPROC SendCommand(HWND wnd, int command, int value)
+void Start(void* param)
{
- switch (command)
- {
- case WAT_CTRL_PREV:
- Netlib_Send(ghConnection, "previous\n", strlen("previous\n"), 0);
- break;
- case WAT_CTRL_PLAY: //add resuming support
- if(gbState != WAT_MES_PAUSED)
- Netlib_Send(ghConnection, "play\n", strlen("play\n"), 0);
- else
- Netlib_Send(ghConnection, "pause 0\n", strlen("pause 0\n"), 0);
- break;
- case WAT_CTRL_PAUSE:
- Netlib_Send(ghConnection, "pause 1\n", strlen("pause 1\n"), 0);
- break;
- case WAT_CTRL_STOP:
- Netlib_Send(ghConnection, "stop\n", strlen("stop\n"), 0);
- break;
- case WAT_CTRL_NEXT:
- Netlib_Send(ghConnection, "next\n", strlen("next\n"), 0);
- break;
- case WAT_CTRL_VOLDN:
- break;
- case WAT_CTRL_VOLUP:
- break;
- case WAT_CTRL_SEEK:
- break;
- default:
- break;
- }
- return 0;
+ NETLIBOPENCONNECTION nloc = {0};
+ char *tmp = (char*)mir_u2a(gbHost);
+ nloc.cbSize = sizeof(nloc);
+ nloc.szHost = tmp;
+ nloc.timeout = 5;
+ nloc.wPort = gbPort;
+ Connected = FALSE;
+ ghConnection = NetLib_CreateConnection(ghNetlibUser, &nloc);
+ if(ghConnection)
+ ghPacketReciever = (HANDLE)CallService(MS_NETLIB_CREATEPACKETRECVER,(WPARAM)ghConnection,2048);
}
-
-void RegisterPlayer()
+void ReStart(void *param)
{
- if(!bWatrackService)
- return;
- {
- PLAYERCELL player = {0};
- player.Desc = "Music Player Daemon";
- player.Check = (LPCHECKPROC)CheckPlayer;
- player.Init = (LPINITPROC)Init;
- player.DeInit = (LPDEINITPROC)DeInit;
- player.GetStatus = (LPGETSTATUSPROC)GetStatus;
- player.Command = (LPCOMMANDPROC)SendCommand;
- player.flags = (WAT_OPT_HASURL|WAT_OPT_SINGLEINST|WAT_OPT_PLAYERINFO);
- player.GetName = (LPNAMEPROC)GetFileName;
- player.GetInfo = (LPINFOPROC)GetPlayerInfo;
-// player.Icon = //TODO:implement icon support
- player.Notes = _T("mpd is a nice music player for *nix which have not any gui, just daemon.\nuses very small amount of ram, cpu.");
- player.URL = "http://www.musicpd.org";
- CallService(MS_WAT_PLAYER, (WPARAM)WAT_ACT_REGISTER, (LPARAM)&player);
- }
+ if(ghPacketReciever)
+ Netlib_CloseHandle(ghPacketReciever);
+ if(ghConnection)
+ Netlib_CloseHandle(ghConnection);
+ Sleep(500);
+ mir_forkthread(&Start, 0);
}
-void ReStart(void *data);
+
int Parser()
{
static NETLIBPACKETRECVER nlpr = {0};
@@ -246,7 +115,7 @@ int Parser()
}
nlpr.bytesUsed = nlpr.bytesAvailable;
}
- buf = nlpr.buffer;
+ buf = (char*)nlpr.buffer;
if(ptr = strstr(buf, "MPD"))
{
Connected = TRUE;
@@ -398,20 +267,6 @@ int Parser()
return 0;
}
-
-void Start(void* param)
-{
- NETLIBOPENCONNECTION nloc = {0};
- char *tmp = (char*)mir_u2a(gbHost);
- nloc.cbSize = sizeof(nloc);
- nloc.szHost = tmp;
- nloc.timeout = 5;
- nloc.wPort = gbPort;
- Connected = FALSE;
- ghConnection = NetLib_CreateConnection(ghNetlibUser, &nloc);
- if(ghConnection)
- ghPacketReciever = (HANDLE)CallService(MS_NETLIB_CREATEPACKETRECVER,(WPARAM)ghConnection,2048);
-}
void Stop()
{
if(ghPacketReciever)
@@ -421,13 +276,158 @@ void Stop()
if(ghNetlibUser && (ghNetlibUser != INVALID_HANDLE_VALUE))
CallService(MS_NETLIB_SHUTDOWN,(WPARAM)ghNetlibUser,0);
}
-void ReStart(void *param)
+
+LPINITPROC Init()
{
- if(ghPacketReciever)
- Netlib_CloseHandle(ghPacketReciever);
- if(ghConnection)
- Netlib_CloseHandle(ghConnection);
- Sleep(500);
mir_forkthread(&Start, 0);
+ return 0;
+}
+
+LPDEINITPROC DeInit()
+{
+ Stop();
+ return 0;
+}
+
+LPCHECKPROC CheckPlayer(HWND wnd, int flags)
+{
+ if(!ghConnection)
+ {
+ mir_forkthread(&Start, 0);
+ return 0;
+ }
+ if(Parser())
+ return (LPCHECKPROC)WAT_MES_STOPPED;
+ if(Connected)
+ return (LPCHECKPROC)WAT_MES_PLAYING;
+ return 0;
}
+LPSTATUSPROC GetStatus()
+{
+ if(!ghConnection)
+ {
+ mir_forkthread(&Start, 0);
+ return 0;
+ }
+ if(Parser())
+ return (LPSTATUSPROC)-1;
+ return (LPSTATUSPROC)(gbState);
+}
+
+LPNAMEPROC GetFileName(HWND wnd, int flags)
+{
+ if(!ghConnection)
+ {
+ mir_forkthread(&Start, 0);
+ return 0;
+ }
+ return 0;
+}
+
+LPINFOPROC GetPlayerInfo(LPSONGINFO info, int flags)
+{
+ if(!ghConnection)
+ {
+ mir_forkthread(&Start, 0);
+ return 0;
+ }
+ if(Parser())
+ return (LPINFOPROC)-1;
+/*
+
+ info->channels = SongInfo.channels;
+ info->codec = SongInfo.codec;
+ info->comment = SongInfo.comment;
+ info->cover = SongInfo.cover;
+ info->date = SongInfo.date;
+ info->fps = SongInfo.fps;
+ info->fsize = SongInfo.fsize;
+
+ info->icon = SongInfo.icon;
+ info->kbps = SongInfo.kbps;
+ info->khz = SongInfo.khz;
+ info->lyric = SongInfo.lyric;
+ info->mfile = SongInfo.mfile;
+ info->player = SongInfo.player;
+ info->plyver = SongInfo.plyver;
+ info->status = SongInfo.status;
+ info->time = SongInfo.time;
+ info->title = SongInfo.title;
+ info->total = SongInfo.total;
+ info->track = SongInfo.track;*/
+ info->total = SongInfo.total;
+ info->time = SongInfo.time;
+ info->mfile = SongInfo.mfile;
+ info->txtver = SongInfo.txtver;
+ info->title = SongInfo.title;
+ info->artist = SongInfo.artist;
+ info->genre = SongInfo.genre;
+ info->album = SongInfo.album;
+ info->year = SongInfo.year;
+ info->kbps = SongInfo.kbps;
+ info->track = SongInfo.track;
+ info->khz = SongInfo.khz;
+ info->volume = SongInfo.volume;
+/* info->url = SongInfo.url; //??
+ info->vbr = SongInfo.vbr;
+ info->volume = SongInfo.volume;
+ */
+ return 0;
+}
+
+LPCOMMANDPROC SendCommand(HWND wnd, int command, int value)
+{
+ switch (command)
+ {
+ case WAT_CTRL_PREV:
+ Netlib_Send(ghConnection, "previous\n", strlen("previous\n"), 0);
+ break;
+ case WAT_CTRL_PLAY: //add resuming support
+ if(gbState != WAT_MES_PAUSED)
+ Netlib_Send(ghConnection, "play\n", strlen("play\n"), 0);
+ else
+ Netlib_Send(ghConnection, "pause 0\n", strlen("pause 0\n"), 0);
+ break;
+ case WAT_CTRL_PAUSE:
+ Netlib_Send(ghConnection, "pause 1\n", strlen("pause 1\n"), 0);
+ break;
+ case WAT_CTRL_STOP:
+ Netlib_Send(ghConnection, "stop\n", strlen("stop\n"), 0);
+ break;
+ case WAT_CTRL_NEXT:
+ Netlib_Send(ghConnection, "next\n", strlen("next\n"), 0);
+ break;
+ case WAT_CTRL_VOLDN:
+ break;
+ case WAT_CTRL_VOLUP:
+ break;
+ case WAT_CTRL_SEEK:
+ break;
+ default:
+ break;
+ }
+ return 0;
+}
+
+void RegisterPlayer()
+{
+ if(!bWatrackService)
+ return;
+ {
+ PLAYERCELL player = {0};
+ player.Desc = "Music Player Daemon";
+ player.Check = (LPCHECKPROC)CheckPlayer;
+ player.Init = (LPINITPROC)Init;
+ player.DeInit = (LPDEINITPROC)DeInit;
+ player.GetStatus = (LPSTATUSPROC)GetStatus;
+ player.Command = (LPCOMMANDPROC)SendCommand;
+ player.flags = (WAT_OPT_HASURL|WAT_OPT_SINGLEINST|WAT_OPT_PLAYERINFO);
+ player.GetName = (LPNAMEPROC)GetFileName;
+ player.GetInfo = (LPINFOPROC)GetPlayerInfo;
+// player.Icon = //TODO:implement icon support
+ player.Notes = _T("mpd is a nice music player for *nix which have not any gui, just daemon.\nuses very small amount of ram, cpu.");
+ player.URL = "http://www.musicpd.org";
+ CallService(MS_WAT_PLAYER, (WPARAM)WAT_ACT_REGISTER, (LPARAM)&player);
+ }
+} \ No newline at end of file