add wavetable saving

This commit is contained in:
tildearrow 2022-01-19 05:10:06 -05:00
parent 7c40948680
commit 62a499644f
4 changed files with 62 additions and 22 deletions

View file

@ -128,6 +128,7 @@ src/engine/pattern.cpp
src/engine/playback.cpp
src/engine/sample.cpp
src/engine/song.cpp
src/engine/wavetable.cpp
src/engine/platform/abstract.cpp
src/engine/platform/genesis.cpp
src/engine/platform/genesisext.cpp

View file

@ -1719,16 +1719,7 @@ SafeWriter* DivEngine::saveFur() {
for (int i=0; i<song.waveLen; i++) {
DivWavetable* wave=song.wave[i];
wavePtr[i]=w->tell();
w->write("WAVE",4);
w->writeI(0);
w->writeC(0); // name
w->writeI(wave->len);
w->writeI(wave->min);
w->writeI(wave->max);
for (int j=0; j<wave->len; j++) {
w->writeI(wave->data[j]);
}
wave->putWaveData(w);
}
/// SAMPLE

View file

@ -1,3 +1,45 @@
#include "engine.h"
#include "wavetable.h"
#include "../ta-log.h"
// ???
void DivWavetable::putWaveData(SafeWriter* w) {
w->write("WAVE",4);
w->writeI(0);
w->writeC(0); // name
w->writeI(len);
w->writeI(min);
w->writeI(max);
for (int j=0; j<len; j++) {
w->writeI(data[j]);
}
}
bool DivWavetable::save(const char* path) {
SafeWriter* w=new SafeWriter();
w->init();
// write magic
w->write("-Furnace waveta-",16);
// write version
w->writeS(DIV_ENGINE_VERSION);
// reserved
w->writeS(0);
putWaveData(w);
FILE* outFile=fopen(path,"wb");
if (outFile==NULL) {
logE("could not save wavetable: %s!\n",strerror(errno));
w->finish();
return false;
}
if (fwrite(w->getFinalBuf(),1,w->size(),outFile)!=w->size()) {
logW("did not write entire wavetable!\n");
}
fclose(outFile);
w->finish();
return true;
}

View file

@ -3110,6 +3110,11 @@ void FurnaceGUI::processDrags(int dragX, int dragY) {
updateWindowTitle(); \
}
#define checkExtension(x) \
if (fileName.size()<4 || fileName.rfind(x)!=fileName.size()-4) { \
fileName+=x; \
}
bool FurnaceGUI::loop() {
while (!quit) {
SDL_Event ev;
@ -3385,19 +3390,16 @@ bool FurnaceGUI::loop() {
if (fileName!="") {
if (curFileDialog==GUI_FILE_SAVE) {
if (ImGuiFileDialog::Instance()->GetCurrentFilter()=="Furnace song") {
if (fileName.size()<4 || fileName.rfind(".fur")!=fileName.size()-4) {
fileName+=".fur";
}
checkExtension(".fur");
} else {
if (fileName.size()<4 || fileName.rfind(".dmf")!=fileName.size()-4) {
fileName+=".dmf";
checkExtension(".dmf");
}
}
}
if (curFileDialog==GUI_FILE_SAMPLE_SAVE) {
if (fileName.size()<4 || fileName.rfind(".wav")!=fileName.size()-4) {
fileName+=".wav";
}
if (curFileDialog==GUI_FILE_SAMPLE_SAVE ||
curFileDialog==GUI_FILE_EXPORT_AUDIO_ONE ||
curFileDialog==GUI_FILE_EXPORT_AUDIO_PER_SYS ||
curFileDialog==GUI_FILE_EXPORT_AUDIO_PER_CHANNEL) {
checkExtension(".wav");
}
String copyOfName=fileName;
switch (curFileDialog) {
@ -3417,6 +3419,11 @@ bool FurnaceGUI::loop() {
e->song.ins[curIns]->save(copyOfName.c_str());
}
break;
case GUI_FILE_WAVE_SAVE:
if (curWave>=0 && curWave<(int)e->song.wave.size()) {
e->song.wave[curWave]->save(copyOfName.c_str());
}
break;
case GUI_FILE_SAMPLE_OPEN:
e->addSampleFromFile(copyOfName.c_str());
modified=true;
@ -3437,7 +3444,6 @@ bool FurnaceGUI::loop() {
break;
case GUI_FILE_INS_OPEN:
case GUI_FILE_WAVE_OPEN:
case GUI_FILE_WAVE_SAVE:
case GUI_FILE_EXPORT_VGM:
case GUI_FILE_EXPORT_ROM:
showError("Coming soon!");