2011-05-21 18:17:37 +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-21 18:17:37 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "StdAfx.h"
|
2012-01-01 18:07:24 +00:00
|
|
|
#include <cmath>
|
2011-05-21 18:17:37 +00:00
|
|
|
#include "PlayerWinamp.h"
|
2011-05-24 18:20:35 +00:00
|
|
|
#include "Winamp/wa_ipc.h"
|
|
|
|
#include "Winamp/wa_cmd.h"
|
2011-05-21 18:17:37 +00:00
|
|
|
|
2013-05-31 14:28:39 +00:00
|
|
|
Player* PlayerWinamp::c_Player = nullptr;
|
2011-05-22 14:45:54 +00:00
|
|
|
|
2011-06-12 10:05:37 +00:00
|
|
|
// This player retrieves data through the Winamp IPC interface.
|
|
|
|
|
2011-05-21 18:17:37 +00:00
|
|
|
/*
|
|
|
|
** Constructor.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
PlayerWinamp::PlayerWinamp(WINAMPTYPE type) : Player(),
|
2011-06-19 14:58:48 +00:00
|
|
|
m_Window(),
|
2011-11-05 17:52:53 +00:00
|
|
|
m_LastCheckTime(0),
|
2011-05-25 14:04:52 +00:00
|
|
|
m_UseUnicodeAPI(false),
|
2011-07-24 15:31:33 +00:00
|
|
|
m_PlayingStream(false),
|
2011-06-19 14:58:48 +00:00
|
|
|
m_WinampType(type),
|
|
|
|
m_WinampHandle(),
|
|
|
|
m_WinampAddress()
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Destructor.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
PlayerWinamp::~PlayerWinamp()
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2013-05-31 14:28:39 +00:00
|
|
|
c_Player = nullptr;
|
2011-05-21 18:17:37 +00:00
|
|
|
if (m_WinampHandle) CloseHandle(m_WinampHandle);
|
|
|
|
}
|
|
|
|
|
2011-06-19 14:58:48 +00:00
|
|
|
/*
|
|
|
|
** Creates a shared class object.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
Player* PlayerWinamp::Create(WINAMPTYPE type)
|
2011-06-19 14:58:48 +00:00
|
|
|
{
|
|
|
|
if (!c_Player)
|
|
|
|
{
|
2013-05-31 14:18:52 +00:00
|
|
|
c_Player = new PlayerWinamp(type);
|
2011-06-19 14:58:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return c_Player;
|
|
|
|
}
|
|
|
|
|
2011-05-21 18:17:37 +00:00
|
|
|
/*
|
2011-06-17 19:07:06 +00:00
|
|
|
** Try to find Winamp periodically.
|
2011-05-21 18:17:37 +00:00
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
bool PlayerWinamp::CheckWindow()
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2011-06-17 19:07:06 +00:00
|
|
|
DWORD time = GetTickCount();
|
2011-10-12 13:34:04 +00:00
|
|
|
|
2011-06-17 19:07:06 +00:00
|
|
|
// Try to find Winamp window every 5 seconds
|
2011-10-12 13:34:04 +00:00
|
|
|
if (time - m_LastCheckTime > 5000)
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2011-10-12 13:34:04 +00:00
|
|
|
m_LastCheckTime = time;
|
2011-05-21 18:17:37 +00:00
|
|
|
|
2013-05-31 14:28:39 +00:00
|
|
|
m_Window = FindWindow(L"Winamp v1.x", nullptr);
|
2011-06-17 19:07:06 +00:00
|
|
|
if (m_Window)
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2011-06-17 19:07:06 +00:00
|
|
|
DWORD pID;
|
|
|
|
GetWindowThreadProcessId(m_Window, &pID);
|
2011-07-01 20:34:12 +00:00
|
|
|
m_WinampHandle = OpenProcess(PROCESS_VM_READ, FALSE, pID);
|
2011-05-21 18:17:37 +00:00
|
|
|
|
2011-06-17 19:07:06 +00:00
|
|
|
if (m_WinampHandle)
|
|
|
|
{
|
|
|
|
m_WinampAddress = (LPCVOID)SendMessage(m_Window, WM_WA_IPC, 0, IPC_GET_PLAYING_FILENAME);
|
|
|
|
m_UseUnicodeAPI = m_WinampAddress ? true : false;
|
|
|
|
m_Initialized = true;
|
|
|
|
}
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-17 19:07:06 +00:00
|
|
|
return m_Initialized;
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Called during each update of the main measure.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void PlayerWinamp::UpdateData()
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2011-06-17 19:07:06 +00:00
|
|
|
if (m_Initialized || CheckWindow())
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2011-06-17 19:07:06 +00:00
|
|
|
int playing = SendMessage(m_Window, WM_WA_IPC, 0, IPC_ISPLAYING);
|
|
|
|
if (playing == 0)
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2011-06-17 19:07:06 +00:00
|
|
|
// Make sure Winamp is still active
|
|
|
|
if (!IsWindow(m_Window))
|
|
|
|
{
|
|
|
|
m_Initialized = false;
|
2012-04-18 16:10:43 +00:00
|
|
|
ClearData();
|
|
|
|
|
2011-06-17 19:07:06 +00:00
|
|
|
if (m_WinampHandle) CloseHandle(m_WinampHandle);
|
|
|
|
}
|
2012-04-18 16:10:43 +00:00
|
|
|
else if (m_State != STATE_STOPPED)
|
2011-06-17 19:07:06 +00:00
|
|
|
{
|
2012-04-18 16:10:43 +00:00
|
|
|
ClearData(false);
|
2011-06-17 19:07:06 +00:00
|
|
|
}
|
2011-05-25 14:04:52 +00:00
|
|
|
|
2011-06-17 19:07:06 +00:00
|
|
|
// Don't continue if Winamp has quit or is stopped
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-01-08 17:35:29 +00:00
|
|
|
m_State = (playing == 1) ? STATE_PLAYING : STATE_PAUSED;
|
2011-06-17 19:07:06 +00:00
|
|
|
m_Position = SendMessage(m_Window, WM_WA_IPC, 0, IPC_GETOUTPUTTIME) / 1000; // ms to secs
|
|
|
|
m_Volume = (SendMessage(m_Window, WM_WA_IPC, -666, IPC_SETVOLUME) * 100) / 255; // 0 - 255 to 0 - 100
|
|
|
|
}
|
2011-05-25 14:04:52 +00:00
|
|
|
|
2011-06-17 19:07:06 +00:00
|
|
|
WCHAR wBuffer[MAX_PATH];
|
|
|
|
char cBuffer[MAX_PATH];
|
2011-05-21 18:17:37 +00:00
|
|
|
|
2011-06-17 19:07:06 +00:00
|
|
|
if (m_UseUnicodeAPI)
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2013-05-31 14:28:39 +00:00
|
|
|
if (!ReadProcessMemory(m_WinampHandle, m_WinampAddress, &wBuffer, sizeof(wBuffer), nullptr))
|
2011-07-24 15:31:33 +00:00
|
|
|
{
|
|
|
|
// Failed to read memory
|
|
|
|
return;
|
|
|
|
}
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-06-17 19:07:06 +00:00
|
|
|
// MediaMonkey doesn't support wide IPC messages
|
|
|
|
int pos = SendMessage(m_Window, WM_WA_IPC, 0, IPC_GETLISTPOS);
|
|
|
|
LPCVOID address = (LPCVOID)SendMessage(m_Window, WM_WA_IPC, pos, IPC_GETPLAYLISTFILE);
|
|
|
|
|
2013-05-31 14:28:39 +00:00
|
|
|
if (!ReadProcessMemory(m_WinampHandle, address, &cBuffer, sizeof(cBuffer), nullptr))
|
2011-07-24 15:31:33 +00:00
|
|
|
{
|
|
|
|
// Failed to read memory
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mbstowcs(wBuffer, cBuffer, MAX_PATH);
|
2011-06-17 19:07:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (wcscmp(wBuffer, m_FilePath.c_str()) != 0)
|
|
|
|
{
|
|
|
|
++m_TrackCount;
|
|
|
|
m_FilePath = wBuffer;
|
2011-07-24 15:31:33 +00:00
|
|
|
m_PlayingStream = (m_FilePath.find(L"://") != std::wstring::npos);
|
2011-06-17 19:07:06 +00:00
|
|
|
|
2011-07-24 15:31:33 +00:00
|
|
|
if (!m_PlayingStream)
|
2011-05-25 14:04:52 +00:00
|
|
|
{
|
2012-04-21 19:36:19 +00:00
|
|
|
int duration = SendMessage(m_Window, WM_WA_IPC, 1, IPC_GETOUTPUTTIME);
|
|
|
|
m_Duration = (duration != -1) ? duration : 0;
|
|
|
|
|
2011-07-24 15:31:33 +00:00
|
|
|
m_Rating = SendMessage(m_Window, WM_WA_IPC, 0, IPC_GETRATING);
|
2011-09-11 08:22:07 +00:00
|
|
|
m_Shuffle = (bool)SendMessage(m_Window, WM_WA_IPC, 0, IPC_GET_SHUFFLE);
|
|
|
|
m_Repeat = (bool)SendMessage(m_Window, WM_WA_IPC, 0, IPC_GET_REPEAT);
|
2011-07-24 15:31:33 +00:00
|
|
|
|
2011-11-10 12:09:50 +00:00
|
|
|
TagLib::FileRef fr(wBuffer, false);
|
2011-06-17 19:07:06 +00:00
|
|
|
TagLib::Tag* tag = fr.tag();
|
2011-07-24 15:31:33 +00:00
|
|
|
if (tag)
|
2011-06-17 19:07:06 +00:00
|
|
|
{
|
2011-07-24 15:31:33 +00:00
|
|
|
m_Artist = tag->artist().toWString();
|
|
|
|
m_Album = tag->album().toWString();
|
|
|
|
m_Title = tag->title().toWString();
|
2012-03-12 12:01:12 +00:00
|
|
|
m_Number = tag->track();
|
|
|
|
m_Year = tag->year();
|
2011-07-24 15:31:33 +00:00
|
|
|
|
2011-09-08 12:42:03 +00:00
|
|
|
if (m_Measures & MEASURE_LYRICS)
|
2011-07-24 15:31:33 +00:00
|
|
|
{
|
|
|
|
FindLyrics();
|
|
|
|
}
|
2011-06-17 19:07:06 +00:00
|
|
|
}
|
2011-09-08 12:42:03 +00:00
|
|
|
else if (m_Measures & MEASURE_LYRICS)
|
2011-06-17 19:07:06 +00:00
|
|
|
{
|
2011-07-24 15:31:33 +00:00
|
|
|
m_Lyrics.clear();
|
2011-06-17 19:07:06 +00:00
|
|
|
}
|
2011-05-21 18:17:37 +00:00
|
|
|
|
2011-07-24 15:31:33 +00:00
|
|
|
// Find cover if needed
|
2011-09-08 12:42:03 +00:00
|
|
|
if (m_Measures & MEASURE_COVER)
|
2011-06-17 19:07:06 +00:00
|
|
|
{
|
2011-11-05 17:52:53 +00:00
|
|
|
if (tag && CCover::GetEmbedded(fr, m_TempCoverPath))
|
2011-07-24 15:31:33 +00:00
|
|
|
{
|
2011-11-05 17:52:53 +00:00
|
|
|
// Got everything, return
|
|
|
|
m_CoverPath = m_TempCoverPath;
|
|
|
|
return;
|
|
|
|
}
|
2011-05-21 18:17:37 +00:00
|
|
|
|
2011-11-05 17:52:53 +00:00
|
|
|
std::wstring trackFolder = CCover::GetFileFolder(m_FilePath);
|
2011-11-10 12:09:50 +00:00
|
|
|
if (tag && !m_Album.empty())
|
2011-11-05 17:52:53 +00:00
|
|
|
{
|
|
|
|
// Winamp stores covers usually as %album%.jpg
|
|
|
|
std::wstring file = m_Album;
|
|
|
|
std::wstring::size_type end = file.length();
|
|
|
|
for (std::wstring::size_type pos = 0; pos < end; ++pos)
|
2011-07-24 15:31:33 +00:00
|
|
|
{
|
2011-11-05 17:52:53 +00:00
|
|
|
// Replace reserved chars according to Winamp specs
|
|
|
|
switch (file[pos])
|
2011-07-24 15:31:33 +00:00
|
|
|
{
|
2011-11-05 17:52:53 +00:00
|
|
|
case L'?':
|
|
|
|
case L'*':
|
|
|
|
case L'|':
|
|
|
|
file[pos] = L'_';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case L'/':
|
|
|
|
case L'\\':
|
|
|
|
case L':':
|
|
|
|
file[pos] = L'-';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case L'\"':
|
|
|
|
file[pos] = L'\'';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case L'<':
|
|
|
|
file[pos] = L'(';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case L'>':
|
|
|
|
file[pos] = L')';
|
|
|
|
break;
|
2011-07-24 15:31:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-05 17:52:53 +00:00
|
|
|
if (CCover::GetLocal(file, trackFolder, m_CoverPath))
|
2011-07-24 15:31:33 +00:00
|
|
|
{
|
2011-11-05 17:52:53 +00:00
|
|
|
// %album% art file found
|
|
|
|
return;
|
2011-07-24 15:31:33 +00:00
|
|
|
}
|
|
|
|
}
|
2011-05-25 14:04:52 +00:00
|
|
|
|
2011-11-05 17:52:53 +00:00
|
|
|
if (!CCover::GetLocal(L"cover", trackFolder, m_CoverPath) &&
|
|
|
|
!CCover::GetLocal(L"folder", trackFolder, m_CoverPath))
|
|
|
|
{
|
|
|
|
// Nothing found
|
|
|
|
m_CoverPath.clear();
|
|
|
|
}
|
|
|
|
}
|
2011-11-10 12:09:50 +00:00
|
|
|
|
|
|
|
if (tag)
|
2011-06-17 19:07:06 +00:00
|
|
|
{
|
2011-07-24 15:31:33 +00:00
|
|
|
return;
|
2011-06-17 19:07:06 +00:00
|
|
|
}
|
2011-07-24 15:31:33 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_Rating = 0;
|
|
|
|
m_Duration = 0;
|
2011-11-05 17:52:53 +00:00
|
|
|
m_CoverPath.clear();
|
2011-05-22 11:05:23 +00:00
|
|
|
}
|
2011-07-24 15:31:33 +00:00
|
|
|
}
|
|
|
|
else if (!m_PlayingStream)
|
|
|
|
{
|
2012-04-21 19:36:19 +00:00
|
|
|
if (m_Duration == 0)
|
|
|
|
{
|
|
|
|
int duration = SendMessage(m_Window, WM_WA_IPC, 1, IPC_GETOUTPUTTIME);
|
|
|
|
m_Duration = (duration != -1) ? duration : 0;
|
|
|
|
}
|
|
|
|
|
2011-07-24 15:31:33 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-05-21 18:17:37 +00:00
|
|
|
|
2011-07-24 15:31:33 +00:00
|
|
|
// TagLib couldn't parse the file or Winamp is playing a stream, try to get title
|
|
|
|
if (m_UseUnicodeAPI)
|
|
|
|
{
|
|
|
|
LPCVOID address = (LPCVOID)SendMessage(m_Window, WM_WA_IPC, 0, IPC_GET_PLAYING_TITLE);
|
2013-05-31 14:28:39 +00:00
|
|
|
ReadProcessMemory(m_WinampHandle, address, &wBuffer, sizeof(wBuffer), nullptr);
|
2011-07-24 15:31:33 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int pos = SendMessage(m_Window, WM_WA_IPC, 0, IPC_GETLISTPOS);
|
|
|
|
LPCVOID address = (LPCVOID)SendMessage(m_Window, WM_WA_IPC, pos, IPC_GETPLAYLISTTITLE);
|
2013-05-31 14:28:39 +00:00
|
|
|
ReadProcessMemory(m_WinampHandle, address, &cBuffer, sizeof(cBuffer), nullptr);
|
2011-07-24 15:31:33 +00:00
|
|
|
mbstowcs(wBuffer, cBuffer, MAX_PATH);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::wstring title = wBuffer;
|
|
|
|
std::wstring::size_type pos = title.find(L" - ");
|
|
|
|
if (pos != std::wstring::npos)
|
|
|
|
{
|
|
|
|
m_Artist.assign(title, 0, pos);
|
|
|
|
pos += 3; // Skip " - "
|
|
|
|
m_Title.assign(title, pos, title.length() - pos);
|
|
|
|
m_Album.clear();
|
2011-05-21 18:17:37 +00:00
|
|
|
|
2011-07-24 15:31:33 +00:00
|
|
|
if (m_PlayingStream)
|
2011-06-19 14:58:48 +00:00
|
|
|
{
|
2011-07-24 15:31:33 +00:00
|
|
|
// Remove crap from title if playing radio
|
|
|
|
pos = m_Title.find(L" (");
|
|
|
|
if (pos != std::wstring::npos)
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2011-07-24 15:31:33 +00:00
|
|
|
m_Title.resize(pos);
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-07-24 15:31:33 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
m_Title = title;
|
|
|
|
m_Artist.clear();
|
|
|
|
m_Album.clear();
|
|
|
|
}
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-09 09:47:55 +00:00
|
|
|
/*
|
|
|
|
** Handles the Pause bang.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void PlayerWinamp::Pause()
|
2011-06-09 09:47:55 +00:00
|
|
|
{
|
2011-06-17 19:07:06 +00:00
|
|
|
SendMessage(m_Window, WM_COMMAND, WINAMP_PAUSE, 0);
|
2011-06-09 09:47:55 +00:00
|
|
|
}
|
|
|
|
|
2011-05-21 18:17:37 +00:00
|
|
|
/*
|
|
|
|
** Handles the Play bang.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void PlayerWinamp::Play()
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2011-06-17 19:07:06 +00:00
|
|
|
SendMessage(m_Window, WM_COMMAND, WINAMP_PLAY, 0);
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Handles the Stop bang.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void PlayerWinamp::Stop()
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2011-06-17 19:07:06 +00:00
|
|
|
SendMessage(m_Window, WM_COMMAND, WINAMP_STOP, 0);
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Handles the Next bang.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void PlayerWinamp::Next()
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2011-06-17 19:07:06 +00:00
|
|
|
SendMessage(m_Window, WM_COMMAND, WINAMP_FASTFWD, 0);
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Handles the Previous bang.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void PlayerWinamp::Previous()
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2011-06-17 19:07:06 +00:00
|
|
|
SendMessage(m_Window, WM_COMMAND, WINAMP_REWIND, 0);
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
|
|
|
|
2011-06-09 09:47:55 +00:00
|
|
|
/*
|
|
|
|
** Handles the SetPosition bang.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void PlayerWinamp::SetPosition(int position)
|
2011-06-09 09:47:55 +00:00
|
|
|
{
|
2011-06-17 19:07:06 +00:00
|
|
|
position *= 1000; // To milliseconds
|
|
|
|
SendMessage(m_Window, WM_WA_IPC, position, IPC_JUMPTOTIME);
|
2011-06-09 09:47:55 +00:00
|
|
|
}
|
|
|
|
|
2011-05-21 18:17:37 +00:00
|
|
|
/*
|
|
|
|
** Handles the SetRating bang.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void PlayerWinamp::SetRating(int rating)
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2011-06-17 19:07:06 +00:00
|
|
|
if (rating < 0)
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2011-06-17 19:07:06 +00:00
|
|
|
rating = 0;
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
2011-06-17 19:07:06 +00:00
|
|
|
else if (rating > 5)
|
|
|
|
{
|
|
|
|
rating = 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
SendMessage(m_Window, WM_WA_IPC, rating, IPC_SETRATING);
|
|
|
|
m_Rating = rating;
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Handles the SetVolume bang.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void PlayerWinamp::SetVolume(int volume)
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2011-06-17 19:07:06 +00:00
|
|
|
// Winamp accepts volume in 0 - 255 range
|
2012-01-01 18:07:24 +00:00
|
|
|
float fVolume = volume * 2.55f;
|
|
|
|
SendMessage(m_Window, WM_WA_IPC, (WPARAM)ceil(fVolume), IPC_SETVOLUME);
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
|
|
|
|
2011-09-11 08:22:07 +00:00
|
|
|
/*
|
|
|
|
** Handles the SetShuffle bang.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void PlayerWinamp::SetShuffle(bool state)
|
2011-09-11 08:22:07 +00:00
|
|
|
{
|
|
|
|
if (!m_PlayingStream)
|
|
|
|
{
|
|
|
|
m_Shuffle = state;
|
|
|
|
SendMessage(m_Window, WM_WA_IPC, (WPARAM)m_Shuffle, IPC_SET_SHUFFLE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Handles the SetRepeat bang.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void PlayerWinamp::SetRepeat(bool state)
|
2011-09-11 08:22:07 +00:00
|
|
|
{
|
|
|
|
if (!m_PlayingStream)
|
|
|
|
{
|
|
|
|
m_Repeat = state;
|
|
|
|
SendMessage(m_Window, WM_WA_IPC, (WPARAM)m_Repeat, IPC_SET_REPEAT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-21 18:17:37 +00:00
|
|
|
/*
|
|
|
|
** Handles the ClosePlayer bang.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void PlayerWinamp::ClosePlayer()
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2011-06-17 19:07:06 +00:00
|
|
|
if (m_WinampType == WA_WINAMP)
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2011-06-17 19:07:06 +00:00
|
|
|
SendMessage(m_Window, WM_CLOSE, 0, 0);
|
|
|
|
}
|
|
|
|
else // if (m_WinampType == WA_MEDIAMONKEY)
|
|
|
|
{
|
|
|
|
HWND wnd = FindWindow(L"TFMainWindow", L"MediaMonkey");
|
|
|
|
if (wnd)
|
2011-05-28 07:50:33 +00:00
|
|
|
{
|
2011-06-17 19:07:06 +00:00
|
|
|
SendMessage(wnd, WM_CLOSE, 0, 0);
|
2011-05-28 07:50:33 +00:00
|
|
|
}
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Handles the OpenPlayer bang.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void PlayerWinamp::OpenPlayer(std::wstring& path)
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2011-05-28 07:50:33 +00:00
|
|
|
if (m_WinampType == WA_WINAMP)
|
|
|
|
{
|
2013-05-31 14:28:39 +00:00
|
|
|
ShellExecute(nullptr, L"open", path.empty() ? L"winamp.exe" : path.c_str(), nullptr, nullptr, SW_SHOW);
|
2011-05-28 07:50:33 +00:00
|
|
|
}
|
|
|
|
else // if (m_WinampType == WA_MEDIAMONKEY)
|
|
|
|
{
|
2011-06-17 19:07:06 +00:00
|
|
|
if (path.empty())
|
2011-05-28 07:50:33 +00:00
|
|
|
{
|
|
|
|
// Gotta figure out where Winamp is located at
|
|
|
|
HKEY hKey;
|
|
|
|
RegOpenKeyEx(HKEY_LOCAL_MACHINE,
|
|
|
|
L"SOFTWARE\\Clients\\Media\\MediaMonkey\\shell\\open\\command",
|
|
|
|
0,
|
|
|
|
KEY_QUERY_VALUE,
|
|
|
|
&hKey);
|
|
|
|
|
|
|
|
DWORD size = 512;
|
|
|
|
WCHAR* data = new WCHAR[size];
|
|
|
|
DWORD type = 0;
|
|
|
|
|
|
|
|
if (RegQueryValueEx(hKey,
|
2013-05-31 14:28:39 +00:00
|
|
|
nullptr,
|
|
|
|
nullptr,
|
2011-05-28 07:50:33 +00:00
|
|
|
(LPDWORD)&type,
|
|
|
|
(LPBYTE)data,
|
|
|
|
(LPDWORD)&size) == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
if (type == REG_SZ)
|
|
|
|
{
|
2013-05-31 14:28:39 +00:00
|
|
|
ShellExecute(nullptr, L"open", data, nullptr, nullptr, SW_SHOW);
|
2011-06-17 19:07:06 +00:00
|
|
|
path = data;
|
2011-05-28 07:50:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
delete [] data;
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-05-31 14:28:39 +00:00
|
|
|
ShellExecute(nullptr, L"open", path.c_str(), nullptr, nullptr, SW_SHOW);
|
2011-05-28 07:50:33 +00:00
|
|
|
}
|
|
|
|
}
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|