Fix playback

This commit is contained in:
illyum 2024-08-08 23:36:30 -06:00
parent 59c36bbd98
commit e78c0fa96a

View File

@ -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<float>(glfwGetTime());
playback_start_time = static_cast<float>(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<float>(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);