From d598c56b76418cd927e8954bea95a41a54304042 Mon Sep 17 00:00:00 2001 From: Birunthan Mohanathas Date: Thu, 8 Sep 2011 12:42:03 +0000 Subject: [PATCH] NowPlayingPlugin: Minor tweaks. --- Plugins/PluginNowPlaying/Cover.cpp | 3 +-- Plugins/PluginNowPlaying/Internet.cpp | 11 +++----- Plugins/PluginNowPlaying/Lyrics.cpp | 12 +++------ Plugins/PluginNowPlaying/NowPlaying.cpp | 1 + Plugins/PluginNowPlaying/Player.cpp | 19 +++---------- Plugins/PluginNowPlaying/Player.h | 31 +++++++++++----------- Plugins/PluginNowPlaying/PlayerAIMP.cpp | 8 +++--- Plugins/PluginNowPlaying/PlayerCAD.cpp | 2 +- Plugins/PluginNowPlaying/PlayerFoobar.cpp | 7 +++-- Plugins/PluginNowPlaying/PlayerITunes.cpp | 4 +-- Plugins/PluginNowPlaying/PlayerSpotify.cpp | 2 +- Plugins/PluginNowPlaying/PlayerWLM.cpp | 2 +- Plugins/PluginNowPlaying/PlayerWMP.cpp | 4 +-- Plugins/PluginNowPlaying/PlayerWinamp.cpp | 8 +++--- 14 files changed, 47 insertions(+), 67 deletions(-) diff --git a/Plugins/PluginNowPlaying/Cover.cpp b/Plugins/PluginNowPlaying/Cover.cpp index 1d692855..e8adb8e4 100644 --- a/Plugins/PluginNowPlaying/Cover.cpp +++ b/Plugins/PluginNowPlaying/Cover.cpp @@ -39,8 +39,7 @@ bool CCover::GetCached(std::wstring& path) */ bool CCover::GetLocal(std::wstring filename, const std::wstring& folder, std::wstring& target) { - std::wstring testPath = folder; - testPath += filename; + std::wstring testPath = folder + filename; testPath += L"."; std::wstring::size_type origLen = testPath.length(); diff --git a/Plugins/PluginNowPlaying/Internet.cpp b/Plugins/PluginNowPlaying/Internet.cpp index 65438b73..17e2b767 100644 --- a/Plugins/PluginNowPlaying/Internet.cpp +++ b/Plugins/PluginNowPlaying/Internet.cpp @@ -257,7 +257,7 @@ void CInternet::DecodeReferences(std::wstring& str) /* ** ConvertToWide ** -** Convert from multibyte ti wide string. +** Convert multibyte string to wide string. ** */ std::wstring CInternet::ConvertToWide(LPCSTR str, int codepage) @@ -266,15 +266,12 @@ std::wstring CInternet::ConvertToWide(LPCSTR str, int codepage) if (str && *str) { - int strLen = (int)strlen(str) + 1; + int strLen = (int)strlen(str); int bufLen = MultiByteToWideChar(codepage, 0, str, strLen, NULL, 0); if (bufLen > 0) { - WCHAR* wideSz = new WCHAR[bufLen]; - wideSz[0] = 0; - MultiByteToWideChar(codepage, 0, str, strLen, wideSz, bufLen); - szWide = wideSz; - delete [] wideSz; + szWide.resize(bufLen); + MultiByteToWideChar(codepage, 0, str, strLen, &szWide[0], bufLen); } } diff --git a/Plugins/PluginNowPlaying/Lyrics.cpp b/Plugins/PluginNowPlaying/Lyrics.cpp index d15400fe..c7e929b6 100644 --- a/Plugins/PluginNowPlaying/Lyrics.cpp +++ b/Plugins/PluginNowPlaying/Lyrics.cpp @@ -49,8 +49,7 @@ bool CLyrics::GetFromWikia(const std::wstring& artist, const std::wstring& title { bool ret = false; - std::wstring url = L"http://lyrics.wikia.com/api.php?func=getSong&fmt=json&artist="; - url += artist; + std::wstring url = L"http://lyrics.wikia.com/api.php?func=getSong&fmt=json&artist=" + artist; url += L"&song="; url += title; @@ -126,8 +125,7 @@ bool CLyrics::GetFromLYRDB(const std::wstring& artist, const std::wstring& title { bool ret = false; - std::wstring query = artist; - query += L"|"; + std::wstring query = artist + L"|"; query += title; // LYRDB doesn't like apostrophes @@ -137,8 +135,7 @@ bool CLyrics::GetFromLYRDB(const std::wstring& artist, const std::wstring& title query.erase(pos, 3); } - std::wstring url = L"http://webservices.lyrdb.com/lookup.php?q="; - url += query; + std::wstring url = L"http://webservices.lyrdb.com/lookup.php?q=" + query; url += L"&for=match&agent=RainmeterNowPlaying"; data = CInternet::DownloadUrl(url, CP_ACP); @@ -172,8 +169,7 @@ bool CLyrics::GetFromLetras(const std::wstring& artist, const std::wstring& titl { bool ret = false; - std::wstring url = L"http://letras.terra.com.br/winamp.php?musica="; - url += title; + std::wstring url = L"http://letras.terra.com.br/winamp.php?musica=" + title; url += L"&artista="; url += artist; data = CInternet::DownloadUrl(url, CP_ACP); diff --git a/Plugins/PluginNowPlaying/NowPlaying.cpp b/Plugins/PluginNowPlaying/NowPlaying.cpp index c02829a4..de2efcb1 100644 --- a/Plugins/PluginNowPlaying/NowPlaying.cpp +++ b/Plugins/PluginNowPlaying/NowPlaying.cpp @@ -242,6 +242,7 @@ UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id) } else if (_wcsicmp(L"LYRICS", str) == 0) { + LSLog(LOG_WARNING, L"Rainmeter", L"NowPlayingPlugin: Using undocumented PlayerType=LYRICS!"); child->type = MEASURE_LYRICS; } else if (_wcsicmp(L"FILE", str) == 0) diff --git a/Plugins/PluginNowPlaying/Player.cpp b/Plugins/PluginNowPlaying/Player.cpp index 134a07d6..5a97f12d 100644 --- a/Plugins/PluginNowPlaying/Player.cpp +++ b/Plugins/PluginNowPlaying/Player.cpp @@ -29,11 +29,10 @@ extern std::wstring g_CachePath; */ CPlayer::CPlayer() : m_Initialized(false), - m_HasCoverMeasure(false), - m_HasLyricsMeasure(false), m_InstanceCount(), m_UpdateCount(), m_TrackCount(), + m_Measures(), m_State(), m_Duration(), m_Position(), @@ -90,18 +89,9 @@ void CPlayer::RemoveInstance() ** Called during initialization of any measure. ** */ -void CPlayer::AddMeasure(MEASURETYPE measure) +void CPlayer::AddMeasure(INT type) { - switch (measure) - { - case MEASURE_LYRICS: - m_HasLyricsMeasure = true; - break; - - case MEASURE_COVER: - m_HasCoverMeasure = true; - break; - } + m_Measures |= type; } /* @@ -135,8 +125,7 @@ std::wstring CPlayer::GetCacheFile() } else { - std::wstring name = m_Artist; - name += L" - "; + std::wstring name = m_Artist + L" - "; name += m_Title; // Replace reserved chars with _ diff --git a/Plugins/PluginNowPlaying/Player.h b/Plugins/PluginNowPlaying/Player.h index 93a6ef4c..cb3abbec 100644 --- a/Plugins/PluginNowPlaying/Player.h +++ b/Plugins/PluginNowPlaying/Player.h @@ -34,19 +34,19 @@ enum PLAYSTATE enum MEASURETYPE { - MEASURE_ARTIST, - MEASURE_TITLE, - MEASURE_ALBUM, - MEASURE_LYRICS, - MEASURE_COVER, - MEASURE_FILE, - MEASURE_DURATION, - MEASURE_POSITION, - MEASURE_PROGRESS, - MEASURE_RATING, - MEASURE_VOLUME, - MEASURE_STATE, - MEASURE_STATUS + MEASURE_ARTIST = 0x00000001, + MEASURE_TITLE = 0x00000002, + MEASURE_ALBUM = 0x00000004, + MEASURE_LYRICS = 0x00000008, + MEASURE_COVER = 0x00000010, + MEASURE_FILE = 0x00000020, + MEASURE_DURATION = 0x00000040, + MEASURE_POSITION = 0x00000080, + MEASURE_PROGRESS = 0x00000100, + MEASURE_RATING = 0x00000200, + MEASURE_VOLUME = 0x00000400, + MEASURE_STATE = 0x00000800, + MEASURE_STATUS = 0x00001000 }; class CPlayer @@ -58,7 +58,7 @@ public: void AddInstance(); void RemoveInstance(); void UpdateMeasure(); - virtual void AddMeasure(MEASURETYPE measure); + virtual void AddMeasure(INT type); virtual void UpdateData() = 0; bool IsInitialized() { return m_Initialized; } @@ -95,12 +95,11 @@ protected: void ClearData(); bool m_Initialized; - bool m_HasCoverMeasure; - bool m_HasLyricsMeasure; UINT m_InstanceCount; UINT m_UpdateCount; UINT m_TrackCount; + INT m_Measures; PLAYSTATE m_State; std::wstring m_Artist; std::wstring m_Title; diff --git a/Plugins/PluginNowPlaying/PlayerAIMP.cpp b/Plugins/PluginNowPlaying/PlayerAIMP.cpp index 5ff6a691..cc709b18 100644 --- a/Plugins/PluginNowPlaying/PlayerAIMP.cpp +++ b/Plugins/PluginNowPlaying/PlayerAIMP.cpp @@ -118,8 +118,8 @@ bool CPlayerAIMP::CheckWindow() */ void CPlayerAIMP::UpdateData() { - static long oldFileSize = 0; - static UINT oldTitleLen = 0; + static INT64 oldFileSize = 0; + static long oldTitleLen = 0; if (!m_Initialized) { @@ -198,12 +198,12 @@ void CPlayerAIMP::UpdateData() ++m_TrackCount; // Find cover if needed - if (m_HasCoverMeasure) + if (m_Measures & MEASURE_COVER) { FindCover(); } - if (m_HasLyricsMeasure) + if (m_Measures & MEASURE_LYRICS) { FindLyrics(); } diff --git a/Plugins/PluginNowPlaying/PlayerCAD.cpp b/Plugins/PluginNowPlaying/PlayerCAD.cpp index de1bda52..67a8b2d7 100644 --- a/Plugins/PluginNowPlaying/PlayerCAD.cpp +++ b/Plugins/PluginNowPlaying/PlayerCAD.cpp @@ -310,7 +310,7 @@ LRESULT CALLBACK CPlayerCAD::WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM player->m_CoverPath.assign(data, 0, len); data.erase(0, ++len); - if (player->m_HasLyricsMeasure) + if (player->m_Measures & MEASURE_LYRICS) { player->FindLyrics(); } diff --git a/Plugins/PluginNowPlaying/PlayerFoobar.cpp b/Plugins/PluginNowPlaying/PlayerFoobar.cpp index 60a93a41..7018d3da 100644 --- a/Plugins/PluginNowPlaying/PlayerFoobar.cpp +++ b/Plugins/PluginNowPlaying/PlayerFoobar.cpp @@ -98,8 +98,7 @@ void CPlayerFoobar::Initialize() int version = (int)SendMessage(m_FooWindow, WM_USER, 0, FOO_GETVERSION); if (version < 100) { - std::wstring error = L"Your copy of the foo_rainmeter.dll plugin for foobar2000 is outdated.\n"; - error += L"Please download the latest version from foo-rainmeter.googlecode.com and try again."; + std::wstring 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.c_str(), L"Rainmeter", MB_OK | MB_ICONERROR | MB_TOPMOST); m_FooWindow = NULL; } @@ -264,12 +263,12 @@ LRESULT CALLBACK CPlayerFoobar::WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPAR player->m_FilePath = token; player->m_Position = 0; - if (player->m_HasCoverMeasure || player->m_InstanceCount == 0) + if (player->m_Measures & MEASURE_COVER || player->m_InstanceCount == 0) { player->FindCover(); } - if (player->m_HasLyricsMeasure) + if (player->m_Measures & MEASURE_LYRICS) { player->FindLyrics(); } diff --git a/Plugins/PluginNowPlaying/PlayerITunes.cpp b/Plugins/PluginNowPlaying/PlayerITunes.cpp index e9bf69ba..8a6b9fc2 100644 --- a/Plugins/PluginNowPlaying/PlayerITunes.cpp +++ b/Plugins/PluginNowPlaying/PlayerITunes.cpp @@ -387,7 +387,7 @@ void CPlayerITunes::OnTrackChange() ++m_TrackCount; m_FilePath = tmpStr; - if (m_HasCoverMeasure) + if (m_Measures & MEASURE_COVER) { m_CoverPath = GetCacheFile(); if (!CCover::GetCached(m_CoverPath)) @@ -432,7 +432,7 @@ void CPlayerITunes::OnTrackChange() } } - if (m_HasLyricsMeasure) + if (m_Measures & MEASURE_LYRICS) { FindLyrics(); } diff --git a/Plugins/PluginNowPlaying/PlayerSpotify.cpp b/Plugins/PluginNowPlaying/PlayerSpotify.cpp index 19efe895..7e80f35d 100644 --- a/Plugins/PluginNowPlaying/PlayerSpotify.cpp +++ b/Plugins/PluginNowPlaying/PlayerSpotify.cpp @@ -115,7 +115,7 @@ void CPlayerSpotify::UpdateData() m_Artist = artist; ++m_TrackCount; - if (m_HasLyricsMeasure) + if (m_Measures & MEASURE_LYRICS) { FindLyrics(); } diff --git a/Plugins/PluginNowPlaying/PlayerWLM.cpp b/Plugins/PluginNowPlaying/PlayerWLM.cpp index fc7de47a..b61f7eb5 100644 --- a/Plugins/PluginNowPlaying/PlayerWLM.cpp +++ b/Plugins/PluginNowPlaying/PlayerWLM.cpp @@ -138,7 +138,7 @@ LRESULT CALLBACK CPlayerWLM::WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM len = data.find_first_of(L'\\'); player->m_Album.assign(data, 0, len); - if (player->m_HasLyricsMeasure) + if (player->m_Measures & MEASURE_LYRICS) { player->FindLyrics(); } diff --git a/Plugins/PluginNowPlaying/PlayerWMP.cpp b/Plugins/PluginNowPlaying/PlayerWMP.cpp index 04146686..02f3efd2 100644 --- a/Plugins/PluginNowPlaying/PlayerWMP.cpp +++ b/Plugins/PluginNowPlaying/PlayerWMP.cpp @@ -451,7 +451,7 @@ void CPlayerWMP::UpdateData() // Find cover if needed // TODO: Fix temp solution - if (m_HasCoverMeasure || m_InstanceCount == 0) + if (m_Measures & MEASURE_COVER || m_InstanceCount == 0) { spMedia->getItemInfo(CComBSTR("WM/WMCollectionID"), &val); targetPath.resize(targetPath.find_last_of(L'\\') + 1); @@ -469,7 +469,7 @@ void CPlayerWMP::UpdateData() } } - if (m_HasLyricsMeasure) + if (m_Measures & MEASURE_LYRICS) { FindLyrics(); } diff --git a/Plugins/PluginNowPlaying/PlayerWinamp.cpp b/Plugins/PluginNowPlaying/PlayerWinamp.cpp index 95920f12..d5aa6147 100644 --- a/Plugins/PluginNowPlaying/PlayerWinamp.cpp +++ b/Plugins/PluginNowPlaying/PlayerWinamp.cpp @@ -184,18 +184,18 @@ void CPlayerWinamp::UpdateData() m_Album = tag->album().toWString(); m_Title = tag->title().toWString(); - if (m_HasLyricsMeasure) + if (m_Measures & MEASURE_LYRICS) { FindLyrics(); } } - else if (m_HasLyricsMeasure) + else if (m_Measures & MEASURE_LYRICS) { m_Lyrics.clear(); } // Find cover if needed - if (m_HasCoverMeasure) + if (m_Measures & MEASURE_COVER) { m_CoverPath = GetCacheFile(); if (!CCover::GetCached(m_CoverPath) && @@ -266,7 +266,7 @@ void CPlayerWinamp::UpdateData() m_Rating = 0; m_Duration = 0; - if (m_HasCoverMeasure) + if (m_Measures & MEASURE_COVER) { m_CoverPath.clear(); }