Browse Source

Add file menu option to export uncompressed json file

tags/22.02
falkTX 3 years ago
parent
commit
454943f2cf
5 changed files with 49 additions and 6 deletions
  1. +18
    -3
      src/CardinalCommon.cpp
  2. +2
    -1
      src/CardinalCommon.hpp
  3. +23
    -2
      src/CardinalUI.cpp
  4. +2
    -0
      src/PluginContext.hpp
  5. +4
    -0
      src/override/MenuBar.cpp

+ 18
- 3
src/CardinalCommon.cpp 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
}



+ 2
- 1
src/CardinalCommon.hpp 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();


+ 23
- 2
src/CardinalUI.cpp 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());


+ 2
- 0
src/PluginContext.hpp 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)
{


+ 4
- 0
src/override/MenuBar.cpp 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", []() {


Loading…
Cancel
Save