From 5e4bfe2f11a675d08c4a79e179d6adf9e63dca38 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Fri, 30 Sep 2022 18:24:20 -0500 Subject: [PATCH] GUI: sample editor changes --- src/engine/engine.cpp | 2 +- src/gui/gui.h | 9 ++++++++ src/gui/guiConst.cpp | 9 ++++++++ src/gui/sampleEdit.cpp | 47 +++++++++++++++++++++++++++++++++++------- src/gui/settings.cpp | 11 ++++++++++ 5 files changed, 69 insertions(+), 9 deletions(-) diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index ed784f17..afcdcebc 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -2125,7 +2125,7 @@ void DivEngine::previewSample(int sample, int note, int pStart, int pEnd) { blip_clear(samp_bb); double rate=song.sample[sample]->rate; if (note>=0) { - rate=(song.tuning*pow(2.0,(double)(note+3)/12.0)*((double)song.sample[sample]->centerRate/8363.0)); + rate=(pow(2.0,(double)(note)/12.0)*((double)song.sample[sample]->centerRate)*0.0625); if (rate<=0) rate=song.sample[sample]->rate; } if (rate<100) rate=100; diff --git a/src/gui/gui.h b/src/gui/gui.h index 6bb0d38f..0c0eb564 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -217,6 +217,15 @@ enum FurnaceGUIColors { GUI_COLOR_PATTERN_EFFECT_SYS_SECONDARY, GUI_COLOR_PATTERN_EFFECT_MISC, + GUI_COLOR_SAMPLE_BG, + GUI_COLOR_SAMPLE_FG, + GUI_COLOR_SAMPLE_LOOP, + GUI_COLOR_SAMPLE_CENTER, + GUI_COLOR_SAMPLE_GRID, + GUI_COLOR_SAMPLE_SEL, + GUI_COLOR_SAMPLE_SEL_POINT, + GUI_COLOR_SAMPLE_NEEDLE, + GUI_COLOR_PAT_MANAGER_NULL, GUI_COLOR_PAT_MANAGER_USED, GUI_COLOR_PAT_MANAGER_OVERUSED, diff --git a/src/gui/guiConst.cpp b/src/gui/guiConst.cpp index 586c45c1..b429a79f 100644 --- a/src/gui/guiConst.cpp +++ b/src/gui/guiConst.cpp @@ -846,6 +846,15 @@ const FurnaceGUIColorDef guiColors[GUI_COLOR_MAX]={ D(GUI_COLOR_PATTERN_EFFECT_SYS_SECONDARY,"",ImVec4(0.0f,1.0f,0.5f,1.0f)), D(GUI_COLOR_PATTERN_EFFECT_MISC,"",ImVec4(0.3f,0.3f,1.0f,1.0f)), + D(GUI_COLOR_SAMPLE_BG,"",ImVec4(0.04f,0.13f,0.2f,1.0f)), + D(GUI_COLOR_SAMPLE_FG,"",ImVec4(0.7f,0.7f,0.7f,1.0f)), + D(GUI_COLOR_SAMPLE_LOOP,"",ImVec4(0.1f,0.22f,0.35f,1.0f)), + D(GUI_COLOR_SAMPLE_CENTER,"",ImVec4(0.2f,0.2f,0.2f,1.0f)), + D(GUI_COLOR_SAMPLE_GRID,"",ImVec4(0.1f,0.1f,0.15f,1.0f)), + D(GUI_COLOR_SAMPLE_SEL,"",ImVec4(0.26f,0.59f,0.98f,0.25f)), + D(GUI_COLOR_SAMPLE_SEL_POINT,"",ImVec4(0.06f,0.53f,0.98f,0.5f)), + D(GUI_COLOR_SAMPLE_NEEDLE,"",ImVec4(1.0f,0.8f,0.0f,1.0f)), + D(GUI_COLOR_PAT_MANAGER_NULL,"",ImVec4(0.15f,0.15f,0.15f,1.0f)), D(GUI_COLOR_PAT_MANAGER_USED,"",ImVec4(0.15f,1.0f,0.15f,1.0f)), D(GUI_COLOR_PAT_MANAGER_OVERUSED,"",ImVec4(1.0f,1.0f,0.15f,1.0f)), diff --git a/src/gui/sampleEdit.cpp b/src/gui/sampleEdit.cpp index 9ba9893c..d5543d42 100644 --- a/src/gui/sampleEdit.cpp +++ b/src/gui/sampleEdit.cpp @@ -1231,10 +1231,10 @@ void FurnaceGUI::drawSampleEdit() { if (SDL_LockTexture(sampleTex,NULL,(void**)&data,&pitch)!=0) { logE("error while locking sample texture! %s",SDL_GetError()); } else { - ImU32 bgColor=ImGui::GetColorU32(ImGuiCol_FrameBg); - ImU32 bgColorLoop=ImAlphaBlendColors(bgColor,ImGui::GetColorU32(ImGuiCol_FrameBgHovered,0.5)); - ImU32 lineColor=ImGui::GetColorU32(ImGuiCol_PlotLines); - ImU32 centerLineColor=ImAlphaBlendColors(bgColor,ImGui::GetColorU32(ImGuiCol_PlotLines,0.25)); + ImU32 bgColor=ImGui::GetColorU32(uiColors[GUI_COLOR_SAMPLE_BG]); + ImU32 bgColorLoop=ImGui::GetColorU32(uiColors[GUI_COLOR_SAMPLE_LOOP]); + ImU32 lineColor=ImGui::GetColorU32(uiColors[GUI_COLOR_SAMPLE_FG]); + ImU32 centerLineColor=ImGui::GetColorU32(uiColors[GUI_COLOR_SAMPLE_CENTER]); for (int i=0; iisPreviewingSample()) { statusBar+=fmt::sprintf(" | %.2fHz",e->getSamplePreviewRate()); + + int start=sampleSelStart; + int end=sampleSelEnd; + if (start>end) { + start^=end; + end^=start; + start^=end; + } + ImDrawList* dl=ImGui::GetWindowDrawList(); + ImVec2 p1=rectMin; + p1.x+=(e->getSamplePreviewPos()-samplePos)/sampleZoom; + ImVec4 posColor=uiColors[GUI_COLOR_SAMPLE_NEEDLE]; + ImVec4 posTrail1=posColor; + ImVec4 posTrail2=posColor; + posTrail1.w*=0.5f; + posTrail2.w=0.0f; + float trailDistance=(e->getSamplePreviewRate()/100.0f)/sampleZoom; + + if (p1.xrectMax.x) p1.x=rectMax.x; + + ImVec2 p2=p1; + p2.y=rectMax.y; + + dl->AddRectFilledMultiColor( + ImVec2(p1.x-trailDistance,p1.y), + p2, + ImGui::GetColorU32(posTrail2), + ImGui::GetColorU32(posTrail1), + ImGui::GetColorU32(posTrail1), + ImGui::GetColorU32(posTrail2) + ); + dl->AddLine(p1,p2,ImGui::GetColorU32(posColor)); } if (drawSelection) { @@ -1458,10 +1491,8 @@ void FurnaceGUI::drawSampleEdit() { p1.x+=(start-samplePos)/sampleZoom; ImVec2 p2=ImVec2(rectMin.x+(end-samplePos)/sampleZoom,rectMax.y); - ImVec4 boundColor=uiColors[GUI_COLOR_ACCENT_PRIMARY]; - ImVec4 selColor=uiColors[GUI_COLOR_ACCENT_SECONDARY]; - boundColor.w*=0.5; - selColor.w*=0.25; + ImVec4 boundColor=uiColors[GUI_COLOR_SAMPLE_SEL_POINT]; + ImVec4 selColor=uiColors[GUI_COLOR_SAMPLE_SEL]; if (p1.xrectMax.x) p1.x=rectMax.x; diff --git a/src/gui/settings.cpp b/src/gui/settings.cpp index 26557acd..e4c40cae 100644 --- a/src/gui/settings.cpp +++ b/src/gui/settings.cpp @@ -1773,6 +1773,17 @@ void FurnaceGUI::drawSettings() { UI_COLOR_CONFIG(GUI_COLOR_EE_VALUE,"External command output"); ImGui::TreePop(); } + if (ImGui::TreeNode("Sample Editor")) { + UI_COLOR_CONFIG(GUI_COLOR_SAMPLE_BG,"Background"); + UI_COLOR_CONFIG(GUI_COLOR_SAMPLE_FG,"Waveform"); + UI_COLOR_CONFIG(GUI_COLOR_SAMPLE_LOOP,"Loop region"); + UI_COLOR_CONFIG(GUI_COLOR_SAMPLE_CENTER,"Center guide"); + UI_COLOR_CONFIG(GUI_COLOR_SAMPLE_GRID,"Grid"); + UI_COLOR_CONFIG(GUI_COLOR_SAMPLE_SEL,"Selection"); + UI_COLOR_CONFIG(GUI_COLOR_SAMPLE_SEL_POINT,"Selection points"); + UI_COLOR_CONFIG(GUI_COLOR_SAMPLE_NEEDLE,"Preview needle"); + ImGui::TreePop(); + } if (ImGui::TreeNode("Pattern Manager")) { UI_COLOR_CONFIG(GUI_COLOR_PAT_MANAGER_NULL,"Unallocated"); UI_COLOR_CONFIG(GUI_COLOR_PAT_MANAGER_UNUSED,"Unused");