diff --git a/CMakeLists.txt b/CMakeLists.txt index 0b754d56c9..d50f193285 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -809,6 +809,7 @@ src/gui/tutorial.cpp src/gui/util.cpp src/gui/waveEdit.cpp src/gui/volMeter.cpp +src/gui/xyOsc.cpp src/gui/gui.cpp ) diff --git a/src/gui/doAction.cpp b/src/gui/doAction.cpp index 8a1fd8a2eb..0d1bcf623a 100644 --- a/src/gui/doAction.cpp +++ b/src/gui/doAction.cpp @@ -279,6 +279,9 @@ void FurnaceGUI::doAction(int what) { case GUI_ACTION_WINDOW_GROOVES: nextWindow=GUI_WINDOW_GROOVES; break; + case GUI_ACTION_WINDOW_XY_OSC: + nextWindow=GUI_WINDOW_XY_OSC; + break; case GUI_ACTION_COLLAPSE_WINDOW: collapseWindow=true; @@ -375,6 +378,9 @@ void FurnaceGUI::doAction(int what) { case GUI_WINDOW_GROOVES: groovesOpen=false; break; + case GUI_WINDOW_XY_OSC: + xyOscOpen=false; + break; default: break; } diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 2a4bc8a0a6..70fb9508e4 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -3430,6 +3430,7 @@ bool FurnaceGUI::loop() { DECLARE_METRIC(readOsc) DECLARE_METRIC(osc) DECLARE_METRIC(chanOsc) + DECLARE_METRIC(xyOsc) DECLARE_METRIC(volMeter) DECLARE_METRIC(settings) DECLARE_METRIC(debug) @@ -4425,6 +4426,7 @@ bool FurnaceGUI::loop() { if (ImGui::MenuItem("piano/input pad",BIND_FOR(GUI_ACTION_WINDOW_PIANO),pianoOpen)) pianoOpen=!pianoOpen; if (ImGui::MenuItem("oscilloscope (master)",BIND_FOR(GUI_ACTION_WINDOW_OSCILLOSCOPE),oscOpen)) oscOpen=!oscOpen; if (ImGui::MenuItem("oscilloscope (per-channel)",BIND_FOR(GUI_ACTION_WINDOW_CHAN_OSC),chanOscOpen)) chanOscOpen=!chanOscOpen; + if (ImGui::MenuItem("oscilloscope (X-Y)",BIND_FOR(GUI_ACTION_WINDOW_XY_OSC),xyOscOpen)) xyOscOpen=!xyOscOpen; if (ImGui::MenuItem("volume meter",BIND_FOR(GUI_ACTION_WINDOW_VOL_METER),volMeterOpen)) volMeterOpen=!volMeterOpen; if (ImGui::MenuItem("clock",BIND_FOR(GUI_ACTION_WINDOW_CLOCK),clockOpen)) clockOpen=!clockOpen; if (ImGui::MenuItem("register view",BIND_FOR(GUI_ACTION_WINDOW_REGISTER_VIEW),regViewOpen)) regViewOpen=!regViewOpen; @@ -4645,6 +4647,7 @@ bool FurnaceGUI::loop() { MEASURE(readOsc,readOsc()); MEASURE(osc,drawOsc()); MEASURE(chanOsc,drawChanOsc()); + MEASURE(xyOsc,drawXYOsc()); MEASURE(grooves,drawGrooves()); MEASURE(regView,drawRegView()); } else { @@ -4674,6 +4677,7 @@ bool FurnaceGUI::loop() { MEASURE(osc,drawOsc()); MEASURE(chanOsc,drawChanOsc()); + MEASURE(xyOsc,drawXYOsc()); MEASURE(volMeter,drawVolMeter()); MEASURE(settings,drawSettings()); MEASURE(debug,drawDebug()); @@ -6413,6 +6417,7 @@ bool FurnaceGUI::init() { mixerOpen=e->getConfBool("mixerOpen",false); oscOpen=e->getConfBool("oscOpen",true); chanOscOpen=e->getConfBool("chanOscOpen",false); + xyOscOpen=e->getConfBool("xyOscOpen",false); volMeterOpen=e->getConfBool("volMeterOpen",true); statsOpen=e->getConfBool("statsOpen",false); compatFlagsOpen=e->getConfBool("compatFlagsOpen",false); @@ -6521,6 +6526,16 @@ bool FurnaceGUI::init() { chanOscGrad.fromString(e->getConfString("chanOscGrad","")); chanOscGrad.render(); + xyOscXChannel=e->getConfInt("xyOscXChannel",0); + xyOscXInvert=e->getConfBool("xyOscXInvert",false); + xyOscYChannel=e->getConfInt("xyOscYChannel",1); + xyOscYInvert=e->getConfBool("xyOscYInvert",false); + xyOscZoom=e->getConfFloat("xyOscZoom",1.0f); + xyOscSamples=e->getConfInt("xyOscSamples",32768); + xyOscDecayTime=e->getConfFloat("xyOscDecayTime",10.0f); + xyOscIntensity=e->getConfFloat("xyOscIntensity",2.0f); + xyOscThickness=e->getConfFloat("xyOscThickness",2.0f); + syncSettings(); syncTutorial(); @@ -6968,6 +6983,7 @@ void FurnaceGUI::commitState() { e->setConf("mixerOpen",mixerOpen); e->setConf("oscOpen",oscOpen); e->setConf("chanOscOpen",chanOscOpen); + e->setConf("xyOscOpen",xyOscOpen); e->setConf("volMeterOpen",volMeterOpen); e->setConf("statsOpen",statsOpen); e->setConf("compatFlagsOpen",compatFlagsOpen); @@ -7062,6 +7078,17 @@ void FurnaceGUI::commitState() { e->setConf("chanOscUseGrad",chanOscUseGrad); e->setConf("chanOscGrad",chanOscGrad.toString()); + // commit x-y osc state + e->setConf("xyOscXChannel",xyOscXChannel); + e->setConf("xyOscXInvert",xyOscXInvert); + e->setConf("xyOscYChannel",xyOscYChannel); + e->setConf("xyOscYInvert",xyOscYInvert); + e->setConf("xyOscZoom",xyOscZoom); + e->setConf("xyOscSamples",xyOscSamples); + e->setConf("xyOscDecayTime",xyOscDecayTime); + e->setConf("xyOscIntensity",xyOscIntensity); + e->setConf("xyOscThickness",xyOscThickness); + // commit recent files for (int i=0; i<30; i++) { String key=fmt::sprintf("recentFile%d",i); @@ -7301,6 +7328,7 @@ FurnaceGUI::FurnaceGUI(): clockOpen(false), speedOpen(true), groovesOpen(false), + xyOscOpen(false), basicMode(true), shortIntro(false), insListDir(false), @@ -7541,6 +7569,17 @@ FurnaceGUI::FurnaceGUI(): chanOscGrad(64,64), chanOscGradTex(NULL), chanOscWorkPool(NULL), + xyOscPointTex(NULL), + xyOscOptions(false), + xyOscXChannel(0), + xyOscXInvert(false), + xyOscYChannel(1), + xyOscYInvert(false), + xyOscZoom(1.0f), + xyOscSamples(32768), + xyOscDecayTime(10.0f), + xyOscIntensity(2.0f), + xyOscThickness(2.0f), followLog(true), #ifdef IS_MOBILE pianoOctaves(7), diff --git a/src/gui/gui.h b/src/gui/gui.h index 5d98548f73..39a412e9b2 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -419,6 +419,7 @@ enum FurnaceGUIWindows { GUI_WINDOW_FIND, GUI_WINDOW_CLOCK, GUI_WINDOW_GROOVES, + GUI_WINDOW_XY_OSC, GUI_WINDOW_INTRO_MON, GUI_WINDOW_SPOILER }; @@ -572,6 +573,7 @@ enum FurnaceGUIActions { GUI_ACTION_WINDOW_FIND, GUI_ACTION_WINDOW_CLOCK, GUI_ACTION_WINDOW_GROOVES, + GUI_ACTION_WINDOW_XY_OSC, GUI_ACTION_COLLAPSE_WINDOW, GUI_ACTION_CLOSE_WINDOW, @@ -1873,7 +1875,7 @@ class FurnaceGUI { bool mixerOpen, debugOpen, inspectorOpen, oscOpen, volMeterOpen, statsOpen, compatFlagsOpen; bool pianoOpen, notesOpen, channelsOpen, regViewOpen, logOpen, effectListOpen, chanOscOpen; bool subSongsOpen, findOpen, spoilerOpen, patManagerOpen, sysManagerOpen, clockOpen, speedOpen; - bool groovesOpen; + bool groovesOpen, xyOscOpen; bool basicMode, shortIntro; bool insListDir, waveListDir, sampleListDir; @@ -2167,6 +2169,19 @@ class FurnaceGUI { planI(NULL) {} } chanOscChan[DIV_MAX_CHANS]; + // x-y oscilloscope + FurnaceGUITexture* xyOscPointTex; + bool xyOscOptions; + int xyOscXChannel; + bool xyOscXInvert; + int xyOscYChannel; + bool xyOscYInvert; + float xyOscZoom; + int xyOscSamples; + float xyOscDecayTime; + float xyOscIntensity; + float xyOscThickness; + // visualizer float keyHit[DIV_MAX_CHANS]; float keyHit1[DIV_MAX_CHANS]; @@ -2357,6 +2372,7 @@ class FurnaceGUI { void drawSpoiler(); void drawClock(); void drawTutorial(); + void drawXYOsc(); void parseKeybinds(); void promptKey(int which); diff --git a/src/gui/guiConst.cpp b/src/gui/guiConst.cpp index a31273004a..0411d8a3cf 100644 --- a/src/gui/guiConst.cpp +++ b/src/gui/guiConst.cpp @@ -594,6 +594,7 @@ const FurnaceGUIActionDef guiActions[GUI_ACTION_MAX]={ D("WINDOW_FIND", "Find/Replace", FURKMOD_CMD|SDLK_f), D("WINDOW_CLOCK", "Clock", 0), D("WINDOW_GROOVES", "Grooves", 0), + D("WINDOW_XY_OSC", "Oscilloscope (X-Y)", 0), D("COLLAPSE_WINDOW", "Collapse/expand current window", 0), D("CLOSE_WINDOW", "Close current window", FURKMOD_SHIFT|SDLK_ESCAPE), diff --git a/src/gui/xyOsc.cpp b/src/gui/xyOsc.cpp new file mode 100644 index 0000000000..3a00b811d5 --- /dev/null +++ b/src/gui/xyOsc.cpp @@ -0,0 +1,232 @@ +/** + * Furnace Tracker - multi-system chiptune tracker + * Copyright (C) 2021-2023 tildearrow and contributors + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "gui.h" +#include "imgui_internal.h" +#include +#include "../ta-log.h" +#include "../engine/filter.h" + +void FurnaceGUI::drawXYOsc() { + if (nextWindow==GUI_WINDOW_XY_OSC) { + xyOscOpen=true; + ImGui::SetNextWindowFocus(); + nextWindow=GUI_WINDOW_NOTHING; + } + if (!xyOscOpen) return; + ImGui::SetNextWindowSizeConstraints(ImVec2(64.0f*dpiScale,32.0f*dpiScale),ImVec2(canvasW,canvasH)); + bool noPadding=settings.oscTakesEntireWindow && !xyOscOptions; + if (noPadding) { + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding,ImVec2(0,0)); + ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing,ImVec2(0,0)); + ImGui::PushStyleVar(ImGuiStyleVar_ItemInnerSpacing,ImVec2(0,0)); + } + if (ImGui::Begin("Oscilloscope (X-Y)",&xyOscOpen,globalWinFlags)) { + if (xyOscOptions) { + int xyOscXChannelP1 = xyOscXChannel+1; + int xyOscYChannelP1 = xyOscYChannel+1; + + ImGui::Text("X Channel"); + ImGui::SameLine(); + if (ImGui::DragInt("##XChannel",&xyOscXChannelP1,1.0f,1,DIV_MAX_OUTPUTS)) { + xyOscXChannel=MIN(MAX(xyOscXChannelP1,1),DIV_MAX_OUTPUTS)-1; + } rightClickable + ImGui::SameLine(); + ImGui::Checkbox("Invert##X",&xyOscXInvert); + ImGui::Text("Y Channel"); + ImGui::SameLine(); + if (ImGui::DragInt("##YChannel",&xyOscYChannelP1,1.0f,1,DIV_MAX_OUTPUTS)) { + xyOscXChannel=MIN(MAX(xyOscYChannelP1,1),DIV_MAX_OUTPUTS)-1; + } rightClickable + ImGui::SameLine(); + ImGui::Checkbox("Invert##Y",&xyOscYInvert); + if (ImGui::SliderFloat("Zoom",&xyOscZoom,0.5f,4.0f,"%.2fx")) { + xyOscZoom=MAX(xyOscZoom,0.0f); + } rightClickable + if (ImGui::IsItemHovered()) { + ImGui::SetTooltip("%.1fdB",20.0f*log10f(xyOscZoom)); + } + if (ImGui::IsItemClicked(ImGuiMouseButton_Middle)) { + xyOscZoom=1.0f; + } + if (ImGui::SliderInt("Samples",&xyOscSamples,2,32768)) { + xyOscSamples=MIN(MAX(xyOscSamples,2),32768); + } rightClickable + if (ImGui::SliderFloat("Decay Time (ms)",&xyOscDecayTime,1.0f,1000.0f,"%.1f",ImGuiSliderFlags_Logarithmic)) { + xyOscDecayTime=MAX(xyOscDecayTime,0.0f); + } rightClickable + if (ImGui::SliderFloat("Intensity",&xyOscIntensity,0.0f,5.0f,"%.2f")) { + xyOscIntensity=MAX(xyOscIntensity,0.0f); + } rightClickable + if (ImGui::SliderFloat("Line Thickness",&xyOscThickness,0.0f,10.0f,"%.2f")) { + xyOscThickness=MAX(xyOscThickness,0.0f); + } rightClickable + if (ImGui::Button("OK")) { + xyOscOptions=false; + } + } else { + ImDrawList* dl=ImGui::GetWindowDrawList(); + ImGuiWindow* window=ImGui::GetCurrentWindow(); + ImVec2 size=ImGui::GetContentRegionAvail(); + + ImVec2 minArea=window->DC.CursorPos; + ImVec2 maxArea=ImVec2( + minArea.x+size.x, + minArea.y+size.y + ); + ImRect rect=ImRect(minArea,maxArea); + ImRect inRect=rect; + inRect.Min.x+=dpiScale; + inRect.Min.y+=dpiScale; + inRect.Max.x-=dpiScale; + inRect.Max.y-=dpiScale; + ImVec2 inSqrCenter=rect.GetCenter(); + float inSqrLength; + ImRect inSqr=inRect; + if (rect.GetWidth() > rect.GetHeight()) { + inSqrLength=inSqr.GetHeight()/2; + inSqr.Min.x=inSqrCenter.x-inSqrLength; + inSqr.Max.x=inSqrCenter.x+inSqrLength; + } else { + inSqrLength=inSqr.GetWidth()/2; + inSqr.Min.y=inSqrCenter.y-inSqrLength; + inSqr.Max.y=inSqrCenter.y+inSqrLength; + } + float scaleX=xyOscZoom*inSqrLength*(xyOscXInvert?-1:1); + float scaleY=xyOscZoom*inSqrLength*(xyOscYInvert?1:-1); + const ImGuiStyle& style=ImGui::GetStyle(); + ImU32 color=ImGui::GetColorU32(uiColors[GUI_COLOR_OSC_WAVE]); + color&=~IM_COL32_A_MASK; + ImU32 borderColor=ImGui::GetColorU32(uiColors[GUI_COLOR_OSC_BORDER]); + ImU32 refColor=ImGui::GetColorU32(uiColors[GUI_COLOR_OSC_REF]); + ImU32 guideColor=ImGui::GetColorU32(uiColors[GUI_COLOR_OSC_GUIDE]); + ImGui::ItemSize(size,style.FramePadding.y); + if (ImGui::ItemAdd(rect,ImGui::GetID("wsDisplay"))) { + // background + dl->AddRectFilledMultiColor( + inRect.Min, + inRect.Max, + ImGui::GetColorU32(uiColors[GUI_COLOR_OSC_BG1]), + ImGui::GetColorU32(uiColors[GUI_COLOR_OSC_BG2]), + ImGui::GetColorU32(uiColors[GUI_COLOR_OSC_BG4]), + ImGui::GetColorU32(uiColors[GUI_COLOR_OSC_BG3]), + settings.oscRoundedCorners?(8.0f*dpiScale):0.0f + ); + + // axis guides + dl->AddLine( + ImLerp(rect.Min,rect.Max,ImVec2(0.0f,0.5f)), + ImLerp(rect.Min,rect.Max,ImVec2(1.0f,0.5f)), + refColor, + dpiScale + ); + + dl->AddLine( + ImLerp(rect.Min,rect.Max,ImVec2(0.5f,0.0f)), + ImLerp(rect.Min,rect.Max,ImVec2(0.5f,1.0f)), + refColor, + dpiScale + ); + + bool reflect=xyOscXInvert!=xyOscYInvert; + dl->AddLine( + ImLerp(inSqr.Min,inSqr.Max,ImVec2(0.0f,reflect?0.0f:1.0f)), + ImLerp(inSqr.Min,inSqr.Max,ImVec2(1.0f,reflect?1.0f:0.0f)), + refColor, + dpiScale + ); + + for (int i=1; i<5; i++) { + float ip = (float)i/8.f; + dl->AddRect( + ImLerp(inSqr.Min,inSqr.Max,ImVec2(0.5f-ip,0.5f-ip)), + ImLerp(inSqr.Min,inSqr.Max,ImVec2(0.5f+ip,0.5f+ip)), + guideColor, + 0.0f,0,dpiScale + ); + } + + // line + const float* oscBufX=e->oscBuf[xyOscXChannel]; + const float* oscBufY=e->oscBuf[xyOscYChannel]; + if (oscBufX!=NULL && oscBufY!=NULL) { + int pos=e->oscWritePos; + float lx=inSqrCenter.x; + float ly=inSqrCenter.y; + float maxA=xyOscIntensity*256.f; + float decay=exp2f(-1e3f/e->getAudioDescGot().rate/xyOscDecayTime); + ImDrawListFlags prevFlags=dl->Flags; + dl->Flags|=ImDrawFlags_RoundCornersNone; + if (!settings.oscAntiAlias || safeMode) { + dl->Flags&=~(ImDrawListFlags_AntiAliasedLines|ImDrawListFlags_AntiAliasedLinesUseTex); + } + if (settings.oscEscapesBoundary) { + dl->PushClipRectFullScreen(); + } + for (int i=0; i=1) { + a=MIN(a,255); + dl->AddLine(ImVec2(lx,ly),ImVec2(x,y),(color|((ImU32)a<PopClipRect(); + } + dl->Flags=prevFlags; + } + if (settings.oscBorder) { + dl->AddRect(inRect.Min,inRect.Max,borderColor,settings.oscRoundedCorners?(8.0f*dpiScale):0.0f,0,1.5f*dpiScale); + } + } + if (ImGui::IsItemHovered()) { + float valX=20.0f*log10f(fabsf((ImGui::GetMousePos().x-inSqrCenter.x)/scaleX)); + float valY=20.0f*log10f(fabsf((ImGui::GetMousePos().y-inSqrCenter.y)/scaleY)); + if (valX<=-INFINITY && valY<=-INFINITY) { + ImGui::SetTooltip("(-Infinity)dB,(-Infinity)dB"); + } else if (valX<=-INFINITY) { + ImGui::SetTooltip("(-Infinity)dB,%.1fdB",valY); + } else if (valY<=-INFINITY) { + ImGui::SetTooltip("%.1fdB,(-Infinity)dB",valY); + } else { + ImGui::SetTooltip("%.1fdB,%.1fdB",valX,valY); + } + } + if (ImGui::IsItemClicked(ImGuiMouseButton_Right)) { + xyOscOptions=true; + } + } + } + if (noPadding) { + ImGui::PopStyleVar(3); + } + if (ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows)) curWindow=GUI_WINDOW_XY_OSC; + ImGui::End(); +}