mirror of
https://github.com/tildearrow/furnace.git
synced 2024-11-27 15:03:01 +00:00
GUI: improve oscilloscope
it's not finished yet
This commit is contained in:
parent
785ac8d1a7
commit
11cdc3924d
5 changed files with 119 additions and 9 deletions
|
@ -3432,7 +3432,9 @@ FurnaceGUI::FurnaceGUI():
|
||||||
openSampleAmplifyOpt(false),
|
openSampleAmplifyOpt(false),
|
||||||
openSampleSilenceOpt(false),
|
openSampleSilenceOpt(false),
|
||||||
openSampleFilterOpt(false),
|
openSampleFilterOpt(false),
|
||||||
oscTotal(0) {
|
oscTotal(0),
|
||||||
|
oscZoom(0.5f),
|
||||||
|
oscZoomSlider(false) {
|
||||||
// value keys
|
// value keys
|
||||||
valueKeys[SDLK_0]=0;
|
valueKeys[SDLK_0]=0;
|
||||||
valueKeys[SDLK_1]=1;
|
valueKeys[SDLK_1]=1;
|
||||||
|
|
|
@ -71,6 +71,16 @@ enum FurnaceGUIColors {
|
||||||
GUI_COLOR_FILE_FONT,
|
GUI_COLOR_FILE_FONT,
|
||||||
GUI_COLOR_FILE_OTHER,
|
GUI_COLOR_FILE_OTHER,
|
||||||
|
|
||||||
|
GUI_COLOR_OSC_BG1,
|
||||||
|
GUI_COLOR_OSC_BG2,
|
||||||
|
GUI_COLOR_OSC_BG3,
|
||||||
|
GUI_COLOR_OSC_BG4,
|
||||||
|
GUI_COLOR_OSC_BORDER,
|
||||||
|
GUI_COLOR_OSC_WAVE,
|
||||||
|
GUI_COLOR_OSC_WAVE_PEAK,
|
||||||
|
GUI_COLOR_OSC_REF,
|
||||||
|
GUI_COLOR_OSC_GUIDE,
|
||||||
|
|
||||||
GUI_COLOR_VOLMETER_LOW,
|
GUI_COLOR_VOLMETER_LOW,
|
||||||
GUI_COLOR_VOLMETER_HIGH,
|
GUI_COLOR_VOLMETER_HIGH,
|
||||||
GUI_COLOR_VOLMETER_PEAK,
|
GUI_COLOR_VOLMETER_PEAK,
|
||||||
|
@ -979,6 +989,8 @@ class FurnaceGUI {
|
||||||
// oscilloscope
|
// oscilloscope
|
||||||
int oscTotal;
|
int oscTotal;
|
||||||
float oscValues[512];
|
float oscValues[512];
|
||||||
|
float oscZoom;
|
||||||
|
bool oscZoomSlider;
|
||||||
|
|
||||||
// visualizer
|
// visualizer
|
||||||
float keyHit[DIV_MAX_CHANS];
|
float keyHit[DIV_MAX_CHANS];
|
||||||
|
|
|
@ -377,6 +377,16 @@ const FurnaceGUIColorDef guiColors[GUI_COLOR_MAX]={
|
||||||
D(GUI_COLOR_FILE_FONT,"",ImVec4(0.3f,1.0f,0.6f,1.0f)),
|
D(GUI_COLOR_FILE_FONT,"",ImVec4(0.3f,1.0f,0.6f,1.0f)),
|
||||||
D(GUI_COLOR_FILE_OTHER,"",ImVec4(0.7f,0.7f,0.7f,1.0f)),
|
D(GUI_COLOR_FILE_OTHER,"",ImVec4(0.7f,0.7f,0.7f,1.0f)),
|
||||||
|
|
||||||
|
D(GUI_COLOR_OSC_BG1,"",ImVec4(0.1f,0.18f,0.3f,1.0f)),
|
||||||
|
D(GUI_COLOR_OSC_BG2,"",ImVec4(0.1f,0.18f,0.3f,1.0f)),
|
||||||
|
D(GUI_COLOR_OSC_BG3,"",ImVec4(0.05f,0.15f,0.25f,1.0f)),
|
||||||
|
D(GUI_COLOR_OSC_BG4,"",ImVec4(0.05f,0.15f,0.25f,1.0f)),
|
||||||
|
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_REF,"",ImVec4(0.3f,0.3f,0.3f,1.0f)),
|
||||||
|
D(GUI_COLOR_OSC_GUIDE,"",ImVec4(0.3,0.3f,0.3f,1.0f)),
|
||||||
|
|
||||||
D(GUI_COLOR_VOLMETER_LOW,"",ImVec4(0.2f,0.6f,0.2f,1.0f)),
|
D(GUI_COLOR_VOLMETER_LOW,"",ImVec4(0.2f,0.6f,0.2f,1.0f)),
|
||||||
D(GUI_COLOR_VOLMETER_HIGH,"",ImVec4(1.0f,0.9f,0.2f,1.0f)),
|
D(GUI_COLOR_VOLMETER_HIGH,"",ImVec4(1.0f,0.9f,0.2f,1.0f)),
|
||||||
D(GUI_COLOR_VOLMETER_PEAK,"",ImVec4(1.0f,0.1f,0.1f,1.0f)),
|
D(GUI_COLOR_VOLMETER_PEAK,"",ImVec4(1.0f,0.1f,0.1f,1.0f)),
|
||||||
|
|
|
@ -18,6 +18,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "gui.h"
|
#include "gui.h"
|
||||||
|
#include "imgui_internal.h"
|
||||||
|
#include <imgui.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
void FurnaceGUI::readOsc() {
|
void FurnaceGUI::readOsc() {
|
||||||
|
@ -71,16 +73,88 @@ void FurnaceGUI::drawOsc() {
|
||||||
}
|
}
|
||||||
if (!oscOpen) return;
|
if (!oscOpen) return;
|
||||||
ImGui::SetNextWindowSizeConstraints(ImVec2(64.0f*dpiScale,32.0f*dpiScale),ImVec2(scrW*dpiScale,scrH*dpiScale));
|
ImGui::SetNextWindowSizeConstraints(ImVec2(64.0f*dpiScale,32.0f*dpiScale),ImVec2(scrW*dpiScale,scrH*dpiScale));
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding,ImVec2(0,0));
|
/*ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding,ImVec2(0,0));
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing,ImVec2(0,0));
|
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing,ImVec2(0,0));
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemInnerSpacing,ImVec2(0,0));
|
ImGui::PushStyleVar(ImGuiStyleVar_ItemInnerSpacing,ImVec2(0,0));*/
|
||||||
if (ImGui::Begin("Oscilloscope",&oscOpen)) {
|
if (ImGui::Begin("Oscilloscope",&oscOpen)) {
|
||||||
//ImGui::SetCursorPos(ImVec2(0,0));
|
if (oscZoomSlider) {
|
||||||
ImGui::BeginDisabled();
|
if (ImGui::VSliderFloat("##OscZoom",ImVec2(20.0f*dpiScale,ImGui::GetContentRegionAvail().y),&oscZoom,0.5,2.0)) {
|
||||||
ImGui::PlotLines("##SingleOsc",oscValues,512,0,NULL,-1.0f,1.0f,ImGui::GetContentRegionAvail());
|
if (oscZoom<0.5) oscZoom=0.5;
|
||||||
ImGui::EndDisabled();
|
if (oscZoom>2.0) oscZoom=2.0;
|
||||||
}
|
}
|
||||||
ImGui::PopStyleVar(3);
|
ImGui::SameLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
ImDrawList* dl=ImGui::GetWindowDrawList();
|
||||||
|
ImGuiWindow* window=ImGui::GetCurrentWindow();
|
||||||
|
|
||||||
|
ImVec2 waveform[512];
|
||||||
|
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);
|
||||||
|
ImGuiStyle& style=ImGui::GetStyle();
|
||||||
|
ImU32 color=ImGui::GetColorU32(isClipping?uiColors[GUI_COLOR_OSC_WAVE_PEAK]:uiColors[GUI_COLOR_OSC_WAVE]);
|
||||||
|
ImU32 borderColor=ImGui::GetColorU32(uiColors[GUI_COLOR_OSC_BORDER]);
|
||||||
|
ImGui::ItemSize(size,style.FramePadding.y);
|
||||||
|
if (ImGui::ItemAdd(rect,ImGui::GetID("wsDisplay"))) {
|
||||||
|
// https://github.com/ocornut/imgui/issues/3710
|
||||||
|
// TODO: improve
|
||||||
|
const int v0 = dl->VtxBuffer.Size;
|
||||||
|
dl->AddRectFilled(rect.Min,rect.Max,0xffffffff,8.0f*dpiScale);
|
||||||
|
const int v1 = dl->VtxBuffer.Size;
|
||||||
|
|
||||||
|
for (int i=v0; i<v1; i++) {
|
||||||
|
ImDrawVert* v=&dl->VtxBuffer.Data[i];
|
||||||
|
ImVec4 col0=uiColors[GUI_COLOR_OSC_BG1];
|
||||||
|
ImVec4 col1=uiColors[GUI_COLOR_OSC_BG3];
|
||||||
|
ImVec4 col2=uiColors[GUI_COLOR_OSC_BG2];
|
||||||
|
ImVec4 col3=uiColors[GUI_COLOR_OSC_BG4];
|
||||||
|
|
||||||
|
float shadeX=(v->pos.x-rect.Min.x)/(rect.Max.x-rect.Min.x);
|
||||||
|
float shadeY=(v->pos.y-rect.Min.y)/(rect.Max.y-rect.Min.y);
|
||||||
|
if (shadeX<0.0f) shadeX=0.0f;
|
||||||
|
if (shadeX>1.0f) shadeX=1.0f;
|
||||||
|
if (shadeY<0.0f) shadeY=0.0f;
|
||||||
|
if (shadeY>1.0f) shadeY=1.0f;
|
||||||
|
|
||||||
|
col0.x+=(col2.x-col0.x)*shadeX;
|
||||||
|
col0.y+=(col2.y-col0.y)*shadeX;
|
||||||
|
col0.z+=(col2.z-col0.z)*shadeX;
|
||||||
|
col0.w+=(col2.w-col0.w)*shadeX;
|
||||||
|
|
||||||
|
col1.x+=(col3.x-col1.x)*shadeX;
|
||||||
|
col1.y+=(col3.y-col1.y)*shadeX;
|
||||||
|
col1.z+=(col3.z-col1.z)*shadeX;
|
||||||
|
col1.w+=(col3.w-col1.w)*shadeX;
|
||||||
|
|
||||||
|
col0.x+=(col1.x-col0.x)*shadeY;
|
||||||
|
col0.y+=(col1.y-col0.y)*shadeY;
|
||||||
|
col0.z+=(col1.z-col0.z)*shadeY;
|
||||||
|
col0.w+=(col1.w-col0.w)*shadeY;
|
||||||
|
|
||||||
|
v->col=ImGui::ColorConvertFloat4ToU32(col0);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t i=0; i<512; i++) {
|
||||||
|
float x=(float)i/512.0f;
|
||||||
|
float y=oscValues[i]*oscZoom;
|
||||||
|
if (y<-0.5f) y=-0.5f;
|
||||||
|
if (y>0.5f) y=0.5f;
|
||||||
|
waveform[i]=ImLerp(rect.Min,rect.Max,ImVec2(x,0.5f-y));
|
||||||
|
}
|
||||||
|
dl->AddPolyline(waveform,512,color,ImDrawFlags_None,dpiScale);
|
||||||
|
dl->AddRect(rect.Min,rect.Max,borderColor,8.0f*dpiScale,0,dpiScale);
|
||||||
|
}
|
||||||
|
if (ImGui::IsItemClicked(ImGuiMouseButton_Right)) {
|
||||||
|
oscZoomSlider=!oscZoomSlider;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//ImGui::PopStyleVar(3);
|
||||||
if (ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows)) curWindow=GUI_WINDOW_OSCILLOSCOPE;
|
if (ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows)) curWindow=GUI_WINDOW_OSCILLOSCOPE;
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
|
@ -942,6 +942,18 @@ void FurnaceGUI::drawSettings() {
|
||||||
UI_COLOR_CONFIG(GUI_COLOR_FILE_OTHER,"Other");
|
UI_COLOR_CONFIG(GUI_COLOR_FILE_OTHER,"Other");
|
||||||
ImGui::TreePop();
|
ImGui::TreePop();
|
||||||
}
|
}
|
||||||
|
if (ImGui::TreeNode("Oscilloscope")) {
|
||||||
|
UI_COLOR_CONFIG(GUI_COLOR_OSC_BORDER,"Border");
|
||||||
|
UI_COLOR_CONFIG(GUI_COLOR_OSC_BG1,"Background (top-left)");
|
||||||
|
UI_COLOR_CONFIG(GUI_COLOR_OSC_BG2,"Background (top-right)");
|
||||||
|
UI_COLOR_CONFIG(GUI_COLOR_OSC_BG3,"Background (bottom-left)");
|
||||||
|
UI_COLOR_CONFIG(GUI_COLOR_OSC_BG4,"Background (bottom-right)");
|
||||||
|
UI_COLOR_CONFIG(GUI_COLOR_OSC_WAVE,"Waveform");
|
||||||
|
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");
|
||||||
|
ImGui::TreePop();
|
||||||
|
}
|
||||||
if (ImGui::TreeNode("Volume Meter")) {
|
if (ImGui::TreeNode("Volume Meter")) {
|
||||||
UI_COLOR_CONFIG(GUI_COLOR_VOLMETER_LOW,"Low");
|
UI_COLOR_CONFIG(GUI_COLOR_VOLMETER_LOW,"Low");
|
||||||
UI_COLOR_CONFIG(GUI_COLOR_VOLMETER_HIGH,"High");
|
UI_COLOR_CONFIG(GUI_COLOR_VOLMETER_HIGH,"High");
|
||||||
|
|
Loading…
Reference in a new issue