diff --git a/src/CardinalCommon.cpp b/src/CardinalCommon.cpp index 6aee003..065eb21 100644 --- a/src/CardinalCommon.cpp +++ b/src/CardinalCommon.cpp @@ -1,6 +1,6 @@ /* * DISTRHO Cardinal Plugin - * Copyright (C) 2021 Filipe Coelho + * Copyright (C) 2021-2022 Filipe Coelho * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -190,9 +190,9 @@ void saveDialog(const std::string& path) #endif } -void saveAsDialog() -{ #ifndef HEADLESS +static void saveAsDialog(const bool uncompressed) +{ std::string dir; if (! APP->patch->path.empty()) dir = system::getDirectory(APP->patch->path); @@ -208,7 +208,22 @@ void saveAsDialog() FileBrowserOptions opts; opts.startDir = dir.c_str(); opts.saving = ui->saving = true; + ui->savingUncompressed = true; ui->openFileBrowser(opts); +} +#endif + +void saveAsDialog() +{ +#ifndef HEADLESS + saveAsDialog(false); +#endif +} + +void saveAsDialogUncompressed() +{ +#ifndef HEADLESS + saveAsDialog(true); #endif } diff --git a/src/CardinalCommon.hpp b/src/CardinalCommon.hpp index f08477a..6824c30 100644 --- a/src/CardinalCommon.hpp +++ b/src/CardinalCommon.hpp @@ -1,6 +1,6 @@ /* * DISTRHO Cardinal Plugin - * Copyright (C) 2021 Filipe Coelho + * Copyright (C) 2021-2022 Filipe Coelho * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -48,6 +48,7 @@ void loadTemplateDialog(); void revertDialog(); void saveDialog(const std::string& path); void saveAsDialog(); +void saveAsDialogUncompressed(); void appendSelectionContextMenu(rack::ui::Menu* menu); bool connectToRemote(); diff --git a/src/CardinalUI.cpp b/src/CardinalUI.cpp index b0e16cb..96b5863 100644 --- a/src/CardinalUI.cpp +++ b/src/CardinalUI.cpp @@ -1,6 +1,6 @@ /* * DISTRHO Cardinal Plugin - * Copyright (C) 2021 Filipe Coelho + * Copyright (C) 2021-2022 Filipe Coelho * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -748,11 +749,31 @@ protected: if (saving) { + const bool uncompressed = savingUncompressed; + savingUncompressed = false; + if (rack::system::getExtension(sfilename) != ".vcv") sfilename += ".vcv"; try { - context->patch->save(sfilename); + if (uncompressed) + { + context->engine->prepareSave(); + + if (json_t* const rootJ = context->patch->toJson()) + { + if (FILE* const file = std::fopen(sfilename.c_str(), "w")) + { + json_dumpf(rootJ, file, JSON_INDENT(2)); + std::fclose(file); + } + json_decref(rootJ); + } + } + else + { + context->patch->save(sfilename); + } } catch (rack::Exception& e) { std::string message = rack::string::f("Could not save patch: %s", e.what()); diff --git a/src/PluginContext.hpp b/src/PluginContext.hpp index 6beab05..da29fa4 100644 --- a/src/PluginContext.hpp +++ b/src/PluginContext.hpp @@ -142,6 +142,7 @@ class CardinalBaseUI : public UI { public: CardinalPluginContext* const context; bool saving; + bool savingUncompressed; // for 3rd party modules std::function filebrowseraction; @@ -151,6 +152,7 @@ public: : UI(width, height), context(getRackContextFromPlugin(getPluginInstancePointer())), saving(false), + savingUncompressed(false), filebrowseraction(), filebrowserhandle(nullptr) { diff --git a/src/override/MenuBar.cpp b/src/override/MenuBar.cpp index 142546f..23647cc 100644 --- a/src/override/MenuBar.cpp +++ b/src/override/MenuBar.cpp @@ -111,6 +111,10 @@ struct FileButton : MenuButton { patchUtils::saveAsDialog(); })); + menu->addChild(createMenuItem("Export uncompressed json...", "", []() { + patchUtils::saveAsDialogUncompressed(); + })); + #ifdef HAVE_LIBLO if (patchUtils::isRemoteConnected()) { menu->addChild(createMenuItem("Deploy to MOD", "F7", []() {