From 9f48bda59af3de1286ec5b801ec09c45290056da Mon Sep 17 00:00:00 2001 From: tildearrow Date: Mon, 13 Feb 2023 18:33:25 -0500 Subject: [PATCH] GUI: fix effect replace issue #652 --- src/gui/findReplace.cpp | 20 ++++++++++++++++---- src/gui/gui.cpp | 2 +- src/gui/gui.h | 10 +++++++--- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/gui/findReplace.cpp b/src/gui/findReplace.cpp index 60b6c899b..0755e791e 100644 --- a/src/gui/findReplace.cpp +++ b/src/gui/findReplace.cpp @@ -117,11 +117,14 @@ void FurnaceGUI::doFind() { curQueryResults.clear(); + signed char effectPos[8]; + for (int i=firstOrder; i<=lastOrder; i++) { for (int j=firstRow; j<=lastRow; j++) { for (int k=firstChan; k<=lastChan; k++) { DivPattern* p=e->curPat[k].getPattern(e->curOrders->ord[k][i],false); bool matched=false; + memset(effectPos,-1,8); for (FurnaceGUIFindQuery& l: curQuery) { if (matched) break; @@ -139,6 +142,7 @@ void FurnaceGUI::doFind() { if (!checkCondition(l.effectMode[m],l.effect[m],l.effectMax[m],p->data[j][4+n*2])) continue; if (!checkCondition(l.effectValMode[m],l.effectVal[m],l.effectValMax[m],p->data[j][5+n*2])) continue; allGood=true; + effectPos[m]=n; break; } if (!allGood) { @@ -175,6 +179,7 @@ void FurnaceGUI::doFind() { notMatched=true; break; } + effectPos[m]=m+posOfFirst; } break; } @@ -192,6 +197,7 @@ void FurnaceGUI::doFind() { notMatched=true; break; } + effectPos[m]=m; } } break; @@ -202,7 +208,7 @@ void FurnaceGUI::doFind() { matched=true; } if (matched) { - curQueryResults.push_back(FurnaceGUIQueryResult(e->getCurrentSubSong(),i,k,j)); + curQueryResults.push_back(FurnaceGUIQueryResult(e->getCurrentSubSong(),i,k,j,effectPos)); } } } @@ -369,6 +375,9 @@ void FurnaceGUI::doReplace() { break; case 1: { // replace matches int placementIndex=0; + for (int j=0; j<8 && placementIndex<8 && i.effectPos[j]>=0; j++) { + effectOrder[placementIndex++]=i.effectPos[j]; + } for (int j=0; jsong.subsong[i.subsong]->pat[i.x].effectCols; j++) { if (p->data[i.y][4+j*2]!=-1 || p->data[i.y][5+j*2]!=-1) { effectOrder[placementIndex++]=j; @@ -378,6 +387,9 @@ void FurnaceGUI::doReplace() { } case 2: { // replace matches then free spaces int placementIndex=0; + for (int j=0; j<8 && placementIndex<8 && i.effectPos[j]>=0; j++) { + effectOrder[placementIndex++]=i.effectPos[j]; + } for (int j=0; jsong.subsong[i.subsong]->pat[i.x].effectCols; j++) { if (p->data[i.y][4+j*2]!=-1 || p->data[i.y][5+j*2]!=-1) { effectOrder[placementIndex++]=j; @@ -1094,15 +1106,15 @@ void FurnaceGUI::drawFindReplace() { ImGui::EndTable(); } ImGui::Text("Effect replace mode:"); - if (ImGui::RadioButton("Clear effects",queryReplaceEffectPos==0)) { - queryReplaceEffectPos=0; - } if (ImGui::RadioButton("Replace matches only",queryReplaceEffectPos==1)) { queryReplaceEffectPos=1; } if (ImGui::RadioButton("Replace matches, then free spaces",queryReplaceEffectPos==2)) { queryReplaceEffectPos=2; } + if (ImGui::RadioButton("Clear effects",queryReplaceEffectPos==0)) { + queryReplaceEffectPos=0; + } if (ImGui::RadioButton("Insert in free spaces",queryReplaceEffectPos==3)) { queryReplaceEffectPos=3; } diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index e239226ed..0fc1b54a2 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -6029,7 +6029,7 @@ FurnaceGUI::FurnaceGUI(): curQueryRangeY(0), curQueryEffectPos(0), queryReplaceEffectCount(0), - queryReplaceEffectPos(0), + queryReplaceEffectPos(1), queryReplaceNoteMode(0), queryReplaceInsMode(0), queryReplaceVolMode(0), diff --git a/src/gui/gui.h b/src/gui/gui.h index ea4b10a71..3ffebf9ef 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -1073,16 +1073,20 @@ struct FurnaceGUIFindQuery { struct FurnaceGUIQueryResult { int subsong, order, x, y; + signed char effectPos[8]; FurnaceGUIQueryResult(): subsong(0), order(0), x(0), - y(0) {} - FurnaceGUIQueryResult(int ss, int o, int xPos, int yPos): + y(0), + effectPos{-1,-1,-1,-1,-1,-1,-1,-1} {} + FurnaceGUIQueryResult(int ss, int o, int xPos, int yPos, const signed char* fxPos): subsong(ss), order(o), x(xPos), - y(yPos) {} + y(yPos) { + memcpy(effectPos,fxPos,8); + } }; class FurnaceGUI {