GUI: implement instrument load replace
This commit is contained in:
parent
6aefd392ff
commit
99a313b684
6 changed files with 63 additions and 7 deletions
|
|
@ -1288,7 +1288,14 @@ void FurnaceGUI::openFileDialog(FurnaceGUIFileDialogs type) {
|
|||
);
|
||||
break;
|
||||
case GUI_FILE_INS_OPEN:
|
||||
case GUI_FILE_INS_OPEN_REPLACE:
|
||||
prevIns=-3;
|
||||
if (prevInsData!=NULL) {
|
||||
delete prevInsData;
|
||||
prevInsData=NULL;
|
||||
}
|
||||
prevInsData=new DivInstrument;
|
||||
*prevInsData=*e->getIns(curIns);
|
||||
if (!dirExists(workingDirIns)) workingDirIns=getHomeDir();
|
||||
hasOpened=fileDialog->openLoad(
|
||||
"Load Instrument",
|
||||
|
|
@ -1300,11 +1307,20 @@ void FurnaceGUI::openFileDialog(FurnaceGUIFileDialogs type) {
|
|||
[this](const char* path) {
|
||||
std::vector<DivInstrument*> instruments=e->instrumentFromFile(path);
|
||||
if (!instruments.empty()) {
|
||||
e->loadTempIns(instruments[0]);
|
||||
if (curIns!=-2) {
|
||||
prevIns=curIns;
|
||||
if (curFileDialog==GUI_FILE_INS_OPEN_REPLACE) {
|
||||
if (prevIns==-3) {
|
||||
prevIns=curIns;
|
||||
}
|
||||
if (prevIns>=0 && prevIns<=(int)e->song.ins.size()) {
|
||||
*e->song.ins[prevIns]=*instruments[0];
|
||||
}
|
||||
} else {
|
||||
e->loadTempIns(instruments[0]);
|
||||
if (curIns!=-2) {
|
||||
prevIns=curIns;
|
||||
}
|
||||
curIns=-2;
|
||||
}
|
||||
curIns=-2;
|
||||
}
|
||||
for (DivInstrument* i: instruments) delete i;
|
||||
}
|
||||
|
|
@ -2911,8 +2927,18 @@ bool FurnaceGUI::loop() {
|
|||
if (fileDialog->render(ImVec2(600.0f*dpiScale,400.0f*dpiScale),ImVec2(scrW*dpiScale,scrH*dpiScale))) {
|
||||
bool openOpen=false;
|
||||
//ImGui::GetIO().ConfigFlags&=~ImGuiConfigFlags_NavEnableKeyboard;
|
||||
if (curFileDialog==GUI_FILE_INS_OPEN && prevIns!=-3) {
|
||||
curIns=prevIns;
|
||||
if ((curFileDialog==GUI_FILE_INS_OPEN || curFileDialog==GUI_FILE_INS_OPEN_REPLACE) && prevIns!=-3) {
|
||||
if (curFileDialog==GUI_FILE_INS_OPEN_REPLACE) {
|
||||
if (prevInsData!=NULL) {
|
||||
logI("try");
|
||||
if (prevIns>=0 && prevIns<(int)e->song.ins.size()) {
|
||||
logI("replace");
|
||||
*e->song.ins[prevIns]=*prevInsData;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
curIns=prevIns;
|
||||
}
|
||||
prevIns=-3;
|
||||
}
|
||||
switch (curFileDialog) {
|
||||
|
|
@ -2922,6 +2948,7 @@ bool FurnaceGUI::loop() {
|
|||
workingDirSong=fileDialog->getPath()+DIR_SEPARATOR_STR;
|
||||
break;
|
||||
case GUI_FILE_INS_OPEN:
|
||||
case GUI_FILE_INS_OPEN_REPLACE:
|
||||
case GUI_FILE_INS_SAVE:
|
||||
workingDirIns=fileDialog->getPath()+DIR_SEPARATOR_STR;
|
||||
break;
|
||||
|
|
@ -3101,6 +3128,25 @@ bool FurnaceGUI::loop() {
|
|||
}
|
||||
break;
|
||||
}
|
||||
case GUI_FILE_INS_OPEN_REPLACE: {
|
||||
std::vector<DivInstrument*> instruments=e->instrumentFromFile(copyOfName.c_str());
|
||||
if (!instruments.empty()) {
|
||||
if (!e->getWarnings().empty()) {
|
||||
showWarning(e->getWarnings(),GUI_WARN_GENERIC);
|
||||
}
|
||||
if (curIns>=0 && curIns<(int)e->song.ins.size()) {
|
||||
*e->song.ins[0]=*instruments[0];
|
||||
} else {
|
||||
showError("...but you haven't selected an instrument!");
|
||||
}
|
||||
for (DivInstrument* i: instruments) {
|
||||
delete i;
|
||||
}
|
||||
} else {
|
||||
showError("cannot load instrument! ("+e->getLastError()+")");
|
||||
}
|
||||
break;
|
||||
}
|
||||
case GUI_FILE_WAVE_OPEN:
|
||||
e->addWaveFromFile(copyOfName.c_str());
|
||||
MARK_MODIFIED;
|
||||
|
|
@ -3816,6 +3862,7 @@ FurnaceGUI::FurnaceGUI():
|
|||
patFont(NULL),
|
||||
bigFont(NULL),
|
||||
fontRange(NULL),
|
||||
prevInsData(NULL),
|
||||
curIns(0),
|
||||
curWave(0),
|
||||
curSample(0),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue