2011-05-21 18:17:37 +00:00
|
|
|
/*
|
|
|
|
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
|
2012-01-23 06:36:15 +00:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2011-05-21 18:17:37 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "StdAfx.h"
|
|
|
|
#include "NowPlaying.h"
|
2011-06-19 14:58:48 +00:00
|
|
|
#include "Internet.h"
|
2011-05-21 18:17:37 +00:00
|
|
|
#include "PlayerAIMP.h"
|
2011-05-24 18:20:35 +00:00
|
|
|
#include "PlayerCAD.h"
|
2011-05-21 18:17:37 +00:00
|
|
|
#include "PlayerFoobar.h"
|
|
|
|
#include "PlayerITunes.h"
|
|
|
|
#include "PlayerSpotify.h"
|
|
|
|
#include "PlayerWinamp.h"
|
2011-06-12 10:05:37 +00:00
|
|
|
#include "PlayerWLM.h"
|
2011-05-21 18:17:37 +00:00
|
|
|
#include "PlayerWMP.h"
|
|
|
|
|
2012-01-08 17:35:29 +00:00
|
|
|
static std::vector<ParentMeasure*> g_ParentMeasures;
|
2011-06-12 10:05:37 +00:00
|
|
|
std::wstring g_SettingsFile;
|
2011-07-15 15:18:02 +00:00
|
|
|
HINSTANCE g_Instance = NULL;
|
2011-05-21 18:17:37 +00:00
|
|
|
|
2012-01-08 17:35:29 +00:00
|
|
|
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2012-01-08 17:35:29 +00:00
|
|
|
switch (fdwReason)
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2012-01-08 17:35:29 +00:00
|
|
|
case DLL_PROCESS_ATTACH:
|
|
|
|
g_Instance = hinstDLL;
|
2011-06-19 14:58:48 +00:00
|
|
|
|
2012-01-08 17:35:29 +00:00
|
|
|
// Disable DLL_THREAD_ATTACH and DLL_THREAD_DETACH notification calls
|
|
|
|
DisableThreadLibraryCalls(hinstDLL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-02-02 07:39:14 +00:00
|
|
|
PLUGIN_EXPORT void Initialize(void** data, void* rm)
|
2012-01-08 17:35:29 +00:00
|
|
|
{
|
|
|
|
Measure* measure = new Measure;
|
|
|
|
*data = measure;
|
|
|
|
|
|
|
|
if (g_SettingsFile.empty())
|
|
|
|
{
|
|
|
|
g_SettingsFile = RmGetSettingsFile();
|
2011-06-19 14:58:48 +00:00
|
|
|
CInternet::Initialize();
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
2012-01-08 17:35:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PLUGIN_EXPORT void Reload(void* data, void* rm, double* maxValue)
|
|
|
|
{
|
|
|
|
Measure* measure = (Measure*)data;
|
2011-05-21 18:17:37 +00:00
|
|
|
|
2012-01-08 17:35:29 +00:00
|
|
|
// Data is stored in two structs: Measure and ParentMeasure. ParentMeasure is created for measures
|
|
|
|
// with PlayerName=someplayer. Measure is created for all measures and points to ParentMeasure as
|
2011-06-17 19:07:06 +00:00
|
|
|
// referenced in PlayerName=[section].
|
2011-05-31 13:15:53 +00:00
|
|
|
|
2011-05-21 18:17:37 +00:00
|
|
|
// Read settings from the ini-file
|
2012-01-08 17:35:29 +00:00
|
|
|
void* skin = RmGetSkin(rm);
|
|
|
|
LPCWSTR str = RmReadString(rm, L"PlayerName", L"", FALSE);
|
|
|
|
if (str[0] == L'[')
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2012-01-08 17:35:29 +00:00
|
|
|
if (measure->parent)
|
|
|
|
{
|
|
|
|
// Don't let a measure measure change its parent
|
|
|
|
}
|
|
|
|
else
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2011-06-17 19:07:06 +00:00
|
|
|
// PlayerName starts with [ so use referenced section
|
2012-01-08 17:35:29 +00:00
|
|
|
++str;
|
|
|
|
int len = wcslen(str);
|
|
|
|
if (len > 0 && str[len - 1] == L']')
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2012-01-08 17:35:29 +00:00
|
|
|
--len;
|
|
|
|
|
|
|
|
std::vector<ParentMeasure*>::iterator iter = g_ParentMeasures.begin();
|
|
|
|
for ( ; iter != g_ParentMeasures.end(); ++iter)
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2012-01-08 17:35:29 +00:00
|
|
|
if (skin == (*iter)->skin &&
|
|
|
|
wcsncmp(str, (*iter)->ownerName, len) == 0)
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2011-06-17 19:07:06 +00:00
|
|
|
// Use same ParentMeasure as referenced section
|
2012-01-08 17:35:29 +00:00
|
|
|
measure->parent = (*iter);
|
|
|
|
++measure->parent->measureCount;
|
|
|
|
|
2011-06-17 19:07:06 +00:00
|
|
|
break;
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-02 12:27:37 +00:00
|
|
|
|
2012-01-08 17:35:29 +00:00
|
|
|
if (!measure->parent)
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2011-06-17 19:07:06 +00:00
|
|
|
// The referenced section doesn't exist
|
2011-10-12 13:34:04 +00:00
|
|
|
std::wstring error = L"NowPlaying.dll: Invalid PlayerName=";
|
2012-01-08 17:35:29 +00:00
|
|
|
error.append(str - 1, len + 2);
|
2011-06-17 19:07:06 +00:00
|
|
|
error += L" in [";
|
2012-01-08 17:35:29 +00:00
|
|
|
error += RmGetMeasureName(rm);
|
2011-09-11 08:22:07 +00:00
|
|
|
error += L"]";
|
2012-01-08 17:35:29 +00:00
|
|
|
RmLog(LOG_WARNING, error.c_str());
|
|
|
|
return;
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-01-08 17:35:29 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// ParentMeasure is created when PlayerName is an actual player (and not a reference)
|
|
|
|
ParentMeasure* parent = measure->parent;
|
|
|
|
CPlayer* oldPlayer = NULL;
|
|
|
|
if (parent)
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2012-01-08 17:35:29 +00:00
|
|
|
if (parent->data != data)
|
2011-05-28 07:50:33 +00:00
|
|
|
{
|
2012-01-08 17:35:29 +00:00
|
|
|
// Don't let a measure-only measure become a parent measure
|
|
|
|
return;
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
|
|
|
|
2012-01-08 17:35:29 +00:00
|
|
|
oldPlayer = parent->player;
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
2012-01-08 17:35:29 +00:00
|
|
|
else
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2012-01-08 17:35:29 +00:00
|
|
|
parent = new ParentMeasure;
|
|
|
|
g_ParentMeasures.push_back(parent);
|
|
|
|
parent->data = data;
|
|
|
|
parent->skin = skin;
|
|
|
|
parent->ownerName = RmGetMeasureName(rm);
|
|
|
|
measure->parent = parent;
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
2012-01-08 17:35:29 +00:00
|
|
|
|
|
|
|
if (_wcsicmp(L"AIMP", str) == 0)
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2012-01-08 17:35:29 +00:00
|
|
|
parent->player = CPlayerAIMP::Create();
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
2012-01-08 17:35:29 +00:00
|
|
|
else if (_wcsicmp(L"CAD", str) == 0)
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2012-01-08 17:35:29 +00:00
|
|
|
parent->player = CPlayerCAD::Create();
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
2012-01-08 17:35:29 +00:00
|
|
|
else if (_wcsicmp(L"foobar2000", str) == 0)
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2012-01-08 17:35:29 +00:00
|
|
|
parent->player = CPlayerFoobar::Create();
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
2012-01-08 17:35:29 +00:00
|
|
|
else if (_wcsicmp(L"iTunes", str) == 0)
|
2011-06-25 12:44:33 +00:00
|
|
|
{
|
2012-01-08 17:35:29 +00:00
|
|
|
parent->player = CPlayerITunes::Create();
|
2011-06-25 12:44:33 +00:00
|
|
|
}
|
2012-01-08 17:35:29 +00:00
|
|
|
else if (_wcsicmp(L"MediaMonkey", str) == 0)
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2012-01-08 17:35:29 +00:00
|
|
|
parent->player = CPlayerWinamp::Create(WA_MEDIAMONKEY);
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
2012-01-08 17:35:29 +00:00
|
|
|
else if (_wcsicmp(L"Spotify", str) == 0)
|
2011-09-11 08:22:07 +00:00
|
|
|
{
|
2012-01-08 17:35:29 +00:00
|
|
|
parent->player = CPlayerSpotify::Create();
|
2011-09-11 08:22:07 +00:00
|
|
|
}
|
2012-01-08 17:35:29 +00:00
|
|
|
else if (_wcsicmp(L"WinAmp", str) == 0)
|
2011-09-11 08:22:07 +00:00
|
|
|
{
|
2012-01-08 17:35:29 +00:00
|
|
|
parent->player = CPlayerWinamp::Create(WA_WINAMP);
|
2011-09-11 08:22:07 +00:00
|
|
|
}
|
2012-01-08 17:35:29 +00:00
|
|
|
else if (_wcsicmp(L"WMP", str) == 0)
|
2011-05-22 08:06:43 +00:00
|
|
|
{
|
2012-01-08 17:35:29 +00:00
|
|
|
parent->player = CPlayerWMP::Create();
|
2011-06-17 19:07:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-03-02 12:27:37 +00:00
|
|
|
// Default to WLM
|
|
|
|
parent->player = CPlayerWLM::Create();
|
|
|
|
|
|
|
|
if (_wcsicmp(L"WLM", str) != 0)
|
|
|
|
{
|
|
|
|
std::wstring error = L"NowPlaying.dll: Invalid PlayerName=";
|
|
|
|
error += str;
|
|
|
|
error += L" in [";
|
|
|
|
error += parent->ownerName;
|
|
|
|
error += L"]";
|
|
|
|
RmLog(LOG_ERROR, error.c_str());
|
|
|
|
}
|
2011-05-22 08:06:43 +00:00
|
|
|
}
|
2011-06-17 19:07:06 +00:00
|
|
|
|
2012-01-08 17:35:29 +00:00
|
|
|
parent->player->AddInstance();
|
|
|
|
parent->playerPath = RmReadString(rm, L"PlayerPath", L"", TRUE);
|
|
|
|
parent->trackChangeAction = RmReadString(rm, L"TrackChangeAction", L"", TRUE);
|
|
|
|
parent->disableLeadingZero = RmReadInt(rm, L"DisableLeadingZero", 0);
|
|
|
|
|
|
|
|
if (oldPlayer)
|
|
|
|
{
|
2012-02-12 15:03:38 +00:00
|
|
|
parent->player->SetMeasures(oldPlayer->GetMeasures());
|
|
|
|
|
2012-01-08 17:35:29 +00:00
|
|
|
// Remove instance here so that player doesn't have to reinitialize if PlayerName was
|
|
|
|
// not changed.
|
|
|
|
oldPlayer->RemoveInstance();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
str = RmReadString(rm, L"PlayerType", L"");
|
|
|
|
if (_wcsicmp(L"ARTIST", str) == 0)
|
|
|
|
{
|
|
|
|
measure->type = MEASURE_ARTIST;
|
|
|
|
}
|
|
|
|
else if (_wcsicmp(L"TITLE", str) == 0)
|
|
|
|
{
|
|
|
|
measure->type = MEASURE_TITLE;
|
|
|
|
}
|
|
|
|
else if (_wcsicmp(L"ALBUM", str) == 0)
|
|
|
|
{
|
|
|
|
measure->type = MEASURE_ALBUM;
|
|
|
|
}
|
|
|
|
else if (_wcsicmp(L"COVER", str) == 0)
|
|
|
|
{
|
|
|
|
measure->type = MEASURE_COVER;
|
|
|
|
}
|
|
|
|
else if (_wcsicmp(L"DURATION", str) == 0)
|
|
|
|
{
|
|
|
|
measure->type = MEASURE_DURATION;
|
|
|
|
}
|
|
|
|
else if (_wcsicmp(L"POSITION", str) == 0)
|
|
|
|
{
|
|
|
|
measure->type = MEASURE_POSITION;
|
|
|
|
}
|
|
|
|
else if (_wcsicmp(L"PROGRESS", str) == 0)
|
|
|
|
{
|
|
|
|
measure->type = MEASURE_PROGRESS;
|
|
|
|
*maxValue = 100.0;
|
|
|
|
}
|
|
|
|
else if (_wcsicmp(L"RATING", str) == 0)
|
|
|
|
{
|
|
|
|
measure->type = MEASURE_RATING;
|
|
|
|
*maxValue = 5.0;
|
|
|
|
}
|
|
|
|
else if (_wcsicmp(L"STATE", str) == 0)
|
|
|
|
{
|
|
|
|
measure->type = MEASURE_STATE;
|
|
|
|
}
|
|
|
|
else if (_wcsicmp(L"STATUS", str) == 0)
|
|
|
|
{
|
|
|
|
measure->type = MEASURE_STATUS;
|
|
|
|
}
|
|
|
|
else if (_wcsicmp(L"VOLUME", str) == 0)
|
|
|
|
{
|
|
|
|
measure->type = MEASURE_VOLUME;
|
|
|
|
*maxValue = 100.0;
|
|
|
|
}
|
|
|
|
else if (_wcsicmp(L"SHUFFLE", str) == 0)
|
|
|
|
{
|
|
|
|
measure->type = MEASURE_SHUFFLE;
|
|
|
|
}
|
|
|
|
else if (_wcsicmp(L"REPEAT", str) == 0)
|
|
|
|
{
|
|
|
|
measure->type = MEASURE_REPEAT;
|
|
|
|
}
|
|
|
|
else if (_wcsicmp(L"LYRICS", str) == 0)
|
|
|
|
{
|
|
|
|
RmLog(LOG_WARNING, L"NowPlaying.dll: Using undocumented PlayerType=LYRICS!");
|
|
|
|
measure->type = MEASURE_LYRICS;
|
|
|
|
}
|
|
|
|
else if (_wcsicmp(L"FILE", str) == 0)
|
|
|
|
{
|
|
|
|
measure->type = MEASURE_FILE;
|
|
|
|
}
|
2012-03-12 12:01:12 +00:00
|
|
|
else if (_wcsicmp(L"NUMBER", str) == 0)
|
|
|
|
{
|
|
|
|
measure->type = MEASURE_NUMBER;
|
|
|
|
}
|
|
|
|
else if (_wcsicmp(L"YEAR", str) == 0)
|
|
|
|
{
|
|
|
|
measure->type = MEASURE_YEAR;
|
|
|
|
}
|
2012-01-08 17:35:29 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
std::wstring error = L"NowPlaying.dll: Invalid PlayerType=";
|
|
|
|
error += str;
|
|
|
|
error += L" in [";
|
|
|
|
error += RmGetMeasureName(rm);
|
|
|
|
error += L"]";
|
|
|
|
RmLog(LOG_WARNING, error.c_str());
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
|
|
|
|
2012-01-08 17:35:29 +00:00
|
|
|
measure->parent->player->AddMeasure(measure->type);
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
|
|
|
|
2012-01-08 17:35:29 +00:00
|
|
|
PLUGIN_EXPORT double Update(void* data)
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2012-01-08 17:35:29 +00:00
|
|
|
Measure* measure = (Measure*)data;
|
|
|
|
ParentMeasure* parent = measure->parent;
|
|
|
|
if (!parent) return 0.0;
|
2011-06-17 19:07:06 +00:00
|
|
|
|
2012-01-08 17:35:29 +00:00
|
|
|
CPlayer* player = parent->player;
|
2011-06-17 19:07:06 +00:00
|
|
|
|
2012-01-08 17:35:29 +00:00
|
|
|
// Only allow parent measure to update
|
|
|
|
if (parent->data == data)
|
|
|
|
{
|
|
|
|
player->UpdateMeasure();
|
2011-06-19 14:58:48 +00:00
|
|
|
|
2012-01-08 17:35:29 +00:00
|
|
|
// Execute TrackChangeAction= if necessary
|
|
|
|
if (!parent->trackChangeAction.empty() &&
|
|
|
|
parent->trackCount != player->GetTrackCount())
|
2011-06-19 14:58:48 +00:00
|
|
|
{
|
2012-01-08 17:35:29 +00:00
|
|
|
RmExecute(parent->skin, parent->trackChangeAction.c_str());
|
|
|
|
parent->trackCount = player->GetTrackCount();
|
2011-06-19 14:58:48 +00:00
|
|
|
}
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
|
|
|
|
2012-01-08 17:35:29 +00:00
|
|
|
switch (measure->type)
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2012-01-08 17:35:29 +00:00
|
|
|
case MEASURE_DURATION:
|
|
|
|
return player->GetDuration();
|
2011-05-22 08:06:43 +00:00
|
|
|
|
2012-01-08 17:35:29 +00:00
|
|
|
case MEASURE_POSITION:
|
|
|
|
return player->GetPosition();
|
2011-05-21 18:17:37 +00:00
|
|
|
|
2012-01-08 17:35:29 +00:00
|
|
|
case MEASURE_PROGRESS:
|
|
|
|
if (player->GetDuration())
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2012-01-08 17:35:29 +00:00
|
|
|
return (player->GetPosition() * 100) / player->GetDuration();
|
|
|
|
}
|
|
|
|
return 0.0;
|
2011-05-22 08:06:43 +00:00
|
|
|
|
2012-01-08 17:35:29 +00:00
|
|
|
case MEASURE_RATING:
|
|
|
|
return player->GetRating();
|
2011-06-25 12:44:33 +00:00
|
|
|
|
2012-01-08 17:35:29 +00:00
|
|
|
case MEASURE_VOLUME:
|
|
|
|
return player->GetVolume();
|
2011-05-21 18:17:37 +00:00
|
|
|
|
2012-01-08 17:35:29 +00:00
|
|
|
case MEASURE_STATE:
|
2012-03-12 12:01:12 +00:00
|
|
|
return player->GetState();
|
2011-09-11 08:22:07 +00:00
|
|
|
|
2012-01-08 17:35:29 +00:00
|
|
|
case MEASURE_STATUS:
|
2012-03-12 12:01:12 +00:00
|
|
|
return player->IsInitialized();
|
2011-09-11 08:22:07 +00:00
|
|
|
|
2012-01-08 17:35:29 +00:00
|
|
|
case MEASURE_SHUFFLE:
|
2012-03-12 12:01:12 +00:00
|
|
|
return player->GetShuffle();
|
2011-05-22 11:05:23 +00:00
|
|
|
|
2012-01-08 17:35:29 +00:00
|
|
|
case MEASURE_REPEAT:
|
2012-03-12 12:01:12 +00:00
|
|
|
return player->GetRepeat();
|
|
|
|
|
|
|
|
case MEASURE_NUMBER:
|
|
|
|
return player->GetNumber();
|
|
|
|
|
|
|
|
case MEASURE_YEAR:
|
|
|
|
return player->GetYear();
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
|
|
|
|
2012-01-08 17:35:29 +00:00
|
|
|
return 0.0;
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
|
|
|
|
2012-01-08 17:35:29 +00:00
|
|
|
PLUGIN_EXPORT LPCWSTR GetString(void* data)
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2012-01-08 17:35:29 +00:00
|
|
|
Measure* measure = (Measure*)data;
|
|
|
|
ParentMeasure* parent = measure->parent;
|
2012-03-02 12:27:37 +00:00
|
|
|
if (!parent) return NULL;
|
2011-05-21 18:17:37 +00:00
|
|
|
|
2012-01-08 17:35:29 +00:00
|
|
|
const CPlayer* player = parent->player;
|
|
|
|
static WCHAR buffer[32];
|
2011-05-21 18:17:37 +00:00
|
|
|
|
2012-01-08 17:35:29 +00:00
|
|
|
switch (measure->type)
|
|
|
|
{
|
|
|
|
case MEASURE_ARTIST:
|
|
|
|
return player->GetArtist();
|
2011-05-21 18:17:37 +00:00
|
|
|
|
2012-01-08 17:35:29 +00:00
|
|
|
case MEASURE_TITLE:
|
|
|
|
return player->GetTitle();
|
2011-05-21 18:17:37 +00:00
|
|
|
|
2012-01-08 17:35:29 +00:00
|
|
|
case MEASURE_ALBUM:
|
|
|
|
return player->GetAlbum();
|
2011-06-19 14:58:48 +00:00
|
|
|
|
2012-01-08 17:35:29 +00:00
|
|
|
case MEASURE_LYRICS:
|
|
|
|
return player->GetLyrics();
|
2011-05-21 18:17:37 +00:00
|
|
|
|
2012-01-08 17:35:29 +00:00
|
|
|
case MEASURE_COVER:
|
|
|
|
return player->GetCoverPath();
|
2011-06-25 12:44:33 +00:00
|
|
|
|
2012-01-08 17:35:29 +00:00
|
|
|
case MEASURE_FILE:
|
|
|
|
return player->GetFilePath();
|
2011-05-21 18:17:37 +00:00
|
|
|
|
2012-01-08 17:35:29 +00:00
|
|
|
case MEASURE_DURATION:
|
|
|
|
SecondsToTime(player->GetDuration(), parent->disableLeadingZero, buffer);
|
|
|
|
return buffer;
|
2011-05-21 18:17:37 +00:00
|
|
|
|
2012-01-08 17:35:29 +00:00
|
|
|
case MEASURE_POSITION:
|
|
|
|
SecondsToTime(player->GetPosition(), parent->disableLeadingZero, buffer);
|
|
|
|
return buffer;
|
2011-05-22 08:06:43 +00:00
|
|
|
|
2012-01-08 17:35:29 +00:00
|
|
|
case MEASURE_PROGRESS:
|
|
|
|
_itow_s(player->GetDuration() ? ((player->GetPosition() * 100) / player->GetDuration()) : 0, buffer, 10);
|
|
|
|
return buffer;
|
2011-05-22 08:06:43 +00:00
|
|
|
|
2012-01-08 17:35:29 +00:00
|
|
|
case MEASURE_RATING:
|
|
|
|
_itow_s(player->GetRating(), buffer, 10);
|
|
|
|
return buffer;
|
2011-06-25 12:44:33 +00:00
|
|
|
|
2012-01-08 17:35:29 +00:00
|
|
|
case MEASURE_VOLUME:
|
|
|
|
_itow_s(player->GetVolume(), buffer, 10);
|
|
|
|
return buffer;
|
2011-05-22 08:06:43 +00:00
|
|
|
|
2012-01-08 17:35:29 +00:00
|
|
|
case MEASURE_STATE:
|
|
|
|
_itow_s(player->GetState(), buffer, 10);
|
|
|
|
return buffer;
|
2011-09-11 08:22:07 +00:00
|
|
|
|
2012-01-08 17:35:29 +00:00
|
|
|
case MEASURE_STATUS:
|
|
|
|
_itow_s((int)player->IsInitialized(), buffer, 10);
|
|
|
|
return buffer;
|
2011-09-11 08:22:07 +00:00
|
|
|
|
2012-01-08 17:35:29 +00:00
|
|
|
case MEASURE_SHUFFLE:
|
|
|
|
_itow_s((int)player->GetShuffle(), buffer, 10);
|
|
|
|
return buffer;
|
|
|
|
|
|
|
|
case MEASURE_REPEAT:
|
|
|
|
_itow_s((int)player->GetRepeat(), buffer, 10);
|
|
|
|
return buffer;
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
|
|
|
|
2011-11-10 12:09:50 +00:00
|
|
|
return NULL;
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
|
|
|
|
2012-01-08 17:35:29 +00:00
|
|
|
PLUGIN_EXPORT void Finalize(void* data)
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2012-01-08 17:35:29 +00:00
|
|
|
Measure* measure = (Measure*)data;
|
|
|
|
ParentMeasure* parent = measure->parent;
|
|
|
|
if (parent)
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2011-06-17 19:07:06 +00:00
|
|
|
CPlayer* player = parent->player;
|
2012-01-08 17:35:29 +00:00
|
|
|
if (--parent->measureCount == 0)
|
2011-07-29 17:18:21 +00:00
|
|
|
{
|
2012-01-08 17:35:29 +00:00
|
|
|
player->RemoveInstance();
|
|
|
|
delete parent;
|
|
|
|
|
|
|
|
std::vector<ParentMeasure*>::iterator iter = std::find(g_ParentMeasures.begin(), g_ParentMeasures.end(), parent);
|
|
|
|
g_ParentMeasures.erase(iter);
|
|
|
|
|
|
|
|
if (g_ParentMeasures.empty())
|
2011-07-29 17:18:21 +00:00
|
|
|
{
|
2012-01-08 17:35:29 +00:00
|
|
|
CInternet::Finalize();
|
2011-07-29 17:18:21 +00:00
|
|
|
}
|
|
|
|
}
|
2012-01-08 17:35:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
delete measure;
|
|
|
|
}
|
|
|
|
|
|
|
|
PLUGIN_EXPORT void ExecuteBang(void* data, LPCWSTR args)
|
|
|
|
{
|
|
|
|
Measure* measure = (Measure*)data;
|
|
|
|
ParentMeasure* parent = measure->parent;
|
|
|
|
if (!parent) return;
|
|
|
|
|
|
|
|
CPlayer* player = parent->player;
|
|
|
|
|
|
|
|
if (!player->IsInitialized())
|
|
|
|
{
|
|
|
|
if (_wcsicmp(args, L"OpenPlayer") == 0 || _wcsicmp(args, L"TogglePlayer") == 0)
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2011-07-29 10:42:10 +00:00
|
|
|
player->OpenPlayer(parent->playerPath);
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
2012-01-08 17:35:29 +00:00
|
|
|
}
|
|
|
|
else if (_wcsicmp(args, L"Pause") == 0)
|
|
|
|
{
|
|
|
|
player->Pause();
|
|
|
|
}
|
|
|
|
else if (_wcsicmp(args, L"Play") == 0)
|
|
|
|
{
|
|
|
|
player->Play();
|
|
|
|
}
|
|
|
|
else if (_wcsicmp(args, L"PlayPause") == 0)
|
|
|
|
{
|
|
|
|
(player->GetState() != STATE_PLAYING) ? player->Play() : player->Pause();
|
|
|
|
}
|
|
|
|
else if (_wcsicmp(args, L"Next") == 0)
|
|
|
|
{
|
|
|
|
player->Next();
|
|
|
|
}
|
|
|
|
else if (_wcsicmp(args, L"Previous") == 0)
|
|
|
|
{
|
|
|
|
player->Previous();
|
|
|
|
}
|
|
|
|
else if (_wcsicmp(args, L"Stop") == 0)
|
|
|
|
{
|
|
|
|
player->Stop();
|
|
|
|
}
|
|
|
|
else if (_wcsicmp(args, L"OpenPlayer") == 0)
|
|
|
|
{
|
|
|
|
player->OpenPlayer(parent->playerPath);
|
|
|
|
}
|
|
|
|
else if (_wcsicmp(args, L"ClosePlayer") == 0 || _wcsicmp(args, L"TogglePlayer") == 0)
|
|
|
|
{
|
|
|
|
player->ClosePlayer();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LPCWSTR arg = wcschr(args, L' ');
|
|
|
|
|
|
|
|
if (arg)
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2012-01-08 17:35:29 +00:00
|
|
|
++arg; // Skip the space
|
2011-05-21 18:17:37 +00:00
|
|
|
|
2012-01-08 17:35:29 +00:00
|
|
|
if (wcsnicmp(args, L"SetPosition", 11) == 0)
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2012-01-08 17:35:29 +00:00
|
|
|
int position = (_wtoi(arg) * (int)player->GetDuration()) / 100;
|
|
|
|
if (arg[0] == L'+' || arg[0] == L'-')
|
2011-06-09 09:47:55 +00:00
|
|
|
{
|
2012-01-08 17:35:29 +00:00
|
|
|
position += player->GetPosition();
|
2011-06-09 09:47:55 +00:00
|
|
|
}
|
2012-01-08 17:35:29 +00:00
|
|
|
|
|
|
|
player->SetPosition(position);
|
|
|
|
}
|
|
|
|
else if (wcsnicmp(args, L"SetRating", 9) == 0)
|
|
|
|
{
|
|
|
|
int rating = _wtoi(arg);
|
|
|
|
if (rating >= 0 && rating <= 5)
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2012-01-08 17:35:29 +00:00
|
|
|
player->SetRating(rating);
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
2012-01-08 17:35:29 +00:00
|
|
|
}
|
|
|
|
else if (wcsnicmp(args, L"SetVolume", 9) == 0)
|
|
|
|
{
|
|
|
|
int volume = _wtoi(arg);
|
|
|
|
if (arg[0] == L'+' || arg[0] == L'-')
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2012-01-08 17:35:29 +00:00
|
|
|
// Relative to current volume
|
|
|
|
volume += player->GetVolume();
|
|
|
|
}
|
2011-09-11 08:22:07 +00:00
|
|
|
|
2012-01-08 17:35:29 +00:00
|
|
|
if (volume < 0)
|
|
|
|
{
|
|
|
|
volume = 0;
|
2011-09-11 08:22:07 +00:00
|
|
|
}
|
2012-01-08 17:35:29 +00:00
|
|
|
else if (volume > 100)
|
2011-09-11 08:22:07 +00:00
|
|
|
{
|
2012-01-08 17:35:29 +00:00
|
|
|
volume = 100;
|
2011-09-11 08:22:07 +00:00
|
|
|
}
|
2012-01-08 17:35:29 +00:00
|
|
|
player->SetVolume(volume);;
|
|
|
|
}
|
|
|
|
else if (wcsnicmp(args, L"SetShuffle", 9) == 0)
|
|
|
|
{
|
|
|
|
int state = _wtoi(arg);
|
|
|
|
if (state == -1)
|
2011-09-11 08:22:07 +00:00
|
|
|
{
|
2012-01-08 17:35:29 +00:00
|
|
|
player->SetShuffle(!player->GetShuffle());
|
|
|
|
}
|
|
|
|
else if (state == 0 || state == 1)
|
|
|
|
{
|
|
|
|
player->SetShuffle((bool)state);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (wcsnicmp(args, L"SetRepeat", 9) == 0)
|
|
|
|
{
|
|
|
|
int state = _wtoi(arg);
|
|
|
|
if (state == -1)
|
|
|
|
{
|
|
|
|
player->SetRepeat(!player->GetRepeat());
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
2012-01-08 17:35:29 +00:00
|
|
|
else if (state == 0 || state == 1)
|
2011-05-21 18:17:37 +00:00
|
|
|
{
|
2012-01-08 17:35:29 +00:00
|
|
|
player->SetRepeat((bool)state);
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
|
|
|
}
|
2011-10-12 13:34:04 +00:00
|
|
|
else
|
|
|
|
{
|
2012-01-08 17:35:29 +00:00
|
|
|
RmLog(LOG_WARNING, L"NowPlaying.dll: Unknown args");
|
2011-10-12 13:34:04 +00:00
|
|
|
}
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
2012-01-08 17:35:29 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
RmLog(LOG_WARNING, L"NowPlaying.dll: Unknown args");
|
|
|
|
}
|
2011-05-21 18:17:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-17 19:07:06 +00:00
|
|
|
void SecondsToTime(UINT seconds, bool leadingZero, WCHAR* buffer)
|
|
|
|
{
|
|
|
|
int hours = seconds;
|
|
|
|
int mins = seconds;
|
|
|
|
hours /= 3600;
|
|
|
|
mins %= 3600;
|
|
|
|
int secs = mins;
|
|
|
|
mins /= 60;
|
|
|
|
secs %= 60;
|
|
|
|
|
2011-09-11 08:22:07 +00:00
|
|
|
if (seconds < 0)
|
|
|
|
{
|
|
|
|
hours = mins = secs = 0;
|
|
|
|
}
|
|
|
|
|
2011-06-17 19:07:06 +00:00
|
|
|
if (hours)
|
|
|
|
{
|
|
|
|
_snwprintf_s(buffer, 32, _TRUNCATE, leadingZero ? L"%i:%02i:%02i" : L"%02i:%02i:%02i", hours, mins, secs);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_snwprintf_s(buffer, 32, _TRUNCATE, leadingZero ? L"%i:%02i" : L"%02i:%02i", mins, secs);
|
|
|
|
}
|
|
|
|
}
|