mirror of
https://github.com/chibicitiberiu/rainmeter-studio.git
synced 2024-02-24 04:33:31 +00:00
NowPlayingPlugin: Added PlayerType=FILE and fixed that TrackChangeAction is executed when track metadata is changed.
This commit is contained in:
parent
e05aca67fc
commit
ef97fb2435
@ -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);
|
||||
@ -285,9 +289,6 @@ UINT Update(UINT id)
|
||||
|
||||
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
|
||||
|
@ -92,6 +92,7 @@ void CPlayer::ClearInfo()
|
||||
m_Artist.clear();
|
||||
m_Album.clear();
|
||||
m_Title.clear();
|
||||
m_FilePath.clear();
|
||||
m_CoverPath.clear();
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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,19 +198,11 @@ void CPlayerAIMP::UpdateData()
|
||||
|
||||
stringData += info->nArtistLen;
|
||||
stringData += info->nDateLen;
|
||||
std::wstring filename(stringData, info->nFileNameLen);
|
||||
|
||||
stringData += info->nFileNameLen;
|
||||
stringData += info->nGenreLen;
|
||||
m_Title.assign(stringData, info->nTitleLen);
|
||||
|
||||
m_Duration = info->nDuration / 1000;
|
||||
|
||||
if (m_WinampWindow)
|
||||
std::wstring filepath(stringData, info->nFileNameLen);
|
||||
if (filepath != m_FilePath)
|
||||
{
|
||||
// Get the rating through the AIMP Winamp API
|
||||
m_Rating = SendMessage(m_WinampWindow, WM_WA_IPC, 0, IPC_GETRATING);
|
||||
}
|
||||
m_FilePath = filepath;
|
||||
m_TrackChanged = true;
|
||||
|
||||
if (m_HasCoverMeasure)
|
||||
{
|
||||
@ -223,7 +214,7 @@ void CPlayerAIMP::UpdateData()
|
||||
return;
|
||||
}
|
||||
|
||||
TagLib::FileRef fr(filename.c_str());
|
||||
TagLib::FileRef fr(m_FilePath.c_str());
|
||||
if (!fr.isNull() && fr.tag() && GetEmbeddedArt(fr, cover))
|
||||
{
|
||||
// Embedded art found
|
||||
@ -231,7 +222,7 @@ void CPlayerAIMP::UpdateData()
|
||||
}
|
||||
|
||||
// Get rid of the name and extension from filename
|
||||
std::wstring trackFolder = 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);
|
||||
@ -246,6 +237,19 @@ void CPlayerAIMP::UpdateData()
|
||||
m_CoverPath.clear();
|
||||
}
|
||||
}
|
||||
|
||||
stringData += info->nFileNameLen;
|
||||
stringData += info->nGenreLen;
|
||||
m_Title.assign(stringData, info->nTitleLen);
|
||||
|
||||
m_Duration = info->nDuration / 1000;
|
||||
|
||||
if (m_WinampWindow)
|
||||
{
|
||||
// Get the rating through the AIMP Winamp API
|
||||
m_Rating = SendMessage(m_WinampWindow, WM_WA_IPC, 0, IPC_GETRATING);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -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,10 +242,17 @@ LRESULT CALLBACK CPlayerFoobar::WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPAR
|
||||
token = wcstok(NULL, L"\t");
|
||||
if (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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
||||
default:
|
||||
|
@ -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
|
||||
}
|
@ -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
|
@ -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,6 +358,17 @@ void CPlayerITunes::OnTrackChange()
|
||||
tmpVal /= 20L;
|
||||
m_Rating = (UINT)tmpVal;
|
||||
|
||||
IITFileOrCDTrack* file;
|
||||
hr = track->QueryInterface(&file);
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
file->get_Location(&tmpStr);
|
||||
file->Release();
|
||||
if (tmpStr && wcscmp(tmpStr, m_FilePath.c_str()) != 0)
|
||||
{
|
||||
m_FilePath = tmpStr;
|
||||
m_TrackChanged = true;
|
||||
|
||||
if (m_HasCoverMeasure)
|
||||
{
|
||||
// Check if MP3 file contains embedded art
|
||||
@ -401,6 +411,8 @@ void CPlayerITunes::OnTrackChange()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
track->Release();
|
||||
}
|
||||
|
@ -25,7 +25,7 @@
|
||||
** Constructor.
|
||||
**
|
||||
*/
|
||||
CPlayerSpotify::CPlayerSpotify() :
|
||||
CPlayerSpotify::CPlayerSpotify() : CPlayer(),
|
||||
m_Window()
|
||||
{
|
||||
GetWindow();
|
||||
|
@ -147,7 +147,7 @@ void CPlayerWMP::CRemoteHost::SwitchedToControl()
|
||||
** Constructor.
|
||||
**
|
||||
*/
|
||||
CPlayerWMP::CPlayerWMP() :
|
||||
CPlayerWMP::CPlayerWMP() : CPlayer(),
|
||||
m_Initialized(false),
|
||||
m_HasCoverMeasure(false),
|
||||
m_ComModule(),
|
||||
@ -448,14 +448,18 @@ void CPlayerWMP::UpdateData()
|
||||
spMedia->get_duration(&duration);
|
||||
m_Duration = (UINT)duration;
|
||||
|
||||
CComBSTR url;
|
||||
spMedia->get_sourceURL(&url);
|
||||
std::wstring targetPath = url;
|
||||
|
||||
if (targetPath != m_FilePath)
|
||||
{
|
||||
m_FilePath = targetPath;
|
||||
|
||||
// TODO: Better solution for this
|
||||
if (m_HasCoverMeasure || m_InstanceCount == 0)
|
||||
{
|
||||
CComBSTR url;
|
||||
spMedia->get_sourceURL(&url);
|
||||
spMedia->getItemInfo(CComBSTR("WM/WMCollectionID"), &val);
|
||||
std::wstring targetPath = url;
|
||||
|
||||
targetPath.resize(targetPath.find_last_of(L'\\') + 1);
|
||||
targetPath += L"AlbumArt_";
|
||||
targetPath += val;
|
||||
@ -503,6 +507,7 @@ void CPlayerWMP::UpdateData()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
static DWORD oldTime = 0;
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user