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: Input Blocking toggle #29

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
1 change: 1 addition & 0 deletions Guitar Player/Guitar Player.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
<ClCompile Include="WindowsUtility.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="globals.h" />
<ClInclude Include="InputBlocker.h" />
<ClInclude Include="Midifile\Binasc.h" />
<ClInclude Include="Midifile\MidiEvent.h" />
Expand Down
3 changes: 3 additions & 0 deletions Guitar Player/Guitar Player.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@
<ClInclude Include="MidiProcessing.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="globals.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
Expand Down
1 change: 0 additions & 1 deletion Guitar Player/Midifile/Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include <string>
#include <vector>


namespace smf {

///////////////////////////////////////////////////////////////////////////
Expand Down
6 changes: 5 additions & 1 deletion Guitar Player/PlayerFunctionality.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <algorithm>
#include "WindowsUtility.h"
#include "InputBlocker.h"
#include "globals.h"



Expand Down Expand Up @@ -345,7 +346,10 @@ void PlaySong(const std::filesystem::path& songPath, bool& isPlaying, bool& isPa
double accumulatedTime = currentProgress;
auto lastUpdateTime = std::chrono::high_resolution_clock::now();
InputBlocker inputBlocker;
inputBlocker.Start(targetWindow);

if (obstruction) {
inputBlocker.Start(targetWindow);
}
while (isPlaying) {
// Handle pausing
if (isPaused) {
Expand Down
29 changes: 27 additions & 2 deletions Guitar Player/Source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "PlayerFunctionality.h"
#include "resource.h"
#include "VersionNum.h"
#include "globals.h"

#ifdef __WXMSW__
#include <wx/msw/private.h>
Expand All @@ -19,6 +20,7 @@
#pragma comment(lib, "dwmapi.lib")
#endif

bool obstruction = true;

class DarkPanel : public wxPanel {
public:
Expand Down Expand Up @@ -404,10 +406,13 @@ class MainFrame : public wxFrame {

searchBox = new DarkSearchBox(groupPanelSongs, wxID_ANY);
refreshButton = new DarkButton(groupPanelSongs, wxID_ANY, "Refresh");
obstructionButton = new DarkButton(groupPanelSongs, wxID_ANY, "Obstruct");

// Add search box and refresh button to the horizontal sizer
searchSizer->Add(obstructionButton, 0, wxEXPAND | wxRIGHT, 5);
searchSizer->Add(searchBox, 1, wxEXPAND | wxRIGHT, 5);
searchSizer->Add(refreshButton, 0, wxEXPAND);
searchSizer->Add(refreshButton, 0, wxEXPAND | wxRIGHT, 5);


listBox = new DarkListBox(groupPanelSongs, wxID_ANY);

Expand Down Expand Up @@ -468,6 +473,7 @@ class MainFrame : public wxFrame {
listBox->Bind(wxEVT_LISTBOX, &MainFrame::OnSongSelect, this);
progressBar->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &MainFrame::OnSeek, this);
refreshButton->Bind(wxEVT_BUTTON, &MainFrame::OnRefresh, this);
obstructionButton->Bind(wxEVT_BUTTON, &MainFrame::OnObstruction, this);

// Create timer for progress updates
progressTimer = new wxTimer(this);
Expand All @@ -483,6 +489,7 @@ class MainFrame : public wxFrame {
timeLabel->SetFont(customFont);
currentSongLabel->SetFont(customFont);
refreshButton->SetFont(customFont);
obstructionButton->SetFont(customFont);

// Bind the close event
Bind(wxEVT_CLOSE_WINDOW, &MainFrame::OnClose, this);
Expand All @@ -501,6 +508,18 @@ class MainFrame : public wxFrame {
RefreshButtonsInWindow(this);
}

void OnObstruction(wxCommandEvent& event) {
if (obstruction) {
obstruction = false;
WindowsUtility::showMessageBox("This is not recommended and will cause playback to be substantially lower quality.", "Warning", MB_OK | MB_ICONWARNING);
}
else {
obstruction = true;
}
RefreshAllButtons();
UpdateButtonStates();
}

void OnRefresh(wxCommandEvent& event) {
wxString currentSearch = searchBox->GetValue();
LoadSongs("songs");
Expand Down Expand Up @@ -768,10 +787,15 @@ class MainFrame : public wxFrame {
pauseButton->SetBackgroundColour(activeColor);
playButton->SetBackgroundColour(inactiveColor);
}
else if (obstruction) {
//If input blocking is disabled
obstructionButton->SetBackgroundColour(activeColor);
}
else {
// Stopped state
playButton->SetBackgroundColour(inactiveColor);
pauseButton->SetBackgroundColour(inactiveColor);
obstructionButton->SetBackgroundColour(inactiveColor);
}

stopButton->SetBackgroundColour(inactiveColor);
Expand All @@ -780,6 +804,7 @@ class MainFrame : public wxFrame {
playButton->ForceRefresh();
pauseButton->ForceRefresh();
stopButton->ForceRefresh();
obstructionButton->ForceRefresh();
}

void OnClose(wxCloseEvent& event) {
Expand All @@ -792,6 +817,7 @@ class MainFrame : public wxFrame {
DarkButton* pauseButton;
DarkButton* stopButton;
DarkButton* refreshButton;
DarkButton* obstructionButton;
CustomProgressBar* progressBar;
wxStaticText* timeLabel;
wxTimer* progressTimer;
Expand Down Expand Up @@ -834,5 +860,4 @@ class MusicPlayerApp : public wxApp {
return true;
}
};

wxIMPLEMENT_APP(MusicPlayerApp);
9 changes: 9 additions & 0 deletions Guitar Player/globals.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once
// globals.h
#ifndef GLOBALS_H
#define GLOBALS_H

// Declare the global variable
extern bool obstruction;

#endif // GLOBALS_H