GUI: add a preliminary oscilloscope

This commit is contained in:
tildearrow 2022-01-27 17:49:00 -05:00
parent 17375cdbe0
commit 0071894471
5 changed files with 39 additions and 1 deletions

View file

@ -4857,6 +4857,7 @@ bool DivEngine::initAudioBackend() {
output=NULL; output=NULL;
return false; return false;
} }
return true; return true;
} }
@ -4931,6 +4932,9 @@ bool DivEngine::init() {
isMuted[i]=0; isMuted[i]=0;
} }
oscBuf[0]=new float[32768];
oscBuf[1]=new float[32768];
initDispatch(); initDispatch();
reset(); reset();
active=true; active=true;
@ -4948,5 +4952,7 @@ bool DivEngine::quit() {
logI("saving config.\n"); logI("saving config.\n");
saveConf(); saveConf();
active=false; active=false;
delete[] oscBuf[0];
delete[] oscBuf[1];
return true; return true;
} }

View file

@ -206,6 +206,8 @@ class DivEngine {
DivSystem sysOfChan[DIV_MAX_CHANS]; DivSystem sysOfChan[DIV_MAX_CHANS];
int dispatchOfChan[DIV_MAX_CHANS]; int dispatchOfChan[DIV_MAX_CHANS];
int dispatchChanOfChan[DIV_MAX_CHANS]; int dispatchChanOfChan[DIV_MAX_CHANS];
float* oscBuf[2];
float oscSize;
void runExportThread(); void runExportThread();
void nextBuf(float** in, float** out, int inChans, int outChans, unsigned int size); void nextBuf(float** in, float** out, int inChans, int outChans, unsigned int size);
@ -549,6 +551,8 @@ class DivEngine {
metroAmp(0.0f), metroAmp(0.0f),
totalProcessed(0), totalProcessed(0),
jediTable(NULL), jediTable(NULL),
oscBuf{NULL,NULL},
oscSize(1),
adpcmMem(NULL), adpcmMem(NULL),
adpcmMemLen(0) {} adpcmMemLen(0) {}
}; };

View file

@ -1138,5 +1138,10 @@ void DivEngine::nextBuf(float** in, float** out, int inChans, int outChans, unsi
metroPos+=metroFreq; metroPos+=metroFreq;
while (metroPos>=1) metroPos--; while (metroPos>=1) metroPos--;
} }
// TODO: improve
memcpy(oscBuf[0],out[0],size*sizeof(float));
memcpy(oscBuf[1],out[1],size*sizeof(float));
oscSize=size;
isBusy.unlock(); isBusy.unlock();
} }

View file

@ -1977,6 +1977,25 @@ void FurnaceGUI::drawMixer() {
ImGui::End(); ImGui::End();
} }
void FurnaceGUI::drawOsc() {
if (!oscOpen) return;
ImGui::SetNextWindowSizeConstraints(ImVec2(64.0f*dpiScale,32.0f*dpiScale),ImVec2(scrW*dpiScale,scrH*dpiScale));
if (ImGui::Begin("Oscilloscope",&oscOpen)) {
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding,ImVec2(0,0));
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding,ImVec2(0,0));
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing,ImVec2(0,0));
ImGui::PushStyleVar(ImGuiStyleVar_ItemInnerSpacing,ImVec2(0,0));
float values[512];
for (int i=0; i<512; i++) {
int pos=i*e->oscSize/512;
values[i]=(e->oscBuf[0][pos]+e->oscBuf[1][pos])*0.5f;
}
ImGui::PlotLines("##SingleOsc",values,512,0,NULL,-1.0f,1.0f,ImGui::GetContentRegionAvail());
ImGui::PopStyleVar(4);
}
ImGui::End();
}
void FurnaceGUI::drawPattern() { void FurnaceGUI::drawPattern() {
if (!patternOpen) return; if (!patternOpen) return;
if (e->isPlaying() && followPattern) cursor.y=oldRow; if (e->isPlaying() && followPattern) cursor.y=oldRow;
@ -4571,6 +4590,7 @@ bool FurnaceGUI::loop() {
if (ImGui::MenuItem("orders")) ordersOpen=!ordersOpen; if (ImGui::MenuItem("orders")) ordersOpen=!ordersOpen;
if (ImGui::MenuItem("pattern")) patternOpen=!patternOpen; if (ImGui::MenuItem("pattern")) patternOpen=!patternOpen;
if (ImGui::MenuItem("mixer")) mixerOpen=!mixerOpen; if (ImGui::MenuItem("mixer")) mixerOpen=!mixerOpen;
if (ImGui::MenuItem("oscilloscope")) oscOpen=!oscOpen;
ImGui::EndMenu(); ImGui::EndMenu();
} }
if (ImGui::BeginMenu("help")) { if (ImGui::BeginMenu("help")) {
@ -4607,6 +4627,7 @@ bool FurnaceGUI::loop() {
drawSampleList(); drawSampleList();
drawSampleEdit(); drawSampleEdit();
drawMixer(); drawMixer();
drawOsc();
drawPattern(); drawPattern();
drawSettings(); drawSettings();
drawDebug(); drawDebug();
@ -5209,6 +5230,7 @@ FurnaceGUI::FurnaceGUI():
settingsOpen(false), settingsOpen(false),
mixerOpen(false), mixerOpen(false),
debugOpen(false), debugOpen(false),
oscOpen(true),
selecting(false), selecting(false),
curNibble(false), curNibble(false),
orderNibble(false), orderNibble(false),

View file

@ -236,7 +236,7 @@ class FurnaceGUI {
int loopOrder, loopRow, loopEnd; int loopOrder, loopRow, loopEnd;
bool editControlsOpen, ordersOpen, insListOpen, songInfoOpen, patternOpen, insEditOpen; bool editControlsOpen, ordersOpen, insListOpen, songInfoOpen, patternOpen, insEditOpen;
bool waveListOpen, waveEditOpen, sampleListOpen, sampleEditOpen, aboutOpen, settingsOpen; bool waveListOpen, waveEditOpen, sampleListOpen, sampleEditOpen, aboutOpen, settingsOpen;
bool mixerOpen, debugOpen; bool mixerOpen, debugOpen, oscOpen;
SelectionPoint selStart, selEnd, cursor; SelectionPoint selStart, selEnd, cursor;
bool selecting, curNibble, orderNibble, extraChannelButtons, followOrders, followPattern, changeAllOrders; bool selecting, curNibble, orderNibble, extraChannelButtons, followOrders, followPattern, changeAllOrders;
FurnaceGUIWindows curWindow; FurnaceGUIWindows curWindow;
@ -315,6 +315,7 @@ class FurnaceGUI {
void drawSampleList(); void drawSampleList();
void drawSampleEdit(); void drawSampleEdit();
void drawMixer(); void drawMixer();
void drawOsc();
void drawAbout(); void drawAbout();
void drawSettings(); void drawSettings();
void drawDebug(); void drawDebug();