commit f12d52d9e2fde089d4f11be6493babcf8b11d8b1
parent fec59af37372d2b84e02b8cae7bda4f2756fedb0
Author: falkTX <falktx@falktx.com>
Date: Thu, 29 Dec 2022 01:11:03 +0000
Handle custom application class name as needed for modguis
Signed-off-by: falkTX <falktx@falktx.com>
Diffstat:
4 files changed, 49 insertions(+), 21 deletions(-)
diff --git a/dgl/src/ApplicationPrivateData.cpp b/dgl/src/ApplicationPrivateData.cpp
@@ -67,9 +67,11 @@ Application::PrivateData::PrivateData(const bool standalone)
DISTRHO_SAFE_ASSERT_RETURN(world != nullptr,);
puglSetWorldHandle(world, this);
-#ifndef __EMSCRIPTEN__
+ #ifdef __EMSCRIPTEN__
+ puglSetClassName(world, "canvas");
+ #else
puglSetClassName(world, DISTRHO_MACRO_AS_STRING(DGL_NAMESPACE));
-#endif
+ #endif
}
Application::PrivateData::~PrivateData()
diff --git a/distrho/src/DistrhoUIInternal.hpp b/distrho/src/DistrhoUIInternal.hpp
@@ -57,9 +57,10 @@ public:
void* const dspPtr = nullptr,
const double scaleFactor = 0.0,
const uint32_t bgColor = 0,
- const uint32_t fgColor = 0xffffffff)
+ const uint32_t fgColor = 0xffffffff,
+ const char* const appClassName = nullptr)
: ui(nullptr),
- uiData(new UI::PrivateData())
+ uiData(new UI::PrivateData(appClassName))
{
uiData->sampleRate = sampleRate;
uiData->bundlePath = bundlePath != nullptr ? strdup(bundlePath) : nullptr;
diff --git a/distrho/src/DistrhoUILV2.cpp b/distrho/src/DistrhoUILV2.cpp
@@ -78,7 +78,8 @@ public:
const float sampleRate,
const float scaleFactor,
const uint32_t bgColor,
- const uint32_t fgColor)
+ const uint32_t fgColor,
+ const char* const appClassName)
: fUridMap(uridMap),
fUridUnmap(getLv2Feature<LV2_URID_Unmap>(features, LV2_URID__unmap)),
fUiPortMap(getLv2Feature<LV2UI_Port_Map>(features, LV2_UI__portMap)),
@@ -97,7 +98,7 @@ public:
sendNoteCallback,
nullptr, // resize is very messy, hosts can do it without extensions
fileRequestCallback,
- bundlePath, dspPtr, scaleFactor, bgColor, fgColor)
+ bundlePath, dspPtr, scaleFactor, bgColor, fgColor, appClassName)
{
if (widget != nullptr)
*widget = (LV2UI_Widget)fUI.getNativeWindowHandle();
@@ -559,17 +560,20 @@ static LV2UI_Handle lv2ui_instantiate(const LV2UI_Descriptor*,
float scaleFactor = 0.0f;
uint32_t bgColor = 0;
uint32_t fgColor = 0xffffffff;
+ const char* appClassName = nullptr;
if (options != nullptr)
{
const LV2_URID uridAtomInt = uridMap->map(uridMap->handle, LV2_ATOM__Int);
const LV2_URID uridAtomFloat = uridMap->map(uridMap->handle, LV2_ATOM__Float);
+ const LV2_URID uridAtomString = uridMap->map(uridMap->handle, LV2_ATOM__String);
const LV2_URID uridSampleRate = uridMap->map(uridMap->handle, LV2_PARAMETERS__sampleRate);
const LV2_URID uridBgColor = uridMap->map(uridMap->handle, LV2_UI__backgroundColor);
const LV2_URID uridFgColor = uridMap->map(uridMap->handle, LV2_UI__foregroundColor);
#ifndef DISTRHO_OS_MAC
const LV2_URID uridScaleFactor = uridMap->map(uridMap->handle, LV2_UI__scaleFactor);
#endif
+ const LV2_URID uridClassName = uridMap->map(uridMap->handle, "urn:distrho:className");
for (int i=0; options[i].key != 0; ++i)
{
@@ -603,6 +607,13 @@ static LV2UI_Handle lv2ui_instantiate(const LV2UI_Descriptor*,
d_stderr("Host provides UI scale factor but has wrong value type");
}
#endif
+ else if (options[i].key == uridClassName)
+ {
+ if (options[i].type == uridAtomString)
+ appClassName = (const char*)options[i].value;
+ else
+ d_stderr("Host provides UI scale factor but has wrong value type");
+ }
}
}
@@ -614,7 +625,7 @@ static LV2UI_Handle lv2ui_instantiate(const LV2UI_Descriptor*,
return new UiLv2(bundlePath, winId, options, uridMap, features,
controller, writeFunction, widget, instance,
- sampleRate, scaleFactor, bgColor, fgColor);
+ sampleRate, scaleFactor, bgColor, fgColor, appClassName);
}
#define uiPtr ((UiLv2*)ui)
@@ -823,6 +834,14 @@ LV2UI_Handle modgui_init(const char* const className, _custom_param_set param_se
uridMap.map(uridMap.handle, LV2_ATOM__Float),
&sampleRateValue
},
+ {
+ LV2_OPTIONS_INSTANCE,
+ 0,
+ uridMap.map(uridMap.handle, "urn:distrho:className"),
+ std::strlen(className) + 1,
+ uridMap.map(uridMap.handle, LV2_ATOM__String),
+ className
+ },
{}
};
diff --git a/distrho/src/DistrhoUIPrivateData.hpp b/distrho/src/DistrhoUIPrivateData.hpp
@@ -60,7 +60,7 @@ struct PluginApplication
DGL_NAMESPACE::IdleCallback* idleCallback;
UI* ui;
- explicit PluginApplication()
+ explicit PluginApplication(const char*)
: idleCallback(nullptr),
ui(nullptr) {}
@@ -105,20 +105,26 @@ struct PluginApplication
class PluginApplication : public DGL_NAMESPACE::Application
{
public:
- explicit PluginApplication()
+ explicit PluginApplication(const char* className)
: DGL_NAMESPACE::Application(DISTRHO_UI_IS_STANDALONE)
{
-#ifndef DISTRHO_OS_WASM
- const char* const className = (
-#ifdef DISTRHO_PLUGIN_BRAND
- DISTRHO_PLUGIN_BRAND
-#else
- DISTRHO_MACRO_AS_STRING(DISTRHO_NAMESPACE)
-#endif
- "-" DISTRHO_PLUGIN_NAME
- );
+ #if defined(__MOD_DEVICES__) || !defined(__EMSCRIPTEN__)
+ if (className == nullptr)
+ {
+ className = (
+ #ifdef DISTRHO_PLUGIN_BRAND
+ DISTRHO_PLUGIN_BRAND
+ #else
+ DISTRHO_MACRO_AS_STRING(DISTRHO_NAMESPACE)
+ #endif
+ "-" DISTRHO_PLUGIN_NAME
+ );
+ }
setClassName(className);
-#endif
+ #else
+ // unused
+ (void)className;
+ #endif
}
void triggerIdleCallbacks()
@@ -337,8 +343,8 @@ struct UI::PrivateData {
setSizeFunc setSizeCallbackFunc;
fileRequestFunc fileRequestCallbackFunc;
- PrivateData() noexcept
- : app(),
+ PrivateData(const char* const appClassName) noexcept
+ : app(appClassName),
window(nullptr),
sampleRate(0),
parameterOffset(0),