From fa5e2bc439472ff948c708870e845e16edce2758 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Tue, 1 Mar 2022 17:19:52 -0500 Subject: [PATCH] TODO: revamp new song system picker --- src/engine/engine.cpp | 19 ++++++- src/engine/engine.h | 2 +- src/gui/gui.cpp | 126 +++++++++++++++++++++++++++++++++--------- src/gui/gui.h | 21 +++++++ 4 files changed, 139 insertions(+), 29 deletions(-) diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index ad0548399..0c3621f81 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -19,6 +19,7 @@ #include "dataErrors.h" #include "song.h" +#include #define _USE_MATH_DEFINES #include "engine.h" #include "instrument.h" @@ -533,13 +534,25 @@ void DivEngine::renderSamples() { qsoundMemLen=memPos+256; } -void DivEngine::createNew() { - DivSystem sys=song.system[0]; +void DivEngine::createNew(int* description) { quitDispatch(); isBusy.lock(); song.unload(); song=DivSong(); - song.system[0]=sys; + if (description!=NULL) { + if (description[0]!=0) { + int index=0; + for (int i=0; description[i]; i+=4) { + song.system[index]=(DivSystem)description[i]; + song.systemVol[index]=description[i+1]; + song.systemPan[index]=description[i+2]; + song.systemFlags[index]=description[i+3]; + index++; + if (index>=32) break; + } + song.systemLen=index; + } + } recalcChans(); renderSamples(); isBusy.unlock(); diff --git a/src/engine/engine.h b/src/engine/engine.h index 2f060f14f..02eed74ed 100644 --- a/src/engine/engine.h +++ b/src/engine/engine.h @@ -262,7 +262,7 @@ class DivEngine { DivWavetable* getWave(int index); DivSample* getSample(int index); // start fresh - void createNew(); + void createNew(int* description); // load a file. bool load(unsigned char* f, size_t length); // save as .dmf. diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 7c3aec199..bec846c83 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -1898,6 +1898,73 @@ void FurnaceGUI::drawDebug() { ImGui::End(); } +#define NEWSONG_CATEGORY(x) \ + if (ImGui::Selectable(x,false,ImGuiSelectableFlags_DontClosePopups)) { \ + printf("selected a category\n"); \ + } + +void FurnaceGUI::drawNewSong() { + bool accepted=false; + + ImGui::PushFont(bigFont); + ImGui::SetCursorPosX((ImGui::GetContentRegionAvail().x-ImGui::CalcTextSize("Choose a System!").x)*0.5); + ImGui::Text("Choose a System!"); + ImGui::PopFont(); + + if (ImGui::BeginTable("sysPicker",2,ImGuiTableFlags_Borders)) { + ImGui::TableSetupColumn("c0",ImGuiTableColumnFlags_WidthFixed,0.0f); + ImGui::TableSetupColumn("c1",ImGuiTableColumnFlags_WidthStretch,0.0f); + + ImGui::TableNextRow(ImGuiTableRowFlags_Headers); + ImGui::TableNextColumn(); + ImGui::Text("Categories"); + ImGui::TableNextColumn(); + ImGui::Text("Systems"); + + ImGui::TableNextRow(); + + // CATEGORIES + ImGui::TableNextColumn(); + NEWSONG_CATEGORY("All chips"); + NEWSONG_CATEGORY("FM"); + NEWSONG_CATEGORY("Square"); + NEWSONG_CATEGORY("Sample"); + NEWSONG_CATEGORY("Wavetable"); + NEWSONG_CATEGORY("Other/Special"); + NEWSONG_CATEGORY("Game consoles"); + NEWSONG_CATEGORY("Computers"); + NEWSONG_CATEGORY("Arcade systems"); + NEWSONG_CATEGORY("DefleMask-compatible"); + + // SYSTEMS + ImGui::TableNextColumn(); + if (ImGui::BeginTable("Systems",1,ImGuiTableFlags_BordersInnerV|ImGuiTableFlags_ScrollY)) { + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + ImGui::Selectable("System system",false,ImGuiSelectableFlags_DontClosePopups); + ImGui::EndTable(); + } + + ImGui::EndTable(); + } + + if (ImGui::Button("Go ahead") || accepted) { + e->createNew(nextDesc); + undoHist.clear(); + redoHist.clear(); + curFileName=""; + modified=false; + curNibble=false; + orderNibble=false; + orderCursor=-1; + selStart=SelectionPoint(); + selEnd=SelectionPoint(); + cursor=SelectionPoint(); + updateWindowTitle(); + ImGui::CloseCurrentPopup(); + } +} + void FurnaceGUI::drawStats() { if (nextWindow==GUI_WINDOW_STATS) { statsOpen=true; @@ -4391,22 +4458,11 @@ bool FurnaceGUI::loop() { ImGui::BeginMainMenuBar(); if (ImGui::BeginMenu("file")) { - if (ImGui::MenuItem("new")) { + if (ImGui::MenuItem("new...")) { if (modified) { showWarning("Unsaved changes! Are you sure?",GUI_WARN_NEW); } else { - e->createNew(); - undoHist.clear(); - redoHist.clear(); - curFileName=""; - modified=false; - curNibble=false; - orderNibble=false; - orderCursor=-1; - selStart=SelectionPoint(); - selEnd=SelectionPoint(); - cursor=SelectionPoint(); - updateWindowTitle(); + displayNew=true; } } if (ImGui::MenuItem("open...",BIND_FOR(GUI_ACTION_OPEN))) { @@ -5107,6 +5163,11 @@ bool FurnaceGUI::loop() { ImGui::OpenPopup("Rendering..."); } + if (displayNew) { + displayNew=false; + ImGui::OpenPopup("New Song"); + } + if (nextWindow==GUI_WINDOW_ABOUT) { aboutOpen=true; nextWindow=GUI_WINDOW_NOTHING; @@ -5126,6 +5187,13 @@ bool FurnaceGUI::loop() { ImGui::EndPopup(); } + ImGui::SetNextWindowSizeConstraints(ImVec2(400.0f*dpiScale,200.0f*dpiScale),ImVec2(scrW*dpiScale,scrH*dpiScale)); + if (ImGui::BeginPopupModal("New Song",NULL)) { + ImGui::SetWindowPos(ImVec2(((scrW*dpiScale)-ImGui::GetWindowSize().x)*0.5,((scrH*dpiScale)-ImGui::GetWindowSize().y)*0.5)); + drawNewSong(); + ImGui::EndPopup(); + } + if (ImGui::BeginPopupModal("Error",NULL,ImGuiWindowFlags_AlwaysAutoResize)) { ImGui::Text("%s",errorString.c_str()); if (ImGui::Button("OK")) { @@ -5143,18 +5211,7 @@ bool FurnaceGUI::loop() { quit=true; break; case GUI_WARN_NEW: - e->createNew(); - undoHist.clear(); - redoHist.clear(); - curFileName=""; - modified=false; - curNibble=false; - orderNibble=false; - orderCursor=-1; - selStart=SelectionPoint(); - selEnd=SelectionPoint(); - cursor=SelectionPoint(); - updateWindowTitle(); + displayNew=true; break; case GUI_WARN_OPEN: openFileDialog(GUI_FILE_OPEN); @@ -5743,6 +5800,7 @@ FurnaceGUI::FurnaceGUI(): displayError(false), displayExporting(false), vgmExportLoop(true), + displayNew(false), curFileDialog(GUI_FILE_OPEN), warnAction(GUI_WARN_OPEN), scrW(1280), @@ -5804,6 +5862,7 @@ FurnaceGUI::FurnaceGUI(): wantPatName(false), curWindow(GUI_WINDOW_NOTHING), nextWindow(GUI_WINDOW_NOTHING), + nextDesc(NULL), wavePreviewOn(false), wavePreviewKey((SDL_Scancode)0), wavePreviewNote(0), @@ -5923,6 +5982,23 @@ FurnaceGUI::FurnaceGUI(): valueKeys[SDLK_KP_7]=7; valueKeys[SDLK_KP_8]=8; valueKeys[SDLK_KP_9]=9; + + /* +const char* sysCategories[]={ + "All chips", + "FM", + "Square", + "Sample", + "Wavetable", + "Other/Special", + "Game consoles", + "Computers", + "Arcade systems", + "DefleMask-compatible" +}; +*/ + + sysCategories.push_back(FurnaceGUISysCategory("All chips")); memset(willExport,1,32*sizeof(bool)); diff --git a/src/gui/gui.h b/src/gui/gui.h index 291db6d8d..c59705961 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -402,6 +402,22 @@ struct Particle { lifeSpeed(lS) {} }; +struct FurnaceGUISysDef { + const char* name; + const int* definition; + FurnaceGUISysDef(const char* n, const int* def): + name(n), definition(def) {} +}; + +struct FurnaceGUISysCategory { + const char* name; + std::vector systems; + FurnaceGUISysCategory(const char* n): + name(n) {} + FurnaceGUISysCategory(): + name(NULL) {} +}; + class FurnaceGUI { DivEngine* e; @@ -413,6 +429,7 @@ class FurnaceGUI { String mmlStringW; bool quit, warnQuit, willCommit, edit, modified, displayError, displayExporting, vgmExportLoop; + bool displayNew; bool willExport[32]; FurnaceGUIFileDialogs curFileDialog; @@ -533,6 +550,7 @@ class FurnaceGUI { float peak[2]; float patChanX[DIV_MAX_CHANS+1]; float patChanSlideY[DIV_MAX_CHANS+1]; + int* nextDesc; // bit 31: ctrl // bit 30: reserved for SDL scancode mask @@ -563,6 +581,8 @@ class FurnaceGUI { std::vector cmdStream; std::vector particles; + std::vector sysCategories; + bool wavePreviewOn; SDL_Scancode wavePreviewKey; int wavePreviewNote; @@ -657,6 +677,7 @@ class FurnaceGUI { void drawAbout(); void drawSettings(); void drawDebug(); + void drawNewSong(); void parseKeybinds(); void promptKey(int which);