NowPlayingPlugin: Added PlayerType=FILE and fixed that TrackChangeAction is executed when track metadata is changed.

This commit is contained in:
Birunthan Mohanathas 2011-05-22 08:06:43 +00:00
parent e05aca67fc
commit ef97fb2435
12 changed files with 179 additions and 358 deletions

View File

@ -240,6 +240,10 @@ UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id)
data->measure = MEASURE_VOLUME;
maxValue = 100;
}
else if (_wcsicmp(L"FILE", str) == 0)
{
data->measure = MEASURE_FILE;
}
}
data->player->AddInstance(data->measure);
@ -280,14 +284,11 @@ UINT Update(UINT id)
// Only allow main measure to update
(*i).second->player->UpdateData();
}
CPlayer* player = (*i).second->player;
switch ((*i).second->measure)
{
case MEASURE_RATING:
return player->GetRating();
case MEASURE_DURATION:
return player->GetDuration();
@ -301,6 +302,9 @@ UINT Update(UINT id)
}
return 0;
case MEASURE_RATING:
return player->GetRating();
case MEASURE_STATE:
return (int)player->GetState();
@ -340,18 +344,6 @@ LPCTSTR GetString(UINT id, UINT flags)
case MEASURE_COVER:
return player->GetCoverPath();
case MEASURE_RATING:
_itow(player->GetRating(), buffer, 10);
return buffer;
case MEASURE_STATE:
_itow(player->GetState(), buffer, 10);
return buffer;
case MEASURE_VOLUME:
_itow(player->GetVolume(), buffer, 10);
return buffer;
case MEASURE_DURATION:
SecondsToTime(player->GetDuration(), buffer);
return buffer;
@ -368,6 +360,21 @@ LPCTSTR GetString(UINT id, UINT flags)
return buffer;
}
return L"0";
case MEASURE_RATING:
_itow(player->GetRating(), buffer, 10);
return buffer;
case MEASURE_STATE:
_itow(player->GetState(), buffer, 10);
return buffer;
case MEASURE_VOLUME:
_itow(player->GetVolume(), buffer, 10);
return buffer;
case MEASURE_FILE:
return player->GetFilePath();
}
}
else

View File

@ -92,6 +92,7 @@ void CPlayer::ClearInfo()
m_Artist.clear();
m_Album.clear();
m_Title.clear();
m_FilePath.clear();
m_CoverPath.clear();
}

View File

@ -64,7 +64,8 @@ enum MEASURETYPE
MEASURE_PROGRESS,
MEASURE_RATING,
MEASURE_STATE,
MEASURE_VOLUME
MEASURE_VOLUME,
MEASURE_FILE
};
class CPlayer
@ -93,6 +94,7 @@ public:
LPCTSTR GetArtist() { return m_Artist.c_str(); }
LPCTSTR GetAlbum() { return m_Album.c_str(); }
LPCTSTR GetTitle() { return m_Title.c_str(); }
LPCTSTR GetFilePath() { return m_FilePath.c_str(); }
LPCTSTR GetCoverPath() { return m_CoverPath.c_str(); }
LPCTSTR GetPlayerPath() { return m_PlayerPath.c_str(); }
UINT GetDuration() { return m_Duration; }
@ -122,6 +124,7 @@ protected:
std::wstring m_Artist;
std::wstring m_Album;
std::wstring m_Title;
std::wstring m_FilePath; // Path to playing file
std::wstring m_CoverPath; // Path to cover art image
std::wstring m_PlayerPath; // Path to player executable
UINT m_Duration; // Track duration in seconds

View File

@ -25,7 +25,7 @@
** Constructor.
**
*/
CPlayerAIMP::CPlayerAIMP() :
CPlayerAIMP::CPlayerAIMP() : CPlayer(),
m_HasCoverMeasure(false),
m_FileMap(),
m_FileMapHandle(),
@ -183,7 +183,6 @@ void CPlayerAIMP::UpdateData()
info->nFileSize != oldFileSize || // FileSize and TitleLen are probably unique enough
info->nTitleLen != oldTitleLen)
{
m_TrackChanged = true;
oldFileSize = info->nFileSize;
oldTitleLen = info->nTitleLen;
@ -199,7 +198,45 @@ void CPlayerAIMP::UpdateData()
stringData += info->nArtistLen;
stringData += info->nDateLen;
std::wstring filename(stringData, info->nFileNameLen);
std::wstring filepath(stringData, info->nFileNameLen);
if (filepath != m_FilePath)
{
m_FilePath = filepath;
m_TrackChanged = true;
if (m_HasCoverMeasure)
{
std::wstring cover = CreateCoverArtPath();
if (_waccess(cover.c_str(), 0) == 0)
{
// Cover is in cache, lets use the that
m_CoverPath = cover;
return;
}
TagLib::FileRef fr(m_FilePath.c_str());
if (!fr.isNull() && fr.tag() && GetEmbeddedArt(fr, cover))
{
// Embedded art found
return;
}
// Get rid of the name and extension from filename
std::wstring trackFolder = m_FilePath;
std::wstring::size_type pos = trackFolder.find_last_of(L'\\');
if (pos == std::wstring::npos) return;
trackFolder.resize(++pos);
if (GetLocalArt(trackFolder, L"cover") || GetLocalArt(trackFolder, L"folder"))
{
// Local art found
return;
}
// Nothing found
m_CoverPath.clear();
}
}
stringData += info->nFileNameLen;
stringData += info->nGenreLen;
@ -212,39 +249,6 @@ void CPlayerAIMP::UpdateData()
// Get the rating through the AIMP Winamp API
m_Rating = SendMessage(m_WinampWindow, WM_WA_IPC, 0, IPC_GETRATING);
}
if (m_HasCoverMeasure)
{
std::wstring cover = CreateCoverArtPath();
if (_waccess(cover.c_str(), 0) == 0)
{
// Cover is in cache, lets use the that
m_CoverPath = cover;
return;
}
TagLib::FileRef fr(filename.c_str());
if (!fr.isNull() && fr.tag() && GetEmbeddedArt(fr, cover))
{
// Embedded art found
return;
}
// Get rid of the name and extension from filename
std::wstring trackFolder = filename;
std::wstring::size_type pos = trackFolder.find_last_of(L'\\');
if (pos == std::wstring::npos) return;
trackFolder.resize(++pos);
if (GetLocalArt(trackFolder, L"cover") || GetLocalArt(trackFolder, L"folder"))
{
// Local art found
return;
}
// Nothing found
m_CoverPath.clear();
}
}
}

View File

@ -25,7 +25,7 @@
** Constructor.
**
*/
CPlayerFoobar::CPlayerFoobar() :
CPlayerFoobar::CPlayerFoobar() : CPlayer(),
m_HasCoverMeasure(false),
m_Window(),
m_FooWindow()
@ -209,12 +209,6 @@ LRESULT CALLBACK CPlayerFoobar::WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPAR
foobar->m_State = PLAYER_PLAYING;
}
if (foobar->m_Position != 0)
{
foobar->m_Position = 0;
foobar->m_TrackChanged = true;
}
// In the format "TITLE ARTIST ALBUM LENGTH RATING" (seperated by \t)
WCHAR buffer[1024];
MultiByteToWideChar(CP_UTF8, 0, (char*)cds->lpData, cds->cbData, buffer, 1024);
@ -248,7 +242,14 @@ LRESULT CALLBACK CPlayerFoobar::WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPAR
token = wcstok(NULL, L"\t");
if (token)
{
foobar->GetCoverArt(token);
if (wcscmp(token, foobar->m_FilePath.c_str()) != 0)
{
// If different file
foobar->m_FilePath = token;
foobar->m_TrackChanged = true;
foobar->m_Position = 0;
foobar->GetCoverArt(token);
}
}
}
}

View File

@ -1,163 +0,0 @@
/*
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
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "StdAfx.h"
#include "PlayerGeneric.h"
extern std::wstring g_CachePath;
/*
** CPlayerGeneric
**
** Constructor.
**
*/
CPlayerGeneric::CPlayerGeneric()
{
}
/*
** ~CPlayerGeneric
**
** Destructor.
**
*/
CPlayerGeneric::~CPlayerGeneric()
{
}
/*
** AddInstance
**
** Called during initialization of each measure.
**
*/
void CPlayerGeneric::AddInstance(MEASURETYPE type)
{
++m_InstanceCount;
}
/*
** RemoveInstance
**
** Called during destruction of each measure.
**
*/
void CPlayerGeneric::RemoveInstance()
{
if (--m_InstanceCount == 0)
{
delete this;
}
}
/*
** UpdateData
**
** Called during each update of the main measure.
**
*/
void CPlayerGeneric::UpdateData()
{
// The main measure is the measure without square brackets in MediaPlayer=. In other words,
// MediaPlayer=SOME_MEDIA_PLAYER is the main measure, whereas MediaPlayer=[MAIN_MEASURE] is not.
}
/*
** Play
**
** Handles the Play bang.
**
*/
void CPlayerGeneric::Play()
{
}
/*
** PlayPause
**
** Handles the PlayPause bang.
**
*/
void CPlayerGeneric::PlayPause()
{
}
/*
** Stop
**
** Handles the Stop bang.
**
*/
void CPlayerGeneric::Stop()
{
}
/*
** Next
**
** Handles the Next bang.
**
*/
void CPlayerGeneric::Next()
{
}
/*
** Previous
**
** Handles the Previous bang.
**
*/
void CPlayerGeneric::Previous()
{
}
/*
** SetRating
**
** Handles the SetRating bang.
**
*/
void CPlayerGeneric::SetRating(int rating)
{
// rating is between 0 - 5
}
/*
** ChangeVolume
**
** Handles the ChangeVolume bang.
**
*/
void CPlayerGeneric::ChangeVolume(int volume)
{
// volume is either positive or negative (increase/decrease current volume by that many %).
// Remember to handle special cases if necessary (e.g. current volume is 90% and ChangeVolume(50) is called).
}
/*
** SetVolume
**
** Handles the SetVolume bang.
**
*/
void CPlayerGeneric::SetVolume(int volume)
{
// volume is between 0 - 100
}

View File

@ -1,46 +0,0 @@
/*
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
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __PLAYERGENERIC_H__
#define __PLAYERGENERIC_H__
#include "Player.h"
class CPlayerGeneric : public CPlayer
{
public:
CPlayerGeneric();
~CPlayerGeneric();
virtual void Play();
virtual void PlayPause();
virtual void Stop();
virtual void Next();
virtual void Previous();
virtual void SetRating(int rating);
virtual void SetVolume(int volume);
virtual void ChangeVolume(int volume);
virtual void SetPlayerPath(LPCTSTR path) { m_PlayerPath = path; }
virtual void AddInstance(MEASURETYPE type);
virtual void RemoveInstance();
virtual void UpdateData();
};
#endif

View File

@ -115,7 +115,7 @@ HRESULT STDMETHODCALLTYPE CPlayerITunes::CEventHandler::Invoke(DISPID dispidMemb
** Constructor.
**
*/
CPlayerITunes::CPlayerITunes() :
CPlayerITunes::CPlayerITunes() : CPlayer(),
m_Initialized(false),
m_UserQuitPrompt(false),
m_HasCoverMeasure(false),
@ -338,7 +338,6 @@ void CPlayerITunes::OnTrackChange()
if (SUCCEEDED(hr))
{
m_TrackChanged = true;
CComBSTR tmpStr;
long tmpVal;
@ -359,45 +358,58 @@ void CPlayerITunes::OnTrackChange()
tmpVal /= 20L;
m_Rating = (UINT)tmpVal;
if (m_HasCoverMeasure)
IITFileOrCDTrack* file;
hr = track->QueryInterface(&file);
if (SUCCEEDED(hr))
{
// Check if MP3 file contains embedded art
std::wstring cover = CreateCoverArtPath();
if (_waccess(cover.c_str(), 0) == 0)
file->get_Location(&tmpStr);
file->Release();
if (tmpStr && wcscmp(tmpStr, m_FilePath.c_str()) != 0)
{
// Cover is in cache, lets use the that
m_CoverPath = cover;
}
else
{
IITArtworkCollection* artworkCollection;
hr = track->get_Artwork(&artworkCollection);
m_FilePath = tmpStr;
m_TrackChanged = true;
if (SUCCEEDED(hr))
if (m_HasCoverMeasure)
{
long count;
artworkCollection->get_Count(&count);
if (count > 0)
// Check if MP3 file contains embedded art
std::wstring cover = CreateCoverArtPath();
if (_waccess(cover.c_str(), 0) == 0)
{
IITArtwork* artwork;
hr = artworkCollection->get_Item(1, &artwork);
if (SUCCEEDED(hr))
{
tmpStr = cover.c_str();
hr = artwork->SaveArtworkToFile(tmpStr);
SUCCEEDED(hr) ? m_CoverPath = cover : m_CoverPath.clear();
artwork->Release();
}
// Cover is in cache, lets use the that
m_CoverPath = cover;
}
else
{
m_CoverPath.clear();
}
IITArtworkCollection* artworkCollection;
hr = track->get_Artwork(&artworkCollection);
artworkCollection->Release();
if (SUCCEEDED(hr))
{
long count;
artworkCollection->get_Count(&count);
if (count > 0)
{
IITArtwork* artwork;
hr = artworkCollection->get_Item(1, &artwork);
if (SUCCEEDED(hr))
{
tmpStr = cover.c_str();
hr = artwork->SaveArtworkToFile(tmpStr);
SUCCEEDED(hr) ? m_CoverPath = cover : m_CoverPath.clear();
artwork->Release();
}
}
else
{
m_CoverPath.clear();
}
artworkCollection->Release();
}
}
}
}
}

View File

@ -25,7 +25,7 @@
** Constructor.
**
*/
CPlayerSpotify::CPlayerSpotify() :
CPlayerSpotify::CPlayerSpotify() : CPlayer(),
m_Window()
{
GetWindow();

View File

@ -147,7 +147,7 @@ void CPlayerWMP::CRemoteHost::SwitchedToControl()
** Constructor.
**
*/
CPlayerWMP::CPlayerWMP() :
CPlayerWMP::CPlayerWMP() : CPlayer(),
m_Initialized(false),
m_HasCoverMeasure(false),
m_ComModule(),
@ -448,58 +448,63 @@ void CPlayerWMP::UpdateData()
spMedia->get_duration(&duration);
m_Duration = (UINT)duration;
// TODO: Better solution for this
if (m_HasCoverMeasure || m_InstanceCount == 0)
CComBSTR url;
spMedia->get_sourceURL(&url);
std::wstring targetPath = url;
if (targetPath != m_FilePath)
{
CComBSTR url;
spMedia->get_sourceURL(&url);
spMedia->getItemInfo(CComBSTR("WM/WMCollectionID"), &val);
std::wstring targetPath = url;
m_FilePath = targetPath;
targetPath.resize(targetPath.find_last_of(L'\\') + 1);
targetPath += L"AlbumArt_";
targetPath += val;
targetPath += L"_Large.jpg";
if (_waccess(targetPath.c_str(), 0) == 0)
// TODO: Better solution for this
if (m_HasCoverMeasure || m_InstanceCount == 0)
{
m_CoverPath = targetPath;
spMedia->getItemInfo(CComBSTR("WM/WMCollectionID"), &val);
targetPath.resize(targetPath.find_last_of(L'\\') + 1);
targetPath += L"AlbumArt_";
targetPath += val;
targetPath += L"_Large.jpg";
if (_waccess(targetPath.c_str(), 0) == 0)
{
m_CoverPath = targetPath;
}
else
{
std::wstring cover = CreateCoverArtPath();
if (_waccess(cover.c_str(), 0) == 0)
{
// Cover is in cache, lets use the that
m_CoverPath = cover;
return;
}
TagLib::FileRef fr(url.m_str);
if (!fr.isNull() && fr.tag() && GetEmbeddedArt(fr, cover))
{
// Embedded art found
return;
}
// Get rid of the name and extension from filename
std::wstring trackFolder = url;
std::wstring::size_type pos = trackFolder.find_last_of(L'\\');
if (pos == std::wstring::npos) return;
trackFolder.resize(++pos);
if (GetLocalArt(trackFolder, L"cover") || GetLocalArt(trackFolder, L"folder"))
{
// Local art found
return;
}
// Nothing found
m_CoverPath.clear();
}
}
else
{
std::wstring cover = CreateCoverArtPath();
if (_waccess(cover.c_str(), 0) == 0)
{
// Cover is in cache, lets use the that
m_CoverPath = cover;
return;
}
TagLib::FileRef fr(url.m_str);
if (!fr.isNull() && fr.tag() && GetEmbeddedArt(fr, cover))
{
// Embedded art found
return;
}
// Get rid of the name and extension from filename
std::wstring trackFolder = url;
std::wstring::size_type pos = trackFolder.find_last_of(L'\\');
if (pos == std::wstring::npos) return;
trackFolder.resize(++pos);
if (GetLocalArt(trackFolder, L"cover") || GetLocalArt(trackFolder, L"folder"))
{
// Local art found
return;
}
// Nothing found
m_CoverPath.clear();
}
ExecuteTrackChangeAction();
}
ExecuteTrackChangeAction();
}
}
}

View File

@ -25,7 +25,7 @@
** Constructor.
**
*/
CPlayerWinamp::CPlayerWinamp() :
CPlayerWinamp::CPlayerWinamp() : CPlayer(),
m_HasCoverMeasure(false),
m_Window()
{
@ -155,11 +155,9 @@ void CPlayerWinamp::UpdateData()
int playing = SendMessage(m_Window, WM_WA_IPC, 0, IPC_ISPLAYING);
if (playing == 0)
{
if (!m_Path.empty())
if (!m_FilePath.empty())
{
ClearInfo();
m_State = PLAYER_STOPPED;
m_Path.clear();
}
return; // Don't continue if stopped
}
@ -178,10 +176,10 @@ void CPlayerWinamp::UpdateData()
{
LSLog(LOG_ERROR, L"Rainmeter", L"NowPlayingPlugin: Failed to read Winamp memory");
}
else if (wcscmp(buffer, m_Path.c_str()) != 0)
else if (wcscmp(buffer, m_FilePath.c_str()) != 0)
{
m_TrackChanged = true;
m_Path = buffer;
m_FilePath = buffer;
m_Rating = SendMessage(m_Window, WM_WA_IPC, 0, IPC_GETRATING);
m_Duration = SendMessage(m_Window, WM_WA_IPC, 1, IPC_GETOUTPUTTIME);
@ -236,7 +234,7 @@ void CPlayerWinamp::UpdateData()
}
// Get rid of the name and extension from filename
std::wstring trackFolder = m_Path;
std::wstring trackFolder = m_FilePath;
std::wstring::size_type pos = trackFolder.find_last_of(L'\\');
if (pos == std::wstring::npos) return;
trackFolder.resize(++pos);

View File

@ -51,7 +51,6 @@ private:
bool Initialize();
bool CheckActive();
std::wstring m_Path;
bool m_HasCoverMeasure;
HWND m_Window; // Winamp window
HANDLE m_WinampHandle; // Handle to Winamp process