GUI: improve create ins from sample functionality

pull request #740
This commit is contained in:
tildearrow 2022-11-13 18:29:37 -05:00
parent 9ef3ec19bc
commit c5df68f8af
6 changed files with 94 additions and 7 deletions

View file

@ -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) {

View file

@ -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);

View file

@ -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")) {

View file

@ -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<DivInstrumentType> 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;

View file

@ -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),

View file

@ -1055,9 +1055,11 @@ class FurnaceGUI {
std::vector<DivSystem> sysSearchResults;
std::vector<FurnaceGUISysDef> newSongSearchResults;
std::deque<String> recentFile;
std::vector<DivInstrumentType> 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;