From d8a771e24fc52d645c56b52cb02897ceafef89b2 Mon Sep 17 00:00:00 2001 From: Bruno Herbelin Date: Mon, 23 Dec 2024 19:16:01 +0100 Subject: [PATCH] Merge changes for dev Input Mapping Timer --- src/CMakeLists.txt | 2 +- src/InputMappingWindow.cpp | 79 +++++++++++++++++++++++++++++++++++- src/InputMappingWindow.h | 4 +- src/TimerMetronomeWindow.cpp | 2 - src/defines.h | 1 + 5 files changed, 82 insertions(+), 6 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6d19fba..b93da17 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -309,7 +309,7 @@ IF(APPLE) ## POST INSTALL DMG SIGNING AND NOTARIZATION ## 1. SIGN DMG - ## codesign + ## codesign --force --sign "Developer ID Application: " ## codesign --verify --verbose=2 ./_CPack_Packages/OSX_13_arm64/DragNDrop/vimix_0.8.2_OSX_13_arm64.dmg ## ## 2. SUBMIT TO NOTARIZATION diff --git a/src/InputMappingWindow.cpp b/src/InputMappingWindow.cpp index 490bd50..880ca8c 100644 --- a/src/InputMappingWindow.cpp +++ b/src/InputMappingWindow.cpp @@ -22,6 +22,8 @@ #include #include +#define GLM_ENABLE_EXPERIMENTAL +#include // ImGui #include "ImGuiToolkit.h" @@ -43,7 +45,8 @@ InputMappingWindow::InputMappingWindow() : WorkspaceWindow("InputMappingInterfac input_mode = { ICON_FA_KEYBOARD " Keyboard", ICON_FA_CALCULATOR " Numpad" , ICON_FA_TABLET_ALT " TouchOSC" , - ICON_FA_GAMEPAD " Gamepad" }; + ICON_FA_GAMEPAD " Gamepad", + ICON_FA_CLOCK " Timer" }; current_input_for_mode = { INPUT_KEYBOARD_FIRST, INPUT_NUMPAD_FIRST, INPUT_MULTITOUCH_FIRST, INPUT_JOYSTICK_FIRST }; current_input_ = current_input_for_mode[Settings::application.mapping.mode]; } @@ -1184,6 +1187,80 @@ void InputMappingWindow::Render() // Done with color and font change ImGui::PopStyleColor(2); + } + // + // TIMER + // + else if ( Settings::application.mapping.mode == 4 ) { + + ImGuiIO& io = ImGui::GetIO(); + const ImVec2 circle_center = frame_top + (ImVec2(inputarea_width, inputarea_width) )/ 2.f; + const float circle_radius = (inputarea_width - IMGUI_SAME_LINE) / 2.f; + const glm::vec2 mpo = glm::vec2 (io.MousePos.x - circle_center.x, io.MousePos.y - circle_center.y); + const float angle = - glm::orientedAngle( glm::normalize(mpo), glm::vec2(1.f,0.f)); + const float lenght = glm::length(mpo); + const float cm = 0.02f ; // circle margin + + // color palette + static ImU32 colorbg = ImGui::GetColorU32(ImGuiCol_FrameBgActive, 0.6f); + static ImU32 colorfg = ImGui::GetColorU32(ImGuiCol_FrameBg, 2.5f); + static ImU32 colorover = ImGui::GetColorU32(ImGuiCol_Header); + + // draw background ring + draw_list->AddCircleFilled(circle_center, circle_radius, colorbg, PLOT_CIRCLE_SEGMENTS); + + // draw slices + char text_buf[24] = {0}; + const double q = Metronome::manager().quantum(); + static const float resolution = PLOT_CIRCLE_SEGMENTS / (2.f * M_PI); + static ImVec2 buffer[PLOT_CIRCLE_SEGMENTS]; + + for (int p = 0.0 ; p < (int) floor(q) ; p++) { + float a0 = cm + - M_PI_2 + (float(p)/floor(q)) * (2.f * M_PI); + float a1 = (-2.f * 0.02) + a0 + (1.f / floor(q)) * (2.f * M_PI); + int n = ImMax(3, (int)((a1 - a0) * resolution)); + double da = (a1 - a0) / (n - 1); + int index = 0; + + float a01 = -cm + a0 + (0.5f / floor(q)) * (2.f * M_PI); + buffer[index++] = circle_center + ImVec2(circle_radius * cm * cos(a01), circle_radius * cm * sin(a01)); + for (int i = 0; i < n; ++i) { + double a = a0 + i * da; + buffer[index++] = ImVec2(circle_center.x + circle_radius * cos(a), circle_center.y + circle_radius * sin(a)); + } + + // test mouse over in slices of the circle + // 1) test if mouse is inside area + if (ImGui::IsMouseHoveringRect(frame_top, frame_top + ImVec2(inputarea_width, inputarea_width), true)) + { + // 2) test angle of mouse coordinate in circle + if (lenght < circle_radius && ( ( angle > a0 && angle < a1) || (angle + (2.f * M_PI) > a0 && angle + (2.f * M_PI) < a1) ) ) + { + // draw the mouse-over slice + draw_list->AddConvexPolyFilled(buffer, index, colorover); + // indicate tempo of mouse-over slice + snprintf(text_buf, 24, "%d/%d", p + 1, (int) floor(q) ); + } + } + + float border = 1.f; + // TODO : currently edited slice has a large border + + // draw the border of the slice + draw_list->AddPolyline(buffer, index, colorfg, true, border); + + } + + // centered indicator 'x / N' on mouse over + draw_list->AddCircleFilled(circle_center, circle_radius * 0.25f, colorfg, PLOT_CIRCLE_SEGMENTS); + + // display text indication in the center + ImGuiToolkit::PushFont(ImGuiToolkit::FONT_MONO); + ImVec2 label_size = ImGui::CalcTextSize(text_buf, NULL); + ImGui::SetCursorScreenPos(circle_center - label_size/2); + ImGui::Text("%s", text_buf); + ImGui::PopFont(); + } // Draw child Window (right) to list reactions to input diff --git a/src/InputMappingWindow.h b/src/InputMappingWindow.h index 9ef49fd..4b7fc99 100644 --- a/src/InputMappingWindow.h +++ b/src/InputMappingWindow.h @@ -11,8 +11,8 @@ class SourceCallback; class InputMappingWindow : public WorkspaceWindow { - std::array< std::string, 4 > input_mode; - std::array< uint, 4 > current_input_for_mode; + std::array< std::string, 5 > input_mode; + std::array< uint, 5 > current_input_for_mode; uint current_input_; Target ComboSelectTarget(const Target ¤t); diff --git a/src/TimerMetronomeWindow.cpp b/src/TimerMetronomeWindow.cpp index 76d5282..adbfe63 100644 --- a/src/TimerMetronomeWindow.cpp +++ b/src/TimerMetronomeWindow.cpp @@ -28,8 +28,6 @@ #include "TimerMetronomeWindow.h" -#define PLOT_CIRCLE_SEGMENTS 64 - TimerMetronomeWindow::TimerMetronomeWindow() : WorkspaceWindow("Timer") diff --git a/src/defines.h b/src/defines.h index af90cde..c2987b7 100644 --- a/src/defines.h +++ b/src/defines.h @@ -121,6 +121,7 @@ #define IMGUI_NOTIFICATION_DURATION 2.5f #define IMGUI_TOOLTIP_TIMEOUT 80 #define IMGUI_COLOR_FAILED 1.0, 0.3, 0.2 +#define PLOT_CIRCLE_SEGMENTS 64 #define COLOR_BGROUND 0.2f, 0.2f, 0.2f #define COLOR_NAVIGATOR 0.1f, 0.1f, 0.1f