add loop toggle

Added a Toggle to the Controls that allows the User to Loop the currently playing song
This commit is contained in:
ApfelTeeSaft
2024-12-22 16:08:37 +01:00
parent 61ff4fc306
commit eee7f21af5
4 changed files with 23 additions and 3 deletions
+14 -2
View File
@@ -29,6 +29,7 @@ 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
extern bool isLooping = false;
@@ -346,6 +347,7 @@ void PlaySong(const std::filesystem::path& songPath, bool& isPlaying, bool& isPa
auto lastUpdateTime = std::chrono::high_resolution_clock::now();
InputBlocker inputBlocker;
inputBlocker.Start(targetWindow);
while (isPlaying) {
// Handle pausing
if (isPaused) {
@@ -383,8 +385,17 @@ void PlaySong(const std::filesystem::path& songPath, bool& isPlaying, bool& isPa
}
if (nextIndex >= songData.size()) {
isPlaying = false;
break;
if (isLooping) {
// Restart playback from the beginning
accumulatedTime = 0;
currentProgress = 0;
lastUpdateTime = std::chrono::high_resolution_clock::now();
continue;
}
else {
isPlaying = false;
break;
}
}
const auto& nextEvent = songData[nextIndex];
@@ -422,6 +433,7 @@ void PlaySong(const std::filesystem::path& songPath, bool& isPlaying, bool& isPa
playNotes(nextEvent.notes);
}
}
inputBlocker.Stop();
isPlaying = false;
}
+7
View File
@@ -439,7 +439,9 @@ public:
playButton = new DarkButton(playbackPanel, wxID_ANY, "Play");
pauseButton = new DarkButton(playbackPanel, wxID_ANY, "Pause");
stopButton = new DarkButton(playbackPanel, wxID_ANY, "Stop");
loopCheckbox = new wxCheckBox(playbackPanel, wxID_ANY, "Loop");
buttonSizer->Add(loopCheckbox, 1, wxLEFT | wxRIGHT, 5);
buttonSizer->Add(playButton, 1, wxRIGHT, 5);
buttonSizer->Add(pauseButton, 1, wxLEFT | wxRIGHT, 5);
buttonSizer->Add(stopButton, 1, wxLEFT, 5);
@@ -465,6 +467,9 @@ public:
playButton->Bind(wxEVT_BUTTON, &MainFrame::OnPlay, this);
pauseButton->Bind(wxEVT_BUTTON, &MainFrame::OnPause, this);
stopButton->Bind(wxEVT_BUTTON, &MainFrame::OnStop, this);
loopCheckbox->Bind(wxEVT_CHECKBOX, [this](wxCommandEvent& event) {
isLooping = loopCheckbox->GetValue();
});
listBox->Bind(wxEVT_LISTBOX, &MainFrame::OnSongSelect, this);
progressBar->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &MainFrame::OnSeek, this);
refreshButton->Bind(wxEVT_BUTTON, &MainFrame::OnRefresh, this);
@@ -753,6 +758,7 @@ private:
playButton->Enable(!isPlayingSong || isPaused);
pauseButton->Enable(isPlayingSong && !isPaused);
stopButton->Enable(isPlayingSong || isPaused);
loopCheckbox->SetValue(isLooping); // Sync checkbox state with current loop status
// Update button colors based on current state
wxColour activeColor(147, 112, 219); // Purple highlight color
@@ -791,6 +797,7 @@ private:
DarkButton* playButton;
DarkButton* pauseButton;
DarkButton* stopButton;
wxCheckBox* loopCheckbox;
DarkButton* refreshButton;
CustomProgressBar* progressBar;
wxStaticText* timeLabel;
+1 -1
View File
@@ -1,2 +1,2 @@
#pragma once
#define VERSIONSTR "1.1.3"
#define VERSIONSTR "1.1.4"
+1
View File
@@ -3,6 +3,7 @@
// Used by Guitar Player.rc
//
#define IDI_ICON1 101
#define IDC_LOOP 104 // Unique identifier
// Next default values for new objects
//