add several warning dialogs

This commit is contained in:
tildearrow 2022-01-29 01:22:32 -05:00
parent e9accf16db
commit 5dafd10fc7
4 changed files with 70 additions and 5 deletions

View File

@ -1,4 +1,5 @@
#include "dataErrors.h"
#include "song.h"
#include <cstdint>
#define _USE_MATH_DEFINES
#include "engine.h"
@ -755,8 +756,16 @@ const char* DivEngine::getEffectDesc(unsigned char effect, int chan) {
return "Invalid effect";
}
#define addWarning(x) \
if (warnings.empty()) { \
warnings+=x; \
} else { \
warnings+=("\n" x); \
}
bool DivEngine::loadDMF(unsigned char* file, size_t len) {
SafeReader reader=SafeReader(file,len);
warnings="";
try {
DivSong ds;
@ -895,6 +904,7 @@ bool DivEngine::loadDMF(unsigned char* file, size_t len) {
}
ds.customTempo=true;
ds.timeBase=0;
addWarning("Yamaha YMU759 emulation is not currently possible!");
}
logI("reading pattern matrix (%d)...\n",ds.ordersLen);
@ -1146,6 +1156,7 @@ bool DivEngine::loadDMF(unsigned char* file, size_t len) {
ins->gb.soundLen=ins->std.volMacroLen*2;
}
}
addWarning("Game Boy volume macros converted to envelopes. may not be perfect!");
}
}
@ -1329,6 +1340,7 @@ bool DivEngine::loadFur(unsigned char* file, size_t len) {
char magic[5];
memset(magic,0,5);
SafeReader reader=SafeReader(file,len);
warnings="";
try {
DivSong ds;
@ -1343,6 +1355,7 @@ bool DivEngine::loadFur(unsigned char* file, size_t len) {
if (ds.version>DIV_ENGINE_VERSION) {
logW("this module was created with a more recent version of Furnace!\n");
addWarning("this module was created with a more recent version of Furnace!");
}
reader.readS(); // reserved
@ -1678,6 +1691,7 @@ SafeWriter* DivEngine::saveFur() {
int samplePtr[256];
std::vector<int> patPtr;
size_t ptrSeek;
warnings="";
SafeWriter* w=new SafeWriter;
w->init();
@ -1891,6 +1905,7 @@ SafeWriter* DivEngine::saveDMF() {
lastError="this system is not possible on .dmf";
return NULL;
}
warnings="";
SafeWriter* w=new SafeWriter;
w->init();
@ -1924,6 +1939,25 @@ SafeWriter* DivEngine::saveDMF() {
}
}
if (song.system[0]==DIV_SYSTEM_C64_6581 || song.system[0]==DIV_SYSTEM_C64_8580) {
addWarning("absolute duty/cutoff macro not available in .dmf!");
addWarning("duty precision will be lost");
}
for (DivInstrument* i: song.ins) {
if (i->type==DIV_INS_AMIGA) {
addWarning(".dmf format does not support arbitrary-pitch sample mode");
break;
}
}
for (DivInstrument* i: song.ins) {
if (i->type==DIV_INS_FM) {
addWarning("no FM macros in .dmf format");
break;
}
}
w->writeC(song.ins.size());
for (DivInstrument* i: song.ins) {
w->writeString(i->name,true);
@ -2051,6 +2085,10 @@ SafeWriter* DivEngine::saveDMF() {
}
}
if (song.sample.size()>0) {
addWarning("samples' rates will be rounded to nearest compatible value");
}
w->writeC(song.sample.size());
for (DivSample* i: song.sample) {
w->writeI(i->length);
@ -3870,6 +3908,10 @@ String DivEngine::getLastError() {
return lastError;
}
String DivEngine::getWarnings() {
return warnings;
}
DivInstrument* DivEngine::getIns(int index) {
if (index<0 || index>=song.insLen) return &song.nullIns;
return song.ins[index];
@ -4254,6 +4296,7 @@ int DivEngine::addInstrument(int refChan) {
}
bool DivEngine::addInstrumentFromFile(const char *path) {
warnings="";
FILE* f=ps_fopen(path,"rb");
if (f==NULL) {
return false;
@ -4304,6 +4347,10 @@ bool DivEngine::addInstrumentFromFile(const char *path) {
short version=reader.readS();
reader.readS(); // reserved
if (version>DIV_ENGINE_VERSION) {
warnings="this instrument is made with a more recent version of Furnace!";
}
unsigned int dataPtr=reader.readI();
reader.seek(dataPtr,SEEK_SET);

View File

@ -154,6 +154,7 @@ class DivEngine {
String configPath;
String configFile;
String lastError;
String warnings;
struct SamplePreview {
int sample;
@ -495,6 +496,9 @@ class DivEngine {
// get last error
String getLastError();
// get warnings
String getWarnings();
// switch master
void switchMaster();

View File

@ -4170,6 +4170,9 @@ int FurnaceGUI::save(String path) {
w->finish();
curFileName=path;
modified=false;
if (!e->getWarnings().empty()) {
showWarning(e->getWarnings(),GUI_WARN_GENERIC);
}
return 0;
}
@ -4240,6 +4243,9 @@ int FurnaceGUI::load(String path) {
undoHist.clear();
redoHist.clear();
updateWindowTitle();
if (!e->getWarnings().empty()) {
showWarning(e->getWarnings(),GUI_WARN_GENERIC);
}
return 0;
}
@ -4892,6 +4898,9 @@ bool FurnaceGUI::loop() {
break;
case GUI_FILE_INS_OPEN:
e->addInstrumentFromFile(copyOfName.c_str());
if (!e->getWarnings().empty()) {
showWarning(e->getWarnings(),GUI_WARN_GENERIC);
}
break;
case GUI_FILE_WAVE_OPEN:
e->addWaveFromFile(copyOfName.c_str());
@ -4970,7 +4979,7 @@ bool FurnaceGUI::loop() {
if (ImGui::BeginPopupModal("Warning",NULL,ImGuiWindowFlags_AlwaysAutoResize)) {
ImGui::Text("%s",warnString.c_str());
if (ImGui::Button("Yes")) {
if (ImGui::Button(warnAction==GUI_WARN_GENERIC?"OK":"Yes")) {
ImGui::CloseCurrentPopup();
switch (warnAction) {
case GUI_WARN_QUIT:
@ -4993,11 +5002,15 @@ bool FurnaceGUI::loop() {
case GUI_WARN_OPEN:
openFileDialog(GUI_FILE_OPEN);
break;
case GUI_WARN_GENERIC:
break;
}
}
ImGui::SameLine();
if (ImGui::Button("No")) {
ImGui::CloseCurrentPopup();
if (warnAction==GUI_WARN_GENERIC) {
ImGui::SameLine();
if (ImGui::Button("No")) {
ImGui::CloseCurrentPopup();
}
}
ImGui::EndPopup();
}

View File

@ -102,7 +102,8 @@ enum FurnaceGUIFileDialogs {
enum FurnaceGUIWarnings {
GUI_WARN_QUIT,
GUI_WARN_NEW,
GUI_WARN_OPEN
GUI_WARN_OPEN,
GUI_WARN_GENERIC
};
struct SelectionPoint {