Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: Option for debug click trackers #37

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
27 changes: 27 additions & 0 deletions Guitar Player/InputBlocker.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
#include <windows.h>
#include <thread>
#include <atomic>
#include <vector>

BOOLEAN debugCirclesEnabled = FALSE;

struct MouseClick {
int x;
int y;
bool isLeft;
};

class InputBlocker {
private:
Expand All @@ -13,7 +22,9 @@ class InputBlocker {
static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
switch (msg) {
case WM_PAINT: {
MouseClick* clickArray = reinterpret_cast<MouseClick*>(lParam);
PAINTSTRUCT ps;
InvalidateRect(hwnd, NULL, TRUE);
HDC hdc = BeginPaint(hwnd, &ps);

// Fill with semi-transparent purple
Expand All @@ -33,6 +44,17 @@ class InputBlocker {
TextOutA(hdc, 20, 30, text, (int)strlen(text));
DeleteObject(hFont);

// Draw debug circles
if (debugCirclesEnabled) {
static const int debugCircleRadius = 10;
for (int i = 0; i < wParam; i++) {
MouseClick click = clickArray[i];
int x = click.x;
int y = click.y;
Ellipse(hdc, x - debugCircleRadius, y - debugCircleRadius, x + debugCircleRadius, y + debugCircleRadius);
}
}

EndPaint(hwnd, &ps);
return 0;
}
Expand Down Expand Up @@ -145,6 +167,11 @@ class InputBlocker {
public:
InputBlocker() : targetWindow(NULL), overlayWindow(NULL) {}

HWND getOverlayWindow() {
// Used for receiving updates
return overlayWindow;
}

bool Start(HWND window) {
if (active) return false;
if (!IsWindow(window)) {
Expand Down
16 changes: 8 additions & 8 deletions Guitar Player/PlayerFunctionality.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,11 @@ const std::array<int, 16> b = { 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70,
const std::array<int, 16> high_e = { 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79 };
HWND targetWindow = NULL;
static std::vector<int> lastClickedPositions(6, 0); // Track last clicked position for each string
static std::vector<MouseClick> debugClicksVector; // Track recent mouse clicks





struct MouseClick {
int x;
int y;
bool isLeft;
};

std::pair<int, int> getClickPosition(int windowWidth, int windowHeight, int x, int y) {
const double xMinRatio = 0.17740;
const double xMaxRatio = 0.263975;
Expand Down Expand Up @@ -87,6 +81,9 @@ void sendMultipleKeys(const std::vector<char>& keys, int sleepTime, bool down =

void sendMultipleClicks(const std::vector<MouseClick>& clicks, int sleepTime, bool down = false) {
for (const auto& click : clicks) {
debugClicksVector.push_back(click);


LPARAM lParam = MAKELPARAM(click.x, click.y);
WPARAM wParam = click.isLeft ? MK_LBUTTON : MK_RBUTTON;
UINT downMsg = click.isLeft ? WM_LBUTTONDOWN : WM_RBUTTONDOWN;
Expand Down Expand Up @@ -294,7 +291,7 @@ void clickThroughAllPositions(int windowWidth, int windowHeight) {
for (int string = 0; string <= 5; ++string) {
for (int fret = 0; fret <= 15; ++fret) {
auto [clickX, clickY] = getClickPosition(windowWidth, windowHeight, string, fret);

std::vector<MouseClick> clicksToSend;
clicksToSend.push_back({ clickX, clickY, true });
sendMultipleClicks(clicksToSend, 1, true);
Expand Down Expand Up @@ -420,6 +417,9 @@ void PlaySong(const std::filesystem::path& songPath, bool& isPlaying, bool& isPa

if (isPlaying && !isPaused && abs(currentProgress - nextEvent.timestamp) < 100) {
playNotes(nextEvent.notes);
// convert our vector to an array and send it over for painting
MouseClick* debugClicksArray = &debugClicksVector[0];
SendMessage(inputBlocker.getOverlayWindow(), WM_PAINT, debugClicksVector.size(), reinterpret_cast<LPARAM>(debugClicksArray));
}
}
inputBlocker.Stop();
Expand Down