Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
65adb88
Ignore /src/MPCTestAPI/.vs
DRSDavidSoft Jun 2, 2025
f98d5cf
Safe path handling
DRSDavidSoft Jun 2, 2025
4ea5d6a
Add simple error handling on process start
DRSDavidSoft Jun 2, 2025
d3c7f9e
Display unknown command code; Add missing CMD_DISCONNECT case
DRSDavidSoft Jun 2, 2025
51f70cb
Add missing CMD_NOTIFYSEEK case to GetMPCCommandName
DRSDavidSoft Jun 2, 2025
9cf034b
Update version to 1.0.2.0 and copyright year to 2025
DRSDavidSoft Jun 2, 2025
611d18e
Add CMD_VERSION handling and version retrieval command
DRSDavidSoft Jun 2, 2025
47c82bf
Add CMD_NOTIFYENDOFSTREAM to GetMPCCommandName
DRSDavidSoft Jun 2, 2025
0d5a239
Fix indentation for variable in HTML
DRSDavidSoft Jun 2, 2025
5d75694
Improve comment
DRSDavidSoft Jun 2, 2025
8ac3df0
Improve comments
DRSDavidSoft Jun 2, 2025
d1b5fce
Add API enum for retrieving volume; cleaned-up comments
DRSDavidSoft Jun 2, 2025
a59d5b8
Update version information
DRSDavidSoft Jun 2, 2025
a044a1a
Add API to send current volume
DRSDavidSoft Jun 2, 2025
7c08a3a
Use `GetVolume()` and `IsMuted()` instead of control's implementation…
DRSDavidSoft Jun 2, 2025
0646a42
Improved web interface
DRSDavidSoft Jun 2, 2025
c338485
Refactor process handling and add OnOK function
DRSDavidSoft Jun 2, 2025
eda3efc
fix: Use UNKNOWN directly in the Format string.
DRSDavidSoft Jun 3, 2025
808aa2b
fix: A single string can be used here.
DRSDavidSoft Jun 3, 2025
cc33aee
Optimized png filesize
DRSDavidSoft Jun 3, 2025
6544c02
Introduce new `CMD_SETVOLUME` API for volume and mute control
DRSDavidSoft Jun 3, 2025
86f9670
Merge branch 'clsid2:develop' into develop
DRSDavidSoft Jun 30, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ _*.bat
/src/mpc-hc/mpcresources/*.rc
/src/mpc-hc/mpcresources/tx.exe
/src/mpc-hc/res/mpc-hc.exe.manifest
/src/MPCTestAPI/.vs
/src/MPCTestAPI/bin
/src/MPCTestAPI/bin17
/src/thirdparty/DoctorDump/obj
Expand Down
48 changes: 24 additions & 24 deletions src/MPCTestAPI/MPCTestAPI.rc
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ CAPTION "About MPC-HC Test API"
FONT 8, "MS Shell Dlg", 0, 0, 0x0
BEGIN
ICON IDR_MAINFRAME,IDC_STATIC,11,17,20,20
LTEXT "MPC-HC Test API Version 1.0.1.0",IDC_STATIC,40,10,120,10,SS_NOPREFIX
LTEXT "Copyright � 2005-2013 all contributors, see Authors.txt",IDC_STATIC,40,27,197,10
LTEXT "MPC-HC Test API Version 1.0.2.0",IDC_STATIC,40,10,120,10,SS_NOPREFIX
LTEXT "Copyright � 2005-2025 all contributors, see Authors.txt",IDC_STATIC,40,27,197,10
DEFPUSHBUTTON "OK",IDOK,187,7,50,14,WS_GROUP
END

Expand All @@ -98,8 +98,8 @@ END
//

VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,0,1,0
PRODUCTVERSION 1,0,1,0
FILEVERSION 1,0,2,0
PRODUCTVERSION 1,0,2,0
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
#ifdef _DEBUG
FILEFLAGS VS_FF_DEBUG
Expand All @@ -116,12 +116,12 @@ BEGIN
BEGIN
VALUE "CompanyName", "MPC-HC Team"
VALUE "FileDescription", "MPC-HC Test API"
VALUE "FileVersion", "1.0.1.0"
VALUE "FileVersion", "1.0.2.0"
VALUE "InternalName", "MPC-HC Test API"
VALUE "LegalCopyright", "Copyright � 2005-2013 all contributors, see Authors.txt"
VALUE "LegalCopyright", "Copyright � 2005-2025 all contributors, see Authors.txt"
VALUE "OriginalFilename", "MPCTestAPI.exe"
VALUE "ProductName", "MPC-HC Test API"
VALUE "ProductVersion", "1.0.1.0"
VALUE "ProductVersion", "1.0.2.0"
END
END
BLOCK "VarFileInfo"
Expand Down Expand Up @@ -204,23 +204,24 @@ BEGIN
"\000"
IDC_COMBO1, 0x403, 11, 0
0x7546, 0x6c6c, 0x6353, 0x6572, 0x6e65, "\000"
IDC_COMBO1, 0x403, 19, 0
0x4d43, 0x5f44, 0x554a, 0x504d, 0x4f46, 0x5752, 0x5241, 0x4d44, 0x4445,
"\000"
IDC_COMBO1, 0x403, 20, 0
0x4d43, 0x5f44, 0x554a, 0x504d, 0x4142, 0x4b43, 0x4157, 0x4452, 0x454d,
0x0044,
IDC_COMBO1, 0x403, 19, 0
0x4d43, 0x5f44, 0x4e49, 0x5243, 0x4145, 0x4553, 0x4f56, 0x554c, 0x454d,
"\000"
IDC_COMBO1, 0x403, 19, 0
0x4d43, 0x5f44, 0x4544, 0x5243, 0x4145, 0x4553, 0x4f56, 0x554c, 0x454d,
"\000"
IDC_COMBO1, 0x403, 18, 0
0x4d43, 0x5f44, 0x4853, 0x4441, 0x5245, 0x545f, 0x474f, 0x4c47, 0x0045,

IDC_COMBO1, 0x403, 13, 0
0x4d43, 0x5f44, 0x4c43, 0x534f, 0x4145, 0x5050, "\000"
0x754a, 0x706d, 0x6620, 0x726f, 0x6177, 0x6472, "\000"
IDC_COMBO1, 0x403, 14, 0
0x754a, 0x706d, 0x6220, 0x6361, 0x776b, 0x7261, 0x0064,
IDC_COMBO1, 0x403, 16, 0
0x6e49, 0x7263, 0x6165, 0x6573, 0x7620, 0x6c6f, 0x6d75, 0x0065,
IDC_COMBO1, 0x403, 16, 0
0x6544, 0x7263, 0x6165, 0x6573, 0x7620, 0x6c6f, 0x6d75, 0x0065,
IDC_COMBO1, 0x403, 11, 0
0x6547, 0x2074, 0x6f76, 0x756c, 0x656d, "\000"
IDC_COMBO1, 0x403, 11, 0
0x6553, 0x2074, 0x6f76, 0x756c, 0x656d, "\000"
IDC_COMBO1, 0x403, 12, 0
0x6547, 0x2074, 0x6576, 0x7372, 0x6f69, 0x006e,
IDC_COMBO1, 0x403, 14, 0
0x6f54, 0x6767, 0x656c, 0x7320, 0x6168, 0x6564, 0x0072,
IDC_COMBO1, 0x403, 10, 0
0x6c43, 0x736f, 0x2065, 0x7061, 0x0070,
0
END

Expand Down Expand Up @@ -257,4 +258,3 @@ LANGUAGE 9, 1
#endif
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

68 changes: 62 additions & 6 deletions src/MPCTestAPI/MPCTestAPIDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ LPCTSTR GetMPCCommandName(MPCAPI_COMMAND nCmd)
switch (nCmd) {
case CMD_CONNECT:
return _T("CMD_CONNECT");
case CMD_DISCONNECT:
return _T("CMD_DISCONNECT");
case CMD_STATE:
return _T("CMD_STATE");
case CMD_PLAYMODE:
Expand All @@ -44,8 +46,20 @@ LPCTSTR GetMPCCommandName(MPCAPI_COMMAND nCmd)
return _T("CMD_LISTAUDIOTRACKS");
case CMD_PLAYLIST:
return _T("CMD_PLAYLIST");
case CMD_NOTIFYSEEK:
return _T("CMD_NOTIFYSEEK");
case CMD_CURRENTVOLUME:
return _T("CMD_CURRENTVOLUME");
case CMD_VERSION:
return _T("CMD_VERSION");
case CMD_NOTIFYENDOFSTREAM:
return _T("CMD_NOTIFYENDOFSTREAM");
default:
return _T("CMD_UNK");
// Missing a COMMAND from MpcApi.h file
static CString strResult;
LPCTSTR pszName = nullptr;
strResult.Format(_T("%s (0x%08X)"), _T("UNKNOWN"), (unsigned int)nCmd);
return strResult;
}
}

Expand Down Expand Up @@ -242,16 +256,35 @@ void CRegisterCopyDataDlg::OnButtonFindwindow()
STARTUPINFO StartupInfo;
PROCESS_INFORMATION ProcessInfo;

strExec.Format(_T("%s /slave %d"), (LPCTSTR)m_strMPCPath, PtrToInt(GetSafeHwnd()));
UpdateData(TRUE);

strExec.Format(_T("\"%s\" /slave %d"), (LPCTSTR)m_strMPCPath, PtrToInt(GetSafeHwnd()));

ZeroMemory(&StartupInfo, sizeof(StartupInfo));
StartupInfo.cb = sizeof(StartupInfo);
GetStartupInfo(&StartupInfo);
if (CreateProcess(nullptr, (LPTSTR)(LPCTSTR)strExec, nullptr, nullptr, FALSE, 0, nullptr, nullptr, &StartupInfo, &ProcessInfo)) {
CloseHandle(ProcessInfo.hProcess);
CloseHandle(ProcessInfo.hThread);

LPTSTR cmdLine = strExec.GetBuffer();
BOOL bResult = CreateProcess(nullptr, cmdLine, nullptr, nullptr, FALSE, 0, nullptr, nullptr, &StartupInfo, &ProcessInfo);
strExec.ReleaseBuffer();

if (!bResult) {
CString strError;
DWORD dwError = GetLastError();
LPTSTR lpMsgBuf = nullptr;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, nullptr, dwError, 0, (LPTSTR)&lpMsgBuf, 0, nullptr);
if (lpMsgBuf) {
strError.Format(_T("Failed to start MPC-HC process.\nError: %s"), lpMsgBuf);
LocalFree(lpMsgBuf);
} else {
strError.Format(_T("Failed to start MPC-HC process.\nError code: %lu"), dwError);
}
AfxMessageBox(strError, MB_ICONERROR | MB_OK);
return;
}

CloseHandle(ProcessInfo.hProcess);
CloseHandle(ProcessInfo.hThread);
}

void CRegisterCopyDataDlg::Senddata(MPCAPI_COMMAND nCmd, LPCTSTR strCommand)
Expand All @@ -273,6 +306,7 @@ BOOL CRegisterCopyDataDlg::OnCopyData(CWnd* pWnd, COPYDATASTRUCT* pCopyDataStruc

if (pCopyDataStruct->dwData == CMD_CONNECT) {
m_hWndMPC = (HWND)IntToPtr(_ttoi((LPCTSTR)pCopyDataStruct->lpData));
Senddata(CMD_GETVERSION, _T(""));
}

strMsg.Format(_T("%s : %s"), GetMPCCommandName((MPCAPI_COMMAND)pCopyDataStruct->dwData), (LPCTSTR)pCopyDataStruct->lpData);
Expand Down Expand Up @@ -350,10 +384,32 @@ void CRegisterCopyDataDlg::OnBnClickedButtonSendcommand()
Senddata(CMD_DECREASEVOLUME, m_txtCommand);
break;
case 21:
//Senddata(CMD_SHADER_TOGGLE, m_txtCommand);
Senddata(CMD_GETVOLUME, m_txtCommand);
break;
case 22:
Senddata(CMD_SETVOLUME, m_txtCommand);
break;
case 23:
Senddata(CMD_GETVERSION, m_txtCommand);
break;
case 24:
//Senddata(CMD_SHADER_TOGGLE, m_txtCommand);
break;
case 25:
Senddata(CMD_CLOSEAPP, m_txtCommand);
break;
}
}

void CRegisterCopyDataDlg::OnOK()
{
CWnd* pFocus = GetFocus();
if (pFocus->GetDlgCtrlID() == IDC_EDIT1)
{
OnButtonFindwindow();
}
if (pFocus->GetDlgCtrlID() == IDC_EDIT2 || pFocus->GetDlgCtrlID() == IDC_COMBO1)
{
OnBnClickedButtonSendcommand();
}
}
1 change: 1 addition & 0 deletions src/MPCTestAPI/MPCTestAPIDlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,6 @@ class CRegisterCopyDataDlg : public CDialog
CString m_txtCommand;
int m_nCommandType;
afx_msg void OnBnClickedButtonSendcommand();
void OnOK();
void Senddata(MPCAPI_COMMAND nCmd, LPCTSTR strCommand);
};
49 changes: 46 additions & 3 deletions src/mpc-hc/MainFrm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10035,16 +10035,18 @@ void CMainFrame::OnPlayVolume(UINT nID)
m_pBA->put_Volume(m_wndToolBar.Volume);

//strVolume.Format (L"Vol : %d dB", m_wndToolBar.Volume / 100);
if (m_wndToolBar.Volume == -10000) {
if (IsMuted()) {
strVolume.Format(IDS_VOLUME_OSD, 0);
} else {
strVolume.Format(IDS_VOLUME_OSD, m_wndToolBar.m_volctrl.GetPos());
strVolume.Format(IDS_VOLUME_OSD, GetVolume());
}
m_OSD.DisplayMessage(OSD_TOPLEFT, strVolume);
//SendStatusMessage(strVolume, 3000); // Now the volume is displayed in three places at once.
}

m_Lcd.SetVolume((m_wndToolBar.Volume > -10000 ? m_wndToolBar.m_volctrl.GetPos() : 1));
m_Lcd.SetVolume((!IsMuted() ? GetVolume() : 1));

SendCurrentVolumeToApi();
}

void CMainFrame::OnPlayVolumeBoost(UINT nID)
Expand Down Expand Up @@ -20074,6 +20076,32 @@ void CMainFrame::ProcessAPICommand(COPYDATASTRUCT* pCDS)
// show current position overridden by play command
m_OSD.DisplayMessage(OSD_TOPLEFT, m_wndStatusBar.GetStatusTimer(), 2000);
break;
case CMD_SETVOLUME: {
fn = CString((LPCWSTR)pCDS->lpData);
int sep = fn.Find(L'|');
CString vol = fn, muted = "";
bool updated = false;
if (fn.Find(L'|') >= 0) {
muted = fn.Mid(sep + 1);
vol = fn.Left(sep);
}
if (!muted.IsEmpty()) {
if (muted == L"0" || muted == L"1") {
m_wndToolBar.Mute = muted == L"1";
updated = true;
}
}
if (!vol.IsEmpty()) {
wchar_t* endptr = nullptr;
long volume = wcstol(vol, &endptr, 10);
if (endptr != vol && *endptr == 0) {
m_wndToolBar.Volume = std::min(std::max((int)volume, 0), 100);
updated = true;
}
}
if (updated) OnPlayVolume(0);
break;
}
case CMD_SETAUDIODELAY:
rtPos = (REFERENCE_TIME)_wtol((LPCWSTR)pCDS->lpData) * 10000;
SetAudioDelay(rtPos);
Expand Down Expand Up @@ -20110,6 +20138,9 @@ void CMainFrame::ProcessAPICommand(COPYDATASTRUCT* pCDS)
case CMD_GETCURRENTPOSITION:
SendCurrentPositionToApi();
break;
case CMD_GETVOLUME:
SendCurrentVolumeToApi();
break;
case CMD_GETNOWPLAYING:
SendNowPlayingToApi();
break;
Expand Down Expand Up @@ -20534,6 +20565,18 @@ void CMainFrame::SendCurrentPositionToApi(bool fNotifySeek)
}
}

void CMainFrame::SendCurrentVolumeToApi()
{
if (!AfxGetAppSettings().hMasterWnd) {
return;
}

CStringW strVol;
strVol.Format(L"%d|%d", GetVolume(), IsMuted() ? 1 : 0);

SendAPICommand(CMD_CURRENTVOLUME, L"%s", static_cast<LPCWSTR>(strVol));
}

void CMainFrame::ShowOSDCustomMessageApi(const MPC_OSDDATA* osdData)
{
m_OSD.DisplayMessage((OSD_MESSAGEPOS)osdData->nMsgPos, osdData->strMsg, osdData->nDurationMS);
Expand Down
1 change: 1 addition & 0 deletions src/mpc-hc/MainFrm.h
Original file line number Diff line number Diff line change
Expand Up @@ -1252,6 +1252,7 @@ class CMainFrame : public CFrameWnd, public CDropClient
afx_msg void OnFileOpendirectory();

void SendCurrentPositionToApi(bool fNotifySeek = false);
void SendCurrentVolumeToApi();
void ShowOSDCustomMessageApi(const MPC_OSDDATA* osdData);
void JumpOfNSeconds(int seconds);

Expand Down
31 changes: 23 additions & 8 deletions src/mpc-hc/MpcApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,15 @@ typedef enum MPCAPI_COMMAND :
unsigned int {
// ==== Commands from MPC-HC to host

// Send after connection
// Parameter 1: MPC-HC window handle (command should be sent to this HWnd)
// Send after connection made to host
// Parameter 1: MPC-HC window handle (commands must be sent to this hWnd)
CMD_CONNECT = 0x50000000,

// Send when opening or closing file
// Parameter 1: current state (see MPC_LOADSTATE enum)
CMD_STATE = 0x50000001,

// Send when playing, pausing or closing file
// Send when playing, pausing or closing a file
// Parameter 1: current play mode (see MPC_PLAYSTATE enum)
CMD_PLAYMODE = 0x50000002,

Expand Down Expand Up @@ -135,6 +135,11 @@ typedef enum MPCAPI_COMMAND :
// Parameter 1: current position in seconds
CMD_CURRENTPOSITION = 0x50000007,

// Send current volume when changed or in response
// Parameter 1: current volume (0-100)
// Parameter 2: muted state
CMD_CURRENTVOLUME = 0x5000000E,

// Send the current playback position after a jump.
// (Automatically sent after a seek event).
// Parameter 1: new playback position (in seconds).
Expand All @@ -145,7 +150,7 @@ typedef enum MPCAPI_COMMAND :
// Parameter 1: none.
CMD_NOTIFYENDOFSTREAM = 0x50000009,

// Send version str
// Send version string
// Parameter 1: MPC-HC's version
CMD_VERSION = 0x5000000A,

Expand Down Expand Up @@ -221,16 +226,26 @@ typedef enum MPCAPI_COMMAND :
// return a CMD_LISTSUBTITLETRACKS
CMD_GETSUBTITLETRACKS = 0xA0003000,

// Ask for the current playback position,
// see CMD_CURRENTPOSITION.
// Parameter 1: current position in seconds
// Ask for the current playback position
// return a CMD_CURRENTPOSITION
CMD_GETCURRENTPOSITION = 0xA0003004,

// Ask for the current volume value
// return a CMD_CURRENTVOLUME
CMD_GETVOLUME = 0xA0003009,

// Set the current volume to a specified value, and/or change the muted state
// (both parameters are optional, if not specified, the current value is kept)
// Parameter 1: current volume (0-100)
// Parameter 2: muted state (0 or 1)
CMD_SETVOLUME = 0xA0003010,

// Jump forward/backward of N seconds,
// Parameter 1: seconds (negative values for backward)
CMD_JUMPOFNSECONDS = 0xA0003005,

// Ask slave for version
// Ask for the MPC-HC's version string
// return a CMD_VERSION
CMD_GETVERSION = 0xA0003006,

// Ask for a list of the audio tracks of the file
Expand Down
5 changes: 3 additions & 2 deletions src/mpc-hc/PlayerToolBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ class CPlayerToolBar : public CToolBar
private:
CMainFrame* m_pMainFrame;

bool IsMuted() const;
void SetMute(bool fMute = true);
int getHitButtonIdx(CPoint point);
bool LoadExternalToolBar(CImage& image);
void LoadToolbarImage();
Expand All @@ -58,6 +56,9 @@ class CPlayerToolBar : public CToolBar

bool LoadExternalToolBar(CImage& image, bool useColor);

bool IsMuted() const;
void SetMute(bool fMute = true);
__declspec(property(get = IsMuted, put = SetMute)) bool Mute;
int GetVolume() const;
int GetMinWidth() const;
void SetVolume(int volume);
Expand Down
Loading