Skip to content

Commit

Permalink
1.0.0.9
Browse files Browse the repository at this point in the history
  • Loading branch information
Exle committed Apr 17, 2020
1 parent b2e4229 commit 42ba79e
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 121 deletions.
Binary file added .github/aimp_icons/aimp_pause.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/aimp_icons/aimp_play.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/aimp_icons/aimp_radio.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/aimp_icons/defaultcover.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
96 changes: 32 additions & 64 deletions AIMPRemote.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//#define _CRT_SECURE_NO_WARNINGS
#include "aimpRemote.h"
//#include <malloc.h>
#include <wchar.h>
#include "helper.h"

AIMPRemote* AIMPRemote::PAIMPRemote;

Expand All @@ -11,10 +9,6 @@ AIMPRemote::AIMPRemote()
{
PAIMPRemote = this;
ARState = AIMPREMOTE_PLAYER_STATE_STOPPED;
//ARTrackInfo = { 0 };
//ARVersion = { 0 };
//ARPosition = { 0 };
//AREvents = { 0 };
}

AIMPRemote::~AIMPRemote()
Expand All @@ -30,15 +24,15 @@ AIMPRemote::~AIMPRemote()
}
}

VOID AIMPRemote::AIMPExecuteCommand(INT Command)
void AIMPRemote::AIMPExecuteCommand(int Command)
{
if (PAIMPRemote->FAIMPRemoteHandle != NULL)
{
SendMessage(PAIMPRemote->FAIMPRemoteHandle, WM_AIMP_COMMAND, Command, 0);
}
}

INT AIMPRemote::AIMPGetPropertyValue(INT PropertyID)
int AIMPRemote::AIMPGetPropertyValue(int PropertyID)
{
if (PAIMPRemote->FAIMPRemoteHandle != NULL)
{
Expand All @@ -48,7 +42,7 @@ INT AIMPRemote::AIMPGetPropertyValue(INT PropertyID)
return 0;
}

BOOL AIMPRemote::AIMPSetPropertyValue(INT PropertyID, INT AValue)
bool AIMPRemote::AIMPSetPropertyValue(int PropertyID, int AValue)
{
if (PAIMPRemote->FAIMPRemoteHandle != NULL)
{
Expand All @@ -58,12 +52,12 @@ BOOL AIMPRemote::AIMPSetPropertyValue(INT PropertyID, INT AValue)
return false;
}

VOID AIMPRemote::AIMPSetEvents(AIMPEvents* Events)
void AIMPRemote::AIMPSetEvents(AIMPEvents* Events)
{
PAIMPRemote->AREvents = *Events;
}

BOOL AIMPRemote::AIMPSetRemoteHandle(const HWND* Value)
bool AIMPRemote::AIMPSetRemoteHandle(const HWND* Value)
{
if (PAIMPRemote->FAIMPRemoteHandle == *Value)
{
Expand Down Expand Up @@ -91,26 +85,22 @@ BOOL AIMPRemote::AIMPSetRemoteHandle(const HWND* Value)
{
PAIMPRemote->MyWnd = CreateWindowExW(WS_EX_CLIENTEDGE, AIMPRemoteClassName, AIMPRemoteClassName, NULL, NULL, NULL, NULL, NULL, HWND_MESSAGE, NULL, NULL, NULL);
}
else return false;
}

PAIMPRemote->FAIMPRemoteHandle = *Value;

SendMessage(PAIMPRemote->FAIMPRemoteHandle, WM_AIMP_COMMAND, AIMP_RA_CMD_REGISTER_NOTIFY, reinterpret_cast<LPARAM>(PAIMPRemote->MyWnd));

PAIMPRemote->InfoUpdateVersionInfo();
PAIMPRemote->InfoUpdatePlayerState();
PAIMPRemote->InfoUpdateTrackInfo();
PAIMPRemote->InfoUpdatePlayerState();
PAIMPRemote->InfoUpdateTrackPositionInfo();

if (!PAIMPRemote->MyWnd)
{
return false;
}

SendMessage(PAIMPRemote->FAIMPRemoteHandle, WM_AIMP_COMMAND, AIMP_RA_CMD_REGISTER_NOTIFY, reinterpret_cast<LPARAM>(PAIMPRemote->MyWnd));

return true;
}

BOOL AIMPRemote::InfoUpdateTrackInfo()
bool AIMPRemote::InfoUpdateTrackInfo()
{
if (!AREvents.TrackInfo)
{
Expand Down Expand Up @@ -155,45 +145,19 @@ BOOL AIMPRemote::InfoUpdateTrackInfo()
ARTrackInfo.GenreLength = AIMPRemote_TrackInfo->GenreLength;
ARTrackInfo.TitleLength = AIMPRemote_TrackInfo->TitleLength;

PWCHAR buffer;

ARTrackInfo.Album = new char[AIMPRemote_TrackInfo->AlbumLength * 2];
ARTrackInfo.Artist = new char[AIMPRemote_TrackInfo->ArtistLength * 2];
ARTrackInfo.Date = new char[AIMPRemote_TrackInfo->DateLength * 2];
ARTrackInfo.FileName = new char[AIMPRemote_TrackInfo->FileNameLength * 2];
ARTrackInfo.Genre = new char[AIMPRemote_TrackInfo->GenreLength * 2];
ARTrackInfo.Title = new char[AIMPRemote_TrackInfo->TitleLength * 2];

buffer = new WCHAR[AIMPRemote_TrackInfo->AlbumLength * 2];
wmemcpy(buffer, offset, AIMPRemote_TrackInfo->AlbumLength * 2);
WideCharToMultiByte(CP_UTF8, 0, buffer, -1, ARTrackInfo.Album, AIMPRemote_TrackInfo->AlbumLength, NULL, NULL);

buffer = new WCHAR[AIMPRemote_TrackInfo->ArtistLength * 2];
wmemcpy(buffer, offset += AIMPRemote_TrackInfo->AlbumLength, AIMPRemote_TrackInfo->ArtistLength * 2);
WideCharToMultiByte(CP_UTF8, 0, buffer, -1, ARTrackInfo.Artist, AIMPRemote_TrackInfo->ArtistLength, NULL, NULL);

buffer = new WCHAR[AIMPRemote_TrackInfo->DateLength * 2];
wmemcpy(buffer, offset += AIMPRemote_TrackInfo->ArtistLength, AIMPRemote_TrackInfo->DateLength * 2);
WideCharToMultiByte(CP_UTF8, 0, buffer, -1, ARTrackInfo.Date, AIMPRemote_TrackInfo->DateLength, NULL, NULL);
ARTrackInfo.Album.resize(AIMPRemote_TrackInfo->AlbumLength * 2);
ARTrackInfo.Artist.resize(AIMPRemote_TrackInfo->ArtistLength * 2);
ARTrackInfo.Date.resize(AIMPRemote_TrackInfo->DateLength * 2);
ARTrackInfo.FileName.resize(AIMPRemote_TrackInfo->FileNameLength * 2);
ARTrackInfo.Genre.resize(AIMPRemote_TrackInfo->GenreLength * 2);
ARTrackInfo.Title.resize(AIMPRemote_TrackInfo->TitleLength * 2);

buffer = new WCHAR[AIMPRemote_TrackInfo->FileNameLength * 2];
wmemcpy(buffer, offset += AIMPRemote_TrackInfo->DateLength, AIMPRemote_TrackInfo->FileNameLength * 2);
WideCharToMultiByte(CP_UTF8, 0, buffer, -1, ARTrackInfo.FileName, AIMPRemote_TrackInfo->FileNameLength, NULL, NULL);

buffer = new WCHAR[AIMPRemote_TrackInfo->GenreLength * 2];
wmemcpy(buffer, offset += AIMPRemote_TrackInfo->FileNameLength, AIMPRemote_TrackInfo->GenreLength * 2);
WideCharToMultiByte(CP_UTF8, 0, buffer, -1, ARTrackInfo.Genre, AIMPRemote_TrackInfo->GenreLength, NULL, NULL);

buffer = new WCHAR[AIMPRemote_TrackInfo->TitleLength * 2];
wmemcpy(buffer, offset += AIMPRemote_TrackInfo->GenreLength, AIMPRemote_TrackInfo->TitleLength * 2);
WideCharToMultiByte(CP_UTF8, 0, buffer, -1, ARTrackInfo.Title, AIMPRemote_TrackInfo->TitleLength, NULL, NULL);

ARTrackInfo.Album[AIMPRemote_TrackInfo->AlbumLength] =
ARTrackInfo.Artist[AIMPRemote_TrackInfo->ArtistLength] =
ARTrackInfo.Date[AIMPRemote_TrackInfo->DateLength] =
ARTrackInfo.FileName[AIMPRemote_TrackInfo->FileNameLength] =
ARTrackInfo.Genre[AIMPRemote_TrackInfo->GenreLength] =
ARTrackInfo.Title[AIMPRemote_TrackInfo->TitleLength] = 0;
ARTrackInfo.Album = toUTF8.to_bytes(std::wstring (offset, AIMPRemote_TrackInfo->AlbumLength));
ARTrackInfo.Artist = toUTF8.to_bytes(std::wstring (offset += AIMPRemote_TrackInfo->AlbumLength, AIMPRemote_TrackInfo->ArtistLength));
ARTrackInfo.Date = toUTF8.to_bytes(std::wstring (offset += AIMPRemote_TrackInfo->ArtistLength, AIMPRemote_TrackInfo->DateLength));
ARTrackInfo.FileName = toUTF8.to_bytes(std::wstring (offset += AIMPRemote_TrackInfo->DateLength, AIMPRemote_TrackInfo->FileNameLength));
ARTrackInfo.Genre = toUTF8.to_bytes(std::wstring (offset += AIMPRemote_TrackInfo->FileNameLength, AIMPRemote_TrackInfo->GenreLength));
ARTrackInfo.Title = toUTF8.to_bytes(std::wstring (offset += AIMPRemote_TrackInfo->GenreLength, AIMPRemote_TrackInfo->TitleLength));

UnmapViewOfFile(AIMPRemote_TrackInfo);
CloseHandle(hFile);
Expand All @@ -203,14 +167,14 @@ BOOL AIMPRemote::InfoUpdateTrackInfo()
return true;
}

BOOL AIMPRemote::InfoUpdatePlayerState()
bool AIMPRemote::InfoUpdatePlayerState()
{
if (!AREvents.State)
{
return true;
}

INT AIMPRemote_State = AIMPGetPropertyValue(AIMP_RA_PROPERTY_PLAYER_STATE);
int AIMPRemote_State = AIMPGetPropertyValue(AIMP_RA_PROPERTY_PLAYER_STATE);
if (ARState == AIMPRemote_State)
{
return false;
Expand All @@ -223,7 +187,7 @@ BOOL AIMPRemote::InfoUpdatePlayerState()
return true;
}

BOOL AIMPRemote::InfoUpdateTrackPositionInfo()
bool AIMPRemote::InfoUpdateTrackPositionInfo()
{
if (!AREvents.TrackPosition)
{
Expand All @@ -247,7 +211,7 @@ BOOL AIMPRemote::InfoUpdateTrackPositionInfo()
return true;
}

BOOL AIMPRemote::InfoUpdateVersionInfo()
bool AIMPRemote::InfoUpdateVersionInfo()
{
if (!AREvents.Version)
{
Expand Down Expand Up @@ -277,7 +241,11 @@ LRESULT CALLBACK AIMPRemote::WMAIMPNotify(HWND hwnd, UINT msg, WPARAM wParam, LP
{
if (wParam == AIMP_RA_NOTIFY_TRACK_INFO)
{
PAIMPRemote->InfoUpdateTrackInfo();
static int th = 0;
if (++th >= 2) {
PAIMPRemote->InfoUpdateTrackInfo();
th = 0;
}
}
else if (wParam == AIMP_RA_NOTIFY_PROPERTY)
{
Expand Down
65 changes: 33 additions & 32 deletions AIMPRemote.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <apiRemote.h>
#include <string>

#define AIMPREMOTE_PLAYER_STATE_STOPPED 0
#define AIMPREMOTE_PLAYER_STATE_PAUSED 1
Expand All @@ -10,35 +11,35 @@ CONST WCHAR AIMPRemoteClassName[] = L"AIMPRemoteApp";

typedef struct AIMPVersion
{
FLOAT Version;
INT Build;
float Version;
int Build;
} *PAIMPVersion;

typedef struct AIMPTrackInfo
{
BOOL Active;
int Active;

DWORD BitRate;
DWORD Channels;
DWORD Duration;
INT64 FileSize;
DWORD FileMark;
DWORD SampleRate;
DWORD TrackNumber;
unsigned long BitRate;
unsigned long Channels;
unsigned long Duration;
signed long long FileSize;
unsigned long FileMark;
unsigned long SampleRate;
unsigned long TrackNumber;

DWORD AlbumLength;
DWORD ArtistLength;
DWORD DateLength;
DWORD FileNameLength;
DWORD GenreLength;
DWORD TitleLength;
unsigned long AlbumLength;
unsigned long ArtistLength;
unsigned long DateLength;
unsigned long FileNameLength;
unsigned long GenreLength;
unsigned long TitleLength;

PCHAR Album;
PCHAR Artist;
PCHAR Date;
PCHAR FileName;
PCHAR Genre;
PCHAR Title;
std::string Album;
std::string Artist;
std::string Date;
std::string FileName;
std::string Genre;
std::string Title;
} *PAIMPTrackInfo;

typedef struct AIMPPosition
Expand All @@ -61,19 +62,19 @@ class AIMPRemote
AIMPRemote();
~AIMPRemote();

static VOID AIMPExecuteCommand(INT ACommand);
static INT AIMPGetPropertyValue(INT APropertyID);
static BOOL AIMPSetPropertyValue(INT APropertyID, INT AValue);
static VOID AIMPSetEvents(AIMPEvents* Events);
static BOOL AIMPSetRemoteHandle(const HWND* Value);
static void AIMPExecuteCommand(int ACommand);
static int AIMPGetPropertyValue(int APropertyID);
static bool AIMPSetPropertyValue(int APropertyID, int AValue);
static void AIMPSetEvents(AIMPEvents* Events);
static bool AIMPSetRemoteHandle(const HWND* Value);
static AIMPTrackInfo AIMPGetTrackInfo();
protected:
static LRESULT CALLBACK WMAIMPNotify(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
private:
BOOL InfoUpdatePlayerState();
BOOL InfoUpdateTrackPositionInfo();
BOOL InfoUpdateVersionInfo();
BOOL InfoUpdateTrackInfo();
bool InfoUpdatePlayerState();
bool InfoUpdateTrackPositionInfo();
bool InfoUpdateVersionInfo();
bool InfoUpdateTrackInfo();

HWND FAIMPRemoteHandle;
HWND MyWnd;
Expand All @@ -83,5 +84,5 @@ class AIMPRemote
AIMPVersion ARVersion = { 0 };
AIMPPosition ARPosition = { 0 };
AIMPEvents AREvents = { 0 };
INT ARState = AIMPREMOTE_PLAYER_STATE_STOPPED;
int ARState = AIMPREMOTE_PLAYER_STATE_STOPPED;
};

0 comments on commit 42ba79e

Please sign in to comment.