GUI: implement instrument preview in file dialog

SADLY it's just for the built-in file dialog
but i'll think of a solution for the external one
This commit is contained in:
tildearrow 2022-04-25 18:58:17 -05:00
parent 663e724111
commit e8c9b645c5
38 changed files with 113 additions and 85 deletions

View file

@ -739,7 +739,9 @@ String DivEngine::getWarnings() {
}
DivInstrument* DivEngine::getIns(int index, DivInstrumentType fallbackType) {
if (index==-2 && tempIns!=NULL) return tempIns;
if (index==-2 && tempIns!=NULL) {
return tempIns;
}
if (index<0 || index>=song.insLen) {
switch (fallbackType) {
case DIV_INS_OPLL:
@ -2027,7 +2029,7 @@ void DivEngine::autoNoteOn(int ch, int ins, int note, int vol) {
}
do {
if ((ins<0 || ins>=song.insLen || getChannelType(finalChan)==4 || getPreferInsType(finalChan)==getIns(ins)->type || getIns(ins)->type==DIV_INS_AMIGA) && chan[finalChan].midiNote==-1) {
if ((ins==-1 || ins>=song.insLen || getChannelType(finalChan)==4 || getPreferInsType(finalChan)==getIns(ins)->type || getIns(ins)->type==DIV_INS_AMIGA) && chan[finalChan].midiNote==-1) {
chan[finalChan].midiNote=note;
pendingNotes.push(DivNoteEvent(finalChan,ins,note,vol,true));
break;

View file

@ -34,7 +34,7 @@ class DivPlatformAmiga: public DivDispatch {
int audSub;
signed char audDat;
int sample, wave;
unsigned char ins;
int ins;
int busClock;
int note;
bool active, insChanged, freqChanged, keyOn, keyOff, inPorta, useWave, setPos, useV, useP;

View file

@ -37,7 +37,7 @@ class DivPlatformArcade: public DivDispatch {
DivMacroInt std;
unsigned char freqH, freqL;
int freq, baseFreq, pitch, note;
unsigned char ins;
int ins;
signed char konCycles;
bool active, insChanged, freqChanged, keyOn, keyOff, inPorta, portaPause, furnacePCM, hardReset;
int vol, outVol;

View file

@ -33,7 +33,8 @@ class DivPlatformAY8910: public DivDispatch {
struct Channel {
unsigned char freqH, freqL;
int freq, baseFreq, note, pitch;
unsigned char ins, psgMode, autoEnvNum, autoEnvDen;
int ins;
unsigned char psgMode, autoEnvNum, autoEnvDen;
signed char konCycles;
bool active, insChanged, freqChanged, keyOn, keyOff, portaPause, inPorta;
int vol, outVol;

View file

@ -29,7 +29,8 @@ class DivPlatformAY8930: public DivDispatch {
struct Channel {
unsigned char freqH, freqL;
int freq, baseFreq, note, pitch;
unsigned char ins, psgMode, autoEnvNum, autoEnvDen, duty;
int ins;
unsigned char psgMode, autoEnvNum, autoEnvDen, duty;
signed char konCycles;
bool active, insChanged, freqChanged, keyOn, keyOff, portaPause, inPorta;
int vol, outVol;

View file

@ -28,8 +28,7 @@
class DivPlatformBubSysWSG: public DivDispatch {
struct Channel {
int freq, baseFreq, pitch, note;
unsigned char ins;
int freq, baseFreq, pitch, note, ins;
bool active, insChanged, freqChanged, keyOn, keyOff, inPorta;
signed char vol, outVol, wave;
signed char waveROM[32] = {0}; // 4 bit PROM per channel on bubble system

View file

@ -26,8 +26,8 @@
class DivPlatformC64: public DivDispatch {
struct Channel {
int freq, baseFreq, pitch, prevFreq, testWhen, note;
unsigned char ins, sweep, wave, attack, decay, sustain, release;
int freq, baseFreq, pitch, prevFreq, testWhen, note, ins;
unsigned char sweep, wave, attack, decay, sustain, release;
short duty;
bool active, insChanged, freqChanged, sweepChanged, keyOn, keyOff, inPorta, filter;
bool resetMask, resetFilter, resetDuty, ring, sync;

View file

@ -26,8 +26,8 @@
class DivPlatformFDS: public DivDispatch {
struct Channel {
int freq, baseFreq, pitch, prevFreq, note, modFreq;
unsigned char ins, duty, sweep, modDepth, modPos;
int freq, baseFreq, pitch, prevFreq, note, modFreq, ins;
unsigned char duty, sweep, modDepth, modPos;
bool active, insChanged, freqChanged, sweepChanged, keyOn, keyOff, inPorta, modOn;
signed char vol, outVol, wave;
signed char modTable[32];

View file

@ -27,8 +27,8 @@
class DivPlatformGB: public DivDispatch {
struct Channel {
int freq, baseFreq, pitch, note;
unsigned char ins, duty, sweep;
int freq, baseFreq, pitch, note, ins;
unsigned char duty, sweep;
bool active, insChanged, freqChanged, sweepChanged, keyOn, keyOff, inPorta;
signed char vol, outVol, wave;
DivMacroInt std;

View file

@ -37,7 +37,7 @@ class DivPlatformGenesis: public DivDispatch {
DivMacroInt std;
unsigned char freqH, freqL;
int freq, baseFreq, pitch, portaPauseFreq, note;
unsigned char ins;
int ins;
bool active, insChanged, freqChanged, keyOn, keyOff, portaPause, furnaceDac, inPorta, hardReset;
int vol, outVol;
unsigned char pan;

View file

@ -25,8 +25,7 @@ class DivPlatformGenesisExt: public DivPlatformGenesis {
struct OpChannel {
DivMacroInt std;
unsigned char freqH, freqL;
int freq, baseFreq, pitch, portaPauseFreq;
unsigned char ins;
int freq, baseFreq, pitch, portaPauseFreq, ins;
signed char konCycles;
bool active, insChanged, freqChanged, keyOn, keyOff, portaPause;
int vol;

View file

@ -44,8 +44,8 @@ class DivPlatformLynx: public DivDispatch {
DivMacroInt std;
MikeyFreqDiv fd;
MikeyDuty duty;
int baseFreq, pitch, note, actualNote, lfsr;
unsigned char ins, pan;
int baseFreq, pitch, note, actualNote, lfsr, ins;
unsigned char pan;
bool active, insChanged, freqChanged, keyOn, keyOff, inPorta;
signed char vol, outVol;
Channel():

View file

@ -25,8 +25,8 @@
class DivPlatformMMC5: public DivDispatch {
struct Channel {
int freq, baseFreq, pitch, prevFreq, note;
unsigned char ins, duty, sweep;
int freq, baseFreq, pitch, prevFreq, note, ins;
unsigned char duty, sweep;
bool active, insChanged, freqChanged, sweepChanged, keyOn, keyOff, inPorta, furnaceDac;
signed char vol, outVol, wave;
DivMacroInt std;

View file

@ -25,8 +25,8 @@
class DivPlatformNES: public DivDispatch {
struct Channel {
int freq, baseFreq, pitch, prevFreq, note;
unsigned char ins, duty, sweep;
int freq, baseFreq, pitch, prevFreq, note, ins;
unsigned char duty, sweep;
bool active, insChanged, freqChanged, sweepChanged, keyOn, keyOff, inPorta, furnaceDac;
signed char vol, outVol, wave;
DivMacroInt std;

View file

@ -30,8 +30,7 @@ class DivPlatformOPL: public DivDispatch {
DivInstrumentFM state;
DivMacroInt std;
unsigned char freqH, freqL;
int freq, baseFreq, pitch, note;
unsigned char ins;
int freq, baseFreq, pitch, note, ins;
bool active, insChanged, freqChanged, keyOn, keyOff, portaPause, furnaceDac, inPorta, fourOp;
int vol, outVol;
unsigned char pan;

View file

@ -33,8 +33,7 @@ class DivPlatformOPLL: public DivDispatch {
DivInstrumentFM state;
DivMacroInt std;
unsigned char freqH, freqL;
int freq, baseFreq, pitch, note;
unsigned char ins;
int freq, baseFreq, pitch, note, ins;
bool active, insChanged, freqChanged, keyOn, keyOff, portaPause, furnaceDac, inPorta;
int vol, outVol;
unsigned char pan;

View file

@ -31,8 +31,8 @@ class DivPlatformPCE: public DivDispatch {
int freq, baseFreq, pitch, note;
int dacPeriod, dacRate;
unsigned int dacPos;
int dacSample;
unsigned char ins, pan;
int dacSample, ins;
unsigned char pan;
bool active, insChanged, freqChanged, keyOn, keyOff, inPorta, noise, pcm, furnaceDac;
signed char vol, outVol, wave;
DivMacroInt std;

View file

@ -25,8 +25,8 @@
class DivPlatformPCSpeaker: public DivDispatch {
struct Channel {
int freq, baseFreq, pitch, note;
unsigned char ins, duty, sweep;
int freq, baseFreq, pitch, note, ins;
unsigned char duty, sweep;
bool active, insChanged, freqChanged, sweepChanged, keyOn, keyOff, inPorta, furnaceDac;
signed char vol, outVol, wave;
DivMacroInt std;

View file

@ -25,8 +25,7 @@
class DivPlatformPET: public DivDispatch {
struct Channel {
int freq, baseFreq, pitch, note;
unsigned char ins;
int freq, baseFreq, pitch, note, ins;
bool active, insChanged, freqChanged, keyOn, keyOff, inPorta;
int vol, outVol, wave;
unsigned char sreg;

View file

@ -30,8 +30,7 @@ class DivPlatformQSound: public DivDispatch {
int freq, baseFreq, pitch;
unsigned short audLen;
unsigned int audPos;
int sample, wave;
unsigned char ins;
int sample, wave, ins;
int note;
int panning;
bool active, insChanged, freqChanged, keyOn, keyOff, inPorta, useWave;

View file

@ -35,8 +35,8 @@ class DivPlatformSAA1099: public DivDispatch {
protected:
struct Channel {
unsigned char freqH, freqL;
int freq, baseFreq, pitch, note;
unsigned char ins, psgMode;
int freq, baseFreq, pitch, note, ins;
unsigned char psgMode;
signed char konCycles;
bool active, insChanged, freqChanged, keyOn, keyOff, portaPause, inPorta;
int vol, outVol;

View file

@ -29,8 +29,7 @@ class DivPlatformSegaPCM: public DivDispatch {
struct Channel {
DivMacroInt std;
unsigned char freqH, freqL;
int freq, baseFreq, pitch, note;
unsigned char ins;
int freq, baseFreq, pitch, note, ins;
signed char konCycles;
bool active, insChanged, freqChanged, keyOn, keyOff, inPorta, portaPause, furnacePCM;
int vol, outVol;

View file

@ -26,8 +26,7 @@
class DivPlatformSMS: public DivDispatch {
struct Channel {
int freq, baseFreq, pitch, note, actualNote;
unsigned char ins;
int freq, baseFreq, pitch, note, actualNote, ins;
bool active, insChanged, freqChanged, keyOn, keyOff, inPorta;
signed char vol, outVol;
DivMacroInt std;

View file

@ -28,8 +28,8 @@
class DivPlatformSwan: public DivDispatch {
struct Channel {
int freq, baseFreq, pitch, note;
unsigned char ins, pan;
int freq, baseFreq, pitch, note, ins;
unsigned char pan;
bool active, insChanged, freqChanged, keyOn, keyOff, inPorta;
int vol, outVol, wave;
DivMacroInt std;

View file

@ -27,8 +27,8 @@
class DivPlatformTIA: public DivDispatch {
protected:
struct Channel {
int freq, baseFreq, pitch, note;
unsigned char ins, shape;
int freq, baseFreq, pitch, note, ins;
unsigned char shape;
signed char konCycles;
bool active, insChanged, freqChanged, keyOn, keyOff, portaPause, inPorta;
int vol, outVol;

View file

@ -35,8 +35,7 @@ class DivPlatformTX81Z: public DivDispatch {
DivInstrumentFM state;
DivMacroInt std;
unsigned char freqH, freqL;
int freq, baseFreq, pitch, note;
unsigned char ins;
int freq, baseFreq, pitch, note, ins;
signed char konCycles;
bool active, insChanged, freqChanged, keyOn, keyOff, inPorta, portaPause, furnacePCM, hardReset;
int vol, outVol;

View file

@ -29,8 +29,8 @@ struct VERA_PCM;
class DivPlatformVERA: public DivDispatch {
protected:
struct Channel {
int freq, baseFreq, pitch, note;
unsigned char ins, pan;
int freq, baseFreq, pitch, note, ins;
unsigned char pan;
bool active, freqChanged, inPorta;
int vol, outVol;
unsigned accum;

View file

@ -27,8 +27,8 @@
class DivPlatformVIC20: public DivDispatch {
struct Channel {
int freq, baseFreq, pitch, note;
unsigned char ins, pan;
int freq, baseFreq, pitch, note, ins;
unsigned char pan;
bool active, insChanged, freqChanged, keyOn, keyOff, inPorta;
int vol, outVol, wave, waveWriteCycle;
DivMacroInt std;

View file

@ -31,8 +31,8 @@ class DivPlatformVRC6: public DivDispatch {
int freq, baseFreq, pitch, note;
int dacPeriod, dacRate, dacOut;
unsigned int dacPos;
int dacSample;
unsigned char ins, duty;
int dacSample, ins;
unsigned char duty;
bool active, insChanged, freqChanged, keyOn, keyOff, inPorta, pcm, furnaceDac;
signed char vol, outVol;
DivMacroInt std;

View file

@ -43,8 +43,8 @@ class DivPlatformYM2610: public DivDispatch {
struct Channel {
DivInstrumentFM state;
unsigned char freqH, freqL;
int freq, baseFreq, pitch, note;
unsigned char ins, psgMode, autoEnvNum, autoEnvDen;
int freq, baseFreq, pitch, note, ins;
unsigned char psgMode, autoEnvNum, autoEnvDen;
signed char konCycles;
bool active, insChanged, freqChanged, keyOn, keyOff, portaPause, inPorta, furnacePCM, hardReset;
int vol, outVol;

View file

@ -35,8 +35,8 @@ class DivPlatformYM2610B: public DivDispatch {
struct Channel {
DivInstrumentFM state;
unsigned char freqH, freqL;
int freq, baseFreq, pitch, note;
unsigned char ins, psgMode, autoEnvNum, autoEnvDen;
int freq, baseFreq, pitch, note, ins;
unsigned char psgMode, autoEnvNum, autoEnvDen;
signed char konCycles;
bool active, insChanged, freqChanged, keyOn, keyOff, portaPause, inPorta, furnacePCM, hardReset;
int vol, outVol;

View file

@ -25,8 +25,7 @@ class DivPlatformYM2610BExt: public DivPlatformYM2610B {
struct OpChannel {
DivMacroInt std;
unsigned char freqH, freqL;
int freq, baseFreq, pitch;
unsigned char ins;
int freq, baseFreq, pitch, ins;
signed char konCycles;
bool active, insChanged, freqChanged, keyOn, keyOff, portaPause;
int vol;

View file

@ -25,8 +25,7 @@ class DivPlatformYM2610Ext: public DivPlatformYM2610 {
struct OpChannel {
DivMacroInt std;
unsigned char freqH, freqL;
int freq, baseFreq, pitch;
unsigned char ins;
int freq, baseFreq, pitch, ins;
signed char konCycles;
bool active, insChanged, freqChanged, keyOn, keyOff, portaPause;
int vol;

View file

@ -4,7 +4,7 @@
#include "../../extern/pfd-fixed/portable-file-dialogs.h"
bool FurnaceGUIFileDialog::openLoad(String header, std::vector<String> filter, const char* noSysFilter, String path, double dpiScale) {
bool FurnaceGUIFileDialog::openLoad(String header, std::vector<String> filter, const char* noSysFilter, String path, double dpiScale, FileDialogSelectCallback clickCallback) {
if (opened) return false;
saving=false;
curPath=path;
@ -13,7 +13,7 @@ bool FurnaceGUIFileDialog::openLoad(String header, std::vector<String> filter, c
dialogO=new pfd::open_file(header,path,filter);
} else {
ImGuiFileDialog::Instance()->DpiScale=dpiScale;
ImGuiFileDialog::Instance()->OpenModal("FileDialog",header,noSysFilter,path);
ImGuiFileDialog::Instance()->OpenModal("FileDialog",header,noSysFilter,path,1,nullptr,0,clickCallback);
}
opened=true;
return true;

View file

@ -7,6 +7,8 @@ namespace pfd {
class save_file;
}
typedef std::function<void(const char*)> FileDialogSelectCallback;
class FurnaceGUIFileDialog {
bool sysDialog;
bool opened;
@ -16,7 +18,7 @@ class FurnaceGUIFileDialog {
pfd::open_file* dialogO;
pfd::save_file* dialogS;
public:
bool openLoad(String header, std::vector<String> filter, const char* noSysFilter, String path, double dpiScale);
bool openLoad(String header, std::vector<String> filter, const char* noSysFilter, String path, double dpiScale, FileDialogSelectCallback clickCallback=NULL);
bool openSave(String header, std::vector<String> filter, const char* noSysFilter, String path, double dpiScale);
bool accepted();
void close();

View file

@ -1293,7 +1293,15 @@ void FurnaceGUI::openFileDialog(FurnaceGUIFileDialogs type) {
"all files", ".*"},
"compatible files{.fui,.dmp,.tfi,.vgi,.s3i,.sbi,.opli,.opni,.y12,.bnk,.ff,.opm},.*",
workingDirIns,
dpiScale
dpiScale,
[this](const char* path) {
std::vector<DivInstrument*> instruments=e->instrumentFromFile(path);
if (!instruments.empty()) {
e->loadTempIns(instruments[0]);
curIns=-2;
}
for (DivInstrument* i: instruments) delete i;
}
);
break;
case GUI_FILE_INS_SAVE: