From d1c5a4725bbb5b919eed2fa32c94b859dd173fad Mon Sep 17 00:00:00 2001 From: tildearrow Date: Tue, 16 Aug 2022 03:42:17 -0500 Subject: [PATCH] add option to save unused patterns closes #106 also prepare for the pattern manager window --- CMakeLists.txt | 1 + src/engine/fileOps.cpp | 30 +++++++++++++++++++++--------- src/gui/doAction.cpp | 6 ++++++ src/gui/gui.cpp | 5 +++++ src/gui/gui.h | 7 ++++++- src/gui/guiConst.cpp | 1 + src/gui/patManager.cpp | 37 +++++++++++++++++++++++++++++++++++++ src/gui/settings.cpp | 8 ++++++++ 8 files changed, 85 insertions(+), 10 deletions(-) create mode 100644 src/gui/patManager.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index e468d407..732cb623 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -531,6 +531,7 @@ src/gui/midiMap.cpp src/gui/newSong.cpp src/gui/orders.cpp src/gui/osc.cpp +src/gui/patManager.cpp src/gui/pattern.cpp src/gui/piano.cpp src/gui/presets.cpp diff --git a/src/engine/fileOps.cpp b/src/engine/fileOps.cpp index 7cdcd5c8..589ca6a5 100644 --- a/src/engine/fileOps.cpp +++ b/src/engine/fileOps.cpp @@ -3515,15 +3515,27 @@ SafeWriter* DivEngine::saveFur(bool notPrimary) { // high short is channel // low short is pattern number std::vector patsToWrite; - bool alreadyAdded[256]; - for (int i=0; iordersLen; k++) { - if (alreadyAdded[subs->orders.ord[i][k]]) continue; - patsToWrite.push_back(PatToWrite(j,i,subs->orders.ord[i][k])); - alreadyAdded[subs->orders.ord[i][k]]=true; + if (getConfInt("saveUnusedPatterns",0)==1) { + for (int i=0; ipat[i].data[k]==NULL) continue; + patsToWrite.push_back(PatToWrite(j,i,k)); + } + } + } + } else { + bool alreadyAdded[256]; + for (int i=0; iordersLen; k++) { + if (alreadyAdded[subs->orders.ord[i][k]]) continue; + patsToWrite.push_back(PatToWrite(j,i,subs->orders.ord[i][k])); + alreadyAdded[subs->orders.ord[i][k]]=true; + } } } } diff --git a/src/gui/doAction.cpp b/src/gui/doAction.cpp index 931de26d..5c840df4 100644 --- a/src/gui/doAction.cpp +++ b/src/gui/doAction.cpp @@ -238,6 +238,9 @@ void FurnaceGUI::doAction(int what) { case GUI_ACTION_WINDOW_CHANNELS: nextWindow=GUI_WINDOW_CHANNELS; break; + case GUI_ACTION_WINDOW_PAT_MANAGER: + nextWindow=GUI_WINDOW_PAT_MANAGER; + break; case GUI_ACTION_WINDOW_REGISTER_VIEW: nextWindow=GUI_WINDOW_REGISTER_VIEW; break; @@ -322,6 +325,9 @@ void FurnaceGUI::doAction(int what) { case GUI_WINDOW_CHANNELS: channelsOpen=false; break; + case GUI_WINDOW_PAT_MANAGER: + patManagerOpen=false; + break; case GUI_WINDOW_REGISTER_VIEW: regViewOpen=false; break; diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 2b4367c9..4a6f3f39 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -3107,6 +3107,7 @@ bool FurnaceGUI::loop() { if (ImGui::MenuItem("pattern",BIND_FOR(GUI_ACTION_WINDOW_PATTERN),patternOpen)) patternOpen=!patternOpen; if (ImGui::MenuItem("mixer",BIND_FOR(GUI_ACTION_WINDOW_MIXER),mixerOpen)) mixerOpen=!mixerOpen; if (ImGui::MenuItem("channels",BIND_FOR(GUI_ACTION_WINDOW_CHANNELS),channelsOpen)) channelsOpen=!channelsOpen; + if (ImGui::MenuItem("pattern manager",BIND_FOR(GUI_ACTION_WINDOW_PAT_MANAGER),patManagerOpen)) patManagerOpen=!patManagerOpen; if (ImGui::MenuItem("compatibility flags",BIND_FOR(GUI_ACTION_WINDOW_COMPAT_FLAGS),compatFlagsOpen)) compatFlagsOpen=!compatFlagsOpen; if (ImGui::MenuItem("song comments",BIND_FOR(GUI_ACTION_WINDOW_NOTES),notesOpen)) notesOpen=!notesOpen; ImGui::Separator(); @@ -3241,6 +3242,7 @@ bool FurnaceGUI::loop() { drawPiano(); drawNotes(); drawChannels(); + drawPatManager(); drawRegView(); drawLog(); drawEffectList(); @@ -4361,6 +4363,7 @@ bool FurnaceGUI::init() { pianoOpen=e->getConfBool("pianoOpen",false); notesOpen=e->getConfBool("notesOpen",false); channelsOpen=e->getConfBool("channelsOpen",false); + patManagerOpen=e->getConfBool("patManagerOpen",false); regViewOpen=e->getConfBool("regViewOpen",false); logOpen=e->getConfBool("logOpen",false); effectListOpen=e->getConfBool("effectListOpen",false); @@ -4603,6 +4606,7 @@ bool FurnaceGUI::finish() { e->setConf("pianoOpen",pianoOpen); e->setConf("notesOpen",notesOpen); e->setConf("channelsOpen",channelsOpen); + e->setConf("patManagerOpen",patManagerOpen); e->setConf("regViewOpen",regViewOpen); e->setConf("logOpen",logOpen); e->setConf("effectListOpen",effectListOpen); @@ -4782,6 +4786,7 @@ FurnaceGUI::FurnaceGUI(): subSongsOpen(true), findOpen(false), spoilerOpen(false), + patManagerOpen(false), selecting(false), selectingFull(false), dragging(false), diff --git a/src/gui/gui.h b/src/gui/gui.h index 1c735506..785c63f9 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -242,6 +242,7 @@ enum FurnaceGUIWindows { GUI_WINDOW_PIANO, GUI_WINDOW_NOTES, GUI_WINDOW_CHANNELS, + GUI_WINDOW_PAT_MANAGER, GUI_WINDOW_REGISTER_VIEW, GUI_WINDOW_LOG, GUI_WINDOW_EFFECT_LIST, @@ -361,6 +362,7 @@ enum FurnaceGUIActions { GUI_ACTION_WINDOW_PIANO, GUI_ACTION_WINDOW_NOTES, GUI_ACTION_WINDOW_CHANNELS, + GUI_ACTION_WINDOW_PAT_MANAGER, GUI_ACTION_WINDOW_REGISTER_VIEW, GUI_ACTION_WINDOW_LOG, GUI_ACTION_WINDOW_EFFECT_LIST, @@ -1117,6 +1119,7 @@ class FurnaceGUI { int unsignedDetune; int noThreadedInput; int clampSamples; + int saveUnusedPatterns; unsigned int maxUndoSteps; String mainFontPath; String patFontPath; @@ -1228,6 +1231,7 @@ class FurnaceGUI { unsignedDetune(0), noThreadedInput(0), clampSamples(0), + saveUnusedPatterns(0), maxUndoSteps(100), mainFontPath(""), patFontPath(""), @@ -1257,7 +1261,7 @@ class FurnaceGUI { bool waveListOpen, waveEditOpen, sampleListOpen, sampleEditOpen, aboutOpen, settingsOpen; bool mixerOpen, debugOpen, inspectorOpen, oscOpen, volMeterOpen, statsOpen, compatFlagsOpen; bool pianoOpen, notesOpen, channelsOpen, regViewOpen, logOpen, effectListOpen, chanOscOpen; - bool subSongsOpen, findOpen, spoilerOpen; + bool subSongsOpen, findOpen, spoilerOpen, patManagerOpen; SelectionPoint selStart, selEnd, cursor, cursorDrag, dragStart, dragEnd; bool selecting, selectingFull, dragging, curNibble, orderNibble, followOrders, followPattern, changeAllOrders, mobileUI; @@ -1566,6 +1570,7 @@ class FurnaceGUI { void drawPiano(); void drawNotes(); void drawChannels(); + void drawPatManager(); void drawRegView(); void drawAbout(); void drawSettings(); diff --git a/src/gui/guiConst.cpp b/src/gui/guiConst.cpp index 5fabb1c7..ea2edf27 100644 --- a/src/gui/guiConst.cpp +++ b/src/gui/guiConst.cpp @@ -487,6 +487,7 @@ const FurnaceGUIActionDef guiActions[GUI_ACTION_MAX]={ D("WINDOW_PIANO", "Piano", 0), D("WINDOW_NOTES", "Song Comments", 0), D("WINDOW_CHANNELS", "Channels", 0), + D("WINDOW_PAT_MANAGER", "Pattern Manager", 0), D("WINDOW_REGISTER_VIEW", "Register View", 0), D("WINDOW_LOG", "Log Viewer", 0), D("EFFECT_LIST", "Effect List", 0), diff --git a/src/gui/patManager.cpp b/src/gui/patManager.cpp new file mode 100644 index 00000000..16fdc345 --- /dev/null +++ b/src/gui/patManager.cpp @@ -0,0 +1,37 @@ +/** + * Furnace Tracker - multi-system chiptune tracker + * Copyright (C) 2021-2022 tildearrow and contributors + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "gui.h" +#include "misc/cpp/imgui_stdlib.h" +#include "IconsFontAwesome4.h" +#include + +void FurnaceGUI::drawPatManager() { + if (nextWindow==GUI_WINDOW_PAT_MANAGER) { + patManagerOpen=true; + ImGui::SetNextWindowFocus(); + nextWindow=GUI_WINDOW_NOTHING; + } + if (!patManagerOpen) return; + if (ImGui::Begin("Pattern Manager",&patManagerOpen,globalWinFlags)) { + ImGui::Text("Hello World!"); + } + if (ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows)) curWindow=GUI_WINDOW_PAT_MANAGER; + ImGui::End(); +} diff --git a/src/gui/settings.cpp b/src/gui/settings.cpp index ee35fd86..3134d9e3 100644 --- a/src/gui/settings.cpp +++ b/src/gui/settings.cpp @@ -514,6 +514,11 @@ void FurnaceGUI::drawSettings() { settings.blankIns=blankInsB; } + bool saveUnusedPatternsB=settings.saveUnusedPatterns; + if (ImGui::Checkbox("Save unused patterns",&saveUnusedPatternsB)) { + settings.saveUnusedPatterns=saveUnusedPatternsB; + } + ImGui::Text("Note preview behavior:"); if (ImGui::RadioButton("Never##npb0",settings.notePreviewBehavior==0)) { settings.notePreviewBehavior=0; @@ -2133,6 +2138,7 @@ void FurnaceGUI::syncSettings() { settings.macroRelLabel=e->getConfString("macroRelLabel","REL"); settings.emptyLabel=e->getConfString("emptyLabel","..."); settings.emptyLabel2=e->getConfString("emptyLabel2",".."); + settings.saveUnusedPatterns=e->getConfInt("saveUnusedPatterns",0); clampSetting(settings.mainFontSize,2,96); clampSetting(settings.patFontSize,2,96); @@ -2221,6 +2227,7 @@ void FurnaceGUI::syncSettings() { clampSetting(settings.unsignedDetune,0,1); clampSetting(settings.noThreadedInput,0,1); clampSetting(settings.clampSamples,0,1); + clampSetting(settings.saveUnusedPatterns,0,1); settings.initialSys=e->decodeSysDesc(e->getConfString("initialSys","")); if (settings.initialSys.size()<4) { @@ -2365,6 +2372,7 @@ void FurnaceGUI::commitSettings() { e->setConf("macroRelLabel",settings.macroRelLabel); e->setConf("emptyLabel",settings.emptyLabel); e->setConf("emptyLabel2",settings.emptyLabel2); + e->setConf("saveUnusedPatterns",settings.saveUnusedPatterns); // colors for (int i=0; i