Allow wasm to load patch from url too
This commit is contained in:
parent
19878f0097
commit
e42dc9154f
5 changed files with 44 additions and 12 deletions
|
@ -99,6 +99,7 @@ std::string getSpecialPath(const SpecialPath type)
|
|||
|
||||
#ifdef DISTRHO_OS_WASM
|
||||
char* patchFromURL = nullptr;
|
||||
char* patchRemoteURL = nullptr;
|
||||
char* patchStorageSlug = nullptr;
|
||||
#endif
|
||||
|
||||
|
|
|
@ -59,6 +59,7 @@ std::string getSpecialPath(SpecialPath type);
|
|||
|
||||
#ifdef DISTRHO_OS_WASM
|
||||
extern char* patchFromURL;
|
||||
extern char* patchRemoteURL;
|
||||
extern char* patchStorageSlug;
|
||||
#endif
|
||||
|
||||
|
|
|
@ -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() {
|
||||
return static_cast<char*>(EM_ASM_PTR({
|
||||
var searchParams = new URLSearchParams(window.location.search);
|
||||
|
@ -620,6 +633,7 @@ public:
|
|||
|
||||
#ifdef DISTRHO_OS_WASM
|
||||
if ((rack::patchStorageSlug = getPatchStorageSlug()) == nullptr &&
|
||||
(rack::patchRemoteURL = getPatchRemoteURL()) == nullptr &&
|
||||
(rack::patchFromURL = getPatchFileEncodedInURL()) == nullptr)
|
||||
#endif
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
||||
rack::ui::MenuOverlay* overlay;
|
||||
|
||||
WasmPatchStorageLoadingDialog()
|
||||
WasmRemotePatchLoadingDialog(const bool isFromPatchStorage)
|
||||
{
|
||||
using rack::ui::Label;
|
||||
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.y = box.size.y - 2*margin;
|
||||
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);
|
||||
|
||||
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);
|
||||
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 = nullptr;
|
||||
asyncDialog::create("Failed to fetch patch from PatchStorage");
|
||||
asyncDialog::create("Failed to fetch remote patch");
|
||||
}
|
||||
|
||||
using namespace rack;
|
||||
|
@ -259,9 +261,9 @@ static void downloadPatchStorageFailed(const char* const filename)
|
|||
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);
|
||||
CardinalBaseUI* const ui = static_cast<CardinalBaseUI*>(context->ui);
|
||||
|
||||
|
@ -390,7 +392,11 @@ public:
|
|||
#ifdef DISTRHO_OS_WASM
|
||||
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)
|
||||
{
|
||||
|
@ -451,7 +457,17 @@ public:
|
|||
rack::patchStorageSlug = nullptr;
|
||||
|
||||
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
|
||||
}
|
||||
|
|
|
@ -142,7 +142,7 @@ public:
|
|||
};
|
||||
|
||||
#ifndef HEADLESS
|
||||
struct WasmPatchStorageLoadingDialog;
|
||||
struct WasmRemotePatchLoadingDialog;
|
||||
|
||||
class CardinalBaseUI : public UI {
|
||||
public:
|
||||
|
@ -151,7 +151,7 @@ public:
|
|||
bool savingUncompressed;
|
||||
|
||||
#ifdef DISTRHO_OS_WASM
|
||||
WasmPatchStorageLoadingDialog* psDialog;
|
||||
WasmRemotePatchLoadingDialog* psDialog;
|
||||
#endif
|
||||
|
||||
// for 3rd party modules
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue