From 1983529bdb1b2f177802113c5af7ff01345cd82c Mon Sep 17 00:00:00 2001 From: tildearrow Date: Sat, 5 Aug 2023 03:26:36 -0500 Subject: [PATCH] GUI: add non-mono mode to osc --- src/gui/gui.cpp | 9 ++- src/gui/gui.h | 22 ++++++- src/gui/guiConst.cpp | 16 +++++ src/gui/osc.cpp | 137 ++++++++++++++++++++++++++----------------- src/gui/settings.cpp | 34 +++++++++++ 5 files changed, 162 insertions(+), 56 deletions(-) diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 430d2845..32f58fc3 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -6706,6 +6706,13 @@ bool FurnaceGUI::finish() { SDL_HapticClose(vibrator); } + for (int i=0; iavail) 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; igetAudioDescGot().outChans; j++) { - avg+=e->oscBuf[j][posInt&0x7fff]; + for (int ch=0; chgetAudioDescGot().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; ioscBuf[ch][posInt&0x7fff]; - prevAvg=avg; - avg=0.0f; - for (int j=0; jgetAudioDescGot().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+10) { + oscValues[ch][i-j]+=t1[j]*-delta; + } + if (i+j+10.001f || oscValues[i]<-0.001f) { - WAKE_UP; + for (int i=0; i0.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; i0.5f) y=0.5f; + ImDrawListFlags prevFlags=dl->Flags; + if (!settings.oscAntiAlias) { + dl->Flags&=~(ImDrawListFlags_AntiAliasedLines|ImDrawListFlags_AntiAliasedLinesUseTex); + } + + if (settings.oscMono) { + for (int i=0; igetAudioDescGot().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; chgetAudioDescGot().outChans; ch++) { + for (int i=0; i0.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); } diff --git a/src/gui/settings.cpp b/src/gui/settings.cpp index f053e617..05eb50c4 100644 --- a/src/gui/settings.cpp +++ b/src/gui/settings.cpp @@ -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);