From cfee9b38105097909aca056393b6444a54bbd58b Mon Sep 17 00:00:00 2001 From: tildearrow Date: Mon, 19 Feb 2024 15:49:56 -0500 Subject: [PATCH] GUI: new osc renderer, part 21 part 11? I must have been drunk alternate approach for OpenGL ES (no more hangs) --- src/gui/chanOsc.cpp | 35 +++++++++++++++------- src/gui/gui.cpp | 6 ++-- src/gui/gui.h | 10 +++++-- src/gui/osc.cpp | 59 ++++++++++++++++++++++--------------- src/gui/render/renderGL.cpp | 3 +- src/gui/settings.cpp | 9 ++++++ 6 files changed, 82 insertions(+), 40 deletions(-) diff --git a/src/gui/chanOsc.cpp b/src/gui/chanOsc.cpp index 4c5e29439..bbc9cd6bb 100644 --- a/src/gui/chanOsc.cpp +++ b/src/gui/chanOsc.cpp @@ -182,16 +182,30 @@ void FurnaceGUI::drawChanOsc() { ImGui::TableNextColumn(); if (ImGui::Checkbox("Randomize phase on note",&chanOscRandomPhase)) { } - ImGui::EndTable(); - } - ImGui::AlignTextToFramePadding(); - ImGui::Text("Amplitude"); - ImGui::SameLine(); - ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); - if (CWSliderFloat("##COSAmp",&chanOscAmplify,0.0f,2.0f)) { - if (chanOscAmplify<0.0f) chanOscAmplify=0.0f; - if (chanOscAmplify>2.0f) chanOscAmplify=2.0f; + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + ImGui::AlignTextToFramePadding(); + ImGui::Text("Amplitude"); + ImGui::SameLine(); + ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); + if (CWSliderFloat("##COSAmp",&chanOscAmplify,0.0f,2.0f)) { + if (chanOscAmplify<0.0f) chanOscAmplify=0.0f; + if (chanOscAmplify>2.0f) chanOscAmplify=2.0f; + } + + ImGui::TableNextColumn(); + ImGui::AlignTextToFramePadding(); + ImGui::Text("Line size"); + ImGui::SameLine(); + ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); + if (CWSliderFloat("##COSLine",&chanOscLineSize,0.25f,16.0f)) { + if (chanOscLineSize<0.25f) chanOscLineSize=0.26f; + if (chanOscLineSize>16.0f) chanOscLineSize=16.0f; + } + + + ImGui::EndTable(); } ImGui::Checkbox("Gradient",&chanOscUseGrad); @@ -706,6 +720,7 @@ void FurnaceGUI::drawChanOsc() { fft->drawOp.pos0=inRect.Min; fft->drawOp.pos1=inRect.Max; fft->drawOp.color=ImGui::ColorConvertU32ToFloat4(color); + fft->drawOp.lineSize=dpiScale*chanOscLineSize; dl->AddCallback(_drawOsc,&fft->drawOp); dl->AddCallback(ImDrawCallback_ResetRenderState,NULL); @@ -713,7 +728,7 @@ void FurnaceGUI::drawChanOsc() { //ImGui::PushClipRect(inRect.Min,inRect.Max,false); //ImDrawListFlags prevFlags=dl->Flags; //dl->Flags&=~(ImDrawListFlags_AntiAliasedLines|ImDrawListFlags_AntiAliasedLinesUseTex); - dl->AddPolyline(waveform,precision,color,ImDrawFlags_None,dpiScale); + dl->AddPolyline(waveform,precision,color,ImDrawFlags_None,dpiScale*chanOscLineSize); //dl->Flags=prevFlags; //ImGui::PopClipRect(); } diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 7bff8b9ac..e2b30f834 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -6613,6 +6613,7 @@ bool FurnaceGUI::init() { chanOscTextX=e->getConfFloat("chanOscTextX",0.0f); chanOscTextY=e->getConfFloat("chanOscTextY",0.0f); chanOscAmplify=e->getConfFloat("chanOscAmplify",0.95f); + chanOscLineSize=e->getConfFloat("chanOscLineSize",1.0f); chanOscWindowSize=e->getConfFloat("chanOscWindowSize",20.0f); chanOscWaveCorr=e->getConfBool("chanOscWaveCorr",true); chanOscOptions=e->getConfBool("chanOscOptions",false); @@ -6935,8 +6936,6 @@ bool FurnaceGUI::init() { } } - newOscLineWidth=dpiScale; - updateWindowTitle(); rend->clear(ImVec4(0.0,0.0,0.0,1.0)); @@ -7165,6 +7164,7 @@ void FurnaceGUI::commitState() { e->setConf("chanOscTextX",chanOscTextX); e->setConf("chanOscTextY",chanOscTextY); e->setConf("chanOscAmplify",chanOscAmplify); + e->setConf("chanOscLineSize",chanOscLineSize); e->setConf("chanOscWindowSize",chanOscWindowSize); e->setConf("chanOscWaveCorr",chanOscWaveCorr); e->setConf("chanOscOptions",chanOscOptions); @@ -7314,7 +7314,6 @@ FurnaceGUI::FurnaceGUI(): shallDetectScale(0), cpuCores(0), secondTimer(0.0f), - newOscLineWidth(2.0f), userEvents(0xffffffff), mobileMenuPos(0.0f), autoButtonSize(0.0f), @@ -7680,6 +7679,7 @@ FurnaceGUI::FurnaceGUI(): chanOscTextX(0.0f), chanOscTextY(0.0f), chanOscAmplify(0.95f), + chanOscLineSize(1.0f), chanOscWaveCorr(true), chanOscOptions(false), updateChanOscGradTex(true), diff --git a/src/gui/gui.h b/src/gui/gui.h index d2da82511..0d0d4f576 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -1455,13 +1455,15 @@ struct PendingDrawOsc { ImVec2 pos0; ImVec2 pos1; ImVec4 color; + float lineSize; PendingDrawOsc(): gui(NULL), data(NULL), len(0), pos0(0,0), pos1(0,0), - color(0,0,0,0) {} + color(0,0,0,0), + lineSize(0.0f) {} }; class FurnaceGUI { @@ -1521,7 +1523,7 @@ class FurnaceGUI { int wheelCalmDown; int shallDetectScale; int cpuCores; - float secondTimer, newOscLineWidth; + float secondTimer; unsigned int userEvents; float mobileMenuPos, autoButtonSize, mobileEditAnim; ImVec2 mobileEditButtonPos, mobileEditButtonSize; @@ -1684,6 +1686,7 @@ class FurnaceGUI { int oscEscapesBoundary; int oscMono; int oscAntiAlias; + float oscLineSize; int separateFMColors; int insEditColorize; int metroVol; @@ -1886,6 +1889,7 @@ class FurnaceGUI { oscEscapesBoundary(0), oscMono(1), oscAntiAlias(1), + oscLineSize(1.0f), separateFMColors(0), insEditColorize(0), metroVol(100), @@ -2284,7 +2288,7 @@ class FurnaceGUI { // per-channel oscilloscope int chanOscCols, chanOscAutoColsType, chanOscColorX, chanOscColorY; - float chanOscWindowSize, chanOscTextX, chanOscTextY, chanOscAmplify; + float chanOscWindowSize, chanOscTextX, chanOscTextY, chanOscAmplify, chanOscLineSize; bool chanOscWaveCorr, chanOscOptions, updateChanOscGradTex, chanOscUseGrad, chanOscNormalize, chanOscRandomPhase; String chanOscTextFormat; ImVec4 chanOscColor, chanOscTextColor; diff --git a/src/gui/osc.cpp b/src/gui/osc.cpp index 82af807a7..e6924d91e 100644 --- a/src/gui/osc.cpp +++ b/src/gui/osc.cpp @@ -110,7 +110,7 @@ void FurnaceGUI::readOsc() { avg+=oscValues[j][i]; } avg/=e->getAudioDescGot().outChans; - oscValuesAverage[i]=avg; + oscValuesAverage[i]=avg*oscZoom; } /*for (int i=0; idrawOsc(which->data,which->len,which->pos0,which->pos1,which->color,ImVec2(canvasW,canvasH),newOscLineWidth); + rend->drawOsc(which->data,which->len,which->pos0,which->pos1,which->color,ImVec2(canvasW,canvasH),which->lineSize); } void FurnaceGUI::drawOsc() { @@ -300,6 +300,7 @@ void FurnaceGUI::drawOsc() { _do.pos0=inRect.Min; _do.pos1=inRect.Max; _do.color=isClipping?uiColors[GUI_COLOR_OSC_WAVE_PEAK]:uiColors[GUI_COLOR_OSC_WAVE]; + _do.lineSize=dpiScale*settings.oscLineSize; dl->AddCallback(_drawOsc,&_do); dl->AddCallback(ImDrawCallback_ResetRenderState,NULL); @@ -316,37 +317,49 @@ void FurnaceGUI::drawOsc() { if (settings.oscEscapesBoundary) { dl->PushClipRectFullScreen(); - dl->AddPolyline(waveform,oscWidth-24,color,ImDrawFlags_None,dpiScale); + dl->AddPolyline(waveform,oscWidth-24,color,ImDrawFlags_None,dpiScale*settings.oscLineSize); dl->PopClipRect(); } else { - dl->AddPolyline(waveform,oscWidth-24,color,ImDrawFlags_None,dpiScale); + dl->AddPolyline(waveform,oscWidth-24,color,ImDrawFlags_None,dpiScale*settings.oscLineSize); } } } else { 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 (!isClipping) { - //color=ImGui::GetColorU32(uiColors[GUI_COLOR_OSC_WAVE_CH0+ch]); - } - - /* - if (settings.oscEscapesBoundary) { - dl->PushClipRectFullScreen(); - dl->AddPolyline(waveform,oscWidth-24,color,ImDrawFlags_None,dpiScale); - dl->PopClipRect(); + if (rend->supportsDrawOsc() && settings.shaderOsc) { + _do.gui=this; + _do.data=&oscValues[ch][12]; + _do.len=oscWidth-24; + _do.pos0=inRect.Min; + _do.pos1=inRect.Max; + _do.color=isClipping?uiColors[GUI_COLOR_OSC_WAVE_PEAK]:uiColors[GUI_COLOR_OSC_WAVE_CH0+ch]; + _do.lineSize=dpiScale*settings.oscLineSize; + + dl->AddCallback(_drawOsc,&_do); + dl->AddCallback(ImDrawCallback_ResetRenderState,NULL); } else { - dl->AddPolyline(waveform,oscWidth-24,color,ImDrawFlags_None,dpiScale); + for (int i=0; i0.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-24,color,ImDrawFlags_None,dpiScale*settings.oscLineSize); + dl->PopClipRect(); + } else { + dl->AddPolyline(waveform,oscWidth-24,color,ImDrawFlags_None,dpiScale*settings.oscLineSize); + } } - */ } } } diff --git a/src/gui/render/renderGL.cpp b/src/gui/render/renderGL.cpp index e3412d853..4633f6ab4 100644 --- a/src/gui/render/renderGL.cpp +++ b/src/gui/render/renderGL.cpp @@ -116,7 +116,8 @@ const char* sh_oscRender_srcF= " float slope=abs(valmax-valmin)*uResolution.y*0.5;\n" " float slopeDiv=min(uAdvance,(uAdvance/slope));\n" " float xRight=uv.x+((uLineWidth)/uResolution.x);\n" - " for (float x=max(0.0,uv.x-(uLineWidth/uResolution.x)); x<=xRight; x+=slopeDiv) {\n" + " for (float s=0.0; s16.0f) settings.oscLineSize=16.0f; + settingsChanged=true; + } rightClickable + // SUBSECTION WINDOWS CONFIG_SUBSECTION("Windows"); bool roundedWindowsB=settings.roundedWindows; @@ -3977,6 +3983,7 @@ void FurnaceGUI::readConfig(DivConfig& conf, FurnaceGUISettingGroups groups) { settings.oscEscapesBoundary=conf.getInt("oscEscapesBoundary",0); settings.oscMono=conf.getInt("oscMono",1); settings.oscAntiAlias=conf.getInt("oscAntiAlias",1); + settings.oscLineSize=conf.getFloat("oscLineSize",1.0f); settings.channelColors=conf.getInt("channelColors",1); settings.channelTextColors=conf.getInt("channelTextColors",0); @@ -4263,6 +4270,7 @@ void FurnaceGUI::readConfig(DivConfig& conf, FurnaceGUISettingGroups groups) { clampSetting(settings.basicColors,0,1); clampSetting(settings.playbackTime,0,1); clampSetting(settings.shaderOsc,0,1); + clampSetting(settings.oscLineSize,0.25f,16.0f); if (settings.exportLoops<0.0) settings.exportLoops=0.0; if (settings.exportFadeOut<0.0) settings.exportFadeOut=0.0; @@ -4443,6 +4451,7 @@ void FurnaceGUI::writeConfig(DivConfig& conf, FurnaceGUISettingGroups groups) { conf.set("oscEscapesBoundary",settings.oscEscapesBoundary); conf.set("oscMono",settings.oscMono); conf.set("oscAntiAlias",settings.oscAntiAlias); + conf.set("oscLineSize",settings.oscLineSize); conf.set("channelColors",settings.channelColors); conf.set("channelTextColors",settings.channelTextColors);