Skip to content

Conversation

DRSDavidSoft
Copy link

@DRSDavidSoft DRSDavidSoft commented Jun 2, 2025

I'm working to improve the MPC-HC's API and Web interface according to the changes in my personal fork, and port my changes changes in order to upstream them.

I would appreciate it if you could have a review. Sorry for having multiple different aspects all integrated in a single PR.

Added features

  • Added new API to query (and set) the current volume: CMD_CURRENTVOLUME and CMD_GETVOLUME
    (This will be automatically sent upon changes and can also be queried from the host side)
    To set the volume, the CMD_SETVOLUME with syntax: <volume>|<is_muted> can be used.
  • Added dark mode to the Web interface and some improvements
    (e.g. the variables.html page now also displays the variable name in addition to its value using CSS)

Fixes and general changes

  • Replaced the repeated volume get logic with pre-existing GetVolume() and IsMuted() to make code DRY
  • Added simple process start error handling to MPCTestAPI app
  • Updated MPCTestAPI app to handle paths with spaces
  • Updated the MPCTestAPI app to handle the Enter key correctly
  • Updated MPCTestAPI to add some missing API items, as well as better handling the unknown codes:
    • CMD_DISCONNECT
    • CMD_NOTIFYSEEK
    • CMD_CURRENTVOLUME (new)
    • CMD_VERSION
    • ...
  • Updated MPCTestAPI's version and copyright year (since we're making changes to it)
  • Updated some comments in the MpcApi.h for clarity

Changes to be made

  • Prevent firing OnPlayVolume() with duplicated values
    To replicate this issue, open the MPCTestAPI app and invoke increase/decrease volume commands.
    This will cause the event to be fired twice, which is not desirable.
    Additionally, dragging the volume bar's handle past zero will fire with the same 0 value repeatedly.

  • Add a new API to query the currently connected host hWnd
    This is useful for scripting purposes and/or when dealing with multiple instances (windows) of MPC-HC
    Allowing us to query whether a particular MPC-HC window has a host connected or not.

  • Add a new API to display status messages using the API

  • Add the missing functionality of sending OSD and Status messages to the MPCTestAPI app
    (Since the parameters format differ from other API commands, this will be skipped)

Edit

Will move some unrelated feature/improvement tasks to their own issue later:

  • Make use of Windows 11 rounded corners for the custom dark mode context menus (fix Dark theme has small bug on win 11 #2141)
    (Currently they are not rounded)

  • Re-write the web interface (and the HTTP server) to make use of Web-sockets instead of polling interval to improve user-experience
    Completely drop support for Microsoft IE
    (Unless someone is still using it instead of modern web browsers)

When a certain specified path contains spaces (such as "..\..\..\..\bin\mpc-hc_x64_Debug Lite\mpc-hc64.exe" that contains a space between "Debug" and "Lite"), then double quotes are required to safely quote the path
Updated `GetMPCCommandName` to include a case for `CMD_DISCONNECT`. Enhanced the default case to return a formatted string with the command's hexadecimal value for better debugging of unknown commands, replacing the previous static "CMD_UNK" return value.
Updated the version number of the "MPC-HC Test API" from 1.0.1.0 to 1.0.2.0 in both the dialog resource and the version information block. Changed the copyright year from 2013 to 2025 in the dialog resource and the version information block.
Updated `GetMPCCommandName` to include `CMD_VERSION` case
and modified `OnCopyData` to automatically send `CMD_GETVERSION`
upon receiving `CMD_CONNECT`.
Aligned the `<p id="audiotrack">[audiotrack]</p>` element
by removing spurious leading space to match the indentation
of other elements in the file.
- Added new options to request and receive the current MPC-HC volume through the API.
- Cleaned-up some comments.
- Updated the test application with new combobox items
- The current volume can be requested by `CMD_GETVOLUME` or sent automatically
… detail

These methods existed in the class yet in these places the code was still using the repeated code.
The existing methods return the same value.
- Dark mode support
- Default viewport for mobile
- Transparency for rounded title corners
- Added note regarding future updates to index
- Fixed the order of `UpdateData(TRUE);`, it must come before accessing `m_strMPCPath` otherwise the data is not valid yet and you needed to call the function twice for it to take effect.
- Updated the OnButtonFindwindow function to format the command line string
- Added a simple OnOK function to handle Enter key based on the focused control
@clsid2
Copy link
Owner

clsid2 commented Jun 3, 2025

Future changes unrelated to MPCTestAPI should be in separate PRs.

Removed XMP metadata to reduce filesize as well
@DRSDavidSoft

This comment was marked as resolved.

@DRSDavidSoft
Copy link
Author

  • Prevent firing OnPlayVolume() with duplicated values
    To replicate this issue, open the MPCTestAPI app and invoke increase/decrease volume commands.
    This will cause the event to be fired twice, which is not desirable.
    Additionally, dragging the volume bar's handle past zero will fire with the same 0 value repeatedly.

I'm going to just use a m_lastVolume variable to keep track of the last reported volume value, and only report the new value if it was changed, if this is OK with you @clsid2

- Adds a new command `CMD_SETVOLUME` to manage the current volume and mute state
- The command is defined in `MpcApi.h` and implemented in `CMainFrame::ProcessAPICommand` to handle volume and mute updates
- The `CPlayerToolBar` class has been updated to provide access to methods for mute state management
- Additionally, a conflict with the how `CMD_SETVOLUME` was referenced in the web API has been fixed, where it has been renamed to `CMD_SETVOL` for consistency (It's recommended to rename such cases to `WEBCMD_...` instead to prevent such collisions)
- Resource file `MPCTestAPI.rc` has also been updated to add new combobox items in the MPCTestAPI app
@DRSDavidSoft
Copy link
Author

DRSDavidSoft commented Jun 3, 2025

Added a new commit (6544c02) that allows changing the volume from the API, which was previously missing.

Note: This is kind of off-topic; but sadly there is a noticeable delay from when the volume is changed until is actually reflected, doesn't matter the source (if it was set from either Web or regular API, or from the UI). I hope to investigate and see if I can make this instantaneous for my personal use case.

@clsid2
Copy link
Owner

clsid2 commented Jun 4, 2025

I don't like the combination of volume and mute in a single parameter. Just keep it simple and set only volume. For practical purposes a volume of 0 has the same effect a muting.

@DRSDavidSoft

This comment was marked as outdated.

@clsid2
Copy link
Owner

clsid2 commented Jun 4, 2025

option C, separate command for mute.

Mute state is already correctly reflected in web interface and its variables.

@DRSDavidSoft

This comment was marked as resolved.

@clsid2
Copy link
Owner

clsid2 commented Jun 4, 2025

C2

@DRSDavidSoft
Copy link
Author

DRSDavidSoft commented Jun 4, 2025

OK, I'll make a new commit to make the mute state separate from volume for both GET and SET.

Edit: Investigating this, I see some issues that needs to be addressed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dark theme has small bug on win 11

2 participants