NowPlaying.dll: Removed foobar2000 specific interface (switched to use CAD interface)

This commit is contained in:
Birunthan Mohanathas 2012-03-28 22:12:04 +03:00
parent 4b227b413c
commit 024a720c11
8 changed files with 27 additions and 571 deletions

View File

@ -21,7 +21,6 @@
#include "Internet.h"
#include "PlayerAIMP.h"
#include "PlayerCAD.h"
#include "PlayerFoobar.h"
#include "PlayerITunes.h"
#include "PlayerSpotify.h"
#include "PlayerWinamp.h"
@ -148,7 +147,17 @@ PLUGIN_EXPORT void Reload(void* data, void* rm, double* maxValue)
}
else if (_wcsicmp(L"foobar2000", str) == 0)
{
parent->player = CPlayerFoobar::Create();
HWND fooWindow = FindWindow(L"foo_rainmeter_class", NULL);
if (fooWindow)
{
const WCHAR* error = L"Your foobar2000 plugin is out of date.\n\nDo you want to update the plugin now?";
if (MessageBox(NULL, error, L"Rainmeter", MB_YESNO | MB_ICONINFORMATION | MB_TOPMOST) == IDYES)
{
ShellExecute(NULL, L"open", L"http://github.com/poiru/foo-cad#readme", NULL, NULL, SW_SHOWNORMAL);
}
}
parent->player = CPlayerCAD::Create();
}
else if (_wcsicmp(L"iTunes", str) == 0)
{

View File

@ -30,7 +30,7 @@ CPlayer::CPlayer() :
m_TrackCount(),
m_Measures(),
m_State(),
m_Number(1),
m_Number(),
m_Year(),
m_Shuffle(false),
m_Repeat(false),

View File

@ -77,7 +77,8 @@ void CPlayerCAD::Initialize()
RegisterClass(&wc);
// Create reciever window
m_Window = CreateWindow(L"NowPlayingCADClass",
m_Window = CreateWindow(
L"NowPlayingCADClass",
L"CD Art Display 1.x Class",
WS_DISABLED,
CW_USEDEFAULT,
@ -315,7 +316,7 @@ LRESULT CALLBACK CPlayerCAD::WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
break;
case 11:
if (*data == L' ' && player->m_Measures & MEASURE_COVER)
if (*data == L' ')
{
player->FindCover();
}

View File

@ -1,456 +0,0 @@
/*
Copyright (C) 2011 Birunthan Mohanathas (www.poiru.net)
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "StdAfx.h"
#include "PlayerFoobar.h"
CPlayer* CPlayerFoobar::c_Player = NULL;
extern HINSTANCE g_Instance;
/*
** Constructor.
**
*/
CPlayerFoobar::CPlayerFoobar() : CPlayer(),
m_Window(),
m_FooWindow(),
m_MaximizeOnStart(false)
{
Initialize();
}
/*
** Constructor.
**
*/
CPlayerFoobar::~CPlayerFoobar()
{
c_Player = NULL;
Uninitialize();
}
/*
** Creates a shared class object.
**
*/
CPlayer* CPlayerFoobar::Create()
{
if (!c_Player)
{
c_Player = new CPlayerFoobar();
}
return c_Player;
}
/*
** Create receiver window.
**
*/
void CPlayerFoobar::Initialize()
{
// Create windows class
WNDCLASS wc = {0};
wc.hInstance = g_Instance;
wc.lpfnWndProc = WndProc;
wc.lpszClassName = L"NowPlayingFoobarClass";
RegisterClass(&wc);
// Create window
m_Window = CreateWindow(L"NowPlayingFoobarClass",
L"ReceiverWindow",
WS_DISABLED,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
g_Instance,
this);
m_FooWindow = FindWindow(L"foo_rainmeter_class", NULL);
if (m_FooWindow)
{
int version = (int)SendMessage(m_FooWindow, WM_USER, 0, FOO_GETVERSION);
if (version < 100)
{
const WCHAR* error = L"Your copy of the foo_rainmeter.dll plugin for foobar2000 is outdated.\nDownload the latest version from foo-rainmeter.googlecode.com and try again.";
MessageBox(NULL, error, L"Rainmeter", MB_OK | MB_ICONERROR | MB_TOPMOST);
m_FooWindow = NULL;
}
else
{
m_Initialized = true;
SendMessage(m_FooWindow, WM_USER, (WPARAM)m_Window, FOO_SETCALLBACK);
}
}
}
/*
** Destroy reciever window.
**
*/
void CPlayerFoobar::Uninitialize()
{
if (m_FooWindow)
{
SendMessage(m_FooWindow, WM_USER, 0, FOO_REMOVECALLBACK);
}
DestroyWindow(m_Window);
UnregisterClass(L"NowPlayingFoobarClass", g_Instance);
}
/*
** Window procedure for the reciever window.
**
*/
LRESULT CALLBACK CPlayerFoobar::WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
static CPlayerFoobar* player;
switch (msg)
{
case WM_CREATE:
{
// Get pointer to the CPlayerFoobar class from the CreateWindow call
LPVOID params = ((CREATESTRUCT*)lParam)->lpCreateParams;
player = (CPlayerFoobar*)params;
return 0;
}
case WM_USER:
switch (lParam)
{
case FOO_GETVERSION:
return 100;
case FOO_STATECHANGE:
{
StateType ps = (StateType)wParam;
if (ps == STATE_STOPPED)
{
player->ClearData();
}
else
{
player->m_State = ps;
}
}
break;
case FOO_TIMECHANGE:
player->m_Position = (UINT)wParam;
break;
case FOO_VOLUMECHANGE:
player->m_Volume = (UINT)wParam;
break;
case FOO_PLAYERSTART:
player->m_Initialized = true;
player->m_FooWindow = (HWND)wParam;
if (player->m_MaximizeOnStart)
{
SendMessage(player->m_FooWindow, WM_USER, 0, FOO_SHOWPLAYER);
player->m_MaximizeOnStart = false;
}
break;
case FOO_PLAYERQUIT:
player->m_Initialized = false;
player->ClearData();
break;
}
return 0;
case WM_COPYDATA:
{
PCOPYDATASTRUCT cds = (PCOPYDATASTRUCT)lParam;
if (cds->dwData == FOO_TRACKCHANGE)
{
if (player->m_State != STATE_PLAYING)
{
player->m_State = STATE_PLAYING;
}
// In the format "TITLE ARTIST ALBUM LENGTH RATING" (seperated by \t)
WCHAR buffer[1024];
MultiByteToWideChar(CP_UTF8, 0, (char*)cds->lpData, cds->cbData, buffer, 1024);
player->m_Artist = buffer;
WCHAR* token = wcstok(buffer, L"\t");
if (token)
{
if (wcscmp(token, L" ") == 0)
{
player->m_Title.clear();
}
else
{
player->m_Title = token;
}
}
token = wcstok(NULL, L"\t");
if (token)
{
if (wcscmp(token, L" ") == 0)
{
player->m_Artist.clear();
}
else
{
player->m_Artist = token;
}
}
token = wcstok(NULL, L"\t");
if (token)
{
if (wcscmp(token, L" ") == 0)
{
player->m_Album.clear();
}
else
{
player->m_Album = token;
}
}
token = wcstok(NULL, L"\t");
if (token)
{
player->m_Duration = _wtoi(token);
}
token = wcstok(NULL, L"\t");
if (token)
{
player->m_Rating = _wtoi(token);
}
token = wcstok(NULL, L"\t");
if (token && wcscmp(token, player->m_FilePath.c_str()) != 0)
{
// If different file
++player->m_TrackCount;
player->m_FilePath = token;
player->m_Position = 0;
if (player->m_Measures & MEASURE_COVER || player->m_InstanceCount == 0)
{
player->FindCover();
}
if (player->m_Measures & MEASURE_LYRICS)
{
player->FindLyrics();
}
}
token = wcstok(NULL, L"\t");
if (token)
{
switch (_wtoi(token))
{
case 0:
player->m_Shuffle = player->m_Repeat = false;
break;
case 1:
player->m_Shuffle = true;
player->m_Repeat = false;
break;
case 2:
player->m_Shuffle = false;
player->m_Repeat = true;
break;
}
}
}
}
return 0;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
}
/*
** Called during each update of the main measure.
**
*/
void CPlayerFoobar::UpdateData()
{
}
/*
** Handles the Pause bang.
**
*/
void CPlayerFoobar::Pause()
{
SendMessage(m_FooWindow, WM_USER, 0, FOO_PAUSE);
}
/*
** Handles the Play bang.
**
*/
void CPlayerFoobar::Play()
{
SendMessage(m_FooWindow, WM_USER, 0, (m_State == STATE_PAUSED) ? FOO_PLAYPAUSE : FOO_PLAY);
}
/*
** Handles the Stop bang.
**
*/
void CPlayerFoobar::Stop()
{
SendMessage(m_FooWindow, WM_USER, 0, FOO_STOP);
}
/*
** Handles the Next bang.
**
*/
void CPlayerFoobar::Next()
{
SendMessage(m_FooWindow, WM_USER, 0, FOO_NEXT);
}
/*
** Handles the Previous bang.
**
*/
void CPlayerFoobar::Previous()
{
SendMessage(m_FooWindow, WM_USER, 0, FOO_PREVIOUS);
}
/*
** Handles the SetPosition bang.
**
*/
void CPlayerFoobar::SetPosition(int position)
{
SendMessage(m_FooWindow, WM_USER, position, FOO_SETPOSITION);
}
/*
** Handles the SetShuffle bang.
**
*/
void CPlayerFoobar::SetShuffle(bool state)
{
m_Shuffle = state;
m_Repeat = state ? !m_Shuffle : m_Shuffle;
SendMessage(m_FooWindow, WM_USER, state ? 1 : 0, FOO_SETORDER);
}
/*
** Handles the SetRepeat bang.
**
*/
void CPlayerFoobar::SetRepeat(bool state)
{
m_Repeat = state;
m_Shuffle = state ? !m_Repeat : m_Repeat;
SendMessage(m_FooWindow, WM_USER, state ? 2 : 0, FOO_SETORDER);
}
/*
** Handles the SetVolume bang.
**
*/
void CPlayerFoobar::SetVolume(int volume)
{
SendMessage(m_FooWindow, WM_USER, volume, FOO_SETVOLUME);
}
/*
** Handles the ClosePlayer bang.
**
*/
void CPlayerFoobar::ClosePlayer()
{
SendMessage(m_FooWindow, WM_USER, 0, FOO_QUITPLAYER);
}
/*
** Handles the OpenPlayer bang.
**
*/
void CPlayerFoobar::OpenPlayer(std::wstring& path)
{
if (!m_Initialized)
{
if (path.empty())
{
// Gotta figure out where foobar2000 is located at
HKEY hKey;
RegOpenKeyEx(HKEY_CLASSES_ROOT,
L"Applications\\foobar2000.exe\\shell\\open\\command",
0,
KEY_QUERY_VALUE,
&hKey);
DWORD size = 512;
WCHAR* data = new WCHAR[size];
DWORD type = 0;
if (RegQueryValueEx(hKey,
NULL,
NULL,
(LPDWORD)&type,
(LPBYTE)data,
(LPDWORD)&size) == ERROR_SUCCESS)
{
if (type == REG_SZ && data[0] == L'\"')
{
path = data;
path.erase(0, 1); // Get rid of the leading quote
std::wstring::size_type pos = path.find_first_of(L'\"');
if (pos != std::wstring::npos)
{
path.resize(pos); // Get rid the last quote and everything after it
ShellExecute(NULL, L"open", path.c_str(), NULL, NULL, SW_SHOW);
path = path;
}
else
{
path.clear();
}
}
}
delete [] data;
RegCloseKey(hKey);
}
else
{
ShellExecute(NULL, L"open", path.c_str(), NULL, NULL, SW_SHOW);
m_MaximizeOnStart = true;
}
}
else
{
SendMessage(m_FooWindow, WM_USER, 0, FOO_SHOWPLAYER);
}
}

View File

@ -1,90 +0,0 @@
/*
Copyright (C) 2011 Birunthan Mohanathas (www.poiru.net)
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef __PLAYERFOOBAR_H__
#define __PLAYERFOOBAR_H__
#include "Player.h"
class CPlayerFoobar : public CPlayer
{
public:
virtual ~CPlayerFoobar();
static CPlayer* Create();
virtual void UpdateData();
virtual void Pause();
virtual void Play();
virtual void Stop();
virtual void Next();
virtual void Previous();
virtual void SetPosition(int position);
virtual void SetRating(int rating) {}
virtual void SetVolume(int volume);
virtual void SetShuffle(bool state);
virtual void SetRepeat(bool state);
virtual void ClosePlayer();
virtual void OpenPlayer(std::wstring& path);
protected:
CPlayerFoobar();
private:
enum FOOMESSAGE
{
FOO_TRACKCHANGE = 100,
FOO_STATECHANGE,
FOO_TIMECHANGE,
FOO_VOLUMECHANGE,
FOO_PLAYERSTART,
FOO_PLAYERQUIT
};
enum FOOCOMMAND
{
FOO_GETVERSION,
FOO_PLAY,
FOO_PLAYPAUSE,
FOO_PAUSE,
FOO_STOP,
FOO_NEXT,
FOO_PREVIOUS,
FOO_SETRATING,
FOO_SETVOLUME,
FOO_SHOWPLAYER,
FOO_QUITPLAYER,
FOO_SETCALLBACK,
FOO_REMOVECALLBACK,
FOO_SETPOSITION,
FOO_SETORDER
};
void Initialize();
void Uninitialize();
static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
static CPlayer* c_Player;
HWND m_Window; // Our reciever window
HWND m_FooWindow; // Foobar receiver window
bool m_MaximizeOnStart;
};
#endif

View File

@ -7,7 +7,7 @@
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,1,4,0
FILEVERSION 1,1,5,0
PRODUCTVERSION PRODUCTVER
FILEFLAGSMASK 0x17L
#ifdef _DEBUG
@ -23,7 +23,7 @@ VS_VERSION_INFO VERSIONINFO
{
BLOCK "040904E4"
{
VALUE "FileVersion", "1.1.4.0"
VALUE "FileVersion", "1.1.5.0"
VALUE "LegalCopyright", "© 2012 - Birunthan Mohanathas"
VALUE "ProductName", "Rainmeter"
#ifdef _WIN64

View File

@ -269,7 +269,6 @@
<ClCompile Include="Player.cpp" />
<ClCompile Include="PlayerAIMP.cpp" />
<ClCompile Include="PlayerCAD.cpp" />
<ClCompile Include="PlayerFoobar.cpp" />
<ClCompile Include="PlayerITunes.cpp" />
<ClCompile Include="PlayerSpotify.cpp" />
<ClCompile Include="PlayerWinamp.cpp" />
@ -359,7 +358,6 @@
<ClInclude Include="Player.h" />
<ClInclude Include="PlayerAIMP.h" />
<ClInclude Include="PlayerCAD.h" />
<ClInclude Include="PlayerFoobar.h" />
<ClInclude Include="PlayerITunes.h" />
<ClInclude Include="PlayerSpotify.h" />
<ClInclude Include="PlayerWinamp.h" />

View File

@ -246,9 +246,6 @@
<ClCompile Include="PlayerCAD.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="PlayerFoobar.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="PlayerITunes.cpp">
<Filter>Source Files</Filter>
</ClCompile>
@ -296,9 +293,6 @@
<ClInclude Include="SDKs\CAD\cad_sdk.h">
<Filter>SDKs\CD Art Display</Filter>
</ClInclude>
<ClInclude Include="PlayerFoobar.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="PlayerCAD.h">
<Filter>Header Files</Filter>
</ClInclude>