Allow loading uncompressed plugin state; Allow patch wasm url
This commit is contained in:
parent
accf13abbd
commit
19878f0097
5 changed files with 49 additions and 2 deletions
|
|
@ -98,6 +98,7 @@ std::string getSpecialPath(const SpecialPath type)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef DISTRHO_OS_WASM
|
#ifdef DISTRHO_OS_WASM
|
||||||
|
char* patchFromURL = nullptr;
|
||||||
char* patchStorageSlug = nullptr;
|
char* patchStorageSlug = nullptr;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,7 @@ std::string getSpecialPath(SpecialPath type);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef DISTRHO_OS_WASM
|
#ifdef DISTRHO_OS_WASM
|
||||||
|
extern char* patchFromURL;
|
||||||
extern char* patchStorageSlug;
|
extern char* patchStorageSlug;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -104,6 +104,19 @@ bool d_isDiffHigherThanLimit(const T& v1, const T& v2, const T& limit)
|
||||||
// -----------------------------------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
#ifdef DISTRHO_OS_WASM
|
#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() {
|
static char* getPatchStorageSlug() {
|
||||||
return static_cast<char*>(EM_ASM_PTR({
|
return static_cast<char*>(EM_ASM_PTR({
|
||||||
var searchParams = new URLSearchParams(window.location.search);
|
var searchParams = new URLSearchParams(window.location.search);
|
||||||
|
|
@ -606,7 +619,8 @@ public:
|
||||||
context->window = new rack::window::Window;
|
context->window = new rack::window::Window;
|
||||||
|
|
||||||
#ifdef DISTRHO_OS_WASM
|
#ifdef DISTRHO_OS_WASM
|
||||||
if ((rack::patchStorageSlug = getPatchStorageSlug()) == nullptr)
|
if ((rack::patchStorageSlug = getPatchStorageSlug()) == nullptr &&
|
||||||
|
(rack::patchFromURL = getPatchFileEncodedInURL()) == nullptr)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
context->patch->loadTemplate();
|
context->patch->loadTemplate();
|
||||||
|
|
@ -1143,11 +1157,29 @@ protected:
|
||||||
|
|
||||||
const std::vector<uint8_t> data(d_getChunkFromBase64String(value));
|
const std::vector<uint8_t> data(d_getChunkFromBase64String(value));
|
||||||
|
|
||||||
|
DISTRHO_SAFE_ASSERT_RETURN(data.size() >= 4,);
|
||||||
|
|
||||||
const ScopedContext sc(this);
|
const ScopedContext sc(this);
|
||||||
|
|
||||||
rack::system::removeRecursively(fAutosavePath);
|
rack::system::removeRecursively(fAutosavePath);
|
||||||
rack::system::createDirectories(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 {
|
try {
|
||||||
context->patch->loadAutosave();
|
context->patch->loadAutosave();
|
||||||
|
|
|
||||||
|
|
@ -389,9 +389,18 @@ public:
|
||||||
|
|
||||||
#ifdef DISTRHO_OS_WASM
|
#ifdef DISTRHO_OS_WASM
|
||||||
if (rack::patchStorageSlug != nullptr)
|
if (rack::patchStorageSlug != nullptr)
|
||||||
|
{
|
||||||
psDialog = new WasmPatchStorageLoadingDialog();
|
psDialog = new WasmPatchStorageLoadingDialog();
|
||||||
|
}
|
||||||
|
else if (rack::patchFromURL != nullptr)
|
||||||
|
{
|
||||||
|
static_cast<CardinalBasePlugin*>(context->plugin)->setState("patch", rack::patchFromURL);
|
||||||
|
rack::contextSet(context);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
new WasmWelcomeDialog();
|
new WasmWelcomeDialog();
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
context->window->step();
|
context->window->step();
|
||||||
|
|
|
||||||
|
|
@ -135,6 +135,10 @@ public:
|
||||||
: Plugin(parameterCount, programCount, stateCount),
|
: Plugin(parameterCount, programCount, stateCount),
|
||||||
context(new CardinalPluginContext(this)) {}
|
context(new CardinalPluginContext(this)) {}
|
||||||
~CardinalBasePlugin() override {}
|
~CardinalBasePlugin() override {}
|
||||||
|
|
||||||
|
#ifndef HEADLESS
|
||||||
|
friend class CardinalUI;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifndef HEADLESS
|
#ifndef HEADLESS
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue