diff --git a/Plugins/PluginNowPlaying/NowPlaying.cpp b/Plugins/PluginNowPlaying/NowPlaying.cpp index de2efcb1..71c165b8 100644 --- a/Plugins/PluginNowPlaying/NowPlaying.cpp +++ b/Plugins/PluginNowPlaying/NowPlaying.cpp @@ -61,7 +61,7 @@ UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id) } 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; @@ -100,11 +100,11 @@ UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id) if (!child->parent) { // The referenced section doesn't exist - std::wstring error = L"NowPlayingPlugin: PlayerName="; + std::wstring error = L"NowPlayingPlugin: Invalid PlayerName="; error += str; error += L" in ["; error += section; - error += L"] does not exist."; + error += L"]"; LSLog(LOG_WARNING, L"Rainmeter", error.c_str()); delete child; return maxValue; @@ -156,11 +156,11 @@ UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id) } else { - std::wstring error = L"NowPlayingPlugin: PlayerName="; + std::wstring error = L"NowPlayingPlugin: Invalid PlayerName="; error += str; - error += L" in section ["; + error += L" in ["; error += section; - error += L"] is not valid."; + error += L"]"; LSLog(LOG_ERROR, L"Rainmeter", error.c_str()); delete parent; delete child; @@ -240,6 +240,14 @@ UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id) child->type = MEASURE_VOLUME; 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) { 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 { - std::wstring error = L"NowPlayingPlugin: PlayerType="; + std::wstring error = L"NowPlayingPlugin: Invalid PlayerType="; error += str; - error += L" in section ["; + error += L" in ["; error += section; - error += L"] is not valid."; + error += L"]"; LSLog(LOG_WARNING, L"Rainmeter", error.c_str()); } @@ -352,6 +360,12 @@ UINT Update(UINT id) case MEASURE_STATUS: return (UINT)player->IsInitialized(); + + case MEASURE_SHUFFLE: + return (UINT)player->GetShuffle(); + + case MEASURE_REPEAT: + return (UINT)player->GetRepeat(); } return 0; @@ -421,13 +435,21 @@ LPCTSTR GetString(UINT id, UINT flags) return buffer; 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; } } else { - return L"Error: Invalid player name."; + return L"Error: Invalid player name"; } return L""; @@ -507,7 +529,11 @@ void ExecuteBang(LPCTSTR bang, UINT id) } 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) { @@ -517,8 +543,40 @@ void ExecuteBang(LPCTSTR bang, UINT id) // Relative to current volume 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 { @@ -562,6 +620,11 @@ void SecondsToTime(UINT seconds, bool leadingZero, WCHAR* buffer) mins /= 60; secs %= 60; + if (seconds < 0) + { + hours = mins = secs = 0; + } + if (hours) { _snwprintf_s(buffer, 32, _TRUNCATE, leadingZero ? L"%i:%02i:%02i" : L"%02i:%02i:%02i", hours, mins, secs); diff --git a/Plugins/PluginNowPlaying/Player.cpp b/Plugins/PluginNowPlaying/Player.cpp index 5a97f12d..2b3c984f 100644 --- a/Plugins/PluginNowPlaying/Player.cpp +++ b/Plugins/PluginNowPlaying/Player.cpp @@ -34,6 +34,8 @@ CPlayer::CPlayer() : m_TrackCount(), m_Measures(), m_State(), + m_Shuffle(false), + m_Repeat(false), m_Duration(), m_Position(), m_Rating(), @@ -237,9 +239,6 @@ unsigned __stdcall CPlayer::LyricsThreadProc(void* pParam) */ void CPlayer::ClearData() { - m_Duration = 0; - m_Position = 0; - m_Rating = 0; m_State = PLAYER_STOPPED; m_Artist.clear(); m_Album.clear(); @@ -247,4 +246,7 @@ void CPlayer::ClearData() m_Lyrics.clear(); m_FilePath.clear(); m_CoverPath.clear(); + m_Duration = 0; + m_Position = 0; + m_Rating = 0; } diff --git a/Plugins/PluginNowPlaying/Player.h b/Plugins/PluginNowPlaying/Player.h index cb3abbec..e71111e7 100644 --- a/Plugins/PluginNowPlaying/Player.h +++ b/Plugins/PluginNowPlaying/Player.h @@ -46,7 +46,9 @@ enum MEASURETYPE MEASURE_RATING = 0x00000200, MEASURE_VOLUME = 0x00000400, MEASURE_STATE = 0x00000800, - MEASURE_STATUS = 0x00001000 + MEASURE_STATUS = 0x00001000, + MEASURE_SHUFFLE = 0x00002000, + MEASURE_REPEAT = 0x00004000 }; class CPlayer @@ -73,9 +75,11 @@ public: 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 SetPosition(int position) {} // position: position in seconds + virtual void SetRating(int rating) {} // rating: 0 - 5 + 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 ClosePlayer() {} @@ -90,6 +94,8 @@ public: UINT GetPosition() { return m_Position; } UINT GetRating() { return m_Rating; } UINT GetVolume() { return m_Volume; } + bool GetShuffle() { return m_Shuffle; } + bool GetRepeat() { return m_Repeat; } protected: void ClearData(); @@ -111,6 +117,8 @@ protected: UINT m_Position; // Current position in seconds UINT m_Rating; // Track rating from 0 to 100 UINT m_Volume; // Volume from 0 to 100 + bool m_Shuffle; + bool m_Repeat; private: static unsigned __stdcall LyricsThreadProc(void* pParam); diff --git a/Plugins/PluginNowPlaying/PlayerAIMP.cpp b/Plugins/PluginNowPlaying/PlayerAIMP.cpp index cc709b18..8d19026e 100644 --- a/Plugins/PluginNowPlaying/PlayerAIMP.cpp +++ b/Plugins/PluginNowPlaying/PlayerAIMP.cpp @@ -189,6 +189,9 @@ void CPlayerAIMP::UpdateData() 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 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 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); 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)); } +/* +** 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 ** diff --git a/Plugins/PluginNowPlaying/PlayerAIMP.h b/Plugins/PluginNowPlaying/PlayerAIMP.h index f59274e1..92af5513 100644 --- a/Plugins/PluginNowPlaying/PlayerAIMP.h +++ b/Plugins/PluginNowPlaying/PlayerAIMP.h @@ -38,6 +38,8 @@ public: 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); diff --git a/Plugins/PluginNowPlaying/PlayerCAD.cpp b/Plugins/PluginNowPlaying/PlayerCAD.cpp index 67a8b2d7..d4c32c60 100644 --- a/Plugins/PluginNowPlaying/PlayerCAD.cpp +++ b/Plugins/PluginNowPlaying/PlayerCAD.cpp @@ -249,6 +249,18 @@ LRESULT CALLBACK CPlayerCAD::WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM 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: { 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) { - if (volume < 0) - { - volume = 0; - } - else if (volume > 100) - { - volume = 100; - } 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 ** diff --git a/Plugins/PluginNowPlaying/PlayerCAD.h b/Plugins/PluginNowPlaying/PlayerCAD.h index aa58e8a4..9493a80c 100644 --- a/Plugins/PluginNowPlaying/PlayerCAD.h +++ b/Plugins/PluginNowPlaying/PlayerCAD.h @@ -41,6 +41,8 @@ public: 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); diff --git a/Plugins/PluginNowPlaying/PlayerITunes.cpp b/Plugins/PluginNowPlaying/PlayerITunes.cpp index 8a6b9fc2..769684a2 100644 --- a/Plugins/PluginNowPlaying/PlayerITunes.cpp +++ b/Plugins/PluginNowPlaying/PlayerITunes.cpp @@ -573,6 +573,59 @@ void CPlayerITunes::SetVolume(int 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 ** diff --git a/Plugins/PluginNowPlaying/PlayerITunes.h b/Plugins/PluginNowPlaying/PlayerITunes.h index 293c5c8d..bec881fd 100644 --- a/Plugins/PluginNowPlaying/PlayerITunes.h +++ b/Plugins/PluginNowPlaying/PlayerITunes.h @@ -52,6 +52,8 @@ public: 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); diff --git a/Plugins/PluginNowPlaying/PlayerWMP.cpp b/Plugins/PluginNowPlaying/PlayerWMP.cpp index 02f3efd2..b3daa14c 100644 --- a/Plugins/PluginNowPlaying/PlayerWMP.cpp +++ b/Plugins/PluginNowPlaying/PlayerWMP.cpp @@ -579,31 +579,31 @@ void CPlayerWMP::SetRating(int rating) if (spMedia) { CComBSTR val; - if (rating <= 0) + switch (rating) { - rating = 0; + case 0: val = L"0"; - } - else if (rating == 1) - { + break; + + case 1: val = L"1"; - } - else if (rating == 2) - { + break; + + case 2: val = L"25"; - } - else if (rating == 3) - { + break; + + case 3: val = L"50"; - } - else if (rating == 4) - { + break; + + case 4: val = L"75"; - } - else if (rating >= 5) - { - rating = 5; + break; + + case 5: val = L"99"; + break; } spMedia->setItemInfo(CComBSTR("UserRating"), val); diff --git a/Plugins/PluginNowPlaying/PlayerWinamp.cpp b/Plugins/PluginNowPlaying/PlayerWinamp.cpp index d5aa6147..16c06358 100644 --- a/Plugins/PluginNowPlaying/PlayerWinamp.cpp +++ b/Plugins/PluginNowPlaying/PlayerWinamp.cpp @@ -175,6 +175,8 @@ void CPlayerWinamp::UpdateData() { m_Rating = SendMessage(m_Window, WM_WA_IPC, 0, IPC_GETRATING); 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::Tag* tag = fr.tag(); @@ -415,15 +417,7 @@ void CPlayerWinamp::SetRating(int rating) */ void CPlayerWinamp::SetVolume(int volume) { - ++volume; // For proper scaling - if (volume < 0) - { - volume = 0; - } - else if (volume > 100) - { - volume = 100; - } + if (volume) ++volume; // For proper scaling // Winamp accepts volume in 0 - 255 range volume *= 255; @@ -431,6 +425,36 @@ void CPlayerWinamp::SetVolume(int volume) 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 ** diff --git a/Plugins/PluginNowPlaying/PlayerWinamp.h b/Plugins/PluginNowPlaying/PlayerWinamp.h index 1da24710..c27d63d4 100644 --- a/Plugins/PluginNowPlaying/PlayerWinamp.h +++ b/Plugins/PluginNowPlaying/PlayerWinamp.h @@ -44,6 +44,8 @@ public: 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); diff --git a/Plugins/PluginNowPlaying/SDKs/CAD/cad_sdk.h b/Plugins/PluginNowPlaying/SDKs/CAD/cad_sdk.h index 3130d346..d9745b0c 100644 --- a/Plugins/PluginNowPlaying/SDKs/CAD/cad_sdk.h +++ b/Plugins/PluginNowPlaying/SDKs/CAD/cad_sdk.h @@ -21,10 +21,12 @@ enum IPCMESSAGE IPC_SHOW_WINDOW = 124, IPC_GET_STATE = 125, IPC_STATE_CHANGED_NOTIFICATION = 126, + IPC_REPEAT_CHANGED_NOTIFICATION = 128, IPC_SET_REPEAT = 128, IPC_SHUTDOWN_NOTIFICATION = 129, IPC_GET_REPEAT = 130, IPC_CLOSE = 131, + IPC_SHUFFLE_CHANGED_NOTIFICATION = 140, IPC_GET_SHUFFLE = 140, IPC_SET_SHUFFLE = 141, IPC_RATING_CHANGED_NOTIFICATION = 639,