Add file menu option to export uncompressed json file

This commit is contained in:
falkTX 2022-02-05 01:09:16 +00:00
parent 49c7d32727
commit 454943f2cf
5 changed files with 49 additions and 6 deletions

View file

@ -1,6 +1,6 @@
/*
* DISTRHO Cardinal Plugin
* Copyright (C) 2021 Filipe Coelho <falktx@falktx.com>
* Copyright (C) 2021-2022 Filipe Coelho <falktx@falktx.com>
*
* 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
}

View file

@ -1,6 +1,6 @@
/*
* DISTRHO Cardinal Plugin
* Copyright (C) 2021 Filipe Coelho <falktx@falktx.com>
* Copyright (C) 2021-2022 Filipe Coelho <falktx@falktx.com>
*
* 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();

View file

@ -1,6 +1,6 @@
/*
* DISTRHO Cardinal Plugin
* Copyright (C) 2021 Filipe Coelho <falktx@falktx.com>
* Copyright (C) 2021-2022 Filipe Coelho <falktx@falktx.com>
*
* 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 <app/Scene.hpp>
#include <asset.hpp>
#include <context.hpp>
#include <engine/Engine.hpp>
#include <helpers.hpp>
#include <patch.hpp>
#include <settings.hpp>
@ -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());

View file

@ -142,6 +142,7 @@ class CardinalBaseUI : public UI {
public:
CardinalPluginContext* const context;
bool saving;
bool savingUncompressed;
// for 3rd party modules
std::function<void(char* path)> filebrowseraction;
@ -151,6 +152,7 @@ public:
: UI(width, height),
context(getRackContextFromPlugin(getPluginInstancePointer())),
saving(false),
savingUncompressed(false),
filebrowseraction(),
filebrowserhandle(nullptr)
{

View file

@ -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", []() {