Allow loading uncompressed plugin state; Allow patch wasm url

This commit is contained in:
falkTX 2022-08-13 00:01:06 +01:00
parent accf13abbd
commit 19878f0097
5 changed files with 49 additions and 2 deletions

View file

@ -98,6 +98,7 @@ std::string getSpecialPath(const SpecialPath type)
#endif
#ifdef DISTRHO_OS_WASM
char* patchFromURL = nullptr;
char* patchStorageSlug = nullptr;
#endif

View file

@ -58,6 +58,7 @@ std::string getSpecialPath(SpecialPath type);
#endif
#ifdef DISTRHO_OS_WASM
extern char* patchFromURL;
extern char* patchStorageSlug;
#endif

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();

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();

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