convert presets to new format, part 1
This commit is contained in:
parent
fbacfd421c
commit
d422372b7f
|
@ -308,6 +308,7 @@ endif()
|
|||
|
||||
set(ENGINE_SOURCES
|
||||
src/log.cpp
|
||||
src/baseutils.cpp
|
||||
src/fileutils.cpp
|
||||
src/utfutils.cpp
|
||||
|
||||
|
|
|
@ -0,0 +1,89 @@
|
|||
/**
|
||||
* Furnace Tracker - multi-system chiptune tracker
|
||||
* Copyright (C) 2021-2022 tildearrow and contributors
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "baseutils.h"
|
||||
#include <string.h>
|
||||
|
||||
const char* base64Table="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
|
||||
std::string taEncodeBase64(const std::string& data) {
|
||||
std::string ret;
|
||||
|
||||
ret.reserve((2+data.size()*4)/3);
|
||||
|
||||
unsigned int groupOfThree=0;
|
||||
unsigned char pos=0;
|
||||
for (const char& i: data) {
|
||||
groupOfThree|=((unsigned char)i)<<((2-pos)<<3);
|
||||
if (++pos>=3) {
|
||||
pos=0;
|
||||
ret+=base64Table[(groupOfThree>>18)&63];
|
||||
ret+=base64Table[(groupOfThree>>12)&63];
|
||||
ret+=base64Table[(groupOfThree>>6)&63];
|
||||
ret+=base64Table[groupOfThree&63];
|
||||
groupOfThree=0;
|
||||
}
|
||||
}
|
||||
if (pos==2) {
|
||||
ret+=base64Table[(groupOfThree>>18)&63];
|
||||
ret+=base64Table[(groupOfThree>>12)&63];
|
||||
ret+=base64Table[(groupOfThree>>6)&63];
|
||||
ret+='=';
|
||||
} else if (pos==1) {
|
||||
ret+=base64Table[(groupOfThree>>18)&63];
|
||||
ret+=base64Table[(groupOfThree>>12)&63];
|
||||
ret+="==";
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string taDecodeBase64(const char* buf) {
|
||||
std::string data;
|
||||
|
||||
unsigned int groupOfThree=0;
|
||||
signed char pos=18;
|
||||
for (const char* i=buf; *i; i++) {
|
||||
unsigned char nextVal=0;
|
||||
if ((*i)=='/') {
|
||||
nextVal=63;
|
||||
} else if ((*i)=='+') {
|
||||
nextVal=62;
|
||||
} else if ((*i)>='0' && (*i)<='9') {
|
||||
nextVal=52+((*i)-'0');
|
||||
} else if ((*i)>='a' && (*i)<='z') {
|
||||
nextVal=26+((*i)-'a');
|
||||
} else if ((*i)>='A' && (*i)<='Z') {
|
||||
nextVal=((*i)-'A');
|
||||
} else {
|
||||
nextVal=0;
|
||||
}
|
||||
groupOfThree|=nextVal<<pos;
|
||||
pos-=6;
|
||||
if (pos<0) {
|
||||
pos=18;
|
||||
if ((groupOfThree>>16)&0xff) data+=(groupOfThree>>16)&0xff;
|
||||
if ((groupOfThree>>8)&0xff) data+=(groupOfThree>>8)&0xff;
|
||||
if (groupOfThree&0xff) data+=groupOfThree&0xff;
|
||||
groupOfThree=0;
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
/**
|
||||
* Furnace Tracker - multi-system chiptune tracker
|
||||
* Copyright (C) 2021-2022 tildearrow and contributors
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#ifndef _BASEUTILS_H
|
||||
#define _BASEUTILS_H
|
||||
|
||||
#include <string>
|
||||
|
||||
std::string taEncodeBase64(const std::string& data);
|
||||
std::string taDecodeBase64(const char* str);
|
||||
|
||||
#endif
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
#include "config.h"
|
||||
#include "../ta-log.h"
|
||||
#include "../baseutils.h"
|
||||
#include "../fileutils.h"
|
||||
#include <fmt/printf.h>
|
||||
|
||||
|
@ -48,41 +49,9 @@ String DivConfig::toString() {
|
|||
return ret;
|
||||
}
|
||||
|
||||
const char* base64Table="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
|
||||
String DivConfig::toBase64() {
|
||||
String data=toString();
|
||||
String ret;
|
||||
|
||||
ret.reserve((2+data.size()*4)/3);
|
||||
|
||||
unsigned int groupOfThree=0;
|
||||
unsigned char pos=0;
|
||||
for (char& i: data) {
|
||||
groupOfThree|=((unsigned char)i)<<((2-pos)<<3);
|
||||
if (++pos>=3) {
|
||||
pos=0;
|
||||
ret+=base64Table[(groupOfThree>>18)&63];
|
||||
ret+=base64Table[(groupOfThree>>12)&63];
|
||||
ret+=base64Table[(groupOfThree>>6)&63];
|
||||
ret+=base64Table[groupOfThree&63];
|
||||
groupOfThree=0;
|
||||
}
|
||||
}
|
||||
if (pos==2) {
|
||||
ret+=base64Table[(groupOfThree>>18)&63];
|
||||
ret+=base64Table[(groupOfThree>>12)&63];
|
||||
ret+=base64Table[(groupOfThree>>6)&63];
|
||||
ret+='=';
|
||||
} else if (pos==1) {
|
||||
ret+=base64Table[(groupOfThree>>18)&63];
|
||||
ret+=base64Table[(groupOfThree>>12)&63];
|
||||
ret+="==";
|
||||
}
|
||||
|
||||
logV("toBase64: %s",ret);
|
||||
|
||||
return ret;
|
||||
return taEncodeBase64(data);
|
||||
}
|
||||
|
||||
void DivConfig::parseLine(const char* line) {
|
||||
|
@ -143,38 +112,7 @@ bool DivConfig::loadFromMemory(const char* buf) {
|
|||
}
|
||||
|
||||
bool DivConfig::loadFromBase64(const char* buf) {
|
||||
String data;
|
||||
|
||||
unsigned int groupOfThree=0;
|
||||
signed char pos=18;
|
||||
for (const char* i=buf; *i; i++) {
|
||||
unsigned char nextVal=0;
|
||||
if ((*i)=='/') {
|
||||
nextVal=63;
|
||||
} else if ((*i)=='+') {
|
||||
nextVal=62;
|
||||
} else if ((*i)>='0' && (*i)<='9') {
|
||||
nextVal=52+((*i)-'0');
|
||||
} else if ((*i)>='a' && (*i)<='z') {
|
||||
nextVal=26+((*i)-'a');
|
||||
} else if ((*i)>='A' && (*i)<='Z') {
|
||||
nextVal=((*i)-'A');
|
||||
} else {
|
||||
nextVal=0;
|
||||
}
|
||||
groupOfThree|=nextVal<<pos;
|
||||
pos-=6;
|
||||
if (pos<0) {
|
||||
pos=18;
|
||||
if ((groupOfThree>>16)&0xff) data+=(groupOfThree>>16)&0xff;
|
||||
if ((groupOfThree>>8)&0xff) data+=(groupOfThree>>8)&0xff;
|
||||
if (groupOfThree&0xff) data+=groupOfThree&0xff;
|
||||
groupOfThree=0;
|
||||
}
|
||||
}
|
||||
|
||||
logV("fromBase64: %s",data);
|
||||
|
||||
String data=taDecodeBase64(buf);
|
||||
return loadFromMemory(data.c_str());
|
||||
}
|
||||
|
||||
|
|
|
@ -440,8 +440,6 @@ class DivEngine {
|
|||
void reset();
|
||||
void playSub(bool preserveDrift, int goalRow=0);
|
||||
|
||||
void convertOldFlags(unsigned int oldFlags, DivConfig& newFlags, DivSystem sys);
|
||||
|
||||
bool loadDMF(unsigned char* file, size_t len);
|
||||
bool loadFur(unsigned char* file, size_t len);
|
||||
bool loadMod(unsigned char* file, size_t len);
|
||||
|
@ -537,6 +535,10 @@ class DivEngine {
|
|||
static DivSystem systemFromFileDMF(unsigned char val);
|
||||
static unsigned char systemToFileDMF(DivSystem val);
|
||||
|
||||
// convert old flags
|
||||
static void convertOldFlags(unsigned int oldFlags, DivConfig& newFlags, DivSystem sys);
|
||||
|
||||
|
||||
// benchmark (returns time in seconds)
|
||||
double benchmarkPlayback();
|
||||
double benchmarkSeek();
|
||||
|
|
|
@ -913,10 +913,7 @@ struct FurnaceGUISysDefChip {
|
|||
struct FurnaceGUISysDef {
|
||||
const char* name;
|
||||
String definition;
|
||||
FurnaceGUISysDef(const char* n, std::initializer_list<int> def):
|
||||
name(n) {
|
||||
// fuck it
|
||||
}
|
||||
FurnaceGUISysDef(const char* n, std::initializer_list<int> def);
|
||||
FurnaceGUISysDef(const char* n, std::initializer_list<FurnaceGUISysDefChip> def);
|
||||
};
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
*/
|
||||
|
||||
#include "gui.h"
|
||||
#include "../baseutils.h"
|
||||
#include <fmt/printf.h>
|
||||
|
||||
// add system configurations here.
|
||||
|
@ -2325,6 +2326,32 @@ void FurnaceGUI::initSystemPresets() {
|
|||
sysCategories.push_back(cat);
|
||||
}
|
||||
|
||||
FurnaceGUISysDef::FurnaceGUISysDef(const char* n, std::initializer_list<int> def):
|
||||
name(n) {
|
||||
std::vector<int> uncompiled=def;
|
||||
int index=0;
|
||||
|
||||
for (size_t i=0; i<uncompiled.size(); i+=4) {
|
||||
if (uncompiled[i]==0) break;
|
||||
|
||||
DivConfig oldFlags;
|
||||
DivEngine::convertOldFlags(uncompiled[3],oldFlags,(DivSystem)uncompiled[0]);
|
||||
|
||||
definition+=fmt::sprintf(
|
||||
"id%d=%d\nvol%d=%d\npan%d=%d\nflags%d=%s\n",
|
||||
index,
|
||||
DivEngine::systemToFileFur((DivSystem)uncompiled[0]),
|
||||
index,
|
||||
uncompiled[1],
|
||||
index,
|
||||
uncompiled[2],
|
||||
index,
|
||||
oldFlags.toBase64()
|
||||
);
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
FurnaceGUISysDef::FurnaceGUISysDef(const char* n, std::initializer_list<FurnaceGUISysDefChip> def):
|
||||
name(n) {
|
||||
std::vector<FurnaceGUISysDefChip> uncompiled=def;
|
||||
|
@ -2339,9 +2366,8 @@ FurnaceGUISysDef::FurnaceGUISysDef(const char* n, std::initializer_list<FurnaceG
|
|||
index,
|
||||
i.pan,
|
||||
index,
|
||||
i.flags
|
||||
taEncodeBase64(i.flags)
|
||||
);
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue