From a57d75399ce737a6e5667a78abeaf09e1995bea1 Mon Sep 17 00:00:00 2001 From: Birunthan Mohanathas Date: Mon, 12 Mar 2012 12:01:12 +0000 Subject: [PATCH] NowPlaying.dll: Added support for types NUMBER and YEAR --- Plugins/PluginNowPlaying/NowPlaying.cpp | 22 +++++- Plugins/PluginNowPlaying/Player.cpp | 4 + Plugins/PluginNowPlaying/Player.h | 28 ++++--- Plugins/PluginNowPlaying/PlayerAIMP.cpp | 3 +- Plugins/PluginNowPlaying/PlayerCAD.cpp | 77 ++++++++++++-------- Plugins/PluginNowPlaying/PlayerITunes.cpp | 6 ++ Plugins/PluginNowPlaying/PlayerWMP.cpp | 6 ++ Plugins/PluginNowPlaying/PlayerWinamp.cpp | 2 + Plugins/PluginNowPlaying/PluginNowPlaying.rc | 6 +- 9 files changed, 104 insertions(+), 50 deletions(-) diff --git a/Plugins/PluginNowPlaying/NowPlaying.cpp b/Plugins/PluginNowPlaying/NowPlaying.cpp index 3de0ab60..028a83e8 100644 --- a/Plugins/PluginNowPlaying/NowPlaying.cpp +++ b/Plugins/PluginNowPlaying/NowPlaying.cpp @@ -271,6 +271,14 @@ PLUGIN_EXPORT void Reload(void* data, void* rm, double* maxValue) { measure->type = MEASURE_FILE; } + else if (_wcsicmp(L"NUMBER", str) == 0) + { + measure->type = MEASURE_NUMBER; + } + else if (_wcsicmp(L"YEAR", str) == 0) + { + measure->type = MEASURE_YEAR; + } else { std::wstring error = L"NowPlaying.dll: Invalid PlayerType="; @@ -328,16 +336,22 @@ PLUGIN_EXPORT double Update(void* data) return player->GetVolume(); case MEASURE_STATE: - return (UINT)player->GetState(); + return player->GetState(); case MEASURE_STATUS: - return (UINT)player->IsInitialized(); + return player->IsInitialized(); case MEASURE_SHUFFLE: - return (UINT)player->GetShuffle(); + return player->GetShuffle(); case MEASURE_REPEAT: - return (UINT)player->GetRepeat(); + return player->GetRepeat(); + + case MEASURE_NUMBER: + return player->GetNumber(); + + case MEASURE_YEAR: + return player->GetYear(); } return 0.0; diff --git a/Plugins/PluginNowPlaying/Player.cpp b/Plugins/PluginNowPlaying/Player.cpp index d132e5d4..218b9e41 100644 --- a/Plugins/PluginNowPlaying/Player.cpp +++ b/Plugins/PluginNowPlaying/Player.cpp @@ -30,6 +30,8 @@ CPlayer::CPlayer() : m_TrackCount(), m_Measures(), m_State(), + m_Number(1), + m_Year(), m_Shuffle(false), m_Repeat(false), m_Duration(), @@ -204,4 +206,6 @@ void CPlayer::ClearData() m_Duration = 0; m_Position = 0; m_Rating = 0; + m_Number = 0; + m_Year = 0; } diff --git a/Plugins/PluginNowPlaying/Player.h b/Plugins/PluginNowPlaying/Player.h index 90715f81..a5a81b72 100644 --- a/Plugins/PluginNowPlaying/Player.h +++ b/Plugins/PluginNowPlaying/Player.h @@ -49,7 +49,9 @@ enum MeasureType MEASURE_STATE = 0x00000800, MEASURE_STATUS = 0x00001000, MEASURE_SHUFFLE = 0x00002000, - MEASURE_REPEAT = 0x00004000 + MEASURE_REPEAT = 0x00004000, + MEASURE_NUMBER = 0x00008000, + MEASURE_YEAR = 0x00010000 }; class CPlayer @@ -87,16 +89,18 @@ public: void SetMeasures(INT measures) { m_Measures = measures; } StateType GetState() const { return m_State; } - LPCTSTR GetArtist() const{ return m_Artist.c_str(); } - LPCTSTR GetAlbum() const{ return m_Album.c_str(); } - LPCTSTR GetTitle() const{ return m_Title.c_str(); } - LPCTSTR GetLyrics() const{ return m_Lyrics.c_str(); } - LPCTSTR GetCoverPath() const{ return m_CoverPath.c_str(); } - LPCTSTR GetFilePath() const{ return m_FilePath.c_str(); } - UINT GetDuration() const{ return m_Duration; } - UINT GetPosition() const{ return m_Position; } - UINT GetRating() const{ return m_Rating; } - UINT GetVolume() const{ return m_Volume; } + LPCTSTR GetArtist() const { return m_Artist.c_str(); } + LPCTSTR GetAlbum() const { return m_Album.c_str(); } + LPCTSTR GetTitle() const { return m_Title.c_str(); } + LPCTSTR GetLyrics() const { return m_Lyrics.c_str(); } + LPCTSTR GetCoverPath() const { return m_CoverPath.c_str(); } + LPCTSTR GetFilePath() const { return m_FilePath.c_str(); } + UINT GetDuration() const { return m_Duration; } + UINT GetPosition() const { return m_Position; } + UINT GetRating() const { return m_Rating; } + UINT GetVolume() const { return m_Volume; } + UINT GetNumber() const { return m_Number; } + UINT GetYear() const { return m_Year; } bool GetShuffle() const { return m_Shuffle; } bool GetRepeat() const { return m_Repeat; } @@ -122,6 +126,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 + UINT m_Number; + UINT m_Year; bool m_Shuffle; bool m_Repeat; diff --git a/Plugins/PluginNowPlaying/PlayerAIMP.cpp b/Plugins/PluginNowPlaying/PlayerAIMP.cpp index 01aa5ab1..fab9f6fc 100644 --- a/Plugins/PluginNowPlaying/PlayerAIMP.cpp +++ b/Plugins/PluginNowPlaying/PlayerAIMP.cpp @@ -164,8 +164,9 @@ void CPlayerAIMP::UpdateData() stringData += info->nFileNameLen; stringData += info->nGenreLen; m_Title.assign(stringData, info->nTitleLen); - + m_Duration = info->nDuration / 1000; + m_Number = (UINT)info->nTrackID; 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); diff --git a/Plugins/PluginNowPlaying/PlayerCAD.cpp b/Plugins/PluginNowPlaying/PlayerCAD.cpp index 8625ce4f..a20eb999 100644 --- a/Plugins/PluginNowPlaying/PlayerCAD.cpp +++ b/Plugins/PluginNowPlaying/PlayerCAD.cpp @@ -275,43 +275,58 @@ LRESULT CALLBACK CPlayerCAD::WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM // TODO: Sent on track update? ++player->m_TrackCount; - std::wstring data = (WCHAR*)cds->lpData; - std::wstring::size_type len = data.find_first_of(L'\t'); - player->m_Title.assign(data, 0, len); - data.erase(0, ++len); + WCHAR* data = (WCHAR*)cds->lpData; + WCHAR* pos; + UINT index = 1; + while ((pos = wcschr(data, '\t')) != NULL) + { + switch (index) + { + case 1: + player->m_Title.assign(data, pos - data); + break; - len = data.find_first_of(L'\t'); - player->m_Artist.assign(data, 0, len); - data.erase(0, ++len); + case 2: + player->m_Artist.assign(data, pos - data); + break; - len = data.find_first_of(L'\t'); - player->m_Album.assign(data, 0, len); - data.erase(0, ++len); + case 3: + player->m_Album.assign(data, pos - data); + break; - len = data.find_first_of(L'\t'); // Skip genre - len = data.find_first_of(L'\t', ++len); // Skip year - len = data.find_first_of(L'\t', ++len); // Skip comments - len = data.find_first_of(L'\t', ++len); // Skip track no - data.erase(0, ++len); + case 5: + player->m_Year = (UINT)_wtoi(data); + break; - len = data.find_first_of(L'\t'); - std::wstring tmpStr(data, 0, len); - player->m_Duration = _wtoi(tmpStr.c_str()); - data.erase(0, ++len); + case 7: + player->m_Number = (UINT)_wtoi(data); + break; - len = data.find_first_of(L'\t'); - player->m_FilePath.assign(data, 0, len); - data.erase(0, ++len); + case 8: + player->m_Duration = (UINT)_wtoi(data); + break; - len = data.find_first_of(L'\t'); - tmpStr.assign(data, 0, len); - UINT rating = (_wtoi(tmpStr.c_str()) + 1) / 2; // From 0 - 10 to 0 - 5 - player->m_Rating = rating; - data.erase(0, ++len); + case 9: + player->m_FilePath.assign(data, pos - data); + break; - len = data.find_first_of(L'\t'); - player->m_CoverPath.assign(data, 0, len); - data.erase(0, ++len); + case 10: + player->m_Rating = ((UINT)_wtoi(data) + 1) / 2; // 0 - 10 -> 0 - 5 + break; + + case 11: + player->m_CoverPath.assign(data, pos - data); + break; + } + + data = pos + 1; + ++index; + + if (index == 12) + { + break; + } + } if (player->m_Measures & MEASURE_LYRICS) { @@ -436,7 +451,7 @@ void CPlayerCAD::SetPosition(int position) } /* -** Handles the SetVolume bang. +** Handles the SetRating bang. ** */ void CPlayerCAD::SetRating(int rating) diff --git a/Plugins/PluginNowPlaying/PlayerITunes.cpp b/Plugins/PluginNowPlaying/PlayerITunes.cpp index 71761a37..e6a7abb7 100644 --- a/Plugins/PluginNowPlaying/PlayerITunes.cpp +++ b/Plugins/PluginNowPlaying/PlayerITunes.cpp @@ -378,6 +378,12 @@ void CPlayerITunes::OnTrackChange() tmpVal /= 20L; m_Rating = (UINT)tmpVal; + track->get_TrackNumber(&tmpVal); + m_Number = (UINT)tmpVal; + + track->get_Year(&tmpVal); + m_Year = (UINT)tmpVal; + IITPlaylist* playlist; hr = track->get_Playlist(&playlist); if (SUCCEEDED(hr)) diff --git a/Plugins/PluginNowPlaying/PlayerWMP.cpp b/Plugins/PluginNowPlaying/PlayerWMP.cpp index 16448e61..878cdde4 100644 --- a/Plugins/PluginNowPlaying/PlayerWMP.cpp +++ b/Plugins/PluginNowPlaying/PlayerWMP.cpp @@ -397,6 +397,12 @@ void CPlayerWMP::UpdateData() m_Rating = rating; } + spMedia->getItemInfo(CComBSTR(L"WM/TrackNumber"), &val); + m_Number = (UINT)_wtoi(val); + + spMedia->getItemInfo(CComBSTR(L"WM/Year"), &val); + m_Year = (UINT)_wtoi(val); + double duration; spMedia->get_duration(&duration); m_Duration = (UINT)duration; diff --git a/Plugins/PluginNowPlaying/PlayerWinamp.cpp b/Plugins/PluginNowPlaying/PlayerWinamp.cpp index aa637d9a..673ad120 100644 --- a/Plugins/PluginNowPlaying/PlayerWinamp.cpp +++ b/Plugins/PluginNowPlaying/PlayerWinamp.cpp @@ -176,6 +176,8 @@ void CPlayerWinamp::UpdateData() m_Artist = tag->artist().toWString(); m_Album = tag->album().toWString(); m_Title = tag->title().toWString(); + m_Number = tag->track(); + m_Year = tag->year(); if (m_Measures & MEASURE_LYRICS) { diff --git a/Plugins/PluginNowPlaying/PluginNowPlaying.rc b/Plugins/PluginNowPlaying/PluginNowPlaying.rc index 9af74db7..0d9f9cfa 100644 --- a/Plugins/PluginNowPlaying/PluginNowPlaying.rc +++ b/Plugins/PluginNowPlaying/PluginNowPlaying.rc @@ -7,7 +7,7 @@ // VS_VERSION_INFO VERSIONINFO - FILEVERSION 1,1,3,7 + FILEVERSION 1,1,4,0 PRODUCTVERSION PRODUCTVER FILEFLAGSMASK 0x17L #ifdef _DEBUG @@ -23,8 +23,8 @@ BEGIN BEGIN BLOCK "040904E4" BEGIN - VALUE "FileVersion", "1.1.3.7" - VALUE "LegalCopyright", "© 2011 - Birunthan Mohanathas" + VALUE "FileVersion", "1.1.4.0" + VALUE "LegalCopyright", "© 2012 - Birunthan Mohanathas" VALUE "OriginalFilename", "NowPlaying.dll" VALUE "ProductName", "Rainmeter" #ifdef _WIN64