From e78c0fa96af5492272b0cae6bdb3733da96bcd21 Mon Sep 17 00:00:00 2001 From: illyum <90023277+itzilly@users.noreply.github.com> Date: Thu, 8 Aug 2024 23:36:30 -0600 Subject: [PATCH] Fix playback --- main.cpp | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/main.cpp b/main.cpp index be07f81..32995a3 100644 --- a/main.cpp +++ b/main.cpp @@ -181,7 +181,6 @@ void setupImGui(GLFWwindow* window) { ImGui_ImplOpenGL3_Init("#version 130"); } - void renderImGui() { // Calculate time per beat based on BPM float beat_interval = 60.0f / bpm; @@ -212,7 +211,7 @@ void renderImGui() { if (ImGui::Button(is_playing ? "Pause" : "Play")) { is_playing = !is_playing; if (is_playing) { - playback_start_time = static_cast(glfwGetTime()); + playback_start_time = static_cast(glfwGetTime()) - timeline_position; } } @@ -264,6 +263,38 @@ void renderImGui() { ImGui::EndChild(); ImGui::PopID(); + // Playback logic: Update timeline position based on playback time + if (is_playing) { + current_time = static_cast(glfwGetTime()) - playback_start_time; + timeline_position = current_time; + + // Trigger markers during playback + for (const auto& marker : markers) { + float marker_time = std::get<0>(marker) * timeline_duration; + if (current_time >= marker_time && current_time < marker_time + 0.025f) { // Slight tolerance for timing precision + buffer[0] = std::get<1>(marker); + buffer[1] = std::get<2>(marker); + buffer[2] = std::get<3>(marker); + } + } + + // Stop playback when the timeline reaches the end + if (timeline_position >= timeline_duration) { + is_playing = false; + timeline_position = timeline_duration; + } + } + + // Display added markers with their RGB values and time + for (const auto& marker : markers) { + float marker_time = std::get<0>(marker) * timeline_duration; + ImGui::Text("Marker at %.2f sec: R=%d, G=%d, B=%d", + marker_time, + std::get<1>(marker), + std::get<2>(marker), + std::get<3>(marker)); + } + // Place Zoom and Pan sliders below the timeline to avoid overlap ImGui::SliderFloat("Zoom", &zoom_level, 0.1f, 10.0f); ImGui::SliderFloat("Pan", &pan_offset, 0.0f, timeline_duration * zoom_level);