finally make the save option work

This commit is contained in:
tildearrow 2021-12-30 18:25:55 -05:00
parent cdfe89565c
commit 9a1853249b
4 changed files with 39 additions and 10 deletions

View file

@ -15,17 +15,17 @@
<key>CFBundleInfoDictionaryVersion</key> <key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string> <string>6.0</string>
<key>CFBundleLongVersionString</key> <key>CFBundleLongVersionString</key>
<string>1.0</string> <string>0.2</string>
<key>CFBundleName</key> <key>CFBundleName</key>
<string>Furnace</string> <string>Furnace</string>
<key>CFBundlePackageType</key> <key>CFBundlePackageType</key>
<string>APPL</string> <string>APPL</string>
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>1.0</string> <string>0.2</string>
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>????</string> <string>????</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>1.0</string> <string>0.2</string>
<key>NSHumanReadableCopyright</key> <key>NSHumanReadableCopyright</key>
<string></string> <string></string>
<key>NSHighResolutionCapable</key> <key>NSHighResolutionCapable</key>

View file

@ -9,8 +9,8 @@
#include <map> #include <map>
#include <queue> #include <queue>
#define DIV_VERSION "0.1" #define DIV_VERSION "0.2"
#define DIV_ENGINE_VERSION 11 #define DIV_ENGINE_VERSION 12
enum DivStatusView { enum DivStatusView {
DIV_STATUS_NOTHING=0, DIV_STATUS_NOTHING=0,

View file

@ -495,6 +495,7 @@ void FurnaceGUI::drawInsList() {
if (ImGui::Begin("Instruments",&insListOpen)) { if (ImGui::Begin("Instruments",&insListOpen)) {
if (ImGui::Button(ICON_FA_PLUS "##InsAdd")) { if (ImGui::Button(ICON_FA_PLUS "##InsAdd")) {
curIns=e->addInstrument(); curIns=e->addInstrument();
modified=true;
} }
ImGui::SameLine(); ImGui::SameLine();
if (ImGui::ArrowButton("InsUp",ImGuiDir_Up)) { if (ImGui::ArrowButton("InsUp",ImGuiDir_Up)) {
@ -507,6 +508,7 @@ void FurnaceGUI::drawInsList() {
ImGui::SameLine(); ImGui::SameLine();
if (ImGui::Button(ICON_FA_TIMES "##InsDelete")) { if (ImGui::Button(ICON_FA_TIMES "##InsDelete")) {
e->delInstrument(curIns); e->delInstrument(curIns);
modified=true;
if (curIns>=(int)e->song.ins.size()) { if (curIns>=(int)e->song.ins.size()) {
curIns--; curIns--;
} }
@ -878,6 +880,7 @@ void FurnaceGUI::drawWaveList() {
if (ImGui::Begin("Wavetables",&waveListOpen)) { if (ImGui::Begin("Wavetables",&waveListOpen)) {
if (ImGui::Button(ICON_FA_PLUS "##WaveAdd")) { if (ImGui::Button(ICON_FA_PLUS "##WaveAdd")) {
curWave=e->addWave(); curWave=e->addWave();
modified=true;
} }
ImGui::SameLine(); ImGui::SameLine();
if (ImGui::ArrowButton("WaveUp",ImGuiDir_Up)) { if (ImGui::ArrowButton("WaveUp",ImGuiDir_Up)) {
@ -890,6 +893,7 @@ void FurnaceGUI::drawWaveList() {
ImGui::SameLine(); ImGui::SameLine();
if (ImGui::Button(ICON_FA_TIMES "##WaveDelete")) { if (ImGui::Button(ICON_FA_TIMES "##WaveDelete")) {
e->delWave(curWave); e->delWave(curWave);
modified=true;
if (curWave>=(int)e->song.wave.size()) { if (curWave>=(int)e->song.wave.size()) {
curWave--; curWave--;
} }
@ -958,6 +962,7 @@ void FurnaceGUI::drawSampleList() {
if (ImGui::Begin("Samples",&sampleListOpen)) { if (ImGui::Begin("Samples",&sampleListOpen)) {
if (ImGui::Button(ICON_FA_PLUS "##SampleAdd")) { if (ImGui::Button(ICON_FA_PLUS "##SampleAdd")) {
curSample=e->addSample(); curSample=e->addSample();
modified=true;
} }
ImGui::SameLine(); ImGui::SameLine();
if (ImGui::Button(ICON_FA_FOLDER_OPEN "##SampleLoad")) { if (ImGui::Button(ICON_FA_FOLDER_OPEN "##SampleLoad")) {
@ -978,6 +983,7 @@ void FurnaceGUI::drawSampleList() {
ImGui::SameLine(); ImGui::SameLine();
if (ImGui::Button(ICON_FA_TIMES "##SampleDelete")) { if (ImGui::Button(ICON_FA_TIMES "##SampleDelete")) {
e->delSample(curSample); e->delSample(curSample);
modified=true;
if (curSample>=(int)e->song.sample.size()) { if (curSample>=(int)e->song.sample.size()) {
curSample--; curSample--;
} }
@ -1775,6 +1781,7 @@ void FurnaceGUI::makeUndo(ActionType action) {
break; break;
} }
if (doPush) { if (doPush) {
modified=true;
undoHist.push_back(s); undoHist.push_back(s);
redoHist.clear(); redoHist.clear();
if (undoHist.size()>maxUndoSteps) undoHist.pop_front(); if (undoHist.size()>maxUndoSteps) undoHist.pop_front();
@ -2066,6 +2073,7 @@ void FurnaceGUI::doUndo() {
if (undoHist.empty()) return; if (undoHist.empty()) return;
UndoStep& us=undoHist.back(); UndoStep& us=undoHist.back();
redoHist.push_back(us); redoHist.push_back(us);
modified=true;
switch (us.type) { switch (us.type) {
case GUI_ACTION_CHANGE_SYSTEM: case GUI_ACTION_CHANGE_SYSTEM:
@ -2106,6 +2114,7 @@ void FurnaceGUI::doRedo() {
if (redoHist.empty()) return; if (redoHist.empty()) return;
UndoStep& us=redoHist.back(); UndoStep& us=redoHist.back();
undoHist.push_back(us); undoHist.push_back(us);
modified=true;
switch (us.type) { switch (us.type) {
case GUI_ACTION_CHANGE_SYSTEM: case GUI_ACTION_CHANGE_SYSTEM:
@ -2421,6 +2430,8 @@ int FurnaceGUI::save(String path) {
#endif #endif
fclose(outFile); fclose(outFile);
w->finish(); w->finish();
curFileName=path;
modified=false;
return 0; return 0;
} }
@ -2479,6 +2490,8 @@ int FurnaceGUI::load(String path) {
return 1; return 1;
} }
} }
curFileName=path;
modified=false;
lastError="everything OK"; lastError="everything OK";
undoHist.clear(); undoHist.clear();
redoHist.clear(); redoHist.clear();
@ -2551,6 +2564,7 @@ bool FurnaceGUI::loop() {
processDrags(ev.motion.x,ev.motion.y); processDrags(ev.motion.x,ev.motion.y);
break; break;
case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONUP:
if (macroDragActive || macroLoopDragActive || waveDragActive) modified=true;
macroDragActive=false; macroDragActive=false;
macroLoopDragActive=false; macroLoopDragActive=false;
waveDragActive=false; waveDragActive=false;
@ -2607,7 +2621,15 @@ bool FurnaceGUI::loop() {
openFileDialog(GUI_FILE_OPEN); openFileDialog(GUI_FILE_OPEN);
} }
ImGui::Separator(); ImGui::Separator();
ImGui::MenuItem("save"); if (ImGui::MenuItem("save")) {
if (curFileName=="") {
openFileDialog(GUI_FILE_SAVE);
} else {
if (save(curFileName)>0) {
showError(fmt::sprintf("Error while saving file! (%s)",lastError));
}
}
}
if (ImGui::MenuItem("save as...")) { if (ImGui::MenuItem("save as...")) {
openFileDialog(GUI_FILE_SAVE); openFileDialog(GUI_FILE_SAVE);
} }
@ -2674,12 +2696,17 @@ bool FurnaceGUI::loop() {
} }
ImGui::EndMenu(); ImGui::EndMenu();
} }
ImGui::PushStyleColor(ImGuiCol_Text,uiColors[GUI_COLOR_PLAYBACK_STAT]);
if (e->isPlaying()) { if (e->isPlaying()) {
ImGui::PushStyleColor(ImGuiCol_Text,uiColors[GUI_COLOR_PLAYBACK_STAT]);
int totalTicks=e->getTotalTicks(); int totalTicks=e->getTotalTicks();
int hz=e->getHz(); int hz=e->getHz();
ImGui::Text("| Speed %d:%d | Order %d/%d | Row %d/%d | %d:%.2d:%.2d.%.2d",e->getSpeed1(),e->getSpeed2(),e->getOrder(),e->song.ordersLen,e->getRow(),e->song.patLen,totalTicks/(hz*3600),(totalTicks/(hz*60))%60,(totalTicks/hz)%60,(totalTicks%hz)*100/hz); ImGui::Text("| Speed %d:%d | Order %d/%d | Row %d/%d | %d:%.2d:%.2d.%.2d",e->getSpeed1(),e->getSpeed2(),e->getOrder(),e->song.ordersLen,e->getRow(),e->song.patLen,totalTicks/(hz*3600),(totalTicks/(hz*60))%60,(totalTicks/hz)%60,(totalTicks%hz)*100/hz);
ImGui::PopStyleColor(); } else {
if (curFileName!="") ImGui::Text("| %s",curFileName.c_str());
}
ImGui::PopStyleColor();
if (modified) {
ImGui::Text("| modified");
} }
ImGui::EndMainMenuBar(); ImGui::EndMainMenuBar();
@ -2726,6 +2753,7 @@ bool FurnaceGUI::loop() {
break; break;
case GUI_FILE_SAMPLE_OPEN: case GUI_FILE_SAMPLE_OPEN:
e->addSampleFromFile(copyOfName.c_str()); e->addSampleFromFile(copyOfName.c_str());
modified=true;
break; break;
case GUI_FILE_SAMPLE_SAVE: case GUI_FILE_SAMPLE_SAVE:
if (curSample>=0 && curSample<(int)e->song.sample.size()) { if (curSample>=0 && curSample<(int)e->song.sample.size()) {
@ -2878,6 +2906,7 @@ FurnaceGUI::FurnaceGUI():
quit(false), quit(false),
willCommit(false), willCommit(false),
edit(false), edit(false),
modified(false),
curFileDialog(GUI_FILE_OPEN), curFileDialog(GUI_FILE_OPEN),
scrW(1280), scrW(1280),
scrH(800), scrH(800),

View file

@ -131,9 +131,9 @@ class FurnaceGUI {
SDL_Window* sdlWin; SDL_Window* sdlWin;
SDL_Renderer* sdlRend; SDL_Renderer* sdlRend;
String workingDir, fileName, clipboard, errorString, lastError; String workingDir, fileName, clipboard, errorString, lastError, curFileName;
bool quit, willCommit, edit; bool quit, willCommit, edit, modified;
FurnaceGUIFileDialogs curFileDialog; FurnaceGUIFileDialogs curFileDialog;