Skip to content

Commit

Permalink
GUI: channel pair hints, part 1
Browse files Browse the repository at this point in the history
very ugly
  • Loading branch information
tildearrow committed Oct 8, 2023
1 parent f2e6207 commit 4b008f4
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/engine/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1418,6 +1418,11 @@ void* DivEngine::getDispatchChanState(int ch) {
return disCont[dispatchOfChan[ch]].dispatch->getChanState(dispatchChanOfChan[ch]);
}

DivChannelPair DivEngine::getChanPaired(int ch) {
if (ch<0 || ch>=chans) return DivChannelPair();
return disCont[dispatchOfChan[ch]].dispatch->getPaired(dispatchChanOfChan[ch]);
}

unsigned char* DivEngine::getRegisterPool(int sys, int& size, int& depth) {
if (sys<0 || sys>=song.systemLen) return NULL;
if (disCont[sys].dispatch==NULL) return NULL;
Expand Down Expand Up @@ -1912,11 +1917,13 @@ void DivEngine::recalcChans() {
memset(isInsTypePossible,0,DIV_INS_MAX*sizeof(bool));
for (int i=0; i<song.systemLen; i++) {
int chanCount=getChannelCount(song.system[i]);
int firstChan=chans;
chans+=chanCount;
for (int j=0; j<chanCount; j++) {
sysOfChan[chanIndex]=song.system[i];
dispatchOfChan[chanIndex]=i;
dispatchChanOfChan[chanIndex]=j;
dispatchFirstChan[chanIndex]=firstChan;
chanIndex++;

if (sysDefs[song.system[i]]!=NULL) {
Expand Down
5 changes: 5 additions & 0 deletions src/engine/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,7 @@ class DivEngine {
DivSystem sysOfChan[DIV_MAX_CHANS];
int dispatchOfChan[DIV_MAX_CHANS];
int dispatchChanOfChan[DIV_MAX_CHANS];
int dispatchFirstChan[DIV_MAX_CHANS];
bool keyHit[DIV_MAX_CHANS];
float* oscBuf[DIV_MAX_OUTPUTS];
float oscSize;
Expand Down Expand Up @@ -1009,6 +1010,9 @@ class DivEngine {
// get dispatch channel state
void* getDispatchChanState(int chan);

// get channel pairs
DivChannelPair getChanPaired(int chan);

// get register pool
unsigned char* getRegisterPool(int sys, int& size, int& depth);

Expand Down Expand Up @@ -1320,6 +1324,7 @@ class DivEngine {
mu5ROM(NULL) {
memset(isMuted,0,DIV_MAX_CHANS*sizeof(bool));
memset(keyHit,0,DIV_MAX_CHANS*sizeof(bool));
memset(dispatchFirstChan,0,DIV_MAX_CHANS*sizeof(int));
memset(dispatchChanOfChan,0,DIV_MAX_CHANS*sizeof(int));
memset(dispatchOfChan,0,DIV_MAX_CHANS*sizeof(int));
memset(sysOfChan,0,DIV_MAX_CHANS*sizeof(int));
Expand Down
101 changes: 101 additions & 0 deletions src/gui/pattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ void FurnaceGUI::drawPattern() {
int ord=curOrder;
int chans=e->getTotalChannelCount();
int displayChans=0;
float chanHeadBottom=0.0f;
const DivPattern* patCache[DIV_MAX_CHANS];
for (int i=0; i<chans; i++) {
if (e->curSubSong->chanShow[i]) displayChans++;
Expand Down Expand Up @@ -998,6 +999,7 @@ void FurnaceGUI::drawPattern() {
}
}
}
chanHeadBottom=ImGui::GetCursorScreenPos().y;
}
ImGui::TableNextColumn();
lastPatternWidth=ImGui::GetCursorPosX()-lpwStart+ImGui::GetStyle().ScrollbarSize;
Expand Down Expand Up @@ -1135,6 +1137,105 @@ void FurnaceGUI::drawPattern() {
ImGui::EndTable();
}

if (patChannelPairs && e->isRunning()) { // pair hints
ImDrawList* dl=ImGui::GetWindowDrawList();
float pos=0.0f;
float posCenter=0.0f;
float posMin=FLT_MAX;
float posMax=-FLT_MAX;
float posY=chanHeadBottom;
ImVec2 textSize;

for (int i=0; i<chans; i++) {
bool isPaired=false;
int numPairs=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]) {
continue;
}
isPaired=true;
break;
}

if (!isPaired) continue;

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);
}
dl->AddLine(
ImVec2(pos,posY),
ImVec2(pos,posY+textSize.y),
0xffffffff,
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;
}

pos=(patChanX[pairCh+1]+patChanX[pairCh])*0.5;
posCenter+=pos;
numPairs++;
if (pos<posMin) posMin=pos;
if (pos>posMax) posMax=pos;
dl->AddLine(
ImVec2(pos,posY),
ImVec2(pos,posY+textSize.y),
0xffffffff,
dpiScale
);
}

posCenter/=numPairs;

if (pairs.label==NULL) {
dl->AddLine(
ImVec2(posMin,posY+textSize.y),
ImVec2(posMax,posY+textSize.y),
0xffffffff,
dpiScale
);
} else {
dl->AddLine(
ImVec2(posMin,posY+textSize.y),
ImVec2(posCenter-textSize.x*0.5,posY+textSize.y),
0xffffffff,
dpiScale
);
dl->AddLine(
ImVec2(posCenter+textSize.x*0.5,posY+textSize.y),
ImVec2(posMax,posY+textSize.y),
0xffffffff,
dpiScale
);

dl->AddText(
ImVec2(posCenter-textSize.x*0.5,posY+textSize.y*0.5),
0xffffffff,
pairs.label
);
}
}
}

if (fancyPattern) { // visualizer
e->getCommandStream(cmdStream);
ImDrawList* dl=ImGui::GetWindowDrawList();
Expand Down

0 comments on commit 4b008f4

Please sign in to comment.