From f01be34b5eacc4a91c26d24449a8cd6c8553bd81 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Sat, 20 Aug 2022 01:10:30 -0500 Subject: [PATCH] GUI: highlight current macro position not for op macros (yet) --- src/engine/macroInt.cpp | 108 ++++++++++++++++++++++++++++++++++++++++ src/engine/macroInt.h | 11 +++- src/gui/insEdit.cpp | 30 +++++++++-- src/gui/plot_nolerp.cpp | 24 ++++++--- src/gui/plot_nolerp.h | 4 +- 5 files changed, 162 insertions(+), 15 deletions(-) diff --git a/src/engine/macroInt.cpp b/src/engine/macroInt.cpp index 06f04682e..83ad906fa 100644 --- a/src/engine/macroInt.cpp +++ b/src/engine/macroInt.cpp @@ -41,6 +41,7 @@ void DivMacroStruct::doMacro(DivInstrumentMacro& source, bool released, bool tic actualHad=has; had=actualHad; if (has) { + lastPos=pos; val=source.val[pos++]; if (source.rel>=0 && pos>source.rel && !released) { if (source.loop=0 && source.loop>8)^hashTable[(unsigned char)*i]; + } + return nameHash; +} + +#define CONSIDER(x) case NAME_HASH(#x): return &x; break; + +DivMacroStruct* DivMacroInt::structByName(const String& name) { + unsigned int hash=NAME_HASH(name.c_str()); + + switch (hash) { + CONSIDER(vol) + CONSIDER(arp) + CONSIDER(duty) + CONSIDER(wave) + CONSIDER(pitch) + CONSIDER(ex1) + CONSIDER(ex2) + CONSIDER(ex3) + CONSIDER(alg) + CONSIDER(fb) + CONSIDER(fms) + CONSIDER(ams) + CONSIDER(panL) + CONSIDER(panR) + CONSIDER(phaseReset) + CONSIDER(ex4) + CONSIDER(ex5) + CONSIDER(ex6) + CONSIDER(ex7) + CONSIDER(ex8) + } + + return NULL; +} diff --git a/src/engine/macroInt.h b/src/engine/macroInt.h index 839625558..8569dce42 100644 --- a/src/engine/macroInt.h +++ b/src/engine/macroInt.h @@ -25,13 +25,13 @@ class DivEngine; struct DivMacroStruct { - int pos; + int pos, lastPos; int val; bool has, had, actualHad, finished, will, linger; unsigned int mode; void doMacro(DivInstrumentMacro& source, bool released, bool tick); void init() { - pos=mode=0; + pos=lastPos=mode=0; has=had=actualHad=will=false; linger=false; // TODO: test whether this breaks anything? @@ -127,6 +127,13 @@ class DivMacroInt { */ void notifyInsDeletion(DivInstrument* which); + /** + * get DivMacroStruct by macro name. + * @param which the macro name. + * @return a DivMacroStruct, or NULL if none found. + */ + DivMacroStruct* structByName(const String& name); + DivMacroInt(): e(NULL), ins(NULL), diff --git a/src/gui/insEdit.cpp b/src/gui/insEdit.cpp index d09c8e2e7..dc239fcd7 100644 --- a/src/gui/insEdit.cpp +++ b/src/gui/insEdit.cpp @@ -19,6 +19,7 @@ #include "gui.h" #include "imgui_internal.h" +#include "../engine/macroInt.h" #include "IconsFontAwesome4.h" #include "misc/cpp/imgui_stdlib.h" #include "guiConst.h" @@ -1195,6 +1196,7 @@ void FurnaceGUI::drawMacros(std::vector& macros) { float asFloat[256]; int asInt[256]; float loopIndicator[256]; + bool doHighlight[256]; int index=0; float reservedSpace=(settings.oldMacroVSlider)?(20.0f*dpiScale+ImGui::GetStyle().ItemSpacing.x):ImGui::GetStyle().ScrollbarSize; @@ -1285,11 +1287,33 @@ void FurnaceGUI::drawMacros(std::vector& macros) { if (i.macro->vZoom>(i.max-i.min)) { i.macro->vZoom=i.max-i.min; } - + + memset(doHighlight,0,256*sizeof(bool)); + if (e->isRunning()) for (int j=0; jgetTotalChannelCount(); j++) { + DivChannelState* chanState=e->getChanState(j); + if (chanState==NULL) continue; + + if (chanState->keyOff) continue; + if (chanState->lastIns!=curIns) continue; + + DivMacroInt* macroInt=e->getMacroInt(j); + if (macroInt==NULL) continue; + + DivMacroStruct* macroStruct=macroInt->structByName(i.macro->name); + if (macroStruct==NULL) continue; + + if (macroStruct->lastPos>i.macro->len) continue; + if (macroStruct->lastPoslastPos>255) continue; + if (!macroStruct->actualHad) continue; + + doHighlight[macroStruct->lastPos-macroDragScroll]=true; + } + if (i.isBitfield) { - PlotBitfield("##IMacro",asInt,totalFit,0,i.bitfieldBits,i.max,ImVec2(availableWidth,(i.macro->open)?(i.height*dpiScale):(32.0f*dpiScale))); + PlotBitfield("##IMacro",asInt,totalFit,0,i.bitfieldBits,i.max,ImVec2(availableWidth,(i.macro->open)?(i.height*dpiScale):(32.0f*dpiScale)),sizeof(float),doHighlight); } else { - PlotCustom("##IMacro",asFloat,totalFit,macroDragScroll,NULL,i.min+i.macro->vScroll,i.min+i.macro->vScroll+i.macro->vZoom,ImVec2(availableWidth,(i.macro->open)?(i.height*dpiScale):(32.0f*dpiScale)),sizeof(float),i.color,i.macro->len-macroDragScroll,i.hoverFunc,i.blockMode,i.macro->open?genericGuide:NULL); + PlotCustom("##IMacro",asFloat,totalFit,macroDragScroll,NULL,i.min+i.macro->vScroll,i.min+i.macro->vScroll+i.macro->vZoom,ImVec2(availableWidth,(i.macro->open)?(i.height*dpiScale):(32.0f*dpiScale)),sizeof(float),i.color,i.macro->len-macroDragScroll,i.hoverFunc,i.blockMode,i.macro->open?genericGuide:NULL,doHighlight); } if (i.macro->open && (ImGui::IsItemClicked(ImGuiMouseButton_Left) || ImGui::IsItemClicked(ImGuiMouseButton_Right))) { macroDragStart=ImGui::GetItemRectMin(); diff --git a/src/gui/plot_nolerp.cpp b/src/gui/plot_nolerp.cpp index 64ffc4100..d802cbc52 100644 --- a/src/gui/plot_nolerp.cpp +++ b/src/gui/plot_nolerp.cpp @@ -183,7 +183,7 @@ void PlotNoLerp(const char* label, const float* values, int values_count, int va PlotNoLerpEx(ImGuiPlotType_Lines, label, &Plot_ArrayGetter, (void*)&data, values_count, values_offset, overlay_text, scale_min, scale_max, graph_size); } -int PlotBitfieldEx(const char* label, int (*values_getter)(void* data, int idx), void* data, int values_count, int values_offset, const char** overlay_text, int bits, ImVec2 frame_size) +int PlotBitfieldEx(const char* label, int (*values_getter)(void* data, int idx), void* data, int values_count, int values_offset, const char** overlay_text, int bits, ImVec2 frame_size, const bool* values_highlight, ImVec4 highlightColor) { ImGuiContext& g = *GImGui; ImGuiWindow* window = ImGui::GetCurrentWindow(); @@ -253,7 +253,11 @@ int PlotBitfieldEx(const char* label, int (*values_getter)(void* data, int idx), if (pos1.y <= pos0.y - 2.0f) pos1.y += 1.0f; if (v1&(1<DrawList->AddRectFilled(pos0, pos1, idx_hovered == v1_idx ? col_hovered : col_base); + ImU32 rCol=(idx_hovered == v1_idx ? col_hovered : col_base); + if (values_highlight!=NULL) { + if (values_highlight[v1_idx]) rCol=ImGui::GetColorU32(highlightColor); + } + window->DrawList->AddRectFilled(pos0, pos1, rCol); } } tp0 = tp1; @@ -283,13 +287,13 @@ int PlotBitfieldEx(const char* label, int (*values_getter)(void* data, int idx), return idx_hovered; } -void PlotBitfield(const char* label, const int* values, int values_count, int values_offset, const char** overlay_text, int bits, ImVec2 graph_size, int stride) +void PlotBitfield(const char* label, const int* values, int values_count, int values_offset, const char** overlay_text, int bits, ImVec2 graph_size, int stride, const bool* values_highlight, ImVec4 highlightColor) { FurnacePlotIntArrayGetterData data(values, stride); - PlotBitfieldEx(label, &Plot_IntArrayGetter, (void*)&data, values_count, values_offset, overlay_text, bits, graph_size); + PlotBitfieldEx(label, &Plot_IntArrayGetter, (void*)&data, values_count, values_offset, overlay_text, bits, graph_size, values_highlight, highlightColor); } -int PlotCustomEx(ImGuiPlotType plot_type, const char* label, float (*values_getter)(void* data, int idx), void* data, int values_count, int values_display_offset, const char* overlay_text, float scale_min, float scale_max, ImVec2 frame_size, ImVec4 color, int highlight, std::string (*hoverFunc)(int,float), bool blockMode, std::string (*guideFunc)(float)) +int PlotCustomEx(ImGuiPlotType plot_type, const char* label, float (*values_getter)(void* data, int idx), void* data, int values_count, int values_display_offset, const char* overlay_text, float scale_min, float scale_max, ImVec2 frame_size, ImVec4 color, int highlight, std::string (*hoverFunc)(int,float), bool blockMode, std::string (*guideFunc)(float), const bool* values_highlight, ImVec4 highlightColor) { ImGuiContext& g = *GImGui; ImGuiWindow* window = ImGui::GetCurrentWindow(); @@ -413,7 +417,11 @@ int PlotCustomEx(ImGuiPlotType plot_type, const char* label, float (*values_gett pos0.y-=(inner_bb.Max.y-inner_bb.Min.y)*inv_scale; //pos1.y+=1.0f; } - window->DrawList->AddRectFilled(pos0, pos1, idx_hovered == v1_idx ? col_hovered : col_base); + ImU32 rCol=(idx_hovered == v1_idx ? col_hovered : col_base); + if (values_highlight!=NULL) { + if (values_highlight[v1_idx]) rCol=ImGui::GetColorU32(highlightColor); + } + window->DrawList->AddRectFilled(pos0, pos1, rCol); } t0 = t1; @@ -451,8 +459,8 @@ int PlotCustomEx(ImGuiPlotType plot_type, const char* label, float (*values_gett return idx_hovered; } -void PlotCustom(const char* label, const float* values, int values_count, int values_offset, const char* overlay_text, float scale_min, float scale_max, ImVec2 graph_size, int stride, ImVec4 color, int highlight, std::string (*hoverFunc)(int,float), bool blockMode, std::string (*guideFunc)(float)) +void PlotCustom(const char* label, const float* values, int values_count, int values_offset, const char* overlay_text, float scale_min, float scale_max, ImVec2 graph_size, int stride, ImVec4 color, int highlight, std::string (*hoverFunc)(int,float), bool blockMode, std::string (*guideFunc)(float), const bool* values_highlight, ImVec4 highlightColor) { FurnacePlotArrayGetterData data(values, stride); - PlotCustomEx(ImGuiPlotType_Histogram, label, &Plot_ArrayGetter, (void*)&data, values_count, values_offset, overlay_text, scale_min, scale_max, graph_size, color, highlight, hoverFunc, blockMode, guideFunc); + PlotCustomEx(ImGuiPlotType_Histogram, label, &Plot_ArrayGetter, (void*)&data, values_count, values_offset, overlay_text, scale_min, scale_max, graph_size, color, highlight, hoverFunc, blockMode, guideFunc, values_highlight, highlightColor); } \ No newline at end of file diff --git a/src/gui/plot_nolerp.h b/src/gui/plot_nolerp.h index 5862dfadc..b353e6f8b 100644 --- a/src/gui/plot_nolerp.h +++ b/src/gui/plot_nolerp.h @@ -21,5 +21,5 @@ #include void PlotNoLerp(const char* label, const float* values, int values_count, int values_offset = 0, const char* overlay_text = NULL, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0, 0), int stride = sizeof(float)); -void PlotBitfield(const char* label, const int* values, int values_count, int values_offset = 0, const char** overlay_text = NULL, int bits = 8, ImVec2 graph_size = ImVec2(0, 0), int stride = sizeof(float)); -void PlotCustom(const char* label, const float* values, int values_count, int values_offset = 0, const char* overlay_text = NULL, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0, 0), int stride = sizeof(float), ImVec4 fgColor = ImVec4(1.0f,1.0f,1.0f,1.0f), int highlight = 0, std::string (*hoverFunc)(int,float) = NULL, bool blockMode=false, std::string (*guideFunc)(float) = NULL); \ No newline at end of file +void PlotBitfield(const char* label, const int* values, int values_count, int values_offset = 0, const char** overlay_text = NULL, int bits = 8, ImVec2 graph_size = ImVec2(0, 0), int stride = sizeof(float), const bool* values_highlight = NULL, ImVec4 highlightColor = ImVec4(1.0f,1.0f,1.0f,1.0f)); +void PlotCustom(const char* label, const float* values, int values_count, int values_offset = 0, const char* overlay_text = NULL, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0, 0), int stride = sizeof(float), ImVec4 fgColor = ImVec4(1.0f,1.0f,1.0f,1.0f), int highlight = 0, std::string (*hoverFunc)(int,float) = NULL, bool blockMode=false, std::string (*guideFunc)(float) = NULL, const bool* values_highlight = NULL, ImVec4 highlightColor = ImVec4(1.0f,1.0f,1.0f,1.0f)); \ No newline at end of file