Skip to content

Commit

Permalink
Hook more web-ui calls, fix linux build
Browse files Browse the repository at this point in the history
Signed-off-by: falkTX <[email protected]>
  • Loading branch information
falkTX committed May 9, 2024
1 parent cfbdb86 commit 2dab68f
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Makefile.plugins.mk
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ DGL_LIBS += -framework WebKit
else ifeq ($(WINDOWS),true)
# DGL_FLAGS += -std=gnu++17
DGL_LIBS += -lole32 -luuid
else
DGL_LIBS += -lrt
endif
DGL_LIB = $(DGL_BUILD_DIR)/libdgl-web.a
HAVE_DGL = true
Expand Down
38 changes: 37 additions & 1 deletion distrho/src/DistrhoUI.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* DISTRHO Plugin Framework (DPF)
* Copyright (C) 2012-2023 Filipe Coelho <[email protected]>
* Copyright (C) 2012-2024 Filipe Coelho <[email protected]>
*
* Permission to use, copy, modify, and/or distribute this software for any purpose with
* or without fee is hereby granted, provided that the above copyright notice and this
Expand Down Expand Up @@ -230,14 +230,17 @@ UI::PrivateData::createNextWindow(UI* const ui, uint width, uint height, const b

UI::UI(const uint width, const uint height, const bool automaticallyScaleAndSetAsMinimumSize)
: UIWidget(UI::PrivateData::createNextWindow(this,
// width
#ifdef DISTRHO_UI_DEFAULT_WIDTH
width == 0 ? DISTRHO_UI_DEFAULT_WIDTH :
#endif
width,
// height
#ifdef DISTRHO_UI_DEFAULT_HEIGHT
height == 0 ? DISTRHO_UI_DEFAULT_HEIGHT :
#endif
height,
// adjustForScaleFactor
#ifdef DISTRHO_UI_DEFAULT_WIDTH
width == 0
#else
Expand Down Expand Up @@ -271,6 +274,10 @@ UI::UI(const uint width, const uint height, const bool automaticallyScaleAndSetA
"setParameterValue=function(index,value){window.webkit.messageHandlers.external.postMessage('setparam '+index+' '+value)};"
#if DISTRHO_PLUGIN_WANT_STATE
"setState=function(key,value){window.webkit.messageHandlers.external.postMessage('setstate '+key+' '+value)};"
"requestStateFile=function(key){window.webkit.messageHandlers.external.postMessage('reqstatefile '+key)};"
#endif
#if DISTRHO_PLUGIN_WANT_MIDI_INPUT
"sendNote=function(channel,note,velocity){window.webkit.messageHandlers.external.postMessage('sendnote '+channel+' '+note+' '+velocity)};"
#endif
);
#endif
Expand Down Expand Up @@ -594,6 +601,35 @@ void UI::onMessage(char* const message)
setState(key, value);
return;
}

if (std::strncmp(message, "reqstatefile ", 13) == 0)
{
const char* const key = message + 13;
requestStateFile(key);
return;
}
#endif

#if DISTRHO_PLUGIN_WANT_MIDI_INPUT
if (std::strncmp(message, "sendnote ", 9) == 0)
{
const char* const strchannel = message + 9;
char* strnote = nullptr;
char* strvelocity = nullptr;
char* end = nullptr;

const ulong channel = std::strtoul(strchannel, &strnote, 10);
DISTRHO_SAFE_ASSERT_RETURN(strnote != nullptr && strchannel != strnote,);

const ulong note = std::strtoul(strnote, &strvelocity, 10);
DISTRHO_SAFE_ASSERT_RETURN(strvelocity != nullptr && strchannel != strvelocity,);

const ulong velocity = std::strtoul(strvelocity, &end, 10);
DISTRHO_SAFE_ASSERT_RETURN(end != nullptr && strvelocity != end,);

sendNote(channel, note, started);
return;
}
#endif

d_stderr("UI received unknown message %s", message);
Expand Down
13 changes: 13 additions & 0 deletions examples/WebMeters/ExampleUIWebMeters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@ class ExampleUIMeters : public UI
ExampleUIMeters()
: UI()
{
/*
const double scaleFactor = getScaleFactor();
if (d_isNotEqual(scaleFactor, 1.0))
{
setGeometryConstraints(DISTRHO_UI_DEFAULT_WIDTH * scaleFactor, DISTRHO_UI_DEFAULT_HEIGHT * scaleFactor);
setSize(DISTRHO_UI_DEFAULT_WIDTH * scaleFactor, DISTRHO_UI_DEFAULT_HEIGHT * scaleFactor);
}
else
{
setGeometryConstraints(DISTRHO_UI_DEFAULT_WIDTH, DISTRHO_UI_DEFAULT_HEIGHT);
}
*/
}

private:
Expand Down
1 change: 1 addition & 0 deletions examples/WebMeters/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
repaint();
}
function parameterChanged(index, value) {
// console.log("paramChanged", index, value)
switch (index) {
case 0: // color
updateColor(parseInt(Math.round(value)));
Expand Down

0 comments on commit 2dab68f

Please sign in to comment.