2022-04-30 04:58:30 -04:00
|
|
|
/**
|
|
|
|
* Furnace Tracker - multi-system chiptune tracker
|
2025-01-28 18:49:19 -05:00
|
|
|
* Copyright (C) 2021-2025 tildearrow and contributors
|
2022-04-30 04:58:30 -04:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2022-12-14 23:32:02 -05:00
|
|
|
#define _USE_MATH_DEFINES
|
2022-04-30 04:58:30 -04:00
|
|
|
#include "gui.h"
|
2022-05-31 04:24:29 -04:00
|
|
|
#include "../ta-log.h"
|
2022-04-30 04:58:30 -04:00
|
|
|
#include "imgui.h"
|
|
|
|
#include "imgui_internal.h"
|
2023-06-18 05:27:22 -04:00
|
|
|
#include "misc/cpp/imgui_stdlib.h"
|
2022-04-30 04:58:30 -04:00
|
|
|
|
2022-06-03 04:32:24 -04:00
|
|
|
#define FURNACE_FFT_SIZE 4096
|
2022-05-31 05:09:38 -04:00
|
|
|
#define FURNACE_FFT_RATE 80.0
|
2022-06-03 04:32:24 -04:00
|
|
|
#define FURNACE_FFT_CUTOFF 0.1
|
2022-05-31 04:24:29 -04:00
|
|
|
|
2022-06-22 16:10:53 -04:00
|
|
|
const char* chanOscRefs[]={
|
2024-05-27 00:30:33 -04:00
|
|
|
_N("None (0%)"),
|
|
|
|
_N("None (50%)"),
|
|
|
|
_N("None (100%)"),
|
2022-06-22 16:10:53 -04:00
|
|
|
|
2024-05-27 00:30:33 -04:00
|
|
|
_N("Frequency"),
|
|
|
|
_N("Volume"),
|
|
|
|
_N("Channel"),
|
|
|
|
_N("Brightness"),
|
2022-06-22 16:10:53 -04:00
|
|
|
|
2024-05-27 00:30:33 -04:00
|
|
|
_N("Note Trigger")
|
2022-06-22 16:10:53 -04:00
|
|
|
};
|
|
|
|
|
2023-08-03 06:25:26 -04:00
|
|
|
const char* autoColsTypes[]={
|
2024-05-27 00:30:33 -04:00
|
|
|
_N("Off"),
|
|
|
|
_N("Mode 1"),
|
|
|
|
_N("Mode 2"),
|
|
|
|
_N("Mode 3")
|
2023-08-03 06:25:26 -04:00
|
|
|
};
|
|
|
|
|
2024-02-14 04:09:24 -05:00
|
|
|
static void _drawOsc(const ImDrawList* drawList, const ImDrawCmd* cmd) {
|
|
|
|
if (cmd!=NULL) {
|
|
|
|
if (cmd->UserCallbackData!=NULL) {
|
|
|
|
((FurnaceGUI*)(((PendingDrawOsc*)cmd->UserCallbackData)->gui))->runPendingDrawOsc((PendingDrawOsc*)cmd->UserCallbackData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-22 16:10:53 -04:00
|
|
|
float FurnaceGUI::computeGradPos(int type, int chan) {
|
|
|
|
switch (type) {
|
|
|
|
case GUI_OSCREF_NONE:
|
|
|
|
return 0.0f;
|
|
|
|
break;
|
|
|
|
case GUI_OSCREF_CENTER:
|
|
|
|
return 0.5f;
|
|
|
|
break;
|
|
|
|
case GUI_OSCREF_MAX:
|
|
|
|
return 1.0f;
|
|
|
|
break;
|
|
|
|
case GUI_OSCREF_FREQUENCY:
|
2023-09-07 01:16:47 -04:00
|
|
|
return chanOscChan[chan].pitch;
|
2022-06-22 16:10:53 -04:00
|
|
|
break;
|
|
|
|
case GUI_OSCREF_VOLUME:
|
|
|
|
return chanOscVol[chan];
|
|
|
|
break;
|
|
|
|
case GUI_OSCREF_CHANNEL:
|
|
|
|
return (float)chan/(float)(e->getTotalChannelCount()-1);
|
|
|
|
break;
|
|
|
|
case GUI_OSCREF_BRIGHT:
|
|
|
|
return chanOscBright[chan];
|
|
|
|
break;
|
|
|
|
case GUI_OSCREF_NOTE_TRIGGER:
|
2022-09-20 03:57:56 -04:00
|
|
|
return keyHit1[chan];
|
2022-06-22 16:10:53 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0.0f;
|
|
|
|
}
|
|
|
|
|
2022-09-20 03:32:23 -04:00
|
|
|
void FurnaceGUI::calcChanOsc() {
|
|
|
|
std::vector<DivDispatchOscBuffer*> oscBufs;
|
|
|
|
std::vector<ChanOscStatus*> oscFFTs;
|
|
|
|
std::vector<int> oscChans;
|
|
|
|
|
|
|
|
int chans=e->getTotalChannelCount();
|
|
|
|
|
|
|
|
for (int i=0; i<chans; i++) {
|
2022-11-15 03:25:42 -05:00
|
|
|
int tryAgain=i;
|
2022-09-20 03:32:23 -04:00
|
|
|
DivDispatchOscBuffer* buf=e->getOscBuffer(i);
|
2022-11-15 03:25:42 -05:00
|
|
|
while (buf==NULL) {
|
|
|
|
if (--tryAgain<0) break;
|
|
|
|
buf=e->getOscBuffer(tryAgain);
|
|
|
|
}
|
2023-11-15 09:21:01 -05:00
|
|
|
if (buf!=NULL && e->curSubSong->chanShowChanOsc[i]) {
|
2022-09-20 03:32:23 -04:00
|
|
|
// 30ms should be enough
|
2025-03-01 05:05:50 -05:00
|
|
|
int displaySize=65536.0f*0.03f;
|
2022-09-20 03:32:23 -04:00
|
|
|
if (e->isRunning()) {
|
2023-09-08 00:27:17 -04:00
|
|
|
short minLevel=32767;
|
|
|
|
short maxLevel=-32768;
|
2025-03-03 00:51:47 -05:00
|
|
|
unsigned short needlePos=buf->needle>>16;
|
2025-03-01 05:05:50 -05:00
|
|
|
for (unsigned short i=needlePos-displaySize; i!=needlePos; i++) {
|
|
|
|
short y=buf->data[i];
|
|
|
|
if (y==-1) continue;
|
2022-09-20 03:32:23 -04:00
|
|
|
if (minLevel>y) minLevel=y;
|
|
|
|
if (maxLevel<y) maxLevel=y;
|
|
|
|
}
|
2023-09-08 00:27:17 -04:00
|
|
|
float estimate=pow((float)(maxLevel-minLevel)/32768.0f,0.5f);
|
2022-09-20 03:32:23 -04:00
|
|
|
if (estimate>1.0f) estimate=1.0f;
|
|
|
|
chanOscVol[i]=MAX(chanOscVol[i]*0.87f,estimate);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
chanOscVol[i]=MAX(chanOscVol[i]*0.87f,0.0f);
|
|
|
|
}
|
|
|
|
if (chanOscVol[i]<0.00001f) chanOscVol[i]=0.0f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-30 04:58:30 -04:00
|
|
|
void FurnaceGUI::drawChanOsc() {
|
|
|
|
if (nextWindow==GUI_WINDOW_CHAN_OSC) {
|
|
|
|
chanOscOpen=true;
|
|
|
|
ImGui::SetNextWindowFocus();
|
|
|
|
nextWindow=GUI_WINDOW_NOTHING;
|
|
|
|
}
|
|
|
|
if (!chanOscOpen) return;
|
2022-10-20 03:34:14 -04:00
|
|
|
ImGui::SetNextWindowSizeConstraints(ImVec2(64.0f*dpiScale,32.0f*dpiScale),ImVec2(canvasW,canvasH));
|
2024-05-27 18:53:46 -04:00
|
|
|
if (ImGui::Begin("Oscilloscope (per-channel)",&chanOscOpen,globalWinFlags,_("Oscilloscope (per-channel)"))) {
|
2022-06-03 04:32:24 -04:00
|
|
|
bool centerSettingReset=false;
|
2022-06-22 16:10:53 -04:00
|
|
|
ImDrawList* dl=ImGui::GetWindowDrawList();
|
2022-06-21 19:01:53 -04:00
|
|
|
if (chanOscOptions) {
|
2023-08-22 18:15:49 -04:00
|
|
|
if (ImGui::BeginTable("ChanOscSettings",2)) {
|
2022-06-21 19:01:53 -04:00
|
|
|
ImGui::TableNextRow();
|
|
|
|
ImGui::TableNextColumn();
|
2023-08-06 23:51:51 -04:00
|
|
|
ImGui::AlignTextToFramePadding();
|
2024-05-26 20:31:17 -04:00
|
|
|
ImGui::Text(_("Columns"));
|
2022-06-21 19:01:53 -04:00
|
|
|
ImGui::SameLine();
|
|
|
|
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
|
2023-12-11 18:58:48 -05:00
|
|
|
if (ImGui::InputInt("##COSColumns",&chanOscCols,1,3)) {
|
2022-06-21 19:01:53 -04:00
|
|
|
if (chanOscCols<1) chanOscCols=1;
|
|
|
|
if (chanOscCols>64) chanOscCols=64;
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::TableNextColumn();
|
2024-05-26 20:31:17 -04:00
|
|
|
ImGui::Text(_("Size (ms)"));
|
2022-06-21 19:01:53 -04:00
|
|
|
ImGui::SameLine();
|
|
|
|
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
|
2023-12-11 18:58:48 -05:00
|
|
|
if (ImGui::InputFloat("##COSWinSize",&chanOscWindowSize,1.0f,10.0f)) {
|
2022-06-21 19:01:53 -04:00
|
|
|
if (chanOscWindowSize<1.0f) chanOscWindowSize=1.0f;
|
|
|
|
if (chanOscWindowSize>50.0f) chanOscWindowSize=50.0f;
|
|
|
|
}
|
|
|
|
|
2023-08-28 13:39:40 -04:00
|
|
|
ImGui::TableNextRow();
|
2023-08-03 06:25:26 -04:00
|
|
|
ImGui::TableNextColumn();
|
2023-08-06 23:51:51 -04:00
|
|
|
ImGui::AlignTextToFramePadding();
|
2024-05-26 20:31:17 -04:00
|
|
|
ImGui::Text(_("Automatic columns"));
|
2023-08-03 06:25:26 -04:00
|
|
|
ImGui::SameLine();
|
|
|
|
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
|
2023-08-03 22:32:57 -04:00
|
|
|
const char* previewColType=autoColsTypes[chanOscAutoColsType&3];
|
2023-08-03 06:25:26 -04:00
|
|
|
if (ImGui::BeginCombo("##AutoCols",previewColType)) {
|
|
|
|
for (int j=0; j<4; j++) {
|
|
|
|
const bool isSelected=(chanOscAutoColsType==j);
|
|
|
|
if (ImGui::Selectable(autoColsTypes[j],isSelected)) chanOscAutoColsType=j;
|
|
|
|
if (isSelected) ImGui::SetItemDefaultFocus();
|
|
|
|
}
|
|
|
|
ImGui::EndCombo();
|
|
|
|
}
|
2023-08-22 18:15:49 -04:00
|
|
|
|
|
|
|
ImGui::TableNextColumn();
|
2024-05-26 20:31:17 -04:00
|
|
|
if (ImGui::Checkbox(_("Center waveform"),&chanOscWaveCorr)) {
|
2023-08-22 18:15:49 -04:00
|
|
|
centerSettingReset=true;
|
2023-08-03 06:25:26 -04:00
|
|
|
}
|
2023-11-26 21:55:09 -05:00
|
|
|
|
|
|
|
ImGui::TableNextRow();
|
|
|
|
ImGui::TableNextColumn();
|
2024-05-26 20:31:17 -04:00
|
|
|
if (ImGui::Checkbox(_("Randomize phase on note"),&chanOscRandomPhase)) {
|
2023-11-26 21:55:09 -05:00
|
|
|
}
|
2022-05-01 19:29:16 -04:00
|
|
|
|
2024-02-19 15:49:56 -05:00
|
|
|
ImGui::TableNextRow();
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
ImGui::AlignTextToFramePadding();
|
2024-05-26 20:31:17 -04:00
|
|
|
ImGui::Text(_("Amplitude"));
|
2024-02-19 15:49:56 -05:00
|
|
|
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();
|
2024-05-26 20:31:17 -04:00
|
|
|
ImGui::Text(_("Line size"));
|
2024-02-19 15:49:56 -05:00
|
|
|
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();
|
2023-07-09 19:59:58 -04:00
|
|
|
}
|
|
|
|
|
2024-05-26 20:31:17 -04:00
|
|
|
ImGui::Checkbox(_("Gradient"),&chanOscUseGrad);
|
2022-06-21 19:01:53 -04:00
|
|
|
|
2022-06-22 16:10:53 -04:00
|
|
|
if (chanOscUseGrad) {
|
2022-06-21 19:01:53 -04:00
|
|
|
if (chanOscGradTex==NULL) {
|
2024-05-15 03:48:18 -04:00
|
|
|
chanOscGradTex=rend->createTexture(true,chanOscGrad.width,chanOscGrad.height,true,bestTexFormat);
|
2022-06-22 16:10:53 -04:00
|
|
|
|
|
|
|
if (chanOscGradTex==NULL) {
|
2024-05-26 20:31:17 -04:00
|
|
|
logE(_("error while creating gradient texture!"));
|
2022-06-22 16:10:53 -04:00
|
|
|
} else {
|
|
|
|
updateChanOscGradTex=true;
|
|
|
|
}
|
2022-06-21 19:01:53 -04:00
|
|
|
}
|
2022-05-01 19:29:16 -04:00
|
|
|
|
2022-06-22 16:10:53 -04:00
|
|
|
if (ImGui::BeginTable("ChanOscGradSet",2)) {
|
|
|
|
ImGui::TableSetupColumn("c0",ImGuiTableColumnFlags_WidthFixed);
|
|
|
|
ImGui::TableSetupColumn("c1",ImGuiTableColumnFlags_WidthStretch);
|
2022-06-21 19:01:53 -04:00
|
|
|
|
2022-06-22 16:10:53 -04:00
|
|
|
ImGui::TableNextRow();
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
if (chanOscGradTex!=NULL) {
|
|
|
|
if (updateChanOscGradTex) {
|
|
|
|
chanOscGrad.render();
|
2023-06-02 21:21:37 -04:00
|
|
|
if (rend->updateTexture(chanOscGradTex,chanOscGrad.grad.get(),chanOscGrad.width*4)) {
|
2022-06-22 16:10:53 -04:00
|
|
|
updateChanOscGradTex=false;
|
|
|
|
} else {
|
2024-05-26 20:31:17 -04:00
|
|
|
logE(_("error while updating gradient texture!"));
|
2022-06-22 16:10:53 -04:00
|
|
|
}
|
2022-06-21 19:01:53 -04:00
|
|
|
}
|
|
|
|
|
2022-06-22 16:10:53 -04:00
|
|
|
ImVec2 gradLeft=ImGui::GetCursorPos();
|
|
|
|
ImVec2 gradSize=ImVec2(400.0f*dpiScale,400.0f*dpiScale);
|
2024-04-07 03:58:57 -04:00
|
|
|
ImGui::Image(rend->getTextureID(chanOscGradTex),gradSize,ImVec2(0,0),ImVec2(rend->getTextureU(chanOscGradTex),rend->getTextureV(chanOscGradTex)));
|
2022-06-22 16:10:53 -04:00
|
|
|
ImVec2 gradLeftAbs=ImGui::GetItemRectMin();
|
|
|
|
if (ImGui::IsItemClicked(ImGuiMouseButton_Right)) {
|
2022-06-23 05:02:41 -04:00
|
|
|
if (chanOscGrad.points.size()<32) {
|
|
|
|
chanOscGrad.points.push_back(Gradient2DPoint(
|
|
|
|
(ImGui::GetMousePos().x-gradLeftAbs.x)/gradSize.x,
|
|
|
|
(ImGui::GetMousePos().y-gradLeftAbs.y)/gradSize.y
|
|
|
|
));
|
|
|
|
updateChanOscGradTex=true;
|
|
|
|
}
|
2022-06-22 16:10:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
ImVec2 oldCurPos=ImGui::GetCursorPos();
|
|
|
|
int index=0;
|
|
|
|
int removePoint=-1;
|
|
|
|
for (Gradient2DPoint& i: chanOscGrad.points) {
|
|
|
|
ImGui::PushID(index+16);
|
|
|
|
ImGui::SetCursorPos(ImVec2(gradLeft.x+i.x*gradSize.x-8.0*dpiScale,gradLeft.y+i.y*gradSize.y-8.0*dpiScale));
|
|
|
|
if (ImGui::InvisibleButton("gradPoint",ImVec2(16.0*dpiScale,16.0*dpiScale))) {
|
|
|
|
if (!i.grab) {
|
|
|
|
ImGui::OpenPopup("gradPointSettings");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ImGui::IsItemHovered() || ImGui::IsItemActive()) {
|
|
|
|
ImGui::SetTooltip("(%.1f, %.1f)",i.x*100.0f,(1.0f-i.y)*100.0f);
|
|
|
|
}
|
|
|
|
if (ImGui::IsItemClicked(ImGuiMouseButton_Middle)) {
|
|
|
|
removePoint=index;
|
|
|
|
}
|
|
|
|
if (ImGui::IsItemActive()) {
|
|
|
|
float mX=(ImGui::GetMousePos().x-gradLeftAbs.x)/gradSize.x;
|
|
|
|
float mY=(ImGui::GetMousePos().y-gradLeftAbs.y)/gradSize.y;
|
|
|
|
|
|
|
|
if (i.grab || (fabs(i.x-mX)>0.015 || fabs(i.y-mY)>0.015)) {
|
|
|
|
i.x=mX;
|
|
|
|
i.y=mY;
|
|
|
|
i.grab=true;
|
|
|
|
|
|
|
|
if (i.x<0) i.x=0;
|
|
|
|
if (i.x>1) i.x=1;
|
|
|
|
if (i.y<0) i.y=0;
|
|
|
|
if (i.y>1) i.y=1;
|
|
|
|
updateChanOscGradTex=true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
i.grab=false;
|
|
|
|
i.prevX=i.x;
|
|
|
|
i.prevY=i.y;
|
|
|
|
}
|
|
|
|
if (ImGui::BeginPopup("gradPointSettings",ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_AlwaysAutoResize)) {
|
2024-05-26 20:31:17 -04:00
|
|
|
if (ImGui::ColorPicker4(_("Color"),(float*)&i.color)) {
|
2022-06-22 16:10:53 -04:00
|
|
|
updateChanOscGradTex=true;
|
|
|
|
}
|
2023-08-06 23:51:51 -04:00
|
|
|
ImGui::AlignTextToFramePadding();
|
2024-05-26 20:31:17 -04:00
|
|
|
ImGui::Text(_("Distance"));
|
2022-06-22 16:10:53 -04:00
|
|
|
ImGui::SameLine();
|
|
|
|
float pDist=i.distance*100.0f;
|
|
|
|
if (ImGui::SliderFloat("##PDistance",&pDist,0.0f,150.0f,"%.1f%%")) {
|
|
|
|
i.distance=pDist/100.0f;
|
|
|
|
updateChanOscGradTex=true;
|
|
|
|
}
|
|
|
|
|
2023-08-06 23:51:51 -04:00
|
|
|
ImGui::AlignTextToFramePadding();
|
2024-05-26 20:31:17 -04:00
|
|
|
ImGui::Text(_("Spread"));
|
2022-06-22 16:10:53 -04:00
|
|
|
ImGui::SameLine();
|
|
|
|
float pSpread=i.spread*100.0f;
|
|
|
|
if (ImGui::SliderFloat("##PSpread",&pSpread,0.0f,150.0f,"%.1f%%")) {
|
|
|
|
i.spread=pSpread/100.0f;
|
|
|
|
updateChanOscGradTex=true;
|
|
|
|
}
|
|
|
|
|
2023-08-26 05:35:26 -04:00
|
|
|
pushDestColor();
|
2024-05-26 20:31:17 -04:00
|
|
|
if (ImGui::Button(_("Remove"))) {
|
2022-06-22 16:10:53 -04:00
|
|
|
removePoint=index;
|
|
|
|
ImGui::CloseCurrentPopup();
|
|
|
|
}
|
2023-08-26 05:35:26 -04:00
|
|
|
popDestColor();
|
2022-06-22 16:10:53 -04:00
|
|
|
|
|
|
|
ImGui::EndPopup();
|
|
|
|
}
|
|
|
|
|
|
|
|
dl->AddCircle(ImVec2(gradLeftAbs.x+i.x*gradSize.x,gradLeftAbs.y+i.y*gradSize.y),8.0*dpiScale,ImGui::ColorConvertFloat4ToU32(ImVec4(0.5,0.5,0.5,1.0)),6,2.0f*dpiScale);
|
|
|
|
dl->AddCircle(ImVec2(gradLeftAbs.x+i.x*gradSize.x,gradLeftAbs.y+i.y*gradSize.y),5.0*dpiScale,ImGui::ColorConvertFloat4ToU32(ImVec4(0.1,0.1,0.1,1.0)),6,2.0f*dpiScale);
|
|
|
|
|
|
|
|
ImGui::PopID();
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
ImGui::SetCursorPos(oldCurPos);
|
|
|
|
|
|
|
|
if (removePoint>=0) {
|
|
|
|
chanOscGrad.points.erase(chanOscGrad.points.begin()+removePoint);
|
|
|
|
updateChanOscGradTex=true;
|
|
|
|
}
|
2022-06-21 19:01:53 -04:00
|
|
|
}
|
|
|
|
|
2022-06-22 16:10:53 -04:00
|
|
|
ImGui::TableNextColumn();
|
2024-05-26 20:31:17 -04:00
|
|
|
if (ImGui::ColorEdit4(_("Background"),(float*)&chanOscGrad.bgColor)) {
|
2022-06-22 16:10:53 -04:00
|
|
|
updateChanOscGradTex=true;
|
2022-06-21 19:01:53 -04:00
|
|
|
}
|
2024-05-27 00:30:33 -04:00
|
|
|
ImGui::Combo(_("X Axis##AxisX"),&chanOscColorX,LocalizedComboGetter,chanOscRefs,GUI_OSCREF_MAX);
|
|
|
|
ImGui::Combo(_("Y Axis##AxisY"),&chanOscColorY,LocalizedComboGetter,chanOscRefs,GUI_OSCREF_MAX);
|
2022-06-21 19:01:53 -04:00
|
|
|
|
2022-06-22 16:10:53 -04:00
|
|
|
ImGui::EndTable();
|
2022-06-21 19:01:53 -04:00
|
|
|
}
|
2022-06-22 16:10:53 -04:00
|
|
|
} else {
|
|
|
|
ImGui::SetNextItemWidth(400.0f*dpiScale);
|
2024-05-26 20:31:17 -04:00
|
|
|
ImGui::ColorPicker4(_("Color"),(float*)&chanOscColor);
|
2022-06-22 16:10:53 -04:00
|
|
|
}
|
2022-06-21 19:01:53 -04:00
|
|
|
|
2023-08-06 23:51:51 -04:00
|
|
|
ImGui::AlignTextToFramePadding();
|
2024-05-26 20:31:17 -04:00
|
|
|
ImGui::Text(_("Text format:"));
|
2023-06-18 05:27:22 -04:00
|
|
|
ImGui::SameLine();
|
|
|
|
ImGui::InputText("##TextFormat",&chanOscTextFormat);
|
|
|
|
if (ImGui::IsItemHovered()) {
|
|
|
|
if (ImGui::BeginTooltip()) {
|
2024-05-26 20:31:17 -04:00
|
|
|
ImGui::TextUnformatted(_(
|
2023-06-18 05:27:22 -04:00
|
|
|
"format guide:\n"
|
|
|
|
"- %c: channel name\n"
|
|
|
|
"- %C: channel short name\n"
|
|
|
|
"- %d: channel number (starting from 0)\n"
|
|
|
|
"- %D: channel number (starting from 1)\n"
|
2023-07-30 07:10:45 -04:00
|
|
|
"- %n: channel note\n"
|
2023-06-18 05:27:22 -04:00
|
|
|
"- %i: instrument name\n"
|
|
|
|
"- %I: instrument number (decimal)\n"
|
|
|
|
"- %x: instrument number (hex)\n"
|
|
|
|
"- %s: chip name\n"
|
2023-07-16 07:10:09 -04:00
|
|
|
"- %p: chip part number\n"
|
2023-06-18 05:27:22 -04:00
|
|
|
"- %S: chip ID\n"
|
|
|
|
"- %v: volume (decimal)\n"
|
|
|
|
"- %V: volume (percentage)\n"
|
|
|
|
"- %b: volume (hex)\n"
|
2024-01-17 11:19:44 -05:00
|
|
|
"- %l: new line\n"
|
2023-06-18 05:27:22 -04:00
|
|
|
"- %%: percent sign"
|
2024-05-26 20:31:17 -04:00
|
|
|
));
|
2023-06-18 05:27:22 -04:00
|
|
|
ImGui::EndTooltip();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-26 20:31:17 -04:00
|
|
|
ImGui::ColorEdit4(_("Text color"),(float*)&chanOscTextColor);
|
2023-06-18 05:27:22 -04:00
|
|
|
|
2024-05-26 20:31:17 -04:00
|
|
|
if (ImGui::Button(_("OK"))) {
|
2022-06-22 16:10:53 -04:00
|
|
|
chanOscOptions=false;
|
2022-06-21 19:01:53 -04:00
|
|
|
}
|
2023-06-18 05:27:22 -04:00
|
|
|
} else {
|
|
|
|
ImGui::PushStyleVar(ImGuiStyleVar_CellPadding,ImVec2(0.0f,0.0f));
|
|
|
|
float availY=ImGui::GetContentRegionAvail().y;
|
2023-09-19 04:01:13 -04:00
|
|
|
if (ImGui::BeginTable("ChanOsc",chanOscCols,ImGuiTableFlags_Borders|ImGuiTableFlags_NoClip)) {
|
2023-06-18 05:27:22 -04:00
|
|
|
std::vector<DivDispatchOscBuffer*> oscBufs;
|
|
|
|
std::vector<ChanOscStatus*> oscFFTs;
|
|
|
|
std::vector<int> oscChans;
|
|
|
|
int chans=e->getTotalChannelCount();
|
|
|
|
ImGuiWindow* window=ImGui::GetCurrentWindow();
|
|
|
|
|
|
|
|
ImGuiStyle& style=ImGui::GetStyle();
|
2023-09-04 19:35:18 -04:00
|
|
|
ImVec2 waveform[1024];
|
2023-06-18 05:27:22 -04:00
|
|
|
|
2023-09-05 05:38:57 -04:00
|
|
|
// check work thread
|
|
|
|
if (chanOscWorkPool==NULL) {
|
2024-05-26 20:31:17 -04:00
|
|
|
logV(_("creating chan osc work pool"));
|
2023-09-05 05:38:57 -04:00
|
|
|
chanOscWorkPool=new DivWorkPool(settings.chanOscThreads);
|
|
|
|
}
|
|
|
|
|
2023-09-04 19:35:18 -04:00
|
|
|
// fill buffers
|
2023-06-18 05:27:22 -04:00
|
|
|
for (int i=0; i<chans; i++) {
|
|
|
|
DivDispatchOscBuffer* buf=e->getOscBuffer(i);
|
2023-11-15 09:21:01 -05:00
|
|
|
if (buf!=NULL && e->curSubSong->chanShowChanOsc[i]) {
|
2023-06-18 05:27:22 -04:00
|
|
|
oscBufs.push_back(buf);
|
|
|
|
oscFFTs.push_back(&chanOscChan[i]);
|
|
|
|
oscChans.push_back(i);
|
|
|
|
}
|
2022-05-01 19:29:16 -04:00
|
|
|
}
|
2023-08-03 06:25:26 -04:00
|
|
|
|
2023-09-04 19:35:18 -04:00
|
|
|
// process
|
|
|
|
for (size_t i=0; i<oscBufs.size(); i++) {
|
2023-09-05 05:38:57 -04:00
|
|
|
ChanOscStatus* fft_=oscFFTs[i];
|
2023-09-04 19:35:18 -04:00
|
|
|
|
2023-09-05 05:38:57 -04:00
|
|
|
fft_->relatedBuf=oscBufs[i];
|
|
|
|
fft_->relatedCh=oscChans[i];
|
|
|
|
|
|
|
|
if (fft_->relatedBuf!=NULL) {
|
2023-09-04 19:54:33 -04:00
|
|
|
// prepare
|
|
|
|
if (centerSettingReset) {
|
2025-03-03 00:51:47 -05:00
|
|
|
fft_->relatedBuf->readNeedle=fft_->relatedBuf->needle>>16;
|
2023-09-04 19:54:33 -04:00
|
|
|
}
|
|
|
|
|
2023-09-04 19:35:18 -04:00
|
|
|
// check FFT status existence
|
2023-09-05 05:38:57 -04:00
|
|
|
if (!fft_->ready) {
|
2024-05-26 20:31:17 -04:00
|
|
|
logD(_("creating FFT plan for channel %d"),fft_->relatedCh);
|
2023-09-05 05:38:57 -04:00
|
|
|
fft_->inBuf=(double*)fftw_malloc(FURNACE_FFT_SIZE*sizeof(double));
|
|
|
|
fft_->outBuf=(fftw_complex*)fftw_malloc(FURNACE_FFT_SIZE*sizeof(fftw_complex));
|
|
|
|
fft_->corrBuf=(double*)fftw_malloc(FURNACE_FFT_SIZE*sizeof(double));
|
|
|
|
fft_->plan=fftw_plan_dft_r2c_1d(FURNACE_FFT_SIZE,fft_->inBuf,fft_->outBuf,FFTW_ESTIMATE);
|
|
|
|
fft_->planI=fftw_plan_dft_c2r_1d(FURNACE_FFT_SIZE,fft_->outBuf,fft_->corrBuf,FFTW_ESTIMATE);
|
|
|
|
if (fft_->plan==NULL) {
|
2024-05-26 20:31:17 -04:00
|
|
|
logE(_("failed to create plan!"));
|
2023-09-05 05:38:57 -04:00
|
|
|
} else if (fft_->planI==NULL) {
|
2024-05-26 20:31:17 -04:00
|
|
|
logE(_("failed to create inverse plan!"));
|
2023-09-05 05:38:57 -04:00
|
|
|
} else if (fft_->inBuf==NULL || fft_->outBuf==NULL || fft_->corrBuf==NULL) {
|
2024-05-26 20:31:17 -04:00
|
|
|
logE(_("failed to create FFT buffers"));
|
2023-09-04 19:35:18 -04:00
|
|
|
} else {
|
2023-09-05 05:38:57 -04:00
|
|
|
fft_->ready=true;
|
2023-09-04 19:35:18 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-05 05:38:57 -04:00
|
|
|
if (fft_->ready && e->isRunning()) {
|
2023-09-07 01:16:47 -04:00
|
|
|
fft_->windowSize=chanOscWindowSize;
|
|
|
|
fft_->waveCorr=chanOscWaveCorr;
|
|
|
|
chanOscWorkPool->push([](void* fft_v) {
|
2023-09-05 05:38:57 -04:00
|
|
|
ChanOscStatus* fft=(ChanOscStatus*)fft_v;
|
|
|
|
DivDispatchOscBuffer* buf=fft->relatedBuf;
|
|
|
|
|
|
|
|
// the STRATEGY
|
|
|
|
// 1. FFT of windowed signal
|
|
|
|
// 2. inverse FFT of auto-correlation
|
|
|
|
// 3. find size of one period
|
|
|
|
// 4. DFT of the fundamental of ONE PERIOD
|
|
|
|
// 5. now we can get phase information
|
|
|
|
//
|
|
|
|
// I have a feeling this could be simplified to two FFTs or even one...
|
|
|
|
// if you know how, please tell me
|
|
|
|
|
|
|
|
// initialization
|
|
|
|
double phase=0.0;
|
2025-03-01 05:05:50 -05:00
|
|
|
int displaySize=65536.0f*(fft->windowSize/1000.0f);
|
|
|
|
int displaySize2=65536.0f*(fft->windowSize/500.0f);
|
2023-09-05 05:38:57 -04:00
|
|
|
fft->loudEnough=false;
|
2025-03-03 00:51:47 -05:00
|
|
|
fft->needle=buf->needle>>16;
|
2023-09-04 19:35:18 -04:00
|
|
|
|
2023-09-05 05:38:57 -04:00
|
|
|
// first FFT
|
2025-03-01 05:05:50 -05:00
|
|
|
int k=0;
|
|
|
|
short lastSample=0;
|
|
|
|
memset(fft->inBuf,0,FURNACE_FFT_SIZE*sizeof(double));
|
|
|
|
if (displaySize2<FURNACE_FFT_SIZE) {
|
2025-03-01 17:22:34 -05:00
|
|
|
for (int j=-FURNACE_FFT_SIZE; j<FURNACE_FFT_SIZE; j++) {
|
2025-03-01 05:05:50 -05:00
|
|
|
const short newData=buf->data[(unsigned short)(fft->needle-displaySize2+((j*displaySize2)/(FURNACE_FFT_SIZE)))];
|
|
|
|
if (newData!=-1) lastSample=newData;
|
2025-03-01 17:22:34 -05:00
|
|
|
if (j<0) continue;
|
2025-03-01 05:05:50 -05:00
|
|
|
fft->inBuf[j]=(double)lastSample/32768.0;
|
|
|
|
if (fft->inBuf[j]>0.001 || fft->inBuf[j]<-0.001) fft->loudEnough=true;
|
|
|
|
fft->inBuf[j]*=0.55-0.45*cos(M_PI*(double)j/(double)(FURNACE_FFT_SIZE>>1));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (unsigned short j=fft->needle-displaySize2; j!=fft->needle; j++, k++) {
|
|
|
|
const int kIn=(k*FURNACE_FFT_SIZE)/displaySize2;
|
|
|
|
if (kIn>=FURNACE_FFT_SIZE) break;
|
|
|
|
if (buf->data[j]!=-1) lastSample=buf->data[j];
|
|
|
|
fft->inBuf[kIn]=(double)lastSample/32768.0;
|
|
|
|
if (fft->inBuf[kIn]>0.001 || fft->inBuf[kIn]<-0.001) fft->loudEnough=true;
|
|
|
|
fft->inBuf[kIn]*=0.55-0.45*cos(M_PI*(double)kIn/(double)(FURNACE_FFT_SIZE>>1));
|
|
|
|
}
|
2023-09-04 19:35:18 -04:00
|
|
|
}
|
|
|
|
|
2023-09-05 05:38:57 -04:00
|
|
|
// only proceed if not quiet
|
|
|
|
if (fft->loudEnough) {
|
|
|
|
fftw_execute(fft->plan);
|
|
|
|
|
|
|
|
// auto-correlation and second FFT
|
|
|
|
for (int j=0; j<FURNACE_FFT_SIZE; j++) {
|
|
|
|
fft->outBuf[j][0]/=FURNACE_FFT_SIZE;
|
|
|
|
fft->outBuf[j][1]/=FURNACE_FFT_SIZE;
|
|
|
|
fft->outBuf[j][0]=fft->outBuf[j][0]*fft->outBuf[j][0]+fft->outBuf[j][1]*fft->outBuf[j][1];
|
|
|
|
fft->outBuf[j][1]=0;
|
2023-09-04 19:35:18 -04:00
|
|
|
}
|
2023-09-05 05:38:57 -04:00
|
|
|
fft->outBuf[0][0]=0;
|
|
|
|
fft->outBuf[0][1]=0;
|
|
|
|
fft->outBuf[1][0]=0;
|
|
|
|
fft->outBuf[1][1]=0;
|
|
|
|
fftw_execute(fft->planI);
|
|
|
|
|
|
|
|
// window
|
|
|
|
for (int j=0; j<(FURNACE_FFT_SIZE>>1); j++) {
|
|
|
|
fft->corrBuf[j]*=1.0-((double)j/(double)(FURNACE_FFT_SIZE<<1));
|
2023-09-04 19:35:18 -04:00
|
|
|
}
|
|
|
|
|
2023-09-05 05:38:57 -04:00
|
|
|
// find size of period
|
|
|
|
double waveLenCandL=DBL_MAX;
|
|
|
|
double waveLenCandH=DBL_MIN;
|
|
|
|
fft->waveLen=FURNACE_FFT_SIZE-1;
|
|
|
|
fft->waveLenBottom=0;
|
|
|
|
fft->waveLenTop=0;
|
|
|
|
|
|
|
|
// find lowest point
|
|
|
|
for (int j=(FURNACE_FFT_SIZE>>2); j>2; j--) {
|
|
|
|
if (fft->corrBuf[j]<waveLenCandL) {
|
|
|
|
waveLenCandL=fft->corrBuf[j];
|
|
|
|
fft->waveLenBottom=j;
|
|
|
|
}
|
|
|
|
}
|
2023-09-04 19:35:18 -04:00
|
|
|
|
2023-09-05 05:38:57 -04:00
|
|
|
// find highest point
|
|
|
|
for (int j=(FURNACE_FFT_SIZE>>1)-1; j>fft->waveLenBottom; j--) {
|
|
|
|
if (fft->corrBuf[j]>waveLenCandH) {
|
|
|
|
waveLenCandH=fft->corrBuf[j];
|
|
|
|
fft->waveLen=j;
|
|
|
|
}
|
2023-09-04 19:35:18 -04:00
|
|
|
}
|
2023-09-05 05:38:57 -04:00
|
|
|
fft->waveLenTop=fft->waveLen;
|
|
|
|
|
|
|
|
// did we find the period size?
|
|
|
|
if (fft->waveLen<(FURNACE_FFT_SIZE-32)) {
|
|
|
|
// we got pitch
|
2023-09-07 01:16:47 -04:00
|
|
|
fft->pitch=pow(1.0-(fft->waveLen/(double)(FURNACE_FFT_SIZE>>1)),4.0);
|
2023-09-05 05:38:57 -04:00
|
|
|
|
|
|
|
fft->waveLen*=(double)displaySize*2.0/(double)FURNACE_FFT_SIZE;
|
|
|
|
|
|
|
|
// DFT of one period (x_1)
|
|
|
|
double dft[2];
|
|
|
|
dft[0]=0.0;
|
|
|
|
dft[1]=0.0;
|
2025-03-01 18:46:11 -05:00
|
|
|
lastSample=0;
|
|
|
|
for (int j=fft->needle-1-displaySize-(int)fft->waveLen, k=-(displaySize>>1); k<fft->waveLen; j++, k++) {
|
|
|
|
if (buf->data[j&0xffff]!=-1) lastSample=buf->data[j&0xffff];
|
|
|
|
if (k<0) continue;
|
|
|
|
double one=((double)lastSample/32768.0);
|
2023-09-05 05:38:57 -04:00
|
|
|
double two=(double)k*(-2.0*M_PI)/fft->waveLen;
|
|
|
|
dft[0]+=one*cos(two);
|
|
|
|
dft[1]+=one*sin(two);
|
|
|
|
}
|
2023-09-04 19:35:18 -04:00
|
|
|
|
2023-09-05 05:38:57 -04:00
|
|
|
// calculate and lock into phase
|
|
|
|
phase=(0.5+(atan2(dft[1],dft[0])/(2.0*M_PI)));
|
2023-09-04 19:35:18 -04:00
|
|
|
|
2025-03-01 18:46:11 -05:00
|
|
|
fft->debugPhase=phase;
|
|
|
|
|
2023-09-07 01:16:47 -04:00
|
|
|
if (fft->waveCorr) {
|
2023-11-26 21:55:09 -05:00
|
|
|
fft->needle-=(phase+(fft->phaseOff*2))*fft->waveLen;
|
2023-09-05 05:38:57 -04:00
|
|
|
}
|
2023-09-04 19:35:18 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-05 05:38:57 -04:00
|
|
|
fft->needle-=displaySize;
|
|
|
|
},fft_);
|
2023-09-04 19:35:18 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-09-05 05:38:57 -04:00
|
|
|
chanOscWorkPool->wait();
|
2023-09-04 19:35:18 -04:00
|
|
|
|
2023-08-03 22:32:57 -04:00
|
|
|
// 0: none
|
|
|
|
// 1: sqrt(chans)
|
|
|
|
// 2: sqrt(chans+1)
|
|
|
|
// 3: sqrt(chans)+1
|
2023-08-03 06:25:26 -04:00
|
|
|
switch (chanOscAutoColsType) {
|
2023-08-03 22:32:57 -04:00
|
|
|
case 1:
|
|
|
|
chanOscCols=sqrt(oscChans.size());
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
chanOscCols=sqrt(oscChans.size()+1);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
chanOscCols=sqrt(oscChans.size())+1;
|
|
|
|
break;
|
2023-08-03 06:25:26 -04:00
|
|
|
}
|
|
|
|
if (chanOscCols<1) chanOscCols=1;
|
|
|
|
if (chanOscCols>64) chanOscCols=64;
|
|
|
|
|
2023-06-18 05:27:22 -04:00
|
|
|
int rows=(oscBufs.size()+(chanOscCols-1))/chanOscCols;
|
2022-04-30 23:59:26 -04:00
|
|
|
|
2023-09-04 19:35:18 -04:00
|
|
|
// render
|
2023-06-18 05:27:22 -04:00
|
|
|
for (size_t i=0; i<oscBufs.size(); i++) {
|
|
|
|
if (i%chanOscCols==0) ImGui::TableNextRow();
|
|
|
|
ImGui::TableNextColumn();
|
2022-04-30 04:58:30 -04:00
|
|
|
|
2023-06-18 05:27:22 -04:00
|
|
|
DivDispatchOscBuffer* buf=oscBufs[i];
|
|
|
|
ChanOscStatus* fft=oscFFTs[i];
|
|
|
|
int ch=oscChans[i];
|
|
|
|
if (buf==NULL) {
|
2024-05-26 20:31:17 -04:00
|
|
|
ImGui::Text(_("Error!"));
|
2023-06-18 05:27:22 -04:00
|
|
|
} else {
|
|
|
|
ImVec2 size=ImGui::GetContentRegionAvail();
|
|
|
|
size.y=availY/rows;
|
2022-06-03 04:32:24 -04:00
|
|
|
|
2023-06-18 05:27:22 -04:00
|
|
|
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+=2.0*dpiScale;
|
|
|
|
inRect.Max.x-=dpiScale;
|
|
|
|
inRect.Max.y-=2.0*dpiScale;
|
|
|
|
|
|
|
|
int precision=inRect.Max.x-inRect.Min.x;
|
|
|
|
if (precision<1) precision=1;
|
2023-09-04 19:35:18 -04:00
|
|
|
if (precision>1024) precision=1024;
|
|
|
|
|
2023-06-18 05:27:22 -04:00
|
|
|
ImGui::ItemSize(size,style.FramePadding.y);
|
|
|
|
if (ImGui::ItemAdd(rect,ImGui::GetID("chOscDisplay"))) {
|
|
|
|
if (!e->isRunning()) {
|
2024-02-19 17:26:58 -05:00
|
|
|
if (rend->supportsDrawOsc() && settings.shaderOsc) {
|
2024-02-14 04:09:24 -05:00
|
|
|
memset(fft->oscTex,0,2048*sizeof(float));
|
|
|
|
} else {
|
|
|
|
for (unsigned short j=0; j<precision; j++) {
|
|
|
|
float x=(float)j/(float)precision;
|
|
|
|
waveform[j]=ImLerp(inRect.Min,inRect.Max,ImVec2(x,0.5f));
|
|
|
|
}
|
2023-06-18 05:27:22 -04:00
|
|
|
}
|
|
|
|
} else {
|
2025-03-01 05:05:50 -05:00
|
|
|
int displaySize=65536.0f*(chanOscWindowSize/1000.0f);
|
|
|
|
int displaySize2=65536.0f*(chanOscWindowSize/500.0f);
|
2023-09-04 19:54:33 -04:00
|
|
|
|
|
|
|
float minLevel=1.0f;
|
|
|
|
float maxLevel=-1.0f;
|
|
|
|
|
|
|
|
if (debugFFT) {
|
|
|
|
// FFT debug code!
|
|
|
|
double maxavg=0.0;
|
|
|
|
for (unsigned short j=0; j<(FURNACE_FFT_SIZE>>1); j++) {
|
|
|
|
if (fabs(fft->corrBuf[j]>maxavg)) {
|
|
|
|
maxavg=fabs(fft->corrBuf[j]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (maxavg>0.0000001) maxavg=0.5/maxavg;
|
|
|
|
|
2024-02-19 17:26:58 -05:00
|
|
|
if (rend->supportsDrawOsc() && settings.shaderOsc) {
|
2024-02-14 04:09:24 -05:00
|
|
|
for (unsigned short j=0; j<precision && j<2048; j++) {
|
|
|
|
float y;
|
|
|
|
if (j>=precision/2) {
|
|
|
|
y=fft->inBuf[((j-(precision/2))*FURNACE_FFT_SIZE*2)/(precision)];
|
|
|
|
} else {
|
|
|
|
y=fft->corrBuf[(j*FURNACE_FFT_SIZE)/precision]*maxavg;
|
|
|
|
}
|
|
|
|
fft->oscTex[j]=y*2.0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (unsigned short j=0; j<precision; j++) {
|
|
|
|
float x=(float)j/(float)precision;
|
|
|
|
float y;
|
|
|
|
if (j>=precision/2) {
|
|
|
|
y=fft->inBuf[((j-(precision/2))*FURNACE_FFT_SIZE*2)/(precision)];
|
|
|
|
} else {
|
|
|
|
y=fft->corrBuf[(j*FURNACE_FFT_SIZE)/precision]*maxavg;
|
|
|
|
}
|
|
|
|
waveform[j]=ImLerp(inRect.Min,inRect.Max,ImVec2(x,0.5f-y));
|
2023-09-04 19:54:33 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (fft->loudEnough) {
|
2025-03-01 18:46:11 -05:00
|
|
|
String cPhase=fmt::sprintf("\n%.1f (b: %d t: %d)\nSIZES: %d, %d, %d\nPHASE %f",fft->waveLen,fft->waveLenBottom,fft->waveLenTop,displaySize,displaySize2,FURNACE_FFT_SIZE,fft->debugPhase);
|
2023-09-04 19:54:33 -04:00
|
|
|
dl->AddText(inRect.Min,0xffffffff,cPhase.c_str());
|
|
|
|
|
|
|
|
dl->AddLine(
|
|
|
|
ImLerp(inRect.Min,inRect.Max,ImVec2((double)fft->waveLenBottom/(double)FURNACE_FFT_SIZE,0.0)),
|
|
|
|
ImLerp(inRect.Min,inRect.Max,ImVec2((double)fft->waveLenBottom/(double)FURNACE_FFT_SIZE,1.0)),
|
|
|
|
0xffffff00
|
|
|
|
);
|
|
|
|
dl->AddLine(
|
|
|
|
ImLerp(inRect.Min,inRect.Max,ImVec2((double)fft->waveLenTop/(double)FURNACE_FFT_SIZE,0.0)),
|
|
|
|
ImLerp(inRect.Min,inRect.Max,ImVec2((double)fft->waveLenTop/(double)FURNACE_FFT_SIZE,1.0)),
|
|
|
|
0xff00ff00
|
|
|
|
);
|
2025-03-01 18:46:11 -05:00
|
|
|
dl->AddLine(
|
|
|
|
ImLerp(inRect.Min,inRect.Max,ImVec2(0.75-(fft->debugPhase*0.25),0.0)),
|
|
|
|
ImLerp(inRect.Min,inRect.Max,ImVec2(0.75-(fft->debugPhase*0.25),1.0)),
|
|
|
|
0xff00ffff
|
|
|
|
);
|
2023-09-04 19:54:33 -04:00
|
|
|
} else {
|
|
|
|
if (debugFFT) {
|
|
|
|
dl->AddText(inRect.Min,0xffffffff,"\nquiet");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2025-03-01 19:49:56 -05:00
|
|
|
/*
|
2025-03-01 18:46:11 -05:00
|
|
|
String dStr=fmt::sprintf("DS: %d P: %d\nMAX: %d\nPHASE %f",displaySize,precision,(short)((fft->needle+displaySize)-fft->relatedBuf->needle),fft->debugPhase);
|
2025-03-01 05:05:50 -05:00
|
|
|
dl->AddText(inRect.Min,0xffffffff,dStr.c_str());
|
2025-03-01 19:49:56 -05:00
|
|
|
*/
|
2025-03-01 05:05:50 -05:00
|
|
|
if (displaySize<precision) {
|
|
|
|
float y=0;
|
2025-03-01 17:22:34 -05:00
|
|
|
for (int j=-2048; j<precision; j++) {
|
2025-03-01 05:05:50 -05:00
|
|
|
const short y_s=buf->data[(unsigned short)(fft->needle+(j*displaySize/precision))];
|
|
|
|
if (y_s!=-1) {
|
|
|
|
y=(float)y_s/32768.0f;
|
2025-03-01 17:22:34 -05:00
|
|
|
if (j<0) continue;
|
2025-03-01 05:05:50 -05:00
|
|
|
if (minLevel>y) minLevel=y;
|
|
|
|
if (maxLevel<y) maxLevel=y;
|
|
|
|
}
|
2025-03-01 17:22:34 -05:00
|
|
|
if (j<0) continue;
|
2025-03-02 18:02:38 -05:00
|
|
|
float yOut=y-fft->dcOff;
|
2025-03-10 13:52:28 -04:00
|
|
|
if (!settings.audioHiPass) {
|
|
|
|
fft->dcOff=0;
|
|
|
|
} else {
|
|
|
|
fft->dcOff+=(y-fft->dcOff)*0.001;
|
|
|
|
}
|
2025-03-01 05:05:50 -05:00
|
|
|
if (yOut<-0.5f) yOut=-0.5f;
|
|
|
|
if (yOut>0.5f) yOut=0.5f;
|
|
|
|
yOut*=chanOscAmplify*2.0f;
|
|
|
|
fft->oscTex[j]=yOut;
|
2024-02-14 04:09:24 -05:00
|
|
|
}
|
|
|
|
} else {
|
2025-03-01 05:05:50 -05:00
|
|
|
float y=0;
|
2025-03-01 17:22:34 -05:00
|
|
|
int k=-2048;
|
|
|
|
for (unsigned short j=fft->needle-2048; j!=fft->needle+displaySize; j++, k++) {
|
2025-03-01 05:05:50 -05:00
|
|
|
const short y_s=buf->data[j];
|
|
|
|
const int kTex=(k*precision)/displaySize;
|
|
|
|
if (kTex>=precision) break;
|
|
|
|
if (y_s!=-1) {
|
|
|
|
y=(float)y_s/32768.0f;
|
2025-03-01 17:22:34 -05:00
|
|
|
if (k<0) continue;
|
2025-03-01 05:05:50 -05:00
|
|
|
if (minLevel>y) minLevel=y;
|
|
|
|
if (maxLevel<y) maxLevel=y;
|
|
|
|
}
|
2025-03-01 17:22:34 -05:00
|
|
|
if (kTex<0) continue;
|
2025-03-02 18:02:38 -05:00
|
|
|
float yOut=y-fft->dcOff;
|
2025-03-10 13:52:28 -04:00
|
|
|
if (!settings.audioHiPass) {
|
|
|
|
fft->dcOff=0;
|
|
|
|
} else {
|
|
|
|
fft->dcOff+=(y-fft->dcOff)*0.001;
|
|
|
|
}
|
2025-03-01 05:05:50 -05:00
|
|
|
if (yOut<-0.5f) yOut=-0.5f;
|
|
|
|
if (yOut>0.5f) yOut=0.5f;
|
|
|
|
yOut*=chanOscAmplify*2.0f;
|
|
|
|
fft->oscTex[kTex]=yOut;
|
|
|
|
}
|
|
|
|
}
|
2025-03-02 18:02:38 -05:00
|
|
|
//dcOff=(minLevel+maxLevel)*0.5f;
|
2025-03-01 05:05:50 -05:00
|
|
|
|
|
|
|
if (!(rend->supportsDrawOsc() && settings.shaderOsc)) {
|
2024-02-14 04:09:24 -05:00
|
|
|
for (unsigned short j=0; j<precision; j++) {
|
|
|
|
float x=(float)j/(float)precision;
|
2025-03-01 05:05:50 -05:00
|
|
|
waveform[j]=ImLerp(inRect.Min,inRect.Max,ImVec2(x,0.5f-fft->oscTex[j]*0.5f));
|
2024-02-14 04:09:24 -05:00
|
|
|
}
|
2023-09-04 19:54:33 -04:00
|
|
|
}
|
|
|
|
}
|
2022-06-22 16:10:53 -04:00
|
|
|
}
|
2023-06-18 05:27:22 -04:00
|
|
|
ImU32 color=ImGui::GetColorU32(chanOscColor);
|
|
|
|
if (chanOscUseGrad) {
|
|
|
|
float xVal=computeGradPos(chanOscColorX,ch);
|
|
|
|
float yVal=computeGradPos(chanOscColorY,ch);
|
|
|
|
|
|
|
|
xVal=CLAMP(xVal,0.0f,1.0f);
|
|
|
|
yVal=CLAMP(yVal,0.0f,1.0f);
|
|
|
|
|
|
|
|
color=chanOscGrad.get(xVal,1.0f-yVal);
|
2022-06-22 16:10:53 -04:00
|
|
|
}
|
2023-06-18 05:27:22 -04:00
|
|
|
|
2024-02-19 02:57:48 -05:00
|
|
|
if (rend->supportsDrawOsc() && settings.shaderOsc) {
|
2024-02-14 04:09:24 -05:00
|
|
|
fft->drawOp.gui=this;
|
|
|
|
fft->drawOp.data=fft->oscTex;
|
|
|
|
fft->drawOp.len=precision;
|
|
|
|
fft->drawOp.pos0=inRect.Min;
|
|
|
|
fft->drawOp.pos1=inRect.Max;
|
|
|
|
fft->drawOp.color=ImGui::ColorConvertU32ToFloat4(color);
|
2024-02-19 15:49:56 -05:00
|
|
|
fft->drawOp.lineSize=dpiScale*chanOscLineSize;
|
2024-02-14 04:09:24 -05:00
|
|
|
|
|
|
|
dl->AddCallback(_drawOsc,&fft->drawOp);
|
|
|
|
dl->AddCallback(ImDrawCallback_ResetRenderState,NULL);
|
|
|
|
} else {
|
|
|
|
//ImGui::PushClipRect(inRect.Min,inRect.Max,false);
|
|
|
|
//ImDrawListFlags prevFlags=dl->Flags;
|
|
|
|
//dl->Flags&=~(ImDrawListFlags_AntiAliasedLines|ImDrawListFlags_AntiAliasedLinesUseTex);
|
2024-02-19 15:49:56 -05:00
|
|
|
dl->AddPolyline(waveform,precision,color,ImDrawFlags_None,dpiScale*chanOscLineSize);
|
2024-02-14 04:09:24 -05:00
|
|
|
//dl->Flags=prevFlags;
|
|
|
|
//ImGui::PopClipRect();
|
|
|
|
}
|
2023-06-18 05:27:22 -04:00
|
|
|
|
2024-02-14 04:09:24 -05:00
|
|
|
//ImGui::PushClipRect(inRect.Min,inRect.Max,false);
|
2023-06-18 05:27:22 -04:00
|
|
|
if (!chanOscTextFormat.empty()) {
|
|
|
|
String text;
|
|
|
|
bool inFormat=false;
|
|
|
|
|
2023-09-03 05:22:00 -04:00
|
|
|
for (char j: chanOscTextFormat) {
|
2023-06-18 05:27:22 -04:00
|
|
|
if (inFormat) {
|
2023-09-03 05:22:00 -04:00
|
|
|
switch (j) {
|
2023-06-18 05:27:22 -04:00
|
|
|
case 'c':
|
|
|
|
text+=e->getChannelName(ch);
|
|
|
|
break;
|
|
|
|
case 'C':
|
|
|
|
text+=e->getChannelShortName(ch);
|
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
text+=fmt::sprintf("%d",ch);
|
|
|
|
break;
|
|
|
|
case 'D':
|
|
|
|
text+=fmt::sprintf("%d",ch+1);
|
|
|
|
break;
|
|
|
|
case 'i': {
|
|
|
|
DivChannelState* chanState=e->getChanState(ch);
|
|
|
|
if (chanState==NULL) break;
|
|
|
|
DivInstrument* ins=e->getIns(chanState->lastIns);
|
|
|
|
text+=ins->name;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'I': {
|
|
|
|
DivChannelState* chanState=e->getChanState(ch);
|
|
|
|
if (chanState==NULL) break;
|
|
|
|
text+=fmt::sprintf("%d",chanState->lastIns);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'x': {
|
|
|
|
DivChannelState* chanState=e->getChanState(ch);
|
|
|
|
if (chanState==NULL) break;
|
|
|
|
if (chanState->lastIns<0) {
|
|
|
|
text+="??";
|
|
|
|
} else {
|
|
|
|
text+=fmt::sprintf("%.2X",chanState->lastIns);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 's': {
|
|
|
|
text+=e->getSystemName(e->sysOfChan[ch]);
|
|
|
|
break;
|
|
|
|
}
|
2023-07-12 06:17:08 -04:00
|
|
|
case 'p': {
|
2023-09-03 05:22:00 -04:00
|
|
|
text+=FurnaceGUI::getSystemPartNumber(e->sysOfChan[ch],e->song.systemFlags[e->dispatchOfChan[ch]]);
|
2023-07-12 06:17:08 -04:00
|
|
|
break;
|
|
|
|
}
|
2023-06-18 05:27:22 -04:00
|
|
|
case 'S': {
|
|
|
|
text+=fmt::sprintf("%d",e->dispatchOfChan[ch]);
|
|
|
|
break;
|
|
|
|
}
|
2023-07-08 21:02:05 -04:00
|
|
|
case 'v': {
|
|
|
|
DivChannelState* chanState=e->getChanState(ch);
|
|
|
|
if (chanState==NULL) break;
|
|
|
|
text+=fmt::sprintf("%d",chanState->volume>>8);
|
2023-06-18 05:27:22 -04:00
|
|
|
break;
|
2023-07-08 21:02:05 -04:00
|
|
|
}
|
|
|
|
case 'V': {
|
|
|
|
DivChannelState* chanState=e->getChanState(ch);
|
|
|
|
if (chanState==NULL) break;
|
|
|
|
int volMax=chanState->volMax>>8;
|
|
|
|
if (volMax<1) volMax=1;
|
|
|
|
text+=fmt::sprintf("%d%%",(chanState->volume>>8)/volMax);
|
2023-06-18 05:27:22 -04:00
|
|
|
break;
|
2023-07-08 21:02:05 -04:00
|
|
|
}
|
|
|
|
case 'b': {
|
|
|
|
DivChannelState* chanState=e->getChanState(ch);
|
|
|
|
if (chanState==NULL) break;
|
|
|
|
text+=fmt::sprintf("%.2X",chanState->volume>>8);
|
2023-06-18 05:27:22 -04:00
|
|
|
break;
|
2023-07-08 21:02:05 -04:00
|
|
|
}
|
2023-07-30 07:10:45 -04:00
|
|
|
case 'n': {
|
|
|
|
DivChannelState* chanState=e->getChanState(ch);
|
|
|
|
if (chanState==NULL || !(chanState->keyOn)) break;
|
2023-08-03 06:25:26 -04:00
|
|
|
short tempNote=chanState->note; //all of this conversion is necessary because notes 100-102 are special chars
|
|
|
|
short noteMod=tempNote%12+12; //also note 0 is a BUG, hence +12 on the note and -1 on the octave
|
|
|
|
short oct=tempNote/12-1;
|
|
|
|
text+=fmt::sprintf("%s",noteName(noteMod,oct));
|
2023-07-30 07:10:45 -04:00
|
|
|
break;
|
|
|
|
}
|
2024-01-17 11:19:44 -05:00
|
|
|
case 'l': {
|
2024-01-17 15:32:50 -05:00
|
|
|
text+='\n';
|
2024-01-17 11:19:44 -05:00
|
|
|
break;
|
|
|
|
}
|
2023-06-18 05:27:22 -04:00
|
|
|
case '%':
|
|
|
|
text+='%';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
text+='%';
|
2023-09-03 05:22:00 -04:00
|
|
|
text+=j;
|
2023-06-18 05:27:22 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
inFormat=false;
|
|
|
|
} else {
|
2023-09-03 05:22:00 -04:00
|
|
|
if (j=='%') {
|
2023-06-18 05:27:22 -04:00
|
|
|
inFormat=true;
|
|
|
|
} else {
|
2023-09-03 05:22:00 -04:00
|
|
|
text+=j;
|
2023-06-18 05:27:22 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dl->AddText(ImLerp(inRect.Min,inRect.Max,ImVec2(0.0f,0.0f)),ImGui::GetColorU32(chanOscTextColor),text.c_str());
|
|
|
|
}
|
2022-06-22 16:10:53 -04:00
|
|
|
|
2024-02-14 04:09:24 -05:00
|
|
|
//ImGui::PopClipRect();
|
2022-04-30 04:58:30 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-06-18 05:27:22 -04:00
|
|
|
ImGui::EndTable();
|
2022-06-21 19:01:53 -04:00
|
|
|
|
2023-06-18 05:27:22 -04:00
|
|
|
if (ImGui::IsItemClicked(ImGuiMouseButton_Right)) {
|
|
|
|
chanOscOptions=!chanOscOptions;
|
|
|
|
}
|
2023-11-26 21:55:09 -05:00
|
|
|
if (ImGui::IsItemHovered() && CHECK_LONG_HOLD) {
|
|
|
|
NOTIFY_LONG_HOLD;
|
|
|
|
chanOscOptions=!chanOscOptions;
|
|
|
|
}
|
2022-06-21 19:01:53 -04:00
|
|
|
}
|
2023-06-18 05:27:22 -04:00
|
|
|
ImGui::PopStyleVar();
|
2022-04-30 04:58:30 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows)) curWindow=GUI_WINDOW_CHAN_OSC;
|
|
|
|
ImGui::End();
|
2022-05-19 17:35:00 -04:00
|
|
|
}
|