Browse Source

Allow wasm to load patch from url too

tags/22.09
falkTX 2 years ago
parent
commit
e42dc9154f
5 changed files with 44 additions and 12 deletions
  1. +1
    -0
      src/CardinalCommon.cpp
  2. +1
    -0
      src/CardinalCommon.hpp
  3. +14
    -0
      src/CardinalPlugin.cpp
  4. +26
    -10
      src/CardinalUI.cpp
  5. +2
    -2
      src/PluginContext.hpp

+ 1
- 0
src/CardinalCommon.cpp View File

@@ -99,6 +99,7 @@ std::string getSpecialPath(const SpecialPath type)


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




+ 1
- 0
src/CardinalCommon.hpp View File

@@ -59,6 +59,7 @@ std::string getSpecialPath(SpecialPath type);


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




+ 14
- 0
src/CardinalPlugin.cpp View File

@@ -117,6 +117,19 @@ static char* getPatchFileEncodedInURL() {
})); }));
}; };
static char* getPatchRemoteURL() {
return static_cast<char*>(EM_ASM_PTR({
var searchParams = new URLSearchParams(window.location.search);
var patch = searchParams.get('patchurl');
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);
@@ -620,6 +633,7 @@ public:
#ifdef DISTRHO_OS_WASM #ifdef DISTRHO_OS_WASM
if ((rack::patchStorageSlug = getPatchStorageSlug()) == nullptr && if ((rack::patchStorageSlug = getPatchStorageSlug()) == nullptr &&
(rack::patchRemoteURL = getPatchRemoteURL()) == nullptr &&
(rack::patchFromURL = getPatchFileEncodedInURL()) == nullptr) (rack::patchFromURL = getPatchFileEncodedInURL()) == nullptr)
#endif #endif
{ {


+ 26
- 10
src/CardinalUI.cpp View File

@@ -191,13 +191,13 @@ struct WasmWelcomeDialog : rack::widget::OpaqueWidget
} }
}; };


struct WasmPatchStorageLoadingDialog : rack::widget::OpaqueWidget
struct WasmRemotePatchLoadingDialog : rack::widget::OpaqueWidget
{ {
static const constexpr float margin = 10; static const constexpr float margin = 10;


rack::ui::MenuOverlay* overlay; rack::ui::MenuOverlay* overlay;


WasmPatchStorageLoadingDialog()
WasmRemotePatchLoadingDialog(const bool isFromPatchStorage)
{ {
using rack::ui::Label; using rack::ui::Label;
using rack::ui::MenuOverlay; using rack::ui::MenuOverlay;
@@ -218,7 +218,9 @@ struct WasmPatchStorageLoadingDialog : rack::widget::OpaqueWidget
label->box.size.x = box.size.x - 2*margin; label->box.size.x = box.size.x - 2*margin;
label->box.size.y = box.size.y - 2*margin; label->box.size.y = box.size.y - 2*margin;
label->fontSize = 16; label->fontSize = 16;
label->text = "Loading patch from PatchStorage...\n";
label->text = isFromPatchStorage
? "Loading patch from PatchStorage...\n"
: "Loading remote patch...\n";
layout->addChild(label); layout->addChild(label);


overlay = new MenuOverlay; overlay = new MenuOverlay;
@@ -240,9 +242,9 @@ struct WasmPatchStorageLoadingDialog : rack::widget::OpaqueWidget
} }
}; };


static void downloadPatchStorageFailed(const char* const filename)
static void downloadRemotePatchFailed(const char* const filename)
{ {
d_stdout("downloadPatchStorageFailed %s", filename);
d_stdout("downloadRemotePatchFailed %s", filename);
CardinalPluginContext* const context = static_cast<CardinalPluginContext*>(APP); CardinalPluginContext* const context = static_cast<CardinalPluginContext*>(APP);
CardinalBaseUI* const ui = static_cast<CardinalBaseUI*>(context->ui); CardinalBaseUI* const ui = static_cast<CardinalBaseUI*>(context->ui);


@@ -250,7 +252,7 @@ static void downloadPatchStorageFailed(const char* const filename)
{ {
ui->psDialog->overlay->requestDelete(); ui->psDialog->overlay->requestDelete();
ui->psDialog = nullptr; ui->psDialog = nullptr;
asyncDialog::create("Failed to fetch patch from PatchStorage");
asyncDialog::create("Failed to fetch remote patch");
} }


using namespace rack; using namespace rack;
@@ -259,9 +261,9 @@ static void downloadPatchStorageFailed(const char* const filename)
context->scene->rackScroll->reset(); context->scene->rackScroll->reset();
} }


static void downloadPatchStorageSucceeded(const char* const filename)
static void downloadRemotePatchSucceeded(const char* const filename)
{ {
d_stdout("downloadPatchStorageSucceeded %s | %s", filename, APP->patch->templatePath.c_str());
d_stdout("downloadRemotePatchSucceeded %s | %s", filename, APP->patch->templatePath.c_str());
CardinalPluginContext* const context = static_cast<CardinalPluginContext*>(APP); CardinalPluginContext* const context = static_cast<CardinalPluginContext*>(APP);
CardinalBaseUI* const ui = static_cast<CardinalBaseUI*>(context->ui); CardinalBaseUI* const ui = static_cast<CardinalBaseUI*>(context->ui);


@@ -390,7 +392,11 @@ public:
#ifdef DISTRHO_OS_WASM #ifdef DISTRHO_OS_WASM
if (rack::patchStorageSlug != nullptr) if (rack::patchStorageSlug != nullptr)
{ {
psDialog = new WasmPatchStorageLoadingDialog();
psDialog = new WasmRemotePatchLoadingDialog(true);
}
else if (rack::patchRemoteURL != nullptr)
{
psDialog = new WasmRemotePatchLoadingDialog(false);
} }
else if (rack::patchFromURL != nullptr) else if (rack::patchFromURL != nullptr)
{ {
@@ -451,7 +457,17 @@ public:
rack::patchStorageSlug = nullptr; rack::patchStorageSlug = nullptr;


emscripten_async_wget(url.c_str(), context->patch->templatePath.c_str(), emscripten_async_wget(url.c_str(), context->patch->templatePath.c_str(),
downloadPatchStorageSucceeded, downloadPatchStorageFailed);
downloadRemotePatchSucceeded, downloadRemotePatchFailed);
}
else if (rack::patchRemoteURL != nullptr)
{
std::string url("/patchurl.php?url=");
url += rack::patchRemoteURL;
std::free(rack::patchRemoteURL);
rack::patchRemoteURL = nullptr;

emscripten_async_wget(url.c_str(), context->patch->templatePath.c_str(),
downloadRemotePatchSucceeded, downloadRemotePatchFailed);
} }
#endif #endif
} }


+ 2
- 2
src/PluginContext.hpp View File

@@ -142,7 +142,7 @@ public:
}; };


#ifndef HEADLESS #ifndef HEADLESS
struct WasmPatchStorageLoadingDialog;
struct WasmRemotePatchLoadingDialog;


class CardinalBaseUI : public UI { class CardinalBaseUI : public UI {
public: public:
@@ -151,7 +151,7 @@ public:
bool savingUncompressed; bool savingUncompressed;


#ifdef DISTRHO_OS_WASM #ifdef DISTRHO_OS_WASM
WasmPatchStorageLoadingDialog* psDialog;
WasmRemotePatchLoadingDialog* psDialog;
#endif #endif


// for 3rd party modules // for 3rd party modules


Loading…
Cancel
Save