From eb71c27ad9256cb9c2974eb5c7f368df5dc29283 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Sun, 5 Jun 2022 19:04:41 -0500 Subject: [PATCH] GUI: preliminary "select instrument" dialog --- src/gui/gui.cpp | 71 ++++++++++++++++++++++++++++++++++++++++++------- src/gui/gui.h | 4 ++- 2 files changed, 65 insertions(+), 10 deletions(-) diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index bc18ae3c4..68196c352 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -3330,8 +3330,16 @@ bool FurnaceGUI::loop() { if (!e->getWarnings().empty()) { showWarning(e->getWarnings(),GUI_WARN_GENERIC); } - for (DivInstrument* i: instruments) { - e->addInstrumentPtr(i); + if (instruments.size()>1) { // ask which instruments to load + for (DivInstrument* i: instruments) { + pendingIns.push_back(std::make_pair(i,false)); + } + displayPendingIns=true; + pendingInsSingle=false; + } else { // load the only instrument + for (DivInstrument* i: instruments) { + e->addInstrumentPtr(i); + } } } else { showError("cannot load instrument! ("+e->getLastError()+")"); @@ -3344,13 +3352,21 @@ bool FurnaceGUI::loop() { if (!e->getWarnings().empty()) { showWarning(e->getWarnings(),GUI_WARN_GENERIC); } - if (curIns>=0 && curIns<(int)e->song.ins.size()) { - *e->song.ins[curIns]=*instruments[0]; - } else { - showError("...but you haven't selected an instrument!"); - } - for (DivInstrument* i: instruments) { - delete i; + if (instruments.size()>1) { // ask which instrument + for (DivInstrument* i: instruments) { + pendingIns.push_back(std::make_pair(i,false)); + } + displayPendingIns=true; + pendingInsSingle=true; + } else { // replace with the only instrument + if (curIns>=0 && curIns<(int)e->song.ins.size()) { + *e->song.ins[curIns]=*instruments[0]; + } else { + showError("...but you haven't selected an instrument!"); + } + for (DivInstrument* i: instruments) { + delete i; + } } } else { showError("cannot load instrument! ("+e->getLastError()+")"); @@ -3442,6 +3458,11 @@ bool FurnaceGUI::loop() { ImGui::OpenPopup("Error"); } + if (displayPendingIns) { + displayPendingIns=false; + ImGui::OpenPopup("Select Instrument"); + } + if (displayExporting) { displayExporting=false; ImGui::OpenPopup("Rendering..."); @@ -3792,6 +3813,36 @@ bool FurnaceGUI::loop() { ImGui::EndPopup(); } + // TODO: + // - multiple selection + // - replace instrument + if (ImGui::BeginPopupModal("Select Instrument",NULL,ImGuiWindowFlags_AlwaysAutoResize)) { + bool quitPlease=false; + if (pendingInsSingle) { + ImGui::Text("this is an instrument bank! select which one to use:"); + } else { + ImGui::Text("this is an instrument bank! select which ones to load:"); + } + for (size_t i=0; iname); + if (ImGui::Selectable(id.c_str())) { + pendingIns[i].second=true; + e->addInstrumentPtr(pendingIns[i].first); + quitPlease=true; + } + } + if (quitPlease) { + ImGui::CloseCurrentPopup(); + for (std::pair i: pendingIns) { + if (!i.second) { + delete i.first; + } + } + pendingIns.clear(); + } + ImGui::EndPopup(); + } + layoutTimeEnd=SDL_GetPerformanceCounter(); // backup trigger @@ -4198,6 +4249,8 @@ FurnaceGUI::FurnaceGUI(): preserveChanPos(false), wantScrollList(false), noteInputPoly(true), + displayPendingIns(false), + pendingInsSingle(false), vgmExportVersion(0x171), drawHalt(10), macroPointSize(16), diff --git a/src/gui/gui.h b/src/gui/gui.h index 60d492633..5bda0246c 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -32,6 +32,7 @@ #include #include #include +#include #include #include "fileDialog.h" @@ -816,6 +817,7 @@ class FurnaceGUI { bool quit, warnQuit, willCommit, edit, modified, displayError, displayExporting, vgmExportLoop, wantCaptureKeyboard, oldWantCaptureKeyboard, displayMacroMenu; bool displayNew, fullScreen, preserveChanPos, wantScrollList, noteInputPoly; + bool displayPendingIns, pendingInsSingle; bool willExport[32]; int vgmExportVersion; int drawHalt; @@ -1130,7 +1132,7 @@ class FurnaceGUI { std::vector activeNotes; std::vector cmdStream; std::vector particles; - std::vector pendingIns; + std::vector> pendingIns; std::vector sysCategories;