From 564b74be7f410c5c98eaf55323a011d7d9867920 Mon Sep 17 00:00:00 2001 From: dreamer Date: Fri, 10 Nov 2023 09:28:53 +0100 Subject: [PATCH] use enumerator for parameter IDs in the UI --- .../c2dpf/templates/HeavyDPF_UI.cpp | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/hvcc/generators/c2dpf/templates/HeavyDPF_UI.cpp b/hvcc/generators/c2dpf/templates/HeavyDPF_UI.cpp index 20f53805..7343eb3f 100644 --- a/hvcc/generators/c2dpf/templates/HeavyDPF_UI.cpp +++ b/hvcc/generators/c2dpf/templates/HeavyDPF_UI.cpp @@ -6,6 +6,14 @@ START_NAMESPACE_DISTRHO // -------------------------------------------------------------------------------------------------------------------- +{%- if receivers|length > 0 %} +enum HeavyParams { + {%- for k, v in receivers %} + {{v.display|upper}}, + {%- endfor %} +}; +{%- endif %} + class ImGuiPluginUI : public UI { {% for k, v in receivers -%} @@ -51,7 +59,7 @@ class ImGuiPluginUI : public UI {%- if receivers|length > 0 %} switch (index) { {% for k, v in receivers -%} - case {{loop.index-1}}: + case {{v.display|upper}}: {%- if v.attributes.type == 'bool': %} f{{v.display|lower}} = value != 0.0f; {%- else %} @@ -105,8 +113,8 @@ class ImGuiPluginUI : public UI if (ImGui::Selectable({{enum_list}}[n], is_selected)) { f{{v_display}} = n; - editParameter({{loop.index-1}}, true); - setParameterValue({{loop.index-1}}, f{{v_display}}); + editParameter({{v.display|upper}}, true); + setParameterValue({{v.display|upper}}, f{{v_display}}); } if (is_selected) ImGui::SetItemDefaultFocus(); @@ -124,17 +132,17 @@ class ImGuiPluginUI : public UI { if (ImGui::IsItemActivated()) { - editParameter({{loop.index-1}}, true); - setParameterValue({{loop.index-1}}, f{{v_display}}); + editParameter({{v.display|upper}}, true); + setParameterValue({{v.display|upper}}, f{{v_display}}); } } {%- endif %} {% endfor %} if (ImGui::IsItemDeactivated()) { - {%- for i in range(0, receivers|length) %} - editParameter({{i}}, false); - {%- endfor %} + {%- for k, v in receivers -%} + editParameter({{v.display|upper}}, false); + {% endfor -%} } } ImGui::End();