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

View File

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

View File

@ -5655,7 +5655,6 @@ FurnaceGUI::FurnaceGUI():
curWindowLast(GUI_WINDOW_NOTHING),
curWindowThreadSafe(GUI_WINDOW_NOTHING),
lastPatternWidth(0.0f),
nextDesc(NULL),
latchNote(-1),
latchIns(-2),
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 {
const char* name;
std::vector<int> definition;
String definition;
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 {
@ -1404,7 +1417,7 @@ class FurnaceGUI {
float patChanX[DIV_MAX_CHANS+1];
float patChanSlideY[DIV_MAX_CHANS+1];
float lastPatternWidth;
const int* nextDesc;
String nextDesc;
String nextDescName;
OperationMask opMaskDelete, opMaskPullDelete, opMaskInsert, opMaskPaste, opMaskTransposeNote, opMaskTransposeValue;

View File

@ -107,7 +107,7 @@ void FurnaceGUI::drawNewSong() {
ImGui::TableNextRow();
ImGui::TableNextColumn();
if (ImGui::Selectable(i.name,false,ImGuiSelectableFlags_DontClosePopups)) {
nextDesc=i.definition.data();
nextDesc=i.definition;
nextDescName=i.name;
accepted=true;
}
@ -129,7 +129,7 @@ void FurnaceGUI::drawNewSong() {
ImGui::CloseCurrentPopup();
} else {
unsigned int selection=rand()%newSystemCat->systems.size();
nextDesc=newSystemCat->systems[selection].definition.data();
nextDesc=newSystemCat->systems[selection].definition;
nextDescName=newSystemCat->systems[selection].name;
accepted=true;
}
@ -143,16 +143,7 @@ void FurnaceGUI::drawNewSong() {
}
if (accepted) {
// TODO: remove after porting all presets to new format
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);
e->createNew(nextDesc.c_str(),nextDescName);
undoHist.clear();
redoHist.clear();
curFileName="";

View File

@ -18,6 +18,7 @@
*/
#include "gui.h"
#include <fmt/printf.h>
// add system configurations here.
// every entry is written in the following format:
@ -2323,3 +2324,24 @@ void FurnaceGUI::initSystemPresets() {
));
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++;
}
}