2011-05-24 18:20:35 +00:00
|
|
|
/*
|
|
|
|
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
|
2012-01-23 06:36:15 +00:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2011-05-24 18:20:35 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "StdAfx.h"
|
|
|
|
#include "PlayerCAD.h"
|
2011-05-28 07:50:33 +00:00
|
|
|
#include "CAD/cad_sdk.h"
|
2011-05-24 18:20:35 +00:00
|
|
|
|
2013-05-31 14:28:39 +00:00
|
|
|
Player* PlayerCAD::c_Player = nullptr;
|
2011-07-15 15:18:02 +00:00
|
|
|
extern HINSTANCE g_Instance;
|
2011-06-12 10:05:37 +00:00
|
|
|
|
|
|
|
// This player emulates the CD Art Display IPC interface, which is supported by
|
|
|
|
// MusicBee, VLC (with libcad plugin), and possibly others.
|
2011-05-24 18:20:35 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
** Constructor.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
PlayerCAD::PlayerCAD() : Player(),
|
2011-05-24 18:20:35 +00:00
|
|
|
m_Window(),
|
2011-07-10 09:30:51 +00:00
|
|
|
m_PlayerWindow(),
|
2012-04-04 12:21:02 +00:00
|
|
|
m_ExtendedAPI(false),
|
|
|
|
m_Open(false)
|
2011-05-24 18:20:35 +00:00
|
|
|
{
|
|
|
|
Initialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Constructor.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
PlayerCAD::~PlayerCAD()
|
2011-05-24 18:20:35 +00:00
|
|
|
{
|
2013-05-31 14:28:39 +00:00
|
|
|
c_Player = nullptr;
|
2011-05-24 18:20:35 +00:00
|
|
|
Uninitialize();
|
|
|
|
}
|
|
|
|
|
2011-06-19 14:58:48 +00:00
|
|
|
/*
|
|
|
|
** Creates a shared class object.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
Player* PlayerCAD::Create()
|
2011-06-19 14:58:48 +00:00
|
|
|
{
|
|
|
|
if (!c_Player)
|
|
|
|
{
|
2013-05-31 14:18:52 +00:00
|
|
|
c_Player = new PlayerCAD();
|
2011-06-19 14:58:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return c_Player;
|
|
|
|
}
|
|
|
|
|
2011-05-24 18:20:35 +00:00
|
|
|
/*
|
|
|
|
** Create receiver window.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void PlayerCAD::Initialize()
|
2011-05-24 18:20:35 +00:00
|
|
|
{
|
|
|
|
// Create windows class
|
|
|
|
WNDCLASS wc = {0};
|
2011-07-15 15:18:02 +00:00
|
|
|
wc.hInstance = g_Instance;
|
2011-05-24 18:20:35 +00:00
|
|
|
wc.lpfnWndProc = WndProc;
|
|
|
|
wc.lpszClassName = L"NowPlayingCADClass";
|
|
|
|
RegisterClass(&wc);
|
|
|
|
|
2011-06-25 12:44:33 +00:00
|
|
|
// Create reciever window
|
2012-03-28 19:12:04 +00:00
|
|
|
m_Window = CreateWindow(
|
|
|
|
L"NowPlayingCADClass",
|
|
|
|
L"CD Art Display 1.x Class",
|
|
|
|
WS_DISABLED,
|
|
|
|
CW_USEDEFAULT,
|
|
|
|
CW_USEDEFAULT,
|
|
|
|
CW_USEDEFAULT,
|
|
|
|
CW_USEDEFAULT,
|
2013-05-31 14:28:39 +00:00
|
|
|
nullptr,
|
|
|
|
nullptr,
|
2012-03-28 19:12:04 +00:00
|
|
|
g_Instance,
|
|
|
|
this);
|
2011-05-24 18:20:35 +00:00
|
|
|
|
2011-06-25 12:44:33 +00:00
|
|
|
// Add WM_USER/WM_COPYDATA to allowed messages from lower level processes
|
|
|
|
HMODULE hUser32 = LoadLibrary(L"user32.dll");
|
|
|
|
if (hUser32)
|
|
|
|
{
|
|
|
|
// Try ChangeWindowMessageFilterEx first (Win7+)
|
|
|
|
FPCHANGEWINDOWMESSAGEFILTEREX ChangeWindowMessageFilterEx = (FPCHANGEWINDOWMESSAGEFILTEREX)GetProcAddress(hUser32, "ChangeWindowMessageFilterEx");
|
|
|
|
if (ChangeWindowMessageFilterEx)
|
|
|
|
{
|
2013-05-31 14:28:39 +00:00
|
|
|
ChangeWindowMessageFilterEx(m_Window, WM_USER, MSGFLT_ALLOW, nullptr);
|
|
|
|
ChangeWindowMessageFilterEx(m_Window, WM_COPYDATA, MSGFLT_ALLOW, nullptr);
|
2011-06-25 12:44:33 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Try ChangeWindowMessageFilter (Vista)
|
|
|
|
FPCHANGEWINDOWMESSAGEFILTER ChangeWindowMessageFilter = (FPCHANGEWINDOWMESSAGEFILTER)GetProcAddress(hUser32, "ChangeWindowMessageFilter");
|
|
|
|
if (ChangeWindowMessageFilter)
|
|
|
|
{
|
|
|
|
ChangeWindowMessageFilter(WM_USER, MSGFLT_ALLOW);
|
|
|
|
ChangeWindowMessageFilter(WM_COPYDATA, MSGFLT_ALLOW);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FreeLibrary(hUser32);
|
|
|
|
}
|
|
|
|
|
2011-06-12 10:05:37 +00:00
|
|
|
WCHAR buffer[MAX_PATH];
|
2012-05-05 16:37:55 +00:00
|
|
|
LPCTSTR file = RmGetSettingsFile();
|
2011-06-12 10:05:37 +00:00
|
|
|
|
|
|
|
// Read saved settings
|
2013-05-31 14:28:39 +00:00
|
|
|
GetPrivateProfileString(L"NowPlaying.dll", L"ClassName", nullptr, buffer, MAX_PATH, file);
|
2011-06-12 10:05:37 +00:00
|
|
|
std::wstring className = buffer;
|
|
|
|
|
2013-05-31 14:28:39 +00:00
|
|
|
GetPrivateProfileString(L"NowPlaying.dll", L"WindowName", nullptr, buffer, MAX_PATH, file);
|
2011-06-12 10:05:37 +00:00
|
|
|
std::wstring windowName = buffer;
|
|
|
|
|
2013-05-31 14:28:39 +00:00
|
|
|
GetPrivateProfileString(L"NowPlaying.dll", L"PlayerPath", nullptr, buffer, MAX_PATH, file);
|
2011-06-12 10:05:37 +00:00
|
|
|
m_PlayerPath = buffer;
|
|
|
|
|
2013-05-31 14:28:39 +00:00
|
|
|
LPCTSTR classSz = className.empty() ? nullptr : className.c_str();
|
|
|
|
LPCTSTR windowSz = windowName.empty() ? nullptr : windowName.c_str();
|
2011-06-12 10:05:37 +00:00
|
|
|
|
|
|
|
if (classSz || windowSz)
|
|
|
|
{
|
|
|
|
m_PlayerWindow = FindWindow(classSz, windowSz);
|
|
|
|
}
|
|
|
|
else
|
2011-05-24 18:20:35 +00:00
|
|
|
{
|
2011-08-21 13:24:24 +00:00
|
|
|
classSz = L"CD Art Display IPC Class";
|
2013-05-31 14:28:39 +00:00
|
|
|
m_PlayerWindow = FindWindow(classSz, nullptr);
|
2011-06-12 10:05:37 +00:00
|
|
|
if (m_PlayerWindow)
|
2011-05-24 18:20:35 +00:00
|
|
|
{
|
2011-07-01 20:34:12 +00:00
|
|
|
WritePrivateProfileString(L"NowPlaying.dll", L"ClassName", classSz, file);
|
|
|
|
|
2013-05-31 14:28:39 +00:00
|
|
|
windowSz = (GetWindowText(m_PlayerWindow, buffer, MAX_PATH) > 0) ? buffer : nullptr;
|
2011-07-01 20:34:12 +00:00
|
|
|
WritePrivateProfileString(L"NowPlaying.dll", L"WindowName", windowSz, file);
|
|
|
|
|
|
|
|
DWORD pID;
|
|
|
|
GetWindowThreadProcessId(m_PlayerWindow, &pID);
|
|
|
|
HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pID);
|
|
|
|
if (hProcess)
|
|
|
|
{
|
2013-05-31 14:28:39 +00:00
|
|
|
if (GetModuleFileNameEx(hProcess, nullptr, buffer, MAX_PATH) > 0)
|
2011-07-01 20:34:12 +00:00
|
|
|
{
|
|
|
|
WritePrivateProfileString(L"NowPlaying.dll", L"PlayerPath", buffer, file);
|
|
|
|
}
|
|
|
|
|
|
|
|
CloseHandle(hProcess);
|
|
|
|
}
|
2011-05-24 18:20:35 +00:00
|
|
|
}
|
2011-06-12 10:05:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (m_PlayerWindow)
|
|
|
|
{
|
2011-06-19 14:58:48 +00:00
|
|
|
m_Initialized = true;
|
2011-08-21 13:24:24 +00:00
|
|
|
|
|
|
|
if (classSz && wcscmp(classSz, L"CD Art Display IPC Class") == 0)
|
|
|
|
{
|
|
|
|
m_ExtendedAPI = true;
|
|
|
|
}
|
|
|
|
|
2011-06-12 10:05:37 +00:00
|
|
|
SendMessage(m_PlayerWindow, WM_USER, (WPARAM)m_Window, IPC_SET_CALLBACK_HWND);
|
2012-01-08 17:35:29 +00:00
|
|
|
m_State = (StateType)SendMessage(m_PlayerWindow, WM_USER, 0, IPC_GET_STATE);
|
2011-06-12 10:05:37 +00:00
|
|
|
|
2012-01-08 17:35:29 +00:00
|
|
|
if (m_State != STATE_STOPPED)
|
2011-05-24 18:20:35 +00:00
|
|
|
{
|
2011-06-12 10:05:37 +00:00
|
|
|
SendMessage(m_PlayerWindow, WM_USER, 0, IPC_GET_CURRENT_TRACK);
|
2011-05-24 18:20:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Destroy reciever window.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void PlayerCAD::Uninitialize()
|
2011-05-24 18:20:35 +00:00
|
|
|
{
|
|
|
|
DestroyWindow(m_Window);
|
2011-07-15 15:18:02 +00:00
|
|
|
UnregisterClass(L"NowPlayingCADClass", g_Instance);
|
2011-05-24 18:20:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Window procedure for the reciever window.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
LRESULT CALLBACK PlayerCAD::WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
2011-05-24 18:20:35 +00:00
|
|
|
{
|
2013-05-31 14:18:52 +00:00
|
|
|
static PlayerCAD* player;
|
2011-05-24 18:20:35 +00:00
|
|
|
|
|
|
|
switch (msg)
|
|
|
|
{
|
|
|
|
case WM_CREATE:
|
2011-07-01 20:34:12 +00:00
|
|
|
{
|
2013-05-31 14:18:52 +00:00
|
|
|
// Get pointer to the PlayerCAD class from the CreateWindow call
|
|
|
|
player = (PlayerCAD*)((CREATESTRUCT*)lParam)->lpCreateParams;
|
2011-07-01 20:34:12 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2011-05-24 18:20:35 +00:00
|
|
|
|
|
|
|
case WM_DESTROY:
|
2011-07-01 20:34:12 +00:00
|
|
|
{
|
|
|
|
SendMessage(player->m_PlayerWindow, WM_USER, 0, IPC_SHUTDOWN_NOTIFICATION);
|
|
|
|
return 0;
|
|
|
|
}
|
2011-05-24 18:20:35 +00:00
|
|
|
|
|
|
|
case WM_USER:
|
|
|
|
switch (lParam)
|
|
|
|
{
|
|
|
|
case IPC_TRACK_CHANGED_NOTIFICATION:
|
2011-07-01 20:34:12 +00:00
|
|
|
{
|
|
|
|
PostMessage(player->m_PlayerWindow, WM_USER, 0, IPC_GET_CURRENT_TRACK);
|
|
|
|
break;
|
|
|
|
}
|
2011-05-24 18:20:35 +00:00
|
|
|
|
2011-07-01 20:34:12 +00:00
|
|
|
case IPC_STATE_CHANGED_NOTIFICATION:
|
2011-05-24 18:20:35 +00:00
|
|
|
{
|
2012-01-08 17:35:29 +00:00
|
|
|
player->m_State = (StateType)wParam;
|
|
|
|
if (player->m_State == STATE_STOPPED)
|
2011-07-01 20:34:12 +00:00
|
|
|
{
|
2012-04-18 16:10:43 +00:00
|
|
|
player->ClearData(false);
|
2011-07-01 20:34:12 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case IPC_VOLUME_CHANGED_NOTIFICATION:
|
|
|
|
{
|
2013-12-23 19:44:42 +00:00
|
|
|
player->m_Volume = (UINT)wParam;
|
2011-07-01 20:34:12 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-09-11 08:22:07 +00:00
|
|
|
case IPC_REPEAT_CHANGED_NOTIFICATION:
|
|
|
|
{
|
2013-12-23 19:44:42 +00:00
|
|
|
player->m_Repeat = wParam != 0;
|
2011-09-11 08:22:07 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case IPC_SHUFFLE_CHANGED_NOTIFICATION:
|
|
|
|
{
|
2013-12-23 19:44:42 +00:00
|
|
|
player->m_Shuffle = wParam != 0;
|
2011-09-11 08:22:07 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-07-01 20:34:12 +00:00
|
|
|
case IPC_RATING_CHANGED_NOTIFICATION:
|
|
|
|
{
|
2013-12-23 19:44:42 +00:00
|
|
|
player->m_Rating = ((UINT)wParam + 1) / 2; // From 0 - 10 to 0 - 5
|
2011-07-01 20:34:12 +00:00
|
|
|
break;
|
2011-05-24 18:20:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case IPC_SHUTDOWN_NOTIFICATION:
|
2011-07-01 20:34:12 +00:00
|
|
|
{
|
|
|
|
player->m_Initialized = false;
|
|
|
|
player->ClearData();
|
|
|
|
break;
|
|
|
|
}
|
2011-05-24 18:20:35 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case WM_COPYDATA:
|
|
|
|
{
|
|
|
|
PCOPYDATASTRUCT cds = (PCOPYDATASTRUCT)lParam;
|
2011-07-01 20:34:12 +00:00
|
|
|
if (cds->dwData == IPC_CURRENT_TRACK_NOTIFICATION)
|
2011-05-24 18:20:35 +00:00
|
|
|
{
|
2013-12-23 19:44:42 +00:00
|
|
|
player->m_Shuffle = SendMessage(player->m_PlayerWindow, WM_USER, 0, IPC_GET_SHUFFLE) != 0;
|
|
|
|
player->m_Repeat = SendMessage(player->m_PlayerWindow, WM_USER, 0, IPC_GET_REPEAT) != 0;
|
2011-09-11 12:14:52 +00:00
|
|
|
|
2011-06-17 19:07:06 +00:00
|
|
|
// TODO: Sent on track update?
|
2011-06-19 14:58:48 +00:00
|
|
|
++player->m_TrackCount;
|
2011-06-17 19:07:06 +00:00
|
|
|
|
2012-03-12 12:01:12 +00:00
|
|
|
WCHAR* data = (WCHAR*)cds->lpData;
|
|
|
|
WCHAR* pos;
|
|
|
|
UINT index = 1;
|
2013-05-31 14:28:39 +00:00
|
|
|
while ((pos = wcschr(data, '\t')) != nullptr)
|
2012-03-12 12:01:12 +00:00
|
|
|
{
|
|
|
|
switch (index)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
player->m_Title.assign(data, pos - data);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
player->m_Artist.assign(data, pos - data);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
player->m_Album.assign(data, pos - data);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 5:
|
|
|
|
player->m_Year = (UINT)_wtoi(data);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 7:
|
|
|
|
player->m_Number = (UINT)_wtoi(data);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 8:
|
|
|
|
player->m_Duration = (UINT)_wtoi(data);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 9:
|
|
|
|
player->m_FilePath.assign(data, pos - data);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 10:
|
|
|
|
player->m_Rating = ((UINT)_wtoi(data) + 1) / 2; // 0 - 10 -> 0 - 5
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 11:
|
2012-03-28 19:12:04 +00:00
|
|
|
if (*data == L' ')
|
2012-03-25 14:18:03 +00:00
|
|
|
{
|
|
|
|
player->FindCover();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
player->m_CoverPath.assign(data, pos - data);
|
|
|
|
}
|
2012-03-12 12:01:12 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
data = pos + 1;
|
|
|
|
++index;
|
|
|
|
|
|
|
|
if (index == 12)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-06-19 14:58:48 +00:00
|
|
|
|
2011-09-08 12:42:03 +00:00
|
|
|
if (player->m_Measures & MEASURE_LYRICS)
|
2011-06-19 14:58:48 +00:00
|
|
|
{
|
|
|
|
player->FindLyrics();
|
|
|
|
}
|
2011-05-24 18:20:35 +00:00
|
|
|
}
|
2012-12-26 18:05:17 +00:00
|
|
|
else if (cds->dwData == IPC_NEW_COVER_NOTIFICATION)
|
|
|
|
{
|
|
|
|
WCHAR* data = (WCHAR*)cds->lpData;
|
|
|
|
if (data)
|
|
|
|
{
|
|
|
|
player->m_CoverPath.assign(data);
|
|
|
|
}
|
|
|
|
}
|
2011-07-01 20:34:12 +00:00
|
|
|
else if (cds->dwData == IPC_REGISTER_NOTIFICATION && !player->m_Initialized)
|
2011-05-24 18:20:35 +00:00
|
|
|
{
|
|
|
|
std::wstring data = (WCHAR*)cds->lpData;
|
|
|
|
if (data[0] == L'1')
|
|
|
|
{
|
|
|
|
data.erase(0, 2); // Get rid of the 1\t at the beginning
|
|
|
|
|
|
|
|
std::wstring::size_type len = data.find_first_of(L'\t');
|
2011-07-14 10:12:02 +00:00
|
|
|
std::wstring className(data, 0, len);
|
2011-05-24 18:20:35 +00:00
|
|
|
data.erase(0, ++len);
|
|
|
|
|
|
|
|
len = data.find_first_of(L'\t');
|
2011-07-14 10:12:02 +00:00
|
|
|
std::wstring windowName(data, 0, len);
|
2011-05-24 18:20:35 +00:00
|
|
|
data.erase(0, ++len);
|
|
|
|
|
|
|
|
len = data.find_first_of(L'\t');
|
2011-06-19 14:58:48 +00:00
|
|
|
player->m_PlayerPath.assign(data, 0, len);
|
2011-05-24 18:20:35 +00:00
|
|
|
data.erase(0, ++len);
|
|
|
|
|
2013-05-31 14:28:39 +00:00
|
|
|
LPCTSTR classSz = className.empty() ? nullptr : className.c_str();
|
|
|
|
LPCTSTR windowSz = windowName.empty() ? nullptr : windowName.c_str();
|
2012-05-05 16:37:55 +00:00
|
|
|
LPCTSTR file = RmGetSettingsFile();
|
2011-06-12 10:05:37 +00:00
|
|
|
|
|
|
|
WritePrivateProfileString(L"NowPlaying.dll", L"ClassName", classSz, file);
|
|
|
|
WritePrivateProfileString(L"NowPlaying.dll", L"WindowName", windowSz, file);
|
2011-06-19 14:58:48 +00:00
|
|
|
WritePrivateProfileString(L"NowPlaying.dll", L"PlayerPath", player->m_PlayerPath.c_str(), file);
|
2011-06-12 10:05:37 +00:00
|
|
|
|
2011-06-19 14:58:48 +00:00
|
|
|
player->m_PlayerWindow = FindWindow(classSz, windowSz);
|
2011-06-12 10:05:37 +00:00
|
|
|
|
2011-06-19 14:58:48 +00:00
|
|
|
if (player->m_PlayerWindow)
|
2011-06-12 10:05:37 +00:00
|
|
|
{
|
2011-06-19 14:58:48 +00:00
|
|
|
player->m_Initialized = true;
|
2011-08-21 13:24:24 +00:00
|
|
|
player->m_ExtendedAPI = (classSz && wcscmp(classSz, L"CD Art Display IPC Class") == 0);
|
2012-01-08 17:35:29 +00:00
|
|
|
player->m_State = (StateType)SendMessage(player->m_PlayerWindow, WM_USER, 0, IPC_GET_STATE);
|
2011-06-12 10:05:37 +00:00
|
|
|
|
2012-01-08 17:35:29 +00:00
|
|
|
if (player->m_State != STATE_STOPPED)
|
2011-06-12 10:05:37 +00:00
|
|
|
{
|
2011-06-25 12:44:33 +00:00
|
|
|
PostMessage(player->m_PlayerWindow, WM_USER, 0, IPC_GET_CURRENT_TRACK);
|
2011-06-12 10:05:37 +00:00
|
|
|
}
|
2012-04-04 12:21:02 +00:00
|
|
|
|
|
|
|
if (player->m_Open)
|
|
|
|
{
|
2012-12-26 18:00:30 +00:00
|
|
|
if (windowSz && wcscmp(windowSz, L"foobar2000") == 0)
|
2012-04-04 12:21:02 +00:00
|
|
|
{
|
|
|
|
// Activate foobar2000 in case it starts minimized
|
|
|
|
SendMessage(player->m_PlayerWindow, WM_USER, 0, IPC_SHOW_WINDOW);
|
|
|
|
}
|
|
|
|
|
|
|
|
player->m_Open = false;
|
|
|
|
}
|
2011-06-12 10:05:37 +00:00
|
|
|
}
|
2011-05-24 18:20:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return DefWindowProc(hwnd, msg, wParam, lParam);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Called during each update of the main measure.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void PlayerCAD::UpdateData()
|
2011-05-24 18:20:35 +00:00
|
|
|
{
|
2012-01-08 17:35:29 +00:00
|
|
|
if (m_State != STATE_STOPPED)
|
2011-05-24 18:20:35 +00:00
|
|
|
{
|
2013-12-23 19:44:42 +00:00
|
|
|
m_Position = (UINT)SendMessage(m_PlayerWindow, WM_USER, 0, IPC_GET_POSITION);
|
|
|
|
m_Volume = (UINT)SendMessage(m_PlayerWindow, WM_USER, 0, IPC_GET_VOLUME);
|
2011-05-24 18:20:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-09 09:47:55 +00:00
|
|
|
/*
|
|
|
|
** Handles the Pause bang.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void PlayerCAD::Pause()
|
2011-06-09 09:47:55 +00:00
|
|
|
{
|
2011-07-10 09:30:51 +00:00
|
|
|
SendMessage(m_PlayerWindow, WM_USER, 0, m_ExtendedAPI ? IPC_PAUSE : IPC_PLAYPAUSE);
|
2011-06-09 09:47:55 +00:00
|
|
|
}
|
|
|
|
|
2011-05-24 18:20:35 +00:00
|
|
|
/*
|
|
|
|
** Handles the Play bang.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void PlayerCAD::Play()
|
2011-05-24 18:20:35 +00:00
|
|
|
{
|
2011-07-10 09:30:51 +00:00
|
|
|
SendMessage(m_PlayerWindow, WM_USER, 0, m_ExtendedAPI ? IPC_PLAY : IPC_PLAYPAUSE);
|
2011-05-24 18:20:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Handles the Stop bang.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void PlayerCAD::Stop()
|
2011-05-24 18:20:35 +00:00
|
|
|
{
|
2011-06-17 19:07:06 +00:00
|
|
|
SendMessage(m_PlayerWindow, WM_USER, 0, IPC_STOP);
|
2011-05-24 18:20:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Handles the Next bang.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void PlayerCAD::Next()
|
2011-05-24 18:20:35 +00:00
|
|
|
{
|
2011-06-17 19:07:06 +00:00
|
|
|
SendMessage(m_PlayerWindow, WM_USER, 0, IPC_NEXT);
|
2011-05-24 18:20:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Handles the Previous bang.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void PlayerCAD::Previous()
|
2011-05-24 18:20:35 +00:00
|
|
|
{
|
2011-06-17 19:07:06 +00:00
|
|
|
SendMessage(m_PlayerWindow, WM_USER, 0, IPC_PREVIOUS);
|
2011-05-24 18:20:35 +00:00
|
|
|
}
|
|
|
|
|
2011-06-09 09:47:55 +00:00
|
|
|
/*
|
|
|
|
** Handles the SetPosition bang.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void PlayerCAD::SetPosition(int position)
|
2011-06-09 09:47:55 +00:00
|
|
|
{
|
|
|
|
SendMessage(m_PlayerWindow, WM_USER, position, IPC_SET_POSITION);
|
|
|
|
}
|
|
|
|
|
2011-05-24 18:20:35 +00:00
|
|
|
/*
|
2012-03-12 12:01:12 +00:00
|
|
|
** Handles the SetRating bang.
|
2011-05-24 18:20:35 +00:00
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void PlayerCAD::SetRating(int rating)
|
2011-05-24 18:20:35 +00:00
|
|
|
{
|
2011-06-17 19:07:06 +00:00
|
|
|
m_Rating = rating;
|
|
|
|
rating *= 2; // From 0 - 5 to 0 - 10
|
2011-07-01 20:34:12 +00:00
|
|
|
SendMessage(m_PlayerWindow, WM_USER, rating, IPC_SET_RATING);
|
2011-05-24 18:20:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Handles the SetVolume bang.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void PlayerCAD::SetVolume(int volume)
|
2011-05-24 18:20:35 +00:00
|
|
|
{
|
2011-06-17 19:07:06 +00:00
|
|
|
SendMessage(m_PlayerWindow, WM_USER, volume, IPC_SET_VOLUME);
|
2011-05-24 18:20:35 +00:00
|
|
|
}
|
|
|
|
|
2011-09-11 08:22:07 +00:00
|
|
|
/*
|
|
|
|
** Handles the SetShuffle bang.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void PlayerCAD::SetShuffle(bool state)
|
2011-09-11 08:22:07 +00:00
|
|
|
{
|
2011-09-11 12:14:52 +00:00
|
|
|
SendMessage(m_PlayerWindow, WM_USER, (WPARAM)state, IPC_SET_SHUFFLE);
|
2013-12-23 19:44:42 +00:00
|
|
|
m_Shuffle = SendMessage(m_PlayerWindow, WM_USER, 0, IPC_GET_SHUFFLE) != 0;
|
2011-09-11 08:22:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Handles the SetRepeat bang.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void PlayerCAD::SetRepeat(bool state)
|
2011-09-11 08:22:07 +00:00
|
|
|
{
|
2011-09-11 12:14:52 +00:00
|
|
|
SendMessage(m_PlayerWindow, WM_USER, (WPARAM)state, IPC_SET_REPEAT);
|
2013-12-23 19:44:42 +00:00
|
|
|
m_Repeat = SendMessage(m_PlayerWindow, WM_USER, 0, IPC_GET_REPEAT) != 0;
|
2011-09-11 08:22:07 +00:00
|
|
|
}
|
|
|
|
|
2011-05-24 18:20:35 +00:00
|
|
|
/*
|
|
|
|
** Handles the ClosePlayer bang.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void PlayerCAD::ClosePlayer()
|
2011-05-24 18:20:35 +00:00
|
|
|
{
|
2011-07-01 20:34:12 +00:00
|
|
|
SendMessage(m_PlayerWindow, WM_USER, 0, IPC_CLOSE);
|
2011-06-19 14:58:48 +00:00
|
|
|
// TODO
|
|
|
|
m_Initialized = false;
|
2011-06-17 19:07:06 +00:00
|
|
|
ClearData();
|
2011-05-24 18:20:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Handles the OpenPlayer bang.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void PlayerCAD::OpenPlayer(std::wstring& path)
|
2011-05-24 18:20:35 +00:00
|
|
|
{
|
2011-07-01 20:34:12 +00:00
|
|
|
if (!m_Initialized)
|
2011-06-17 19:07:06 +00:00
|
|
|
{
|
2013-05-31 14:28:39 +00:00
|
|
|
HINSTANCE ret = nullptr;
|
2012-04-04 12:21:02 +00:00
|
|
|
|
2011-07-01 20:34:12 +00:00
|
|
|
if (!path.empty())
|
|
|
|
{
|
2013-05-31 14:28:39 +00:00
|
|
|
ret = ShellExecute(nullptr, L"open", path.c_str(), nullptr, nullptr, SW_SHOW);
|
2011-07-01 20:34:12 +00:00
|
|
|
}
|
|
|
|
else if (!m_PlayerPath.empty())
|
|
|
|
{
|
2013-05-31 14:28:39 +00:00
|
|
|
ret = ShellExecute(nullptr, L"open", m_PlayerPath.c_str(), nullptr, nullptr, SW_SHOW);
|
2011-07-01 20:34:12 +00:00
|
|
|
}
|
2012-04-04 12:21:02 +00:00
|
|
|
|
|
|
|
m_Open = (ret > (HINSTANCE)32);
|
2011-06-17 19:07:06 +00:00
|
|
|
}
|
2011-07-01 20:34:12 +00:00
|
|
|
else
|
2011-06-12 10:05:37 +00:00
|
|
|
{
|
2011-07-01 20:34:12 +00:00
|
|
|
// Bring player to front
|
|
|
|
SendMessage(m_PlayerWindow, WM_USER, 0, IPC_SHOW_WINDOW);
|
2011-06-12 10:05:37 +00:00
|
|
|
}
|
2011-05-24 18:20:35 +00:00
|
|
|
}
|