naive channel pair refactor (dumb replace one pair with vector of pairs)

This commit is contained in:
LTVA1 2024-08-14 20:01:16 +03:00
parent 0ea53fdae5
commit 7c324ec39d
19 changed files with 140 additions and 138 deletions

View file

@ -1282,116 +1282,123 @@ void FurnaceGUI::drawPattern() {
memset(floors,0,4*4*sizeof(unsigned int));
for (int i=0; i<chans; i++) {
bool isPaired=false;
int numPairs=0;
unsigned int pairMin=i;
unsigned int pairMax=i;
unsigned char curFloor=0;
if (!e->curSubSong->chanShow[i]) {
continue;
}
DivChannelPair pairs=e->getChanPaired(i);
for (int j=0; j<8; j++) {
if (pairs.pairs[j]==-1) continue;
int pairCh=e->dispatchFirstChan[i]+pairs.pairs[j];
if (!e->curSubSong->chanShow[pairCh]) {
std::vector<DivChannelPair> pairs;
e->getChanPaired(i, pairs);
for(DivChannelPair pair: pairs)
{
bool isPaired=false;
int numPairs=0;
unsigned int pairMin=i;
unsigned int pairMax=i;
unsigned char curFloor=0;
if (!e->curSubSong->chanShow[i]) {
continue;
}
isPaired=true;
if ((unsigned int)pairCh<pairMin) pairMin=pairCh;
if ((unsigned int)pairCh>pairMax) pairMax=pairCh;
}
if (!isPaired) continue;
float posY=chanHeadBottom;
// find a free floor
while (curFloor<4) {
bool free=true;
for (unsigned int j=pairMin; j<=pairMax; j++) {
const unsigned int j0=j>>5;
const unsigned int j1=1U<<(j&31);
if (floors[curFloor][j0]&j1) {
free=false;
break;
for (int j=0; j<8; j++) {
if (pair.pairs[j]==-1) continue;
int pairCh=e->dispatchFirstChan[i]+pair.pairs[j];
if (!e->curSubSong->chanShow[pairCh]) {
continue;
}
}
if (free) break;
curFloor++;
}
if (curFloor<4) {
// occupy floor
floors[curFloor][pairMin>>5]|=1U<<(pairMin&31);
floors[curFloor][pairMax>>5]|=1U<<(pairMax&31);
}
pos=(patChanX[i+1]+patChanX[i])*0.5;
posCenter=pos;
posMin=pos;
posMax=pos;
numPairs++;
if (pairs.label==NULL) {
textSize=ImGui::CalcTextSize("???");
} else {
textSize=ImGui::CalcTextSize(pairs.label);
}
posY+=(textSize.y+ImGui::GetStyle().ItemSpacing.y)*curFloor;
tdl->AddLine(
ImVec2(pos,chanHeadBottom),
ImVec2(pos,posY+textSize.y),
ImGui::GetColorU32(uiColors[GUI_COLOR_PATTERN_PAIR]),
2.0f*dpiScale
);
for (int j=0; j<8; j++) {
if (pairs.pairs[j]==-1) continue;
int pairCh=e->dispatchFirstChan[i]+pairs.pairs[j];
if (!e->curSubSong->chanShow[pairCh]) {
continue;
isPaired=true;
if ((unsigned int)pairCh<pairMin) pairMin=pairCh;
if ((unsigned int)pairCh>pairMax) pairMax=pairCh;
}
pos=(patChanX[pairCh+1]+patChanX[pairCh])*0.5;
posCenter+=pos;
if (!isPaired) continue;
float posY=chanHeadBottom;
// find a free floor
while (curFloor<4) {
bool free=true;
for (unsigned int j=pairMin; j<=pairMax; j++) {
const unsigned int j0=j>>5;
const unsigned int j1=1U<<(j&31);
if (floors[curFloor][j0]&j1) {
free=false;
break;
}
}
if (free) break;
curFloor++;
}
if (curFloor<4) {
// occupy floor
floors[curFloor][pairMin>>5]|=1U<<(pairMin&31);
floors[curFloor][pairMax>>5]|=1U<<(pairMax&31);
}
pos=(patChanX[i+1]+patChanX[i])*0.5;
posCenter=pos;
posMin=pos;
posMax=pos;
numPairs++;
if (pos<posMin) posMin=pos;
if (pos>posMax) posMax=pos;
if (pair.label==NULL) {
textSize=ImGui::CalcTextSize("???");
} else {
textSize=ImGui::CalcTextSize(pair.label);
}
posY+=(textSize.y+ImGui::GetStyle().ItemSpacing.y)*curFloor;
tdl->AddLine(
ImVec2(pos,chanHeadBottom),
ImVec2(pos,posY+textSize.y),
ImGui::GetColorU32(uiColors[GUI_COLOR_PATTERN_PAIR]),
2.0f*dpiScale
);
}
posCenter/=numPairs;
for (int j=0; j<8; j++) {
if (pair.pairs[j]==-1) continue;
int pairCh=e->dispatchFirstChan[i]+pair.pairs[j];
if (!e->curSubSong->chanShow[pairCh]) {
continue;
}
if (pairs.label==NULL) {
tdl->AddLine(
ImVec2(posMin,posY+textSize.y),
ImVec2(posMax,posY+textSize.y),
ImGui::GetColorU32(uiColors[GUI_COLOR_PATTERN_PAIR]),
2.0f*dpiScale
);
} else {
tdl->AddLine(
ImVec2(posMin,posY+textSize.y),
ImVec2(posCenter-textSize.x*0.5-6.0f*dpiScale,posY+textSize.y),
ImGui::GetColorU32(uiColors[GUI_COLOR_PATTERN_PAIR]),
2.0f*dpiScale
);
tdl->AddLine(
ImVec2(posCenter+textSize.x*0.5+6.0f*dpiScale,posY+textSize.y),
ImVec2(posMax,posY+textSize.y),
ImGui::GetColorU32(uiColors[GUI_COLOR_PATTERN_PAIR]),
2.0f*dpiScale
);
pos=(patChanX[pairCh+1]+patChanX[pairCh])*0.5;
posCenter+=pos;
numPairs++;
if (pos<posMin) posMin=pos;
if (pos>posMax) posMax=pos;
tdl->AddLine(
ImVec2(pos,chanHeadBottom),
ImVec2(pos,posY+textSize.y),
ImGui::GetColorU32(uiColors[GUI_COLOR_PATTERN_PAIR]),
2.0f*dpiScale
);
}
delayedLabels.push_back(DelayedLabel(posCenter,posY,textSize,pairs.label));
posCenter/=numPairs;
if (pair.label==NULL) {
tdl->AddLine(
ImVec2(posMin,posY+textSize.y),
ImVec2(posMax,posY+textSize.y),
ImGui::GetColorU32(uiColors[GUI_COLOR_PATTERN_PAIR]),
2.0f*dpiScale
);
} else {
tdl->AddLine(
ImVec2(posMin,posY+textSize.y),
ImVec2(posCenter-textSize.x*0.5-6.0f*dpiScale,posY+textSize.y),
ImGui::GetColorU32(uiColors[GUI_COLOR_PATTERN_PAIR]),
2.0f*dpiScale
);
tdl->AddLine(
ImVec2(posCenter+textSize.x*0.5+6.0f*dpiScale,posY+textSize.y),
ImVec2(posMax,posY+textSize.y),
ImGui::GetColorU32(uiColors[GUI_COLOR_PATTERN_PAIR]),
2.0f*dpiScale
);
delayedLabels.push_back(DelayedLabel(posCenter,posY,textSize,pair.label));
}
}
}