From c5df68f8af6085597f1a0b2d5e9cb5d7845b569c Mon Sep 17 00:00:00 2001 From: tildearrow Date: Sun, 13 Nov 2022 18:29:37 -0500 Subject: [PATCH] GUI: improve create ins from sample functionality pull request #740 --- src/engine/engine.cpp | 15 +++++++++++---- src/engine/engine.h | 2 +- src/gui/dataList.cpp | 5 +++++ src/gui/doAction.cpp | 42 +++++++++++++++++++++++++++++++++++++++++- src/gui/gui.cpp | 32 ++++++++++++++++++++++++++++++++ src/gui/gui.h | 5 ++++- 6 files changed, 94 insertions(+), 7 deletions(-) diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index 32caa97ba..d9e236016 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -2686,12 +2686,17 @@ void DivEngine::unmuteAll() { BUSY_END; } -int DivEngine::addInstrument(int refChan) { +int DivEngine::addInstrument(int refChan, DivInstrumentType fallbackType) { if (song.ins.size()>=256) return -1; BUSY_BEGIN; DivInstrument* ins=new DivInstrument; int insCount=(int)song.ins.size(); - DivInstrumentType prefType=getPreferInsType(refChan); + DivInstrumentType prefType; + if (refChan<0) { + prefType=fallbackType; + } else { + prefType=getPreferInsType(refChan); + } switch (prefType) { case DIV_INS_OPLL: *ins=song.nullInsOPLL; @@ -2705,8 +2710,10 @@ int DivEngine::addInstrument(int refChan) { default: break; } - if (sysOfChan[refChan]==DIV_SYSTEM_QSOUND) { - *ins=song.nullInsQSound; + if (refChan>=0) { + if (sysOfChan[refChan]==DIV_SYSTEM_QSOUND) { + *ins=song.nullInsQSound; + } } ins->name=fmt::sprintf("Instrument %d",insCount); if (prefType!=DIV_INS_NULL) { diff --git a/src/engine/engine.h b/src/engine/engine.h index c47911cb2..4a36b27d7 100644 --- a/src/engine/engine.h +++ b/src/engine/engine.h @@ -759,7 +759,7 @@ class DivEngine { bool isExporting(); // add instrument - int addInstrument(int refChan=0); + int addInstrument(int refChan=0, DivInstrumentType fallbackType=DIV_INS_STD); // add instrument from pointer int addInstrumentPtr(DivInstrument* which); diff --git a/src/gui/dataList.cpp b/src/gui/dataList.cpp index 8a62c822f..20f66dd59 100644 --- a/src/gui/dataList.cpp +++ b/src/gui/dataList.cpp @@ -60,6 +60,11 @@ void FurnaceGUI::drawInsList(bool asChild) { } ImGui::EndPopup(); } + } else { + if (ImGui::IsItemClicked(ImGuiMouseButton_Right)) { + displayInsTypeList=true; + displayInsTypeListMakeInsSample=-1; + } } ImGui::SameLine(); if (ImGui::Button(ICON_FA_FILES_O "##InsClone")) { diff --git a/src/gui/doAction.cpp b/src/gui/doAction.cpp index d4145276b..941d037c5 100644 --- a/src/gui/doAction.cpp +++ b/src/gui/doAction.cpp @@ -1291,14 +1291,54 @@ void FurnaceGUI::doAction(int what) { break; case GUI_ACTION_SAMPLE_MAKE_INS: { if (curSample<0 || curSample>=(int)e->song.sample.size()) break; + // determine instrument type + std::vector tempTypeList=e->getPossibleInsTypes(); + makeInsTypeList.clear(); + + for (DivInstrumentType& i: tempTypeList) { + if (i==DIV_INS_PCE || + i==DIV_INS_MSM6258 || + i==DIV_INS_MSM6295 || + i==DIV_INS_ADPCMA || + i==DIV_INS_ADPCMB || + i==DIV_INS_SEGAPCM || + i==DIV_INS_QSOUND || + i==DIV_INS_YMZ280B || + i==DIV_INS_RF5C68 || + i==DIV_INS_MULTIPCM || + i==DIV_INS_MIKEY || + i==DIV_INS_X1_010 || + i==DIV_INS_SWAN || + i==DIV_INS_AY || + i==DIV_INS_AY8930 || + i==DIV_INS_VRC6 || + i==DIV_INS_SU || + i==DIV_INS_SNES || + i==DIV_INS_ES5506) { + makeInsTypeList.push_back(i); + } + } + + if (makeInsTypeList.size()>1) { + displayInsTypeList=true; + displayInsTypeListMakeInsSample=curSample; + break; + } + + DivInstrumentType insType=DIV_INS_AMIGA; + if (!makeInsTypeList.empty()) { + insType=makeInsTypeList[0]; + } + DivSample* sample=e->song.sample[curSample]; curIns=e->addInstrument(cursor.xCoarse); if (curIns==-1) { showError("too many instruments!"); } else { - e->song.ins[curIns]->type=DIV_INS_AMIGA; + e->song.ins[curIns]->type=insType; e->song.ins[curIns]->name=sample->name; e->song.ins[curIns]->amiga.initSample=curSample; + if (insType!=DIV_INS_AMIGA) e->song.ins[curIns]->amiga.useSample=true; nextWindow=GUI_WINDOW_INS_EDIT; MARK_MODIFIED; wavePreviewInit=true; diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index dc5e6d6cf..93c333689 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -4409,6 +4409,11 @@ bool FurnaceGUI::loop() { ImGui::OpenPopup("Import Raw Sample"); } + if (displayInsTypeList) { + displayInsTypeList=false; + ImGui::OpenPopup("InsTypeList"); + } + if (displayExporting) { displayExporting=false; ImGui::OpenPopup("Rendering..."); @@ -4789,6 +4794,31 @@ bool FurnaceGUI::loop() { ImGui::EndPopup(); } + if (ImGui::BeginPopup("InsTypeList",ImGuiWindowFlags_NoMove|ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoSavedSettings)) { + char temp[1024]; + for (DivInstrumentType& i: makeInsTypeList) { + strncpy(temp,insTypes[i],1023); + if (ImGui::MenuItem(temp)) { + // create ins + curIns=e->addInstrument(-1,i); + if (curIns==-1) { + showError("too many instruments!"); + } else { + if (displayInsTypeListMakeInsSample>=0 && displayInsTypeListMakeInsSample<(int)e->song.sample.size()) { + e->song.ins[curIns]->type=i; + e->song.ins[curIns]->name=e->song.sample[displayInsTypeListMakeInsSample]->name; + e->song.ins[curIns]->amiga.initSample=displayInsTypeListMakeInsSample; + if (i!=DIV_INS_AMIGA) e->song.ins[curIns]->amiga.useSample=true; + nextWindow=GUI_WINDOW_INS_EDIT; + wavePreviewInit=true; + } + MARK_MODIFIED; + } + } + } + ImGui::EndPopup(); + } + // TODO: // - multiple selection // - replace instrument @@ -5506,6 +5536,7 @@ FurnaceGUI::FurnaceGUI(): zsmExportLoop(true), vgmExportPatternHints(false), vgmExportDirectStream(false), + displayInsTypeList(false), portrait(false), injectBackUp(false), mobileMenuOpen(false), @@ -5526,6 +5557,7 @@ FurnaceGUI::FurnaceGUI(): zsmExportTickRate(60), macroPointSize(16), waveEditStyle(0), + displayInsTypeListMakeInsSample(-1), mobileMenuPos(0.0f), autoButtonSize(0.0f), curSysSection(NULL), diff --git a/src/gui/gui.h b/src/gui/gui.h index 36de61c54..29ece540b 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -1055,9 +1055,11 @@ class FurnaceGUI { std::vector sysSearchResults; std::vector newSongSearchResults; std::deque recentFile; + std::vector makeInsTypeList; + bool quit, warnQuit, willCommit, edit, modified, displayError, displayExporting, vgmExportLoop, zsmExportLoop, vgmExportPatternHints; - bool vgmExportDirectStream; + bool vgmExportDirectStream, displayInsTypeList; bool portrait, injectBackUp, mobileMenuOpen; bool wantCaptureKeyboard, oldWantCaptureKeyboard, displayMacroMenu; bool displayNew, fullScreen, preserveChanPos, wantScrollList, noteInputPoly; @@ -1068,6 +1070,7 @@ class FurnaceGUI { int zsmExportTickRate; int macroPointSize; int waveEditStyle; + int displayInsTypeListMakeInsSample; float mobileMenuPos, autoButtonSize; const int* curSysSection;