GUI: highlight current macro position

not for op macros (yet)
This commit is contained in:
tildearrow 2022-08-20 01:10:30 -05:00
parent 24e3dec84f
commit f01be34b5e
5 changed files with 162 additions and 15 deletions

View File

@ -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<source.len && source.loop>=0 && source.loop<source.rel) {
@ -251,3 +252,110 @@ void DivMacroInt::notifyInsDeletion(DivInstrument* which) {
init(NULL);
}
}
// randomly-generated
constexpr unsigned int hashTable[256]={
0x0718657, 0xe904eb33, 0x14b2da2b, 0x0ef67ca9,
0x0f0559a, 0x4142065a, 0x4d9ab4ba, 0x3cdd601a,
0x6635aca, 0x2c41ab72, 0xf98e8d31, 0x1003ee63,
0x3fd9fb5, 0x30734d16, 0xe8964431, 0x29bb9b79,
0x817f580, 0xfe083b9e, 0x974b5e85, 0x3b5729c2,
0x2afea96, 0xf1573b4b, 0x308a1024, 0xaa94b92d,
0x693fa93, 0x547ba3da, 0xac4f206c, 0x93f72ea9,
0xcc44001, 0x37e27670, 0xf35a63d0, 0xd1cdbb92,
0x7c7ee24, 0xfa267ee9, 0xf9cd9956, 0x6a6768d4,
0x9e6a108, 0xf6ca4bd0, 0xa53cba9f, 0x526a523a,
0xf46f0c8, 0xf131bd4c, 0x82800d48, 0xabff9214,
0x40eabd4, 0xea0ef8f7, 0xdc3968d6, 0x54c3cb63,
0x8855023, 0xaab73861, 0xff0bea2c, 0x139b9765,
0x4a21279, 0x6b2aa29a, 0xf147cc3f, 0xc42edc1a,
0xfe2f86f, 0x6d352047, 0xd3cac3e4, 0x35e5c389,
0xe923727, 0x12fe3b32, 0x204295c5, 0x254a8b7a,
0xc1d995d, 0x26a512d2, 0xa3e34033, 0x9a968df0,
0x53447ed, 0x36cf4077, 0x189b03a7, 0x558790e8,
0x01f921a, 0x840f260c, 0x93dd2b86, 0x12f69cb0,
0x117d93a, 0xcb2cbc2b, 0xd41e3aed, 0x5ff6ec75,
0x607290d, 0xd41adb92, 0x64f94ba7, 0xaff720f7,
0x6bf1d5d, 0xc8e36c6d, 0x7095bab5, 0xdfbf7b0d,
0x01ddeea, 0xe8f262da, 0xf589512f, 0xc2ecac5d,
0xbe29d98, 0xff8b5a2e, 0x18e7279e, 0x6ad24dcb,
0x2b3b9b1, 0x6f5227d8, 0x076d7553, 0x6c5856e2,
0x995f655, 0xe9fcf5a6, 0x83671b70, 0xaf3aed1e,
0xac340f0, 0x5c7008b4, 0x14651282, 0x8bf855b9,
0x4a933af, 0x829b87f1, 0x9a673070, 0xb19da64f,
0x77d8f36, 0x584c9fdc, 0xa9e52c0d, 0x6da5e13d,
0xae1051f, 0xe85e976f, 0xfeac2d9a, 0x19c46754,
0x1cba6f3, 0xaf21bc31, 0x16b6a8d4, 0xe08b0fdb,
0x97e6e54, 0x5da499ae, 0xab472e19, 0xc2491f2e,
0xc08c563, 0xe91b131b, 0xc8e22451, 0x6995c8fe,
0x7042718, 0x01043738, 0xc7d88b28, 0x2d9f330f,
0x4b3aae5, 0xf1e705ba, 0xc5b8ee59, 0xa8ba4e8f,
0x55f65a2, 0xa1899e41, 0x296243c8, 0x1e502bf2,
0x20080de, 0x841d2239, 0x37b082af, 0xbdd7f7da,
0x4075090, 0x1dc7dc49, 0x5cd3c69a, 0x7fb13b62,
0xb382bf1, 0xa0cfbc2f, 0x9eca4dc1, 0xb9355453,
0x5d0dd24, 0x834f4d8e, 0xe9b136b2, 0xe7b8738d,
0x1c91d41, 0x8cb3ddb5, 0xdc600590, 0x607cff55,
0x2ca7675, 0x4622a8e4, 0x9340e414, 0xcb44928a,
0xa9e791c, 0x68849920, 0xc5b5fcd8, 0xbc352269,
0x3ab13cf, 0xaa3cbbd0, 0x1abacc64, 0x623b5b49,
0xcc8c4c3, 0x3c8f2f70, 0x3e584a28, 0x9316d24d,
0xfe315a2, 0x10f0ba7a, 0xed15a523, 0x4f987369,
0x7aa4a4a, 0x90eaf98f, 0xcf0af610, 0x1b38f4e7,
0x19df72d, 0xd8306808, 0xd54e25ac, 0x76b79c6d,
0x58110cf, 0x06a3e5f2, 0x873a6039, 0xf52684e3,
0xecf39c3, 0x7cbb2759, 0xe280d361, 0x91e8471a,
0xa67cdd3, 0x17cac3be, 0xfc9eff1f, 0x71abdf49,
0x6168624, 0xb68f86f7, 0x67a8e72a, 0xe746911d,
0xca48fd7, 0x8f3cc436, 0x3a3851a8, 0x30a7e26e,
0xca49308, 0xb598ef74, 0x49ef167a, 0xa9e17632,
0x0f7308a, 0xf156efed, 0xcf799645, 0xbae4b85a,
0xecba3fe, 0xd97f861d, 0xc164af62, 0xb1aca42f,
0xf249576, 0x83d1bf4e, 0x2f486a9c, 0xd3b53cc2,
0x17d7c26, 0xd95ddae1, 0x76c1a2f5, 0xf8af6782,
0xdbaece4, 0x010b2b53, 0x049be200, 0xd9fd0d1a,
0x37d7e6c, 0x5b848651, 0x203c98c7, 0x669681b0,
0x683086f, 0xdd0ee8ab, 0x5dbe008b, 0xe5d0690d,
0x23dd758, 0x6b34acbc, 0x4b2b3e65, 0xcc7b56c1,
0x196b0a0, 0x7b065105, 0xb731b01a, 0xd37daa16,
0xf77816b, 0x3c9fa546, 0x81dfadb8, 0x39b1fb8b
};
constexpr unsigned int NAME_HASH(const char* name) {
unsigned int nameHash=0xffffffff;
for (const char* i=name; *i; i++) {
nameHash=(nameHash>>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;
}

View File

@ -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),

View File

@ -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<FurnaceGUIMacroDesc>& 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<FurnaceGUIMacroDesc>& 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; j<e->getTotalChannelCount(); 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->lastPos<macroDragScroll) continue;
if (macroStruct->lastPos>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();

View File

@ -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<<o)) {
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);
}
}
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);
}

View File

@ -21,5 +21,5 @@
#include <string>
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);
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));