From 9ac54241fb8bf3b11f93c928688c61b13fa3cc89 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Sat, 25 Sep 2021 06:13:04 -0400 Subject: [PATCH] Add patch:: namespace. --- adapters/standalone.cpp | 2 +- include/context.hpp | 6 +++-- include/patch.hpp | 8 ++++--- src/patch.cpp | 50 +++++++++++++++++++++-------------------- 4 files changed, 36 insertions(+), 30 deletions(-) diff --git a/adapters/standalone.cpp b/adapters/standalone.cpp index 08996021..1cca2087 100644 --- a/adapters/standalone.cpp +++ b/adapters/standalone.cpp @@ -190,7 +190,7 @@ int main(int argc, char* argv[]) { APP->event = new widget::EventState; APP->scene = new app::Scene; APP->event->rootWidget = APP->scene; - APP->patch = new PatchManager; + APP->patch = new patch::Manager; if (!settings::headless) { APP->window = new window::Window; } diff --git a/include/context.hpp b/include/context.hpp index 8cc34a14..cf5629c1 100644 --- a/include/context.hpp +++ b/include/context.hpp @@ -20,7 +20,9 @@ struct Window; } // namespace window -struct PatchManager; +namespace patch { +struct Manager; +} // namespace patch namespace widget { @@ -41,7 +43,7 @@ struct Context { engine::Engine* engine = NULL; window::Window* window = NULL; history::State* history = NULL; - PatchManager* patch = NULL; + patch::Manager* patch = NULL; ~Context(); }; diff --git a/include/patch.hpp b/include/patch.hpp index 9fd59ccb..c081a0b5 100644 --- a/include/patch.hpp +++ b/include/patch.hpp @@ -5,9 +5,10 @@ namespace rack { +namespace patch { -struct PatchManager { +struct Manager { struct Internal; Internal* internal; @@ -22,8 +23,8 @@ struct PatchManager { /** Append to this while loading/saving a patch to display messages to the user after success. */ std::string warningLog; - PatchManager(); - ~PatchManager(); + Manager(); + ~Manager(); void launch(std::string pathArg); /** Clears the patch. */ void clear(); @@ -59,4 +60,5 @@ struct PatchManager { }; +} // namespace patch } // namespace rack diff --git a/src/patch.cpp b/src/patch.cpp index 67361f58..ad7d7e92 100644 --- a/src/patch.cpp +++ b/src/patch.cpp @@ -16,24 +16,25 @@ namespace rack { +namespace patch { static const char PATCH_FILTERS[] = "VCV Rack patch (.vcv):vcv"; -PatchManager::PatchManager() { +Manager::Manager() { autosavePath = asset::user("autosave"); templatePath = asset::user("template.vcv"); factoryTemplatePath = asset::system("template.vcv"); } -PatchManager::~PatchManager() { +Manager::~Manager() { cleanAutosave(); } -void PatchManager::launch(std::string pathArg) { +void Manager::launch(std::string pathArg) { // Load the argument if exists if (pathArg != "") { loadAction(pathArg); @@ -57,7 +58,7 @@ void PatchManager::launch(std::string pathArg) { } -void PatchManager::clear() { +void Manager::clear() { path = ""; if (APP->scene) { APP->scene->rack->clear(); @@ -79,7 +80,7 @@ static bool promptClear(std::string text) { } -void PatchManager::save(std::string path) { +void Manager::save(std::string path) { INFO("Saving patch %s", path.c_str()); // Dispatch SaveEvent to modules APP->engine->prepareSave(); @@ -99,7 +100,7 @@ void PatchManager::save(std::string path) { } -void PatchManager::saveDialog() { +void Manager::saveDialog() { if (path == "") { saveAsDialog(); return; @@ -119,7 +120,7 @@ void PatchManager::saveDialog() { } -void PatchManager::saveAsDialog() { +void Manager::saveAsDialog() { std::string dir; std::string filename; if (this->path == "") { @@ -164,7 +165,7 @@ void PatchManager::saveAsDialog() { } -void PatchManager::saveTemplateDialog() { +void Manager::saveTemplateDialog() { // Even if /template.vcv doesn't exist, this message is still valid because it overrides the /template.vcv patch. if (!osdialog_message(OSDIALOG_INFO, OSDIALOG_OK_CANCEL, "Overwrite template patch?")) return; @@ -180,7 +181,7 @@ void PatchManager::saveTemplateDialog() { } -void PatchManager::saveAutosave() { +void Manager::saveAutosave() { std::string patchPath = system::join(autosavePath, "patch.json"); INFO("Saving autosave %s", patchPath.c_str()); json_t* rootJ = toJson(); @@ -204,7 +205,7 @@ void PatchManager::saveAutosave() { } -void PatchManager::cleanAutosave() { +void Manager::cleanAutosave() { // Remove files and directories in the `autosave/modules` directory that doesn't match a module in the rack. std::string modulesDir = system::join(autosavePath, "modules"); if (system::isDirectory(modulesDir)) { @@ -238,7 +239,7 @@ static bool isPatchLegacyV1(std::string path) { } -void PatchManager::load(std::string path) { +void Manager::load(std::string path) { INFO("Loading patch %s", path.c_str()); system::removeRecursively(autosavePath); @@ -260,7 +261,7 @@ void PatchManager::load(std::string path) { } -void PatchManager::loadTemplate() { +void Manager::loadTemplate() { try { load(templatePath); } @@ -282,7 +283,7 @@ void PatchManager::loadTemplate() { } -void PatchManager::loadTemplateDialog() { +void Manager::loadTemplateDialog() { if (!promptClear("The current patch is unsaved. Clear it and start a new patch?")) { return; } @@ -290,7 +291,7 @@ void PatchManager::loadTemplateDialog() { } -bool PatchManager::hasAutosave() { +bool Manager::hasAutosave() { std::string patchPath = system::join(autosavePath, "patch.json"); INFO("Loading autosave %s", patchPath.c_str()); FILE* file = std::fopen(patchPath.c_str(), "r"); @@ -301,7 +302,7 @@ bool PatchManager::hasAutosave() { } -void PatchManager::loadAutosave() { +void Manager::loadAutosave() { std::string patchPath = system::join(autosavePath, "patch.json"); INFO("Loading autosave %s", patchPath.c_str()); FILE* file = std::fopen(patchPath.c_str(), "r"); @@ -319,7 +320,7 @@ void PatchManager::loadAutosave() { } -void PatchManager::loadAction(std::string path) { +void Manager::loadAction(std::string path) { try { load(path); } @@ -335,7 +336,7 @@ void PatchManager::loadAction(std::string path) { } -void PatchManager::loadDialog() { +void Manager::loadDialog() { if (!promptClear("The current patch is unsaved. Clear it and open a new patch?")) return; @@ -363,7 +364,7 @@ void PatchManager::loadDialog() { } -void PatchManager::loadPathDialog(std::string path) { +void Manager::loadPathDialog(std::string path) { if (!promptClear("The current patch is unsaved. Clear it and open the new patch?")) return; @@ -371,7 +372,7 @@ void PatchManager::loadPathDialog(std::string path) { } -void PatchManager::revertDialog() { +void Manager::revertDialog() { if (path == "") return; if (!promptClear("Revert patch to the last saved state?")) @@ -381,7 +382,7 @@ void PatchManager::revertDialog() { } -void PatchManager::pushRecentPath(std::string path) { +void Manager::pushRecentPath(std::string path) { auto& recent = settings::recentPatchPaths; // Remove path from recent patches (if exists) recent.remove(path); @@ -392,12 +393,12 @@ void PatchManager::pushRecentPath(std::string path) { } -void PatchManager::disconnectDialog() { +void Manager::disconnectDialog() { APP->scene->rack->clearCablesAction(); } -json_t* PatchManager::toJson() { +json_t* Manager::toJson() { // root json_t* rootJ = json_object(); @@ -428,7 +429,7 @@ json_t* PatchManager::toJson() { } -void PatchManager::fromJson(json_t* rootJ) { +void Manager::fromJson(json_t* rootJ) { clear(); // version @@ -473,10 +474,11 @@ void PatchManager::fromJson(json_t* rootJ) { } -void PatchManager::log(std::string msg) { +void Manager::log(std::string msg) { warningLog += msg; warningLog += "\n"; } +} // namespace patch } // namespace rack