Try to fix bpm desync

This commit is contained in:
illyum 2024-08-09 02:44:08 -06:00
parent b3837e21d5
commit 9b738c359d

View File

@ -583,8 +583,6 @@ void renderImGui() {
}
void renderImGuiBpm() {
// Existing DMX Controller window code here...
// New BPM Control Window
ImGui::Begin("BPM Controller");
@ -612,16 +610,22 @@ void renderImGuiBpm() {
// Start/Stop button
static bool is_playing_bpm = false;
static bool has_applied_offset = false; // New variable to track if the offset has been applied
static bool has_applied_offset = false;
static float lastBeatTime = 0.0f;
static float pauseTime = 0.0f; // Store the time when BPM is paused
if (ImGui::Button(is_playing_bpm ? "Stop" : "Start")) {
is_playing_bpm = !is_playing_bpm;
if (is_playing_bpm) {
// Stop BPM playback
pauseTime = timeline_position;
is_playing_bpm = false;
}
else {
// Start BPM playback
if (!is_playing && audioLoaded) {
if (!has_applied_offset) {
// Apply offset only the first time playback starts
playback_start_time = static_cast<float>(glfwGetTime()) - timeline_position - offset_seconds;
has_applied_offset = true; // Mark that offset has been applied
has_applied_offset = true;
}
else {
playback_start_time = static_cast<float>(glfwGetTime()) - timeline_position;
@ -635,13 +639,13 @@ void renderImGuiBpm() {
ma_sound_start(&sound);
is_playing = true;
}
lastBeatTime = timeline_position;
}
else {
if (audioLoaded) {
ma_sound_stop(&sound);
is_playing = false;
if (!is_playing_bpm) {
// Adjust lastBeatTime based on the pause time
lastBeatTime += (timeline_position - pauseTime);
}
is_playing_bpm = true;
}
}