Browse Source

Allow loading uncompressed plugin state; Allow patch wasm url

tags/22.09
falkTX 3 years ago
parent
commit
19878f0097
5 changed files with 49 additions and 2 deletions
  1. +1
    -0
      src/CardinalCommon.cpp
  2. +1
    -0
      src/CardinalCommon.hpp
  3. +34
    -2
      src/CardinalPlugin.cpp
  4. +9
    -0
      src/CardinalUI.cpp
  5. +4
    -0
      src/PluginContext.hpp

+ 1
- 0
src/CardinalCommon.cpp View File

@@ -98,6 +98,7 @@ std::string getSpecialPath(const SpecialPath type)
#endif

#ifdef DISTRHO_OS_WASM
char* patchFromURL = nullptr;
char* patchStorageSlug = nullptr;
#endif



+ 1
- 0
src/CardinalCommon.hpp View File

@@ -58,6 +58,7 @@ std::string getSpecialPath(SpecialPath type);
#endif

#ifdef DISTRHO_OS_WASM
extern char* patchFromURL;
extern char* patchStorageSlug;
#endif



+ 34
- 2
src/CardinalPlugin.cpp View File

@@ -104,6 +104,19 @@ bool d_isDiffHigherThanLimit(const T& v1, const T& v2, const T& limit)
// -----------------------------------------------------------------------------------------------------------
#ifdef DISTRHO_OS_WASM
static char* getPatchFileEncodedInURL() {
return static_cast<char*>(EM_ASM_PTR({
var searchParams = new URLSearchParams(window.location.search);
var patch = searchParams.get('patch');
if (!patch)
return null;
var length = lengthBytesUTF8(patch) + 1;
var str = _malloc(length);
stringToUTF8(patch, str, length);
return str;
}));
};
static char* getPatchStorageSlug() {
return static_cast<char*>(EM_ASM_PTR({
var searchParams = new URLSearchParams(window.location.search);
@@ -606,7 +619,8 @@ public:
context->window = new rack::window::Window;
#ifdef DISTRHO_OS_WASM
if ((rack::patchStorageSlug = getPatchStorageSlug()) == nullptr)
if ((rack::patchStorageSlug = getPatchStorageSlug()) == nullptr &&
(rack::patchFromURL = getPatchFileEncodedInURL()) == nullptr)
#endif
{
context->patch->loadTemplate();
@@ -1143,11 +1157,29 @@ protected:
const std::vector<uint8_t> data(d_getChunkFromBase64String(value));
DISTRHO_SAFE_ASSERT_RETURN(data.size() >= 4,);
const ScopedContext sc(this);
rack::system::removeRecursively(fAutosavePath);
rack::system::createDirectories(fAutosavePath);
rack::system::unarchiveToDirectory(data, fAutosavePath);
static constexpr const char zstdMagic[] = "\x28\xb5\x2f\xfd";
if (std::memcmp(data.data(), zstdMagic, sizeof(zstdMagic)) != 0)
{
FILE* const f = std::fopen(rack::system::join(fAutosavePath, "patch.json").c_str(), "w");
DISTRHO_SAFE_ASSERT_RETURN(f != nullptr,);
std::fwrite(data.data(), data.size(), 1, f);
std::fclose(f);
}
else
{
try {
rack::system::unarchiveToDirectory(data, fAutosavePath);
} DISTRHO_SAFE_EXCEPTION_RETURN("setState unarchiveToDirectory",);
}
try {
context->patch->loadAutosave();


+ 9
- 0
src/CardinalUI.cpp View File

@@ -389,9 +389,18 @@ public:

#ifdef DISTRHO_OS_WASM
if (rack::patchStorageSlug != nullptr)
{
psDialog = new WasmPatchStorageLoadingDialog();
}
else if (rack::patchFromURL != nullptr)
{
static_cast<CardinalBasePlugin*>(context->plugin)->setState("patch", rack::patchFromURL);
rack::contextSet(context);
}
else
{
new WasmWelcomeDialog();
}
#endif

context->window->step();


+ 4
- 0
src/PluginContext.hpp View File

@@ -135,6 +135,10 @@ public:
: Plugin(parameterCount, programCount, stateCount),
context(new CardinalPluginContext(this)) {}
~CardinalBasePlugin() override {}

#ifndef HEADLESS
friend class CardinalUI;
#endif
};

#ifndef HEADLESS


Loading…
Cancel
Save