implement a setting which was missing

store/load ins names when saving .fui
This commit is contained in:
tildearrow 2023-09-16 18:15:03 -05:00
parent b105dd535f
commit 7912a7982c
7 changed files with 47 additions and 15 deletions

View file

@ -903,7 +903,7 @@ class DivEngine {
// get instrument from file // get instrument from file
// if the returned vector is empty then there was an error. // if the returned vector is empty then there was an error.
std::vector<DivInstrument*> instrumentFromFile(const char* path, bool loadAssets=true); std::vector<DivInstrument*> instrumentFromFile(const char* path, bool loadAssets=true, bool readInsName=true);
// load temporary instrument // load temporary instrument
void loadTempIns(DivInstrument* which); void loadTempIns(DivInstrument* which);

View file

@ -1816,7 +1816,7 @@ void DivEngine::loadWOPN(SafeReader& reader, std::vector<DivInstrument*>& ret, S
} }
} }
std::vector<DivInstrument*> DivEngine::instrumentFromFile(const char* path, bool loadAssets) { std::vector<DivInstrument*> DivEngine::instrumentFromFile(const char* path, bool loadAssets, bool readInsName) {
std::vector<DivInstrument*> ret; std::vector<DivInstrument*> ret;
warnings=""; warnings="";
@ -1921,12 +1921,17 @@ std::vector<DivInstrument*> DivEngine::instrumentFromFile(const char* path, bool
reader.seek(dataPtr,SEEK_SET); reader.seek(dataPtr,SEEK_SET);
} }
ins->name=stripPath;
if (ins->readInsData(reader,version,loadAssets?(&song):NULL)!=DIV_DATA_SUCCESS) { if (ins->readInsData(reader,version,loadAssets?(&song):NULL)!=DIV_DATA_SUCCESS) {
lastError="invalid instrument header/data!"; lastError="invalid instrument header/data!";
delete ins; delete ins;
delete[] buf; delete[] buf;
return ret; return ret;
} else { } else {
if (!readInsName) {
ins->name=stripPath;
}
ret.push_back(ins); ret.push_back(ins);
} }
} catch (EndOfFileException& e) { } catch (EndOfFileException& e) {

View file

@ -719,7 +719,7 @@ void DivInstrument::writeFeatureX1(SafeWriter* w) {
FEATURE_END; FEATURE_END;
} }
void DivInstrument::putInsData2(SafeWriter* w, bool fui, const DivSong* song) { void DivInstrument::putInsData2(SafeWriter* w, bool fui, const DivSong* song, bool insName) {
size_t blockStartSeek=0; size_t blockStartSeek=0;
size_t blockEndSeek=0; size_t blockEndSeek=0;
size_t slSeek=0; size_t slSeek=0;
@ -1021,7 +1021,7 @@ void DivInstrument::putInsData2(SafeWriter* w, bool fui, const DivSong* song) {
} }
// check ins name // check ins name
if (!name.empty()) { if (!name.empty() && insName) {
featureNA=true; featureNA=true;
} }
@ -3380,7 +3380,7 @@ DivDataErrors DivInstrument::readInsData(SafeReader& reader, short version, DivS
return readInsDataOld(reader,version); return readInsDataOld(reader,version);
} }
bool DivInstrument::save(const char* path, bool oldFormat, DivSong* song) { bool DivInstrument::save(const char* path, bool oldFormat, DivSong* song, bool writeInsName) {
SafeWriter* w=new SafeWriter(); SafeWriter* w=new SafeWriter();
w->init(); w->init();
@ -3397,14 +3397,14 @@ bool DivInstrument::save(const char* path, bool oldFormat, DivSong* song) {
// pointer to data // pointer to data
w->writeI(32); w->writeI(32);
// currently reserved (TODO; wavetable and sample here) // reserved
w->writeS(0); w->writeS(0);
w->writeS(0); w->writeS(0);
w->writeI(0); w->writeI(0);
putInsData(w); putInsData(w);
} else { } else {
putInsData2(w,true,song); putInsData2(w,true,song,writeInsName);
} }
FILE* outFile=ps_fopen(path,"wb"); FILE* outFile=ps_fopen(path,"wb");

View file

@ -720,7 +720,7 @@ struct DivInstrument {
* save the instrument to a SafeWriter using new format. * save the instrument to a SafeWriter using new format.
* @param w the SafeWriter in question. * @param w the SafeWriter in question.
*/ */
void putInsData2(SafeWriter* w, bool fui=false, const DivSong* song=NULL); void putInsData2(SafeWriter* w, bool fui=false, const DivSong* song=NULL, bool insName=true);
/** /**
* read instrument data in .fui format. * read instrument data in .fui format.
@ -735,9 +735,10 @@ struct DivInstrument {
* @param path file path. * @param path file path.
* @param oldFormat whether to save in legacy Furnace ins format. * @param oldFormat whether to save in legacy Furnace ins format.
* @param song if new format, a DivSong to read wavetables and samples. * @param song if new format, a DivSong to read wavetables and samples.
* @param writeInsName whether to write the instrument name or not. ignored if old format.
* @return whether it was successful. * @return whether it was successful.
*/ */
bool save(const char* path, bool oldFormat=false, DivSong* song=NULL); bool save(const char* path, bool oldFormat=false, DivSong* song=NULL, bool writeInsName=true);
/** /**
* save this instrument to a file in .dmp format. * save this instrument to a file in .dmp format.

View file

@ -3545,7 +3545,7 @@ bool FurnaceGUI::loop() {
case SDL_DROPFILE: case SDL_DROPFILE:
if (ev.drop.file!=NULL) { if (ev.drop.file!=NULL) {
int sampleCountBefore=e->song.sampleLen; int sampleCountBefore=e->song.sampleLen;
std::vector<DivInstrument*> instruments=e->instrumentFromFile(ev.drop.file); std::vector<DivInstrument*> instruments=e->instrumentFromFile(ev.drop.file,true,settings.readInsNames);
DivWavetable* droppedWave=NULL; DivWavetable* droppedWave=NULL;
DivSample* droppedSample=NULL; DivSample* droppedSample=NULL;
if (!instruments.empty()) { if (!instruments.empty()) {
@ -4857,7 +4857,7 @@ bool FurnaceGUI::loop() {
break; break;
case GUI_FILE_INS_SAVE: case GUI_FILE_INS_SAVE:
if (curIns>=0 && curIns<(int)e->song.ins.size()) { if (curIns>=0 && curIns<(int)e->song.ins.size()) {
if (e->song.ins[curIns]->save(copyOfName.c_str(),false,&e->song)) { if (e->song.ins[curIns]->save(copyOfName.c_str(),false,&e->song,settings.writeInsNames)) {
pushRecentSys(copyOfName.c_str()); pushRecentSys(copyOfName.c_str());
} }
} }
@ -4983,7 +4983,7 @@ bool FurnaceGUI::loop() {
String warns="there were some warnings/errors while loading instruments:\n"; String warns="there were some warnings/errors while loading instruments:\n";
int sampleCountBefore=e->song.sampleLen; int sampleCountBefore=e->song.sampleLen;
for (String i: fileDialog->getFileName()) { for (String i: fileDialog->getFileName()) {
std::vector<DivInstrument*> insTemp=e->instrumentFromFile(i.c_str()); std::vector<DivInstrument*> insTemp=e->instrumentFromFile(i.c_str(),true,settings.readInsNames);
if (insTemp.empty()) { if (insTemp.empty()) {
warn=true; warn=true;
warns+=fmt::sprintf("> %s: cannot load instrument! (%s)\n",i,e->getLastError()); warns+=fmt::sprintf("> %s: cannot load instrument! (%s)\n",i,e->getLastError());
@ -5029,7 +5029,7 @@ bool FurnaceGUI::loop() {
} }
case GUI_FILE_INS_OPEN_REPLACE: { case GUI_FILE_INS_OPEN_REPLACE: {
int sampleCountBefore=e->song.sampleLen; int sampleCountBefore=e->song.sampleLen;
std::vector<DivInstrument*> instruments=e->instrumentFromFile(copyOfName.c_str()); std::vector<DivInstrument*> instruments=e->instrumentFromFile(copyOfName.c_str(),true,settings.readInsNames);
if (!instruments.empty()) { if (!instruments.empty()) {
if (e->song.sampleLen!=sampleCountBefore) { if (e->song.sampleLen!=sampleCountBefore) {
e->renderSamplesP(); e->renderSamplesP();

View file

@ -1591,6 +1591,8 @@ class FurnaceGUI {
int chanOscThreads; int chanOscThreads;
int renderPoolThreads; int renderPoolThreads;
int showPool; int showPool;
int writeInsNames;
int readInsNames;
unsigned int maxUndoSteps; unsigned int maxUndoSteps;
String mainFontPath; String mainFontPath;
String headFontPath; String headFontPath;
@ -1771,6 +1773,8 @@ class FurnaceGUI {
chanOscThreads(0), chanOscThreads(0),
renderPoolThreads(0), renderPoolThreads(0),
showPool(0), showPool(0),
writeInsNames(1),
readInsNames(1),
maxUndoSteps(100), maxUndoSteps(100),
mainFontPath(""), mainFontPath(""),
headFontPath(""), headFontPath(""),

View file

@ -498,8 +498,24 @@ void FurnaceGUI::drawSettings() {
} }
ImGui::Unindent(); ImGui::Unindent();
// SUBSECTION CHIP bool writeInsNamesB=settings.writeInsNames;
CONFIG_SUBSECTION("Chip"); if (ImGui::Checkbox("Store instrument name in .fui",&writeInsNamesB)) {
settings.writeInsNames=writeInsNamesB;
}
if (ImGui::IsItemHovered()) {
ImGui::SetTooltip("when enabled,saving an instrument will store its name.\nthis may increase file size.");
}
bool readInsNamesB=settings.readInsNames;
if (ImGui::Checkbox("Load instrument name from .fui",&readInsNamesB)) {
settings.readInsNames=readInsNamesB;
}
if (ImGui::IsItemHovered()) {
ImGui::SetTooltip("when enabled, loading an instrument will use the stored name (if present).\notherwise, it will use the file name.");
}
// SUBSECTION NEW SONG
CONFIG_SUBSECTION("New Song");
ImGui::AlignTextToFramePadding(); ImGui::AlignTextToFramePadding();
ImGui::Text("Initial system:"); ImGui::Text("Initial system:");
ImGui::SameLine(); ImGui::SameLine();
@ -3341,6 +3357,8 @@ void FurnaceGUI::syncSettings() {
settings.chanOscThreads=e->getConfInt("chanOscThreads",0); settings.chanOscThreads=e->getConfInt("chanOscThreads",0);
settings.renderPoolThreads=e->getConfInt("renderPoolThreads",0); settings.renderPoolThreads=e->getConfInt("renderPoolThreads",0);
settings.showPool=e->getConfInt("showPool",0); settings.showPool=e->getConfInt("showPool",0);
settings.writeInsNames=e->getConfInt("writeInsNames",1);
settings.readInsNames=e->getConfInt("readInsNames",1);
clampSetting(settings.mainFontSize,2,96); clampSetting(settings.mainFontSize,2,96);
clampSetting(settings.headFontSize,2,96); clampSetting(settings.headFontSize,2,96);
@ -3494,6 +3512,8 @@ void FurnaceGUI::syncSettings() {
clampSetting(settings.chanOscThreads,0,256); clampSetting(settings.chanOscThreads,0,256);
clampSetting(settings.renderPoolThreads,0,DIV_MAX_CHIPS); clampSetting(settings.renderPoolThreads,0,DIV_MAX_CHIPS);
clampSetting(settings.showPool,0,1); clampSetting(settings.showPool,0,1);
clampSetting(settings.writeInsNames,0,1);
clampSetting(settings.readInsNames,0,1);
if (settings.exportLoops<0.0) settings.exportLoops=0.0; if (settings.exportLoops<0.0) settings.exportLoops=0.0;
if (settings.exportFadeOut<0.0) settings.exportFadeOut=0.0; if (settings.exportFadeOut<0.0) settings.exportFadeOut=0.0;
@ -3755,6 +3775,8 @@ void FurnaceGUI::commitSettings() {
e->setConf("chanOscThreads",settings.chanOscThreads); e->setConf("chanOscThreads",settings.chanOscThreads);
e->setConf("renderPoolThreads",settings.renderPoolThreads); e->setConf("renderPoolThreads",settings.renderPoolThreads);
e->setConf("showPool",settings.showPool); e->setConf("showPool",settings.showPool);
e->setConf("writeInsNames",settings.writeInsNames);
e->setConf("readInsNames",settings.readInsNames);
// colors // colors
for (int i=0; i<GUI_COLOR_MAX; i++) { for (int i=0; i<GUI_COLOR_MAX; i++) {