GUI: add non-mono mode to osc

This commit is contained in:
tildearrow 2023-08-05 03:26:36 -05:00
parent bf77b95ec9
commit 1983529bdb
5 changed files with 162 additions and 56 deletions

View File

@ -6706,6 +6706,13 @@ bool FurnaceGUI::finish() {
SDL_HapticClose(vibrator);
}
for (int i=0; i<DIV_MAX_OUTPUTS; i++) {
if (oscValues[i]) {
delete[] oscValues[i];
oscValues[i]=NULL;
}
}
for (int i=0; i<DIV_MAX_CHANS; i++) {
delete oldPat[i];
}
@ -7220,7 +7227,7 @@ FurnaceGUI::FurnaceGUI():
memset(patChanX,0,sizeof(float)*(DIV_MAX_CHANS+1));
memset(patChanSlideY,0,sizeof(float)*(DIV_MAX_CHANS+1));
memset(lastIns,-1,sizeof(int)*DIV_MAX_CHANS);
memset(oscValues,0,sizeof(float)*1024);
memset(oscValues,0,sizeof(void*)*DIV_MAX_OUTPUTS);
memset(chanOscLP0,0,sizeof(float)*DIV_MAX_CHANS);
memset(chanOscLP1,0,sizeof(float)*DIV_MAX_CHANS);

View File

@ -152,6 +152,22 @@ enum FurnaceGUIColors {
GUI_COLOR_OSC_BORDER,
GUI_COLOR_OSC_WAVE,
GUI_COLOR_OSC_WAVE_PEAK,
GUI_COLOR_OSC_WAVE_CH0,
GUI_COLOR_OSC_WAVE_CH1,
GUI_COLOR_OSC_WAVE_CH2,
GUI_COLOR_OSC_WAVE_CH3,
GUI_COLOR_OSC_WAVE_CH4,
GUI_COLOR_OSC_WAVE_CH5,
GUI_COLOR_OSC_WAVE_CH6,
GUI_COLOR_OSC_WAVE_CH7,
GUI_COLOR_OSC_WAVE_CH8,
GUI_COLOR_OSC_WAVE_CH9,
GUI_COLOR_OSC_WAVE_CH10,
GUI_COLOR_OSC_WAVE_CH11,
GUI_COLOR_OSC_WAVE_CH12,
GUI_COLOR_OSC_WAVE_CH13,
GUI_COLOR_OSC_WAVE_CH14,
GUI_COLOR_OSC_WAVE_CH15,
GUI_COLOR_OSC_REF,
GUI_COLOR_OSC_GUIDE,
@ -1461,6 +1477,8 @@ class FurnaceGUI {
int oscTakesEntireWindow;
int oscBorder;
int oscEscapesBoundary;
int oscMono;
int oscAntiAlias;
int separateFMColors;
int insEditColorize;
int metroVol;
@ -1619,6 +1637,8 @@ class FurnaceGUI {
oscTakesEntireWindow(0),
oscBorder(1),
oscEscapesBoundary(0),
oscMono(1),
oscAntiAlias(1),
separateFMColors(0),
insEditColorize(0),
metroVol(100),
@ -1970,7 +1990,7 @@ class FurnaceGUI {
// oscilloscope
int oscTotal, oscWidth;
float oscValues[1024];
float* oscValues[DIV_MAX_OUTPUTS];
float oscZoom;
float oscWindowSize;
float oscInput, oscInput1;

View File

@ -828,6 +828,22 @@ const FurnaceGUIColorDef guiColors[GUI_COLOR_MAX]={
D(GUI_COLOR_OSC_BORDER,"",ImVec4(0.4f,0.6f,0.95f,1.0f)),
D(GUI_COLOR_OSC_WAVE,"",ImVec4(0.95f,0.95f,1.0f,1.0f)),
D(GUI_COLOR_OSC_WAVE_PEAK,"",ImVec4(0.95f,0.95f,1.0f,1.0f)),
D(GUI_COLOR_OSC_WAVE_CH0,"",ImVec4(1.0f,1.0f,1.0f,1.0f)),
D(GUI_COLOR_OSC_WAVE_CH1,"",ImVec4(1.0f,0.2f,0.2f,1.0f)),
D(GUI_COLOR_OSC_WAVE_CH2,"",ImVec4(0.1f,0.5f,1.0f,1.0f)),
D(GUI_COLOR_OSC_WAVE_CH3,"",ImVec4(0.5f,0.5f,0.5f,1.0f)),
D(GUI_COLOR_OSC_WAVE_CH4,"",ImVec4(0.7f,0.2f,0.7f,1.0f)),
D(GUI_COLOR_OSC_WAVE_CH5,"",ImVec4(0.2f,1.0f,0.2f,1.0f)),
D(GUI_COLOR_OSC_WAVE_CH6,"",ImVec4(1.0f,1.0f,0.1f,1.0f)),
D(GUI_COLOR_OSC_WAVE_CH7,"",ImVec4(1.0f,0.5f,0.1f,1.0f)),
D(GUI_COLOR_OSC_WAVE_CH8,"",ImVec4(0.9f,1.0f,0.1f,1.0f)),
D(GUI_COLOR_OSC_WAVE_CH9,"",ImVec4(0.8f,1.0f,0.1f,1.0f)),
D(GUI_COLOR_OSC_WAVE_CH10,"",ImVec4(0.7f,1.0f,0.1f,1.0f)),
D(GUI_COLOR_OSC_WAVE_CH11,"",ImVec4(0.6f,1.0f,0.1f,1.0f)),
D(GUI_COLOR_OSC_WAVE_CH12,"",ImVec4(0.5f,1.0f,0.1f,1.0f)),
D(GUI_COLOR_OSC_WAVE_CH13,"",ImVec4(0.4f,1.0f,0.1f,1.0f)),
D(GUI_COLOR_OSC_WAVE_CH14,"",ImVec4(0.3f,1.0f,0.1f,1.0f)),
D(GUI_COLOR_OSC_WAVE_CH15,"",ImVec4(0.2f,1.0f,0.1f,1.0f)),
D(GUI_COLOR_OSC_REF,"",ImVec4(0.3,0.65f,1.0f,0.15f)),
D(GUI_COLOR_OSC_GUIDE,"",ImVec4(0.3,0.65f,1.0f,0.13f)),

View File

@ -47,56 +47,47 @@ void FurnaceGUI::readOsc() {
if (total>avail) total=avail;
//printf("total: %d. avail: %d bias: %d\n",total,avail,bias);
memset(oscValues,0,1024*sizeof(float));
int winSize=e->getAudioDescGot().rate*(oscWindowSize/1000.0);
int oscReadPos=(writePos-winSize)&0x7fff;
float* sincITable=DivFilterTables::getSincIntegralTable();
float posFrac=0.0;
int posInt=oscReadPos;
float factor=(float)oscWidth/(float)winSize;
for (int i=0; i<oscWidth; i++) {
float avg=0.0f;
float prevAvg=0.0f;
for (int j=0; j<e->getAudioDescGot().outChans; j++) {
avg+=e->oscBuf[j][posInt&0x7fff];
for (int ch=0; ch<e->getAudioDescGot().outChans; ch++) {
if (oscValues[ch]==NULL) {
oscValues[ch]=new float[1024];
}
avg/=e->getAudioDescGot().outChans;
oscValues[i]+=avg;
memset(oscValues[ch],0,1024*sizeof(float));
float* sincITable=DivFilterTables::getSincIntegralTable();
posFrac+=1.0;
while (posFrac>=1.0) {
unsigned int n=((unsigned int)(posFrac*8192.0))&8191;
posFrac-=factor;
posInt++;
float posFrac=0.0;
int posInt=oscReadPos;
float factor=(float)oscWidth/(float)winSize;
for (int i=0; i<oscWidth; i++) {
oscValues[ch][i]+=e->oscBuf[ch][posInt&0x7fff];
prevAvg=avg;
avg=0.0f;
for (int j=0; j<e->getAudioDescGot().outChans; j++) {
avg+=e->oscBuf[j][posInt&0x7fff];
}
avg/=e->getAudioDescGot().outChans;
posFrac+=1.0;
while (posFrac>=1.0) {
unsigned int n=((unsigned int)(posFrac*8192.0))&8191;
posFrac-=factor;
posInt++;
float* t1=&sincITable[(8191-n)<<3];
float* t2=&sincITable[n<<3];
float delta=avg-prevAvg;
float* t1=&sincITable[(8191-n)<<3];
float* t2=&sincITable[n<<3];
float delta=e->oscBuf[ch][posInt&0x7fff]-e->oscBuf[ch][(posInt-1)&0x7fff];
for (int j=0; j<8; j++) {
if (i-j>0) {
oscValues[i-j]+=t1[j]*-delta;
}
if (i+j+1<oscWidth) {
oscValues[i+j+1]+=t2[j]*delta;
for (int j=0; j<8; j++) {
if (i-j>0) {
oscValues[ch][i-j]+=t1[j]*-delta;
}
if (i+j+1<oscWidth) {
oscValues[ch][i+j+1]+=t2[j]*delta;
}
}
}
}
}
for (int i=0; i<oscWidth; i++) {
if (oscValues[i]>0.001f || oscValues[i]<-0.001f) {
WAKE_UP;
for (int i=0; i<oscWidth; i++) {
if (oscValues[ch][i]>0.001f || oscValues[ch][i]<-0.001f) {
WAKE_UP;
}
}
}
@ -259,25 +250,63 @@ void FurnaceGUI::drawOsc() {
if (oscWidth<1) oscWidth=1;
if (oscWidth>1024) oscWidth=1024;
for (int i=0; i<oscWidth; i++) {
float x=(float)i/(float)oscWidth;
float y=oscValues[i]*oscZoom;
if (!settings.oscEscapesBoundary) {
if (y<-0.5f) y=-0.5f;
if (y>0.5f) y=0.5f;
ImDrawListFlags prevFlags=dl->Flags;
if (!settings.oscAntiAlias) {
dl->Flags&=~(ImDrawListFlags_AntiAliasedLines|ImDrawListFlags_AntiAliasedLinesUseTex);
}
if (settings.oscMono) {
for (int i=0; i<oscWidth; i++) {
float x=(float)i/(float)oscWidth;
float avg=0;
for (int j=0; j<e->getAudioDescGot().outChans; j++) {
avg+=oscValues[j][i];
}
avg/=e->getAudioDescGot().outChans;
float y=avg*oscZoom;
if (!settings.oscEscapesBoundary) {
if (y<-0.5f) y=-0.5f;
if (y>0.5f) y=0.5f;
}
waveform[i]=ImLerp(inRect.Min,inRect.Max,ImVec2(x,0.5f-y));
}
if (settings.oscEscapesBoundary) {
dl->PushClipRectFullScreen();
dl->AddPolyline(waveform,oscWidth,color,ImDrawFlags_None,dpiScale);
dl->PopClipRect();
} else {
dl->AddPolyline(waveform,oscWidth,color,ImDrawFlags_None,dpiScale);
}
waveform[i]=ImLerp(inRect.Min,inRect.Max,ImVec2(x,0.5f-y));
}
//ImDrawListFlags prevFlags=dl->Flags;
//dl->Flags&=~(ImDrawListFlags_AntiAliasedLines|ImDrawListFlags_AntiAliasedLinesUseTex);
if (settings.oscEscapesBoundary) {
dl->PushClipRectFullScreen();
dl->AddPolyline(waveform,oscWidth,color,ImDrawFlags_None,dpiScale);
dl->PopClipRect();
} else {
dl->AddPolyline(waveform,oscWidth,color,ImDrawFlags_None,dpiScale);
for (int ch=0; ch<e->getAudioDescGot().outChans; ch++) {
for (int i=0; i<oscWidth; i++) {
float x=(float)i/(float)oscWidth;
float y=oscValues[ch][i]*oscZoom;
if (!settings.oscEscapesBoundary) {
if (y<-0.5f) y=-0.5f;
if (y>0.5f) y=0.5f;
}
waveform[i]=ImLerp(inRect.Min,inRect.Max,ImVec2(x,0.5f-y));
}
if (!isClipping) {
color=ImGui::GetColorU32(uiColors[GUI_COLOR_OSC_WAVE_CH0+ch]);
}
if (settings.oscEscapesBoundary) {
dl->PushClipRectFullScreen();
dl->AddPolyline(waveform,oscWidth,color,ImDrawFlags_None,dpiScale);
dl->PopClipRect();
} else {
dl->AddPolyline(waveform,oscWidth,color,ImDrawFlags_None,dpiScale);
}
}
}
//dl->Flags=prevFlags;
dl->Flags=prevFlags;
if (settings.oscBorder) {
dl->AddRect(inRect.Min,inRect.Max,borderColor,settings.oscRoundedCorners?(8.0f*dpiScale):0.0f,0,1.5f*dpiScale);
}

View File

@ -2314,6 +2314,16 @@ void FurnaceGUI::drawSettings() {
settings.oscBorder=oscBorderB;
}
bool oscMonoB=settings.oscMono;
if (ImGui::Checkbox("Mono",&oscMonoB)) {
settings.oscMono=oscMonoB;
}
bool oscAntiAliasB=settings.oscAntiAlias;
if (ImGui::Checkbox("Anti-aliased",&oscAntiAliasB)) {
settings.oscAntiAlias=oscAntiAliasB;
}
bool oscTakesEntireWindowB=settings.oscTakesEntireWindow;
if (ImGui::Checkbox("Fill entire window",&oscTakesEntireWindowB)) {
settings.oscTakesEntireWindow=oscTakesEntireWindowB;
@ -2439,6 +2449,26 @@ void FurnaceGUI::drawSettings() {
UI_COLOR_CONFIG(GUI_COLOR_OSC_WAVE_PEAK,"Waveform (clip)");
UI_COLOR_CONFIG(GUI_COLOR_OSC_REF,"Reference");
UI_COLOR_CONFIG(GUI_COLOR_OSC_GUIDE,"Guide");
if (ImGui::TreeNode("Wave (non-mono)")) {
UI_COLOR_CONFIG(GUI_COLOR_OSC_WAVE_CH0,"Waveform (1)");
UI_COLOR_CONFIG(GUI_COLOR_OSC_WAVE_CH1,"Waveform (2)");
UI_COLOR_CONFIG(GUI_COLOR_OSC_WAVE_CH2,"Waveform (3)");
UI_COLOR_CONFIG(GUI_COLOR_OSC_WAVE_CH3,"Waveform (4)");
UI_COLOR_CONFIG(GUI_COLOR_OSC_WAVE_CH4,"Waveform (5)");
UI_COLOR_CONFIG(GUI_COLOR_OSC_WAVE_CH5,"Waveform (6)");
UI_COLOR_CONFIG(GUI_COLOR_OSC_WAVE_CH6,"Waveform (7)");
UI_COLOR_CONFIG(GUI_COLOR_OSC_WAVE_CH7,"Waveform (8)");
UI_COLOR_CONFIG(GUI_COLOR_OSC_WAVE_CH8,"Waveform (9)");
UI_COLOR_CONFIG(GUI_COLOR_OSC_WAVE_CH9,"Waveform (10)");
UI_COLOR_CONFIG(GUI_COLOR_OSC_WAVE_CH10,"Waveform (11)");
UI_COLOR_CONFIG(GUI_COLOR_OSC_WAVE_CH11,"Waveform (12)");
UI_COLOR_CONFIG(GUI_COLOR_OSC_WAVE_CH12,"Waveform (13)");
UI_COLOR_CONFIG(GUI_COLOR_OSC_WAVE_CH13,"Waveform (14)");
UI_COLOR_CONFIG(GUI_COLOR_OSC_WAVE_CH14,"Waveform (15)");
UI_COLOR_CONFIG(GUI_COLOR_OSC_WAVE_CH15,"Waveform (16)");
ImGui::TreePop();
}
ImGui::TreePop();
}
if (ImGui::TreeNode("Volume Meter")) {
@ -2818,6 +2848,8 @@ void FurnaceGUI::syncSettings() {
settings.oscTakesEntireWindow=e->getConfInt("oscTakesEntireWindow",0);
settings.oscBorder=e->getConfInt("oscBorder",1);
settings.oscEscapesBoundary=e->getConfInt("oscEscapesBoundary",0);
settings.oscMono=e->getConfInt("oscMono",1);
settings.oscAntiAlias=e->getConfInt("oscAntiAlias",1);
settings.separateFMColors=e->getConfInt("separateFMColors",0);
settings.insEditColorize=e->getConfInt("insEditColorize",0);
settings.metroVol=e->getConfInt("metroVol",100);
@ -3177,6 +3209,8 @@ void FurnaceGUI::commitSettings() {
e->setConf("oscTakesEntireWindow",settings.oscTakesEntireWindow);
e->setConf("oscBorder",settings.oscBorder);
e->setConf("oscEscapesBoundary",settings.oscEscapesBoundary);
e->setConf("oscMono",settings.oscMono);
e->setConf("oscAntiAlias",settings.oscAntiAlias);
e->setConf("separateFMColors",settings.separateFMColors);
e->setConf("insEditColorize",settings.insEditColorize);
e->setConf("metroVol",settings.metroVol);