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

@ -603,10 +603,10 @@ class DivDispatch {
/** /**
* get "paired" channels. * get "paired" channels.
* @param chan the channel to query. * @param ch the channel to query.
* @return a DivChannelPair. * @param ret the DivChannelPair vector of pairs.
*/ */
virtual DivChannelPair getPaired(int chan); virtual void getPaired(int ch, std::vector<DivChannelPair>& ret);
/** /**
* get channel mode hints. * get channel mode hints.

View file

@ -1549,9 +1549,9 @@ void* DivEngine::getDispatchChanState(int ch) {
return disCont[dispatchOfChan[ch]].dispatch->getChanState(dispatchChanOfChan[ch]); return disCont[dispatchOfChan[ch]].dispatch->getChanState(dispatchChanOfChan[ch]);
} }
DivChannelPair DivEngine::getChanPaired(int ch) { void DivEngine::getChanPaired(int ch, std::vector<DivChannelPair>& ret) {
if (ch<0 || ch>=chans) return DivChannelPair(); if (ch<0 || ch>=chans) return;
return disCont[dispatchOfChan[ch]].dispatch->getPaired(dispatchChanOfChan[ch]); disCont[dispatchOfChan[ch]].dispatch->getPaired(dispatchChanOfChan[ch], ret);
} }
DivChannelModeHints DivEngine::getChanModeHints(int ch) { DivChannelModeHints DivEngine::getChanModeHints(int ch) {

View file

@ -1109,7 +1109,7 @@ class DivEngine {
void* getDispatchChanState(int chan); void* getDispatchChanState(int chan);
// get channel pairs // get channel pairs
DivChannelPair getChanPaired(int chan); void getChanPaired(int chan, std::vector<DivChannelPair>& ret);
// get channel mode hints // get channel mode hints
DivChannelModeHints getChanModeHints(int chan); DivChannelModeHints getChanModeHints(int chan);

View file

@ -37,8 +37,8 @@ unsigned short DivDispatch::getPan(int chan) {
return 0; return 0;
} }
DivChannelPair DivDispatch::getPaired(int chan) { void DivDispatch::getPaired(int ch, std::vector<DivChannelPair>& ret) {
return DivChannelPair(); ret.push_back(DivChannelPair());
} }
DivChannelModeHints DivDispatch::getModeHints(int chan) { DivChannelModeHints DivDispatch::getModeHints(int chan) {

View file

@ -561,12 +561,11 @@ float DivPlatformC140::getPostAmp() {
return 3.0f; return 3.0f;
} }
DivChannelPair DivPlatformC140::getPaired(int ch) { void DivPlatformC140::getPaired(int ch, std::vector<DivChannelPair>& ret) {
if (!is219) return DivChannelPair(); if (!is219) return;
if ((ch&3)==0) { if ((ch&3)==0) {
return DivChannelPair(bankLabel[ch>>2],ch+1,ch+2,ch+3,-1,-1,-1,-1,-1); ret.push_back(DivChannelPair(bankLabel[ch>>2],ch+1,ch+2,ch+3,-1,-1,-1,-1,-1));
} }
return DivChannelPair();
} }
const void* DivPlatformC140::getSampleMem(int index) { const void* DivPlatformC140::getSampleMem(int index) {

View file

@ -89,7 +89,7 @@ class DivPlatformC140: public DivDispatch {
void* getChanState(int chan); void* getChanState(int chan);
DivMacroInt* getChanMacroInt(int ch); DivMacroInt* getChanMacroInt(int ch);
unsigned short getPan(int chan); unsigned short getPan(int chan);
DivChannelPair getPaired(int chan); void getPaired(int ch, std::vector<DivChannelPair>& ret);
DivDispatchOscBuffer* getOscBuffer(int chan); DivDispatchOscBuffer* getOscBuffer(int chan);
unsigned char* getRegisterPool(); unsigned char* getRegisterPool();
int getRegisterPoolSize(); int getRegisterPoolSize();

View file

@ -525,11 +525,10 @@ unsigned short DivPlatformDave::getPan(int ch) {
} }
// TODO: the rest // TODO: the rest
DivChannelPair DivPlatformDave::getPaired(int ch) { void DivPlatformDave::getPaired(int ch, std::vector<DivChannelPair>& ret) {
if (chan[ch].highPass) { if (chan[ch].highPass) {
DivChannelPair("high",(ch+1)&3); ret.push_back(DivChannelPair("high",(ch+1)&3));
} }
return DivChannelPair();
} }
DivChannelModeHints DivPlatformDave::getModeHints(int ch) { DivChannelModeHints DivPlatformDave::getModeHints(int ch) {

View file

@ -76,7 +76,7 @@ class DivPlatformDave: public DivDispatch {
void* getChanState(int chan); void* getChanState(int chan);
DivMacroInt* getChanMacroInt(int ch); DivMacroInt* getChanMacroInt(int ch);
unsigned short getPan(int chan); unsigned short getPan(int chan);
DivChannelPair getPaired(int chan); void getPaired(int ch, std::vector<DivChannelPair>& ret);
DivChannelModeHints getModeHints(int chan); DivChannelModeHints getModeHints(int chan);
DivSamplePos getSamplePos(int ch); DivSamplePos getSamplePos(int ch);
DivDispatchOscBuffer* getOscBuffer(int chan); DivDispatchOscBuffer* getOscBuffer(int chan);

View file

@ -2098,13 +2098,12 @@ unsigned short DivPlatformOPL::getPan(int ch) {
return ((chan[ch].pan&1)<<8)|((chan[ch].pan&2)>>1); return ((chan[ch].pan&1)<<8)|((chan[ch].pan&2)>>1);
} }
DivChannelPair DivPlatformOPL::getPaired(int ch) { void DivPlatformOPL::getPaired(int ch, std::vector<DivChannelPair>& ret) {
if (oplType==3 && ch<12 && !(ch&1)) { if (oplType==3 && ch<12 && !(ch&1)) {
if (chan[ch].fourOp) { if (chan[ch].fourOp) {
return DivChannelPair("4OP",ch+1); ret.push_back(DivChannelPair("4OP",ch+1));
} }
} }
return DivChannelPair();
} }
DivDispatchOscBuffer* DivPlatformOPL::getOscBuffer(int ch) { DivDispatchOscBuffer* DivPlatformOPL::getOscBuffer(int ch) {

View file

@ -151,7 +151,7 @@ class DivPlatformOPL: public DivDispatch {
void* getChanState(int chan); void* getChanState(int chan);
DivMacroInt* getChanMacroInt(int ch); DivMacroInt* getChanMacroInt(int ch);
unsigned short getPan(int chan); unsigned short getPan(int chan);
DivChannelPair getPaired(int chan); void getPaired(int ch, std::vector<DivChannelPair>& ret);
DivDispatchOscBuffer* getOscBuffer(int chan); DivDispatchOscBuffer* getOscBuffer(int chan);
int mapVelocity(int ch, float vel); int mapVelocity(int ch, float vel);
float getGain(int ch, int vol); float getGain(int ch, int vol);

View file

@ -538,11 +538,10 @@ unsigned short DivPlatformPCE::getPan(int ch) {
return ((chan[ch].pan&0xf0)<<4)|(chan[ch].pan&15); return ((chan[ch].pan&0xf0)<<4)|(chan[ch].pan&15);
} }
DivChannelPair DivPlatformPCE::getPaired(int ch) { void DivPlatformPCE::getPaired(int ch, std::vector<DivChannelPair>& ret) {
if (ch==1 && lfoMode>0) { if (ch==1 && lfoMode>0) {
return DivChannelPair("mod",0); ret.push_back(DivChannelPair("mod",0));
} }
return DivChannelPair();
} }
DivChannelModeHints DivPlatformPCE::getModeHints(int ch) { DivChannelModeHints DivPlatformPCE::getModeHints(int ch) {

View file

@ -85,7 +85,7 @@ class DivPlatformPCE: public DivDispatch {
void* getChanState(int chan); void* getChanState(int chan);
DivMacroInt* getChanMacroInt(int ch); DivMacroInt* getChanMacroInt(int ch);
unsigned short getPan(int chan); unsigned short getPan(int chan);
DivChannelPair getPaired(int chan); void getPaired(int ch, std::vector<DivChannelPair>& ret);
DivChannelModeHints getModeHints(int chan); DivChannelModeHints getModeHints(int chan);
DivSamplePos getSamplePos(int ch); DivSamplePos getSamplePos(int ch);
DivDispatchOscBuffer* getOscBuffer(int chan); DivDispatchOscBuffer* getOscBuffer(int chan);

View file

@ -407,22 +407,21 @@ DivMacroInt* DivPlatformPOKEY::getChanMacroInt(int ch) {
return &chan[ch].std; return &chan[ch].std;
} }
DivChannelPair DivPlatformPOKEY::getPaired(int ch) { void DivPlatformPOKEY::getPaired(int ch, std::vector<DivChannelPair>& ret) {
switch (ch) { switch (ch) {
case 0: case 0:
if (audctl&4) return DivChannelPair("filter",2); if (audctl&4) ret.push_back(DivChannelPair("filter",2));
break; break;
case 1: case 1:
if (audctl&16) return DivChannelPair("16-bit",0); if (audctl&16) ret.push_back(DivChannelPair("16-bit",0));
break; break;
case 2: case 2:
if (audctl&8) return DivChannelPair("16-bit",3); if (audctl&8) ret.push_back(DivChannelPair("16-bit",3));
break; break;
case 3: case 3:
if (audctl&2) return DivChannelPair("filter",1); if (audctl&2) ret.push_back(DivChannelPair("filter",1));
break; break;
} }
return DivChannelPair();
} }
DivDispatchOscBuffer* DivPlatformPOKEY::getOscBuffer(int ch) { DivDispatchOscBuffer* DivPlatformPOKEY::getOscBuffer(int ch) {

View file

@ -65,7 +65,7 @@ class DivPlatformPOKEY: public DivDispatch {
int dispatch(DivCommand c); int dispatch(DivCommand c);
void* getChanState(int chan); void* getChanState(int chan);
DivMacroInt* getChanMacroInt(int ch); DivMacroInt* getChanMacroInt(int ch);
DivChannelPair getPaired(int chan); void getPaired(int ch, std::vector<DivChannelPair>& ret);
DivDispatchOscBuffer* getOscBuffer(int chan); DivDispatchOscBuffer* getOscBuffer(int chan);
unsigned char* getRegisterPool(); unsigned char* getRegisterPool();
int getRegisterPoolSize(); int getRegisterPoolSize();

View file

@ -1244,26 +1244,27 @@ void DivPlatformSID3::setFlags(const DivConfig& flags) {
} }
} }
DivChannelPair DivPlatformSID3::getPaired(int ch) void DivPlatformSID3::getPaired(int ch, std::vector<DivChannelPair>& ret)
{ {
if(chan[ch].phase) if(chan[ch].phase)
{ {
return DivChannelPair("phase", chan[ch].phaseSrc); ret.push_back(DivChannelPair("phase", chan[ch].phaseSrc));
} }
if(chan[ch].ring) if(chan[ch].ring)
{ {
if(chan[ch].ringSrc == SID3_NUM_CHANNELS) if(chan[ch].ringSrc == SID3_NUM_CHANNELS)
{ {
return DivChannelPair("ring", ch); ret.push_back(DivChannelPair("ring", ch));
}
else
{
ret.push_back(DivChannelPair("ring", chan[ch].ringSrc));
} }
return DivChannelPair("ring", chan[ch].ringSrc);
} }
if(chan[ch].sync) if(chan[ch].sync)
{ {
return DivChannelPair("sync", chan[ch].syncSrc); ret.push_back(DivChannelPair("sync", chan[ch].syncSrc));
} }
return DivChannelPair();
} }
int DivPlatformSID3::init(DivEngine* p, int channels, int sugRate, const DivConfig& flags) { int DivPlatformSID3::init(DivEngine* p, int channels, int sugRate, const DivConfig& flags) {

View file

@ -250,7 +250,7 @@ class DivPlatformSID3: public DivDispatch {
const char** getRegisterSheet(); const char** getRegisterSheet();
int init(DivEngine* parent, int channels, int sugRate, const DivConfig& flags); int init(DivEngine* parent, int channels, int sugRate, const DivConfig& flags);
int getOutputCount(); int getOutputCount();
DivChannelPair getPaired(int ch); void getPaired(int ch, std::vector<DivChannelPair>& ret);
void quit(); void quit();
~DivPlatformSID3(); ~DivPlatformSID3();
}; };

View file

@ -710,11 +710,10 @@ unsigned short DivPlatformSNES::getPan(int ch) {
return (chan[ch].panL<<8)|chan[ch].panR; return (chan[ch].panL<<8)|chan[ch].panR;
} }
DivChannelPair DivPlatformSNES::getPaired(int ch) { void DivPlatformSNES::getPaired(int ch, std::vector<DivChannelPair>& ret) {
if (chan[ch].pitchMod) { if (chan[ch].pitchMod) {
return DivChannelPair("mod",(ch-1)&7); ret.push_back(DivChannelPair("mod",(ch-1)&7));
} }
return DivChannelPair();
} }
DivChannelModeHints DivPlatformSNES::getModeHints(int ch) { DivChannelModeHints DivPlatformSNES::getModeHints(int ch) {

View file

@ -102,7 +102,7 @@ class DivPlatformSNES: public DivDispatch {
void* getChanState(int chan); void* getChanState(int chan);
DivMacroInt* getChanMacroInt(int ch); DivMacroInt* getChanMacroInt(int ch);
unsigned short getPan(int chan); unsigned short getPan(int chan);
DivChannelPair getPaired(int chan); void getPaired(int ch, std::vector<DivChannelPair>& ret);
DivChannelModeHints getModeHints(int chan); DivChannelModeHints getModeHints(int chan);
DivSamplePos getSamplePos(int ch); DivSamplePos getSamplePos(int ch);
DivDispatchOscBuffer* getOscBuffer(int chan); DivDispatchOscBuffer* getOscBuffer(int chan);

View file

@ -1282,116 +1282,123 @@ void FurnaceGUI::drawPattern() {
memset(floors,0,4*4*sizeof(unsigned int)); memset(floors,0,4*4*sizeof(unsigned int));
for (int i=0; i<chans; i++) { 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++) { std::vector<DivChannelPair> pairs;
if (pairs.pairs[j]==-1) continue; e->getChanPaired(i, pairs);
int pairCh=e->dispatchFirstChan[i]+pairs.pairs[j];
if (!e->curSubSong->chanShow[pairCh]) { 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; continue;
} }
isPaired=true;
if ((unsigned int)pairCh<pairMin) pairMin=pairCh;
if ((unsigned int)pairCh>pairMax) pairMax=pairCh;
}
if (!isPaired) continue; for (int j=0; j<8; j++) {
if (pair.pairs[j]==-1) continue;
float posY=chanHeadBottom; int pairCh=e->dispatchFirstChan[i]+pair.pairs[j];
if (!e->curSubSong->chanShow[pairCh]) {
// find a free floor continue;
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;
} }
} isPaired=true;
if (free) break; if ((unsigned int)pairCh<pairMin) pairMin=pairCh;
curFloor++; if ((unsigned int)pairCh>pairMax) pairMax=pairCh;
}
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;
} }
pos=(patChanX[pairCh+1]+patChanX[pairCh])*0.5; if (!isPaired) continue;
posCenter+=pos;
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++; 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( tdl->AddLine(
ImVec2(pos,chanHeadBottom), ImVec2(pos,chanHeadBottom),
ImVec2(pos,posY+textSize.y), ImVec2(pos,posY+textSize.y),
ImGui::GetColorU32(uiColors[GUI_COLOR_PATTERN_PAIR]), ImGui::GetColorU32(uiColors[GUI_COLOR_PATTERN_PAIR]),
2.0f*dpiScale 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) { pos=(patChanX[pairCh+1]+patChanX[pairCh])*0.5;
tdl->AddLine( posCenter+=pos;
ImVec2(posMin,posY+textSize.y), numPairs++;
ImVec2(posMax,posY+textSize.y), if (pos<posMin) posMin=pos;
ImGui::GetColorU32(uiColors[GUI_COLOR_PATTERN_PAIR]), if (pos>posMax) posMax=pos;
2.0f*dpiScale tdl->AddLine(
); ImVec2(pos,chanHeadBottom),
} else { ImVec2(pos,posY+textSize.y),
tdl->AddLine( ImGui::GetColorU32(uiColors[GUI_COLOR_PATTERN_PAIR]),
ImVec2(posMin,posY+textSize.y), 2.0f*dpiScale
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,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));
}
} }
} }