prepare for new preset format

This commit is contained in:
tildearrow 2022-11-13 15:41:40 -05:00
parent 8ea5c7acc2
commit fbacfd421c
6 changed files with 52 additions and 23 deletions

View file

@ -382,9 +382,9 @@ class DivEngine {
std::vector<String> midiOuts; std::vector<String> midiOuts;
std::vector<DivCommand> cmdStream; std::vector<DivCommand> cmdStream;
std::vector<DivInstrumentType> possibleInsTypes; std::vector<DivInstrumentType> possibleInsTypes;
DivSysDef* sysDefs[256]; static DivSysDef* sysDefs[256];
DivSystem sysFileMapFur[256]; static DivSystem sysFileMapFur[256];
DivSystem sysFileMapDMF[256]; static DivSystem sysFileMapDMF[256];
struct SamplePreview { struct SamplePreview {
double rate; double rate;
@ -532,10 +532,10 @@ class DivEngine {
void notifyWaveChange(int wave); void notifyWaveChange(int wave);
// get system IDs // get system IDs
DivSystem systemFromFileFur(unsigned char val); static DivSystem systemFromFileFur(unsigned char val);
unsigned char systemToFileFur(DivSystem val); static unsigned char systemToFileFur(DivSystem val);
DivSystem systemFromFileDMF(unsigned char val); static DivSystem systemFromFileDMF(unsigned char val);
unsigned char systemToFileDMF(DivSystem val); static unsigned char systemToFileDMF(DivSystem val);
// benchmark (returns time in seconds) // benchmark (returns time in seconds)
double benchmarkPlayback(); double benchmarkPlayback();

View file

@ -23,6 +23,10 @@
#include "song.h" #include "song.h"
#include "../ta-log.h" #include "../ta-log.h"
DivSysDef* DivEngine::sysDefs[256];
DivSystem DivEngine::sysFileMapFur[256];
DivSystem DivEngine::sysFileMapDMF[256];
DivSystem DivEngine::systemFromFileFur(unsigned char val) { DivSystem DivEngine::systemFromFileFur(unsigned char val) {
return sysFileMapFur[val]; return sysFileMapFur[val];
} }

View file

@ -5655,7 +5655,6 @@ FurnaceGUI::FurnaceGUI():
curWindowLast(GUI_WINDOW_NOTHING), curWindowLast(GUI_WINDOW_NOTHING),
curWindowThreadSafe(GUI_WINDOW_NOTHING), curWindowThreadSafe(GUI_WINDOW_NOTHING),
lastPatternWidth(0.0f), lastPatternWidth(0.0f),
nextDesc(NULL),
latchNote(-1), latchNote(-1),
latchIns(-2), latchIns(-2),
latchVol(-1), latchVol(-1),

View file

@ -899,12 +899,25 @@ struct Gradient2D {
} }
}; };
struct FurnaceGUISysDefChip {
DivSystem sys;
int vol, pan;
const char* flags;
FurnaceGUISysDefChip(DivSystem s, int v, int p, const char* f):
sys(s),
vol(v),
pan(p),
flags(f) {}
};
struct FurnaceGUISysDef { struct FurnaceGUISysDef {
const char* name; const char* name;
std::vector<int> definition; String definition;
FurnaceGUISysDef(const char* n, std::initializer_list<int> def): FurnaceGUISysDef(const char* n, std::initializer_list<int> def):
name(n), definition(def) { name(n) {
// fuck it
} }
FurnaceGUISysDef(const char* n, std::initializer_list<FurnaceGUISysDefChip> def);
}; };
struct FurnaceGUISysCategory { struct FurnaceGUISysCategory {
@ -1404,7 +1417,7 @@ class FurnaceGUI {
float patChanX[DIV_MAX_CHANS+1]; float patChanX[DIV_MAX_CHANS+1];
float patChanSlideY[DIV_MAX_CHANS+1]; float patChanSlideY[DIV_MAX_CHANS+1];
float lastPatternWidth; float lastPatternWidth;
const int* nextDesc; String nextDesc;
String nextDescName; String nextDescName;
OperationMask opMaskDelete, opMaskPullDelete, opMaskInsert, opMaskPaste, opMaskTransposeNote, opMaskTransposeValue; OperationMask opMaskDelete, opMaskPullDelete, opMaskInsert, opMaskPaste, opMaskTransposeNote, opMaskTransposeValue;

View file

@ -107,7 +107,7 @@ void FurnaceGUI::drawNewSong() {
ImGui::TableNextRow(); ImGui::TableNextRow();
ImGui::TableNextColumn(); ImGui::TableNextColumn();
if (ImGui::Selectable(i.name,false,ImGuiSelectableFlags_DontClosePopups)) { if (ImGui::Selectable(i.name,false,ImGuiSelectableFlags_DontClosePopups)) {
nextDesc=i.definition.data(); nextDesc=i.definition;
nextDescName=i.name; nextDescName=i.name;
accepted=true; accepted=true;
} }
@ -129,7 +129,7 @@ void FurnaceGUI::drawNewSong() {
ImGui::CloseCurrentPopup(); ImGui::CloseCurrentPopup();
} else { } else {
unsigned int selection=rand()%newSystemCat->systems.size(); unsigned int selection=rand()%newSystemCat->systems.size();
nextDesc=newSystemCat->systems[selection].definition.data(); nextDesc=newSystemCat->systems[selection].definition;
nextDescName=newSystemCat->systems[selection].name; nextDescName=newSystemCat->systems[selection].name;
accepted=true; accepted=true;
} }
@ -143,16 +143,7 @@ void FurnaceGUI::drawNewSong() {
} }
if (accepted) { if (accepted) {
// TODO: remove after porting all presets to new format e->createNew(nextDesc.c_str(),nextDescName);
String oldDescFormat;
for (const int* i=nextDesc; *i; i+=4) {
oldDescFormat+=fmt::sprintf("%d ",e->systemToFileFur((DivSystem)i[0]));
oldDescFormat+=fmt::sprintf("%d ",i[1]);
oldDescFormat+=fmt::sprintf("%d ",i[2]);
oldDescFormat+=fmt::sprintf("%d ",i[3]);
}
String oldDesc=e->decodeSysDesc(oldDescFormat.c_str());
e->createNew(oldDesc.c_str(),nextDescName);
undoHist.clear(); undoHist.clear();
redoHist.clear(); redoHist.clear();
curFileName=""; curFileName="";

View file

@ -18,6 +18,7 @@
*/ */
#include "gui.h" #include "gui.h"
#include <fmt/printf.h>
// add system configurations here. // add system configurations here.
// every entry is written in the following format: // every entry is written in the following format:
@ -2323,3 +2324,24 @@ void FurnaceGUI::initSystemPresets() {
)); ));
sysCategories.push_back(cat); sysCategories.push_back(cat);
} }
FurnaceGUISysDef::FurnaceGUISysDef(const char* n, std::initializer_list<FurnaceGUISysDefChip> def):
name(n) {
std::vector<FurnaceGUISysDefChip> uncompiled=def;
int index=0;
for (FurnaceGUISysDefChip& i: uncompiled) {
definition+=fmt::sprintf(
"id%d=%d\nvol%d=%d\npan%d=%d\nflags%d=%s\n",
index,
DivEngine::systemToFileFur(i.sys),
index,
i.vol,
index,
i.pan,
index,
i.flags
);
index++;
}
}