NowPlayingPlugin: Added SHUFFLE and REPEAT types and accompanying SetShuffle and SetRepeat bangs

This commit is contained in:
Birunthan Mohanathas 2011-09-11 08:22:07 +00:00
parent 6cce1c2233
commit 6b5ca293e8
13 changed files with 271 additions and 65 deletions

View File

@ -61,7 +61,7 @@ UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id)
} }
else else
{ {
LSLog(LOG_ERROR, L"Rainmeter", L"NowPlayingPlugin: Unable to get path to Plugins.ini."); LSLog(LOG_ERROR, L"Rainmeter", L"NowPlayingPlugin: PluginBridge error");
} }
g_Instance = instance; g_Instance = instance;
@ -100,11 +100,11 @@ UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id)
if (!child->parent) if (!child->parent)
{ {
// The referenced section doesn't exist // The referenced section doesn't exist
std::wstring error = L"NowPlayingPlugin: PlayerName="; std::wstring error = L"NowPlayingPlugin: Invalid PlayerName=";
error += str; error += str;
error += L" in ["; error += L" in [";
error += section; error += section;
error += L"] does not exist."; error += L"]";
LSLog(LOG_WARNING, L"Rainmeter", error.c_str()); LSLog(LOG_WARNING, L"Rainmeter", error.c_str());
delete child; delete child;
return maxValue; return maxValue;
@ -156,11 +156,11 @@ UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id)
} }
else else
{ {
std::wstring error = L"NowPlayingPlugin: PlayerName="; std::wstring error = L"NowPlayingPlugin: Invalid PlayerName=";
error += str; error += str;
error += L" in section ["; error += L" in [";
error += section; error += section;
error += L"] is not valid."; error += L"]";
LSLog(LOG_ERROR, L"Rainmeter", error.c_str()); LSLog(LOG_ERROR, L"Rainmeter", error.c_str());
delete parent; delete parent;
delete child; delete child;
@ -240,6 +240,14 @@ UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id)
child->type = MEASURE_VOLUME; child->type = MEASURE_VOLUME;
maxValue = 100; maxValue = 100;
} }
else if (_wcsicmp(L"SHUFFLE", str) == 0)
{
child->type = MEASURE_SHUFFLE;
}
else if (_wcsicmp(L"REPEAT", str) == 0)
{
child->type = MEASURE_REPEAT;
}
else if (_wcsicmp(L"LYRICS", str) == 0) else if (_wcsicmp(L"LYRICS", str) == 0)
{ {
LSLog(LOG_WARNING, L"Rainmeter", L"NowPlayingPlugin: Using undocumented PlayerType=LYRICS!"); LSLog(LOG_WARNING, L"Rainmeter", L"NowPlayingPlugin: Using undocumented PlayerType=LYRICS!");
@ -251,11 +259,11 @@ UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id)
} }
else else
{ {
std::wstring error = L"NowPlayingPlugin: PlayerType="; std::wstring error = L"NowPlayingPlugin: Invalid PlayerType=";
error += str; error += str;
error += L" in section ["; error += L" in [";
error += section; error += section;
error += L"] is not valid."; error += L"]";
LSLog(LOG_WARNING, L"Rainmeter", error.c_str()); LSLog(LOG_WARNING, L"Rainmeter", error.c_str());
} }
@ -352,6 +360,12 @@ UINT Update(UINT id)
case MEASURE_STATUS: case MEASURE_STATUS:
return (UINT)player->IsInitialized(); return (UINT)player->IsInitialized();
case MEASURE_SHUFFLE:
return (UINT)player->GetShuffle();
case MEASURE_REPEAT:
return (UINT)player->GetRepeat();
} }
return 0; return 0;
@ -421,13 +435,21 @@ LPCTSTR GetString(UINT id, UINT flags)
return buffer; return buffer;
case MEASURE_STATUS: case MEASURE_STATUS:
_itow((UINT)player->IsInitialized(), buffer, 10); _itow((int)player->IsInitialized(), buffer, 10);
return buffer;
case MEASURE_SHUFFLE:
_itow((int)player->GetShuffle(), buffer, 10);
return buffer;
case MEASURE_REPEAT:
_itow((int)player->GetRepeat(), buffer, 10);
return buffer; return buffer;
} }
} }
else else
{ {
return L"Error: Invalid player name."; return L"Error: Invalid player name";
} }
return L""; return L"";
@ -507,7 +529,11 @@ void ExecuteBang(LPCTSTR bang, UINT id)
} }
else if (wcsnicmp(bang, L"SetRating", 9) == 0) else if (wcsnicmp(bang, L"SetRating", 9) == 0)
{ {
player->SetRating(_wtoi(arg)); int rating = _wtoi(arg);
if (rating >= 0 && rating <= 5)
{
player->SetRating(rating);
}
} }
else if (wcsnicmp(bang, L"SetVolume", 9) == 0) else if (wcsnicmp(bang, L"SetVolume", 9) == 0)
{ {
@ -517,8 +543,40 @@ void ExecuteBang(LPCTSTR bang, UINT id)
// Relative to current volume // Relative to current volume
volume += player->GetVolume(); volume += player->GetVolume();
} }
player->SetVolume(volume); if (volume < 0)
{
volume = 0;
}
else if (volume > 100)
{
volume = 100;
}
player->SetVolume(volume);;
}
else if (wcsnicmp(bang, L"SetShuffle", 9) == 0)
{
int state = _wtoi(arg);
if (state == -1)
{
player->SetShuffle(!player->GetShuffle());
}
else if (state == 0 || state == 1)
{
player->SetShuffle((bool)state);
}
}
else if (wcsnicmp(bang, L"SetRepeat", 9) == 0)
{
int state = _wtoi(arg);
if (state == -1)
{
player->SetRepeat(!player->GetRepeat());
}
else if (state == 0 || state == 1)
{
player->SetRepeat((bool)state);
}
} }
else else
{ {
@ -562,6 +620,11 @@ void SecondsToTime(UINT seconds, bool leadingZero, WCHAR* buffer)
mins /= 60; mins /= 60;
secs %= 60; secs %= 60;
if (seconds < 0)
{
hours = mins = secs = 0;
}
if (hours) if (hours)
{ {
_snwprintf_s(buffer, 32, _TRUNCATE, leadingZero ? L"%i:%02i:%02i" : L"%02i:%02i:%02i", hours, mins, secs); _snwprintf_s(buffer, 32, _TRUNCATE, leadingZero ? L"%i:%02i:%02i" : L"%02i:%02i:%02i", hours, mins, secs);

View File

@ -34,6 +34,8 @@ CPlayer::CPlayer() :
m_TrackCount(), m_TrackCount(),
m_Measures(), m_Measures(),
m_State(), m_State(),
m_Shuffle(false),
m_Repeat(false),
m_Duration(), m_Duration(),
m_Position(), m_Position(),
m_Rating(), m_Rating(),
@ -237,9 +239,6 @@ unsigned __stdcall CPlayer::LyricsThreadProc(void* pParam)
*/ */
void CPlayer::ClearData() void CPlayer::ClearData()
{ {
m_Duration = 0;
m_Position = 0;
m_Rating = 0;
m_State = PLAYER_STOPPED; m_State = PLAYER_STOPPED;
m_Artist.clear(); m_Artist.clear();
m_Album.clear(); m_Album.clear();
@ -247,4 +246,7 @@ void CPlayer::ClearData()
m_Lyrics.clear(); m_Lyrics.clear();
m_FilePath.clear(); m_FilePath.clear();
m_CoverPath.clear(); m_CoverPath.clear();
m_Duration = 0;
m_Position = 0;
m_Rating = 0;
} }

View File

@ -46,7 +46,9 @@ enum MEASURETYPE
MEASURE_RATING = 0x00000200, MEASURE_RATING = 0x00000200,
MEASURE_VOLUME = 0x00000400, MEASURE_VOLUME = 0x00000400,
MEASURE_STATE = 0x00000800, MEASURE_STATE = 0x00000800,
MEASURE_STATUS = 0x00001000 MEASURE_STATUS = 0x00001000,
MEASURE_SHUFFLE = 0x00002000,
MEASURE_REPEAT = 0x00004000
}; };
class CPlayer class CPlayer
@ -73,9 +75,11 @@ public:
virtual void Stop() {} virtual void Stop() {}
virtual void Next() {} virtual void Next() {}
virtual void Previous() {} virtual void Previous() {}
virtual void SetPosition(int position) {} virtual void SetPosition(int position) {} // position: position in seconds
virtual void SetRating(int rating) {} virtual void SetRating(int rating) {} // rating: 0 - 5
virtual void SetVolume(int volume) {} virtual void SetVolume(int volume) {} // volume: 0 - 100
virtual void SetShuffle(bool state) {} // state: off = 0, on = 1
virtual void SetRepeat(bool state) {} // state: off = 0, on = 1
virtual void OpenPlayer(std::wstring& path) {} virtual void OpenPlayer(std::wstring& path) {}
virtual void ClosePlayer() {} virtual void ClosePlayer() {}
@ -90,6 +94,8 @@ public:
UINT GetPosition() { return m_Position; } UINT GetPosition() { return m_Position; }
UINT GetRating() { return m_Rating; } UINT GetRating() { return m_Rating; }
UINT GetVolume() { return m_Volume; } UINT GetVolume() { return m_Volume; }
bool GetShuffle() { return m_Shuffle; }
bool GetRepeat() { return m_Repeat; }
protected: protected:
void ClearData(); void ClearData();
@ -111,6 +117,8 @@ protected:
UINT m_Position; // Current position in seconds UINT m_Position; // Current position in seconds
UINT m_Rating; // Track rating from 0 to 100 UINT m_Rating; // Track rating from 0 to 100
UINT m_Volume; // Volume from 0 to 100 UINT m_Volume; // Volume from 0 to 100
bool m_Shuffle;
bool m_Repeat;
private: private:
static unsigned __stdcall LyricsThreadProc(void* pParam); static unsigned __stdcall LyricsThreadProc(void* pParam);

View File

@ -189,6 +189,9 @@ void CPlayerAIMP::UpdateData()
m_Duration = info->nDuration / 1000; m_Duration = info->nDuration / 1000;
m_Shuffle = (bool)SendMessage(m_Window, WM_AIMP_COMMAND, WM_AIMP_STATUS_GET, AIMP_STS_SHUFFLE);
m_Repeat = (bool)SendMessage(m_Window, WM_AIMP_COMMAND, WM_AIMP_STATUS_GET, AIMP_STS_REPEAT);
// Get rating through the AIMP Winamp API // Get rating through the AIMP Winamp API
m_Rating = SendMessage(m_WinampWindow, WM_WA_IPC, 0, IPC_GETRATING); m_Rating = SendMessage(m_WinampWindow, WM_WA_IPC, 0, IPC_GETRATING);
@ -288,15 +291,6 @@ void CPlayerAIMP::SetRating(int rating)
// Set rating through the AIMP Winamp API // Set rating through the AIMP Winamp API
if (m_State != PLAYER_STOPPED) if (m_State != PLAYER_STOPPED)
{ {
if (rating < 0)
{
rating = 0;
}
else if (rating > 5)
{
rating = 5;
}
SendMessage(m_WinampWindow, WM_WA_IPC, rating, IPC_SETRATING); SendMessage(m_WinampWindow, WM_WA_IPC, rating, IPC_SETRATING);
m_Rating = rating; m_Rating = rating;
} }
@ -313,6 +307,30 @@ void CPlayerAIMP::SetVolume(int volume)
SendMessage(m_Window, WM_AIMP_COMMAND, WM_AIMP_STATUS_SET, MAKELPARAM(volume, AIMP_STS_VOLUME)); SendMessage(m_Window, WM_AIMP_COMMAND, WM_AIMP_STATUS_SET, MAKELPARAM(volume, AIMP_STS_VOLUME));
} }
/*
** SetShuffle
**
** Handles the SetShuffle bang.
**
*/
void CPlayerAIMP::SetShuffle(bool state)
{
m_Shuffle = state;
SendMessage(m_Window, WM_AIMP_COMMAND, WM_AIMP_STATUS_SET, MAKELPARAM(m_Shuffle, AIMP_STS_SHUFFLE));
}
/*
** SetRepeat
**
** Handles the SetRepeat bang.
**
*/
void CPlayerAIMP::SetRepeat(bool state)
{
m_Repeat = state;
SendMessage(m_Window, WM_AIMP_COMMAND, WM_AIMP_STATUS_SET, MAKELPARAM(m_Repeat, AIMP_STS_REPEAT));
}
/* /*
** ClosePlayer ** ClosePlayer
** **

View File

@ -38,6 +38,8 @@ public:
virtual void SetPosition(int position); virtual void SetPosition(int position);
virtual void SetRating(int rating); virtual void SetRating(int rating);
virtual void SetVolume(int volume); virtual void SetVolume(int volume);
virtual void SetShuffle(bool state);
virtual void SetRepeat(bool state);
virtual void ClosePlayer(); virtual void ClosePlayer();
virtual void OpenPlayer(std::wstring& path); virtual void OpenPlayer(std::wstring& path);

View File

@ -249,6 +249,18 @@ LRESULT CALLBACK CPlayerCAD::WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
break; break;
} }
case IPC_REPEAT_CHANGED_NOTIFICATION:
{
player->m_Repeat = (bool)wParam;
break;
}
case IPC_SHUFFLE_CHANGED_NOTIFICATION:
{
player->m_Shuffle = (bool)wParam;
break;
}
case IPC_RATING_CHANGED_NOTIFICATION: case IPC_RATING_CHANGED_NOTIFICATION:
{ {
player->m_Rating = (wParam + 1) / 2; // From 0 - 10 to 0 - 5 player->m_Rating = (wParam + 1) / 2; // From 0 - 10 to 0 - 5
@ -467,17 +479,33 @@ void CPlayerCAD::SetRating(int rating)
*/ */
void CPlayerCAD::SetVolume(int volume) void CPlayerCAD::SetVolume(int volume)
{ {
if (volume < 0)
{
volume = 0;
}
else if (volume > 100)
{
volume = 100;
}
SendMessage(m_PlayerWindow, WM_USER, volume, IPC_SET_VOLUME); SendMessage(m_PlayerWindow, WM_USER, volume, IPC_SET_VOLUME);
} }
/*
** SetShuffle
**
** Handles the SetShuffle bang.
**
*/
void CPlayerCAD::SetShuffle(bool state)
{
//m_Shuffle = state;
SendMessage(m_PlayerWindow, WM_USER, (WPARAM)m_Shuffle, IPC_SET_SHUFFLE);
}
/*
** SetRepeat
**
** Handles the SetRepeat bang.
**
*/
void CPlayerCAD::SetRepeat(bool state)
{
//m_Repeat = state;
SendMessage(m_PlayerWindow, WM_USER, (WPARAM)m_Repeat, IPC_SET_REPEAT);
}
/* /*
** ClosePlayer ** ClosePlayer
** **

View File

@ -41,6 +41,8 @@ public:
virtual void SetPosition(int position); virtual void SetPosition(int position);
virtual void SetRating(int rating); virtual void SetRating(int rating);
virtual void SetVolume(int volume); virtual void SetVolume(int volume);
virtual void SetShuffle(bool state);
virtual void SetRepeat(bool state);
virtual void ClosePlayer(); virtual void ClosePlayer();
virtual void OpenPlayer(std::wstring& path); virtual void OpenPlayer(std::wstring& path);

View File

@ -573,6 +573,59 @@ void CPlayerITunes::SetVolume(int volume)
m_iTunes->put_SoundVolume((long)volume); m_iTunes->put_SoundVolume((long)volume);
} }
/*
** SetShuffle
**
** Handles the SetShuffle bang.
**
*/
void CPlayerITunes::SetShuffle(bool state)
{
IITTrack* track;
HRESULT hr = m_iTunes->get_CurrentTrack(&track);
if (SUCCEEDED(hr))
{
IITPlaylist* playlist;
hr = track->get_Playlist(&playlist);
if (SUCCEEDED(hr))
{
m_Shuffle = state;
VARIANT_BOOL shuffle = m_Shuffle ? VARIANT_TRUE : VARIANT_FALSE;
playlist->put_Shuffle(shuffle);
playlist->Release();
}
track->Release();
}
}
/*
** SetRepeat
**
** Handles the SetRepeat bang.
**
*/
void CPlayerITunes::SetRepeat(bool state)
{
IITTrack* track;
HRESULT hr = m_iTunes->get_CurrentTrack(&track);
if (SUCCEEDED(hr))
{
IITPlaylist* playlist;
hr = track->get_Playlist(&playlist);
if (SUCCEEDED(hr))
{
m_Repeat = state;
playlist->put_SongRepeat((ITPlaylistRepeatMode)m_Repeat);
playlist->Release();
}
track->Release();
}
}
/* /*
** ClosePlayer ** ClosePlayer
** **

View File

@ -52,6 +52,8 @@ public:
virtual void SetPosition(int position); virtual void SetPosition(int position);
virtual void SetRating(int rating); virtual void SetRating(int rating);
virtual void SetVolume(int volume); virtual void SetVolume(int volume);
virtual void SetShuffle(bool state);
virtual void SetRepeat(bool state);
virtual void ClosePlayer(); virtual void ClosePlayer();
virtual void OpenPlayer(std::wstring& path); virtual void OpenPlayer(std::wstring& path);

View File

@ -579,31 +579,31 @@ void CPlayerWMP::SetRating(int rating)
if (spMedia) if (spMedia)
{ {
CComBSTR val; CComBSTR val;
if (rating <= 0) switch (rating)
{ {
rating = 0; case 0:
val = L"0"; val = L"0";
} break;
else if (rating == 1)
{ case 1:
val = L"1"; val = L"1";
} break;
else if (rating == 2)
{ case 2:
val = L"25"; val = L"25";
} break;
else if (rating == 3)
{ case 3:
val = L"50"; val = L"50";
} break;
else if (rating == 4)
{ case 4:
val = L"75"; val = L"75";
} break;
else if (rating >= 5)
{ case 5:
rating = 5;
val = L"99"; val = L"99";
break;
} }
spMedia->setItemInfo(CComBSTR("UserRating"), val); spMedia->setItemInfo(CComBSTR("UserRating"), val);

View File

@ -175,6 +175,8 @@ void CPlayerWinamp::UpdateData()
{ {
m_Rating = SendMessage(m_Window, WM_WA_IPC, 0, IPC_GETRATING); m_Rating = SendMessage(m_Window, WM_WA_IPC, 0, IPC_GETRATING);
m_Duration = SendMessage(m_Window, WM_WA_IPC, 1, IPC_GETOUTPUTTIME); m_Duration = SendMessage(m_Window, WM_WA_IPC, 1, IPC_GETOUTPUTTIME);
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);
TagLib::FileRef fr(wBuffer); TagLib::FileRef fr(wBuffer);
TagLib::Tag* tag = fr.tag(); TagLib::Tag* tag = fr.tag();
@ -415,15 +417,7 @@ void CPlayerWinamp::SetRating(int rating)
*/ */
void CPlayerWinamp::SetVolume(int volume) void CPlayerWinamp::SetVolume(int volume)
{ {
++volume; // For proper scaling if (volume) ++volume; // For proper scaling
if (volume < 0)
{
volume = 0;
}
else if (volume > 100)
{
volume = 100;
}
// Winamp accepts volume in 0 - 255 range // Winamp accepts volume in 0 - 255 range
volume *= 255; volume *= 255;
@ -431,6 +425,36 @@ void CPlayerWinamp::SetVolume(int volume)
SendMessage(m_Window, WM_WA_IPC, volume, IPC_SETVOLUME); SendMessage(m_Window, WM_WA_IPC, volume, IPC_SETVOLUME);
} }
/*
** SetShuffle
**
** Handles the SetShuffle bang.
**
*/
void CPlayerWinamp::SetShuffle(bool state)
{
if (!m_PlayingStream)
{
m_Shuffle = state;
SendMessage(m_Window, WM_WA_IPC, (WPARAM)m_Shuffle, IPC_SET_SHUFFLE);
}
}
/*
** SetRepeat
**
** Handles the SetRepeat bang.
**
*/
void CPlayerWinamp::SetRepeat(bool state)
{
if (!m_PlayingStream)
{
m_Repeat = state;
SendMessage(m_Window, WM_WA_IPC, (WPARAM)m_Repeat, IPC_SET_REPEAT);
}
}
/* /*
** ClosePlayer ** ClosePlayer
** **

View File

@ -44,6 +44,8 @@ public:
virtual void SetPosition(int position); virtual void SetPosition(int position);
virtual void SetRating(int rating); virtual void SetRating(int rating);
virtual void SetVolume(int volume); virtual void SetVolume(int volume);
virtual void SetShuffle(bool state);
virtual void SetRepeat(bool state);
virtual void ClosePlayer(); virtual void ClosePlayer();
virtual void OpenPlayer(std::wstring& path); virtual void OpenPlayer(std::wstring& path);

View File

@ -21,10 +21,12 @@ enum IPCMESSAGE
IPC_SHOW_WINDOW = 124, IPC_SHOW_WINDOW = 124,
IPC_GET_STATE = 125, IPC_GET_STATE = 125,
IPC_STATE_CHANGED_NOTIFICATION = 126, IPC_STATE_CHANGED_NOTIFICATION = 126,
IPC_REPEAT_CHANGED_NOTIFICATION = 128,
IPC_SET_REPEAT = 128, IPC_SET_REPEAT = 128,
IPC_SHUTDOWN_NOTIFICATION = 129, IPC_SHUTDOWN_NOTIFICATION = 129,
IPC_GET_REPEAT = 130, IPC_GET_REPEAT = 130,
IPC_CLOSE = 131, IPC_CLOSE = 131,
IPC_SHUFFLE_CHANGED_NOTIFICATION = 140,
IPC_GET_SHUFFLE = 140, IPC_GET_SHUFFLE = 140,
IPC_SET_SHUFFLE = 141, IPC_SET_SHUFFLE = 141,
IPC_RATING_CHANGED_NOTIFICATION = 639, IPC_RATING_CHANGED_NOTIFICATION = 639,