diff --git a/CMakeLists.txt b/CMakeLists.txt index 73a694194..2d42183ae 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index 5a217627d..12548e41a 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -1719,16 +1719,7 @@ SafeWriter* DivEngine::saveFur() { for (int i=0; itell(); - 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; jlen; j++) { - w->writeI(wave->data[j]); - } + wave->putWaveData(w); } /// SAMPLE diff --git a/src/engine/wavetable.cpp b/src/engine/wavetable.cpp index 01a8b1614..4a4910cd3 100644 --- a/src/engine/wavetable.cpp +++ b/src/engine/wavetable.cpp @@ -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; jwriteI(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; +} diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 266868271..d872e8dcd 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -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!");