Skip to content

Commit

Permalink
More plugin details, improve handling of rate changes
Browse files Browse the repository at this point in the history
Signed-off-by: falkTX <falktx@falktx.com>
  • Loading branch information
falkTX committed Mar 16, 2024
1 parent 025bcf6 commit 1348a5e
Show file tree
Hide file tree
Showing 14 changed files with 104 additions and 37 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,9 @@ jobs:
run: |
make PAWPAW_TARGET=${{ matrix.target }}
- name: Validate plugins
if: false
#if: steps.cache.outputs.cache-hit == 'true'
if: steps.cache.outputs.cache-hit == 'true'
run: |
# ./utils/plugin-builder/validate-plugins.sh ${{ matrix.target }}
./utils/plugin-builder/validate-plugins.sh ${{ matrix.target }}
# FIXME dirty carla leaves temp folders around
rm -rf *.tmp
- name: Set version tag for release
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ clean:
$(MAKE) clean -C src/systray
rm -rf build
rm -rf build-midi-merger
rm -rf build-plugin
rm -rf build-plugin-stamps
rm -rf build-pedalboard
rm -rf build-ui
Expand Down
2 changes: 1 addition & 1 deletion src/PawPaw
Submodule PawPaw updated 1 files
+1 −1 bootstrap-mod.sh
2 changes: 1 addition & 1 deletion src/mod-host
2 changes: 1 addition & 1 deletion src/plugin/ChildProcess.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class ChildProcess
nullptr, // lpProcessAttributes
nullptr, // lpThreadAttributes
TRUE, // bInheritHandles
/* CREATE_NO_WINDOW | */ CREATE_UNICODE_ENVIRONMENT, // dwCreationFlags
CREATE_NO_WINDOW | CREATE_UNICODE_ENVIRONMENT, // dwCreationFlags
const_cast<LPWSTR>(envp), // lpEnvironment
nullptr, // lpCurrentDirectory
&si, // lpStartupInfo
Expand Down
74 changes: 56 additions & 18 deletions src/plugin/DesktopPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class DesktopPlugin : public Plugin,
ChildProcess jackd;
ChildProcess mod_ui;
SharedMemory shm;
String currentPedalboard;
bool startingJackd = false;
bool startingModUI = false;
bool processing = false;
Expand All @@ -28,7 +29,7 @@ class DesktopPlugin : public Plugin,
float* tmpBuffers[2] = {};
uint32_t numFramesInShmBuffer = 0;
uint32_t numFramesInTmpBuffer = 0;
uint portBaseNum = 0;
int portBaseNum = 0;

#ifdef DISTRHO_OS_WINDOWS
const WCHAR* envp;
Expand All @@ -38,11 +39,14 @@ class DesktopPlugin : public Plugin,

public:
DesktopPlugin()
: Plugin(kParameterCount, 0, 0),
: Plugin(kParameterCount, 0, 1),
envp(nullptr)
{
if (isDummyInstance())
{
portBaseNum = -kErrorUndefined;
return;
}

// TODO check available ports
static int port = 1;
Expand All @@ -53,7 +57,7 @@ class DesktopPlugin : public Plugin,

if (envp == nullptr)
{
parameters[kParameterBasePortNumber] = -kErrorAppDirNotFound;
parameters[kParameterBasePortNumber] = portBaseNum = -kErrorAppDirNotFound;
return;
}

Expand All @@ -67,11 +71,13 @@ class DesktopPlugin : public Plugin,
stopRunner();

if (processing && jackd.isRunning())
{
processing = false;
shm.stopWait();
}

jackd.stop();
mod_ui.stop();

shm.deinit();

delete[] tmpBuffers[0];
Expand Down Expand Up @@ -100,12 +106,18 @@ class DesktopPlugin : public Plugin,
#define APP_EXT ""
#endif

if (shm.data == nullptr && ! shm.init())
{
parameters[kParameterBasePortNumber] = portBaseNum = -kErrorShmSetupFailed;
return false;
}

if (! jackd.isRunning())
{
if (startingJackd)
{
startingJackd = false;
parameters[kParameterBasePortNumber] = -kErrorJackdExecFailed;
parameters[kParameterBasePortNumber] = portBaseNum = -kErrorJackdExecFailed;
return false;
}

Expand All @@ -130,7 +142,7 @@ class DesktopPlugin : public Plugin,
if (jackd.start(jackd_args, envp))
return true;

parameters[kParameterBasePortNumber] = -kErrorJackdExecFailed;
parameters[kParameterBasePortNumber] = portBaseNum = -kErrorJackdExecFailed;
return false;
}

Expand All @@ -149,7 +161,7 @@ class DesktopPlugin : public Plugin,
if (startingModUI)
{
startingModUI = false;
parameters[kParameterBasePortNumber] = -kErrorModUiExecFailed;
parameters[kParameterBasePortNumber] = portBaseNum = -kErrorModUiExecFailed;
return false;
}

Expand All @@ -165,7 +177,7 @@ class DesktopPlugin : public Plugin,
if (mod_ui.start(mod_ui_args, envp))
return true;

parameters[kParameterBasePortNumber] = -kErrorModUiExecFailed;
parameters[kParameterBasePortNumber] = portBaseNum = -kErrorModUiExecFailed;
return false;
}

Expand Down Expand Up @@ -225,6 +237,7 @@ class DesktopPlugin : public Plugin,
*/
uint32_t getVersion() const override
{
// return d_version(VERSION[0]-'0', VERSION[2]-'0', VERSION[4]-'0');
return d_version(1, 0, 0);
}

Expand Down Expand Up @@ -267,9 +280,12 @@ class DesktopPlugin : public Plugin,
Set a state key and default value.
This function will be called once, shortly after the plugin is created.
*/
void initState(uint32_t, String&, String&) override
void initState(uint32_t, State& state) override
{
// we are using states but don't want them saved in the host
state.hints = kStateIsFilenamePath | kStateIsOnlyForDSP;
state.key = "pedalboard";
state.defaultValue = "";
state.label = "Pedalboard";
}

/* --------------------------------------------------------------------------------------------------------
Expand All @@ -291,11 +307,25 @@ class DesktopPlugin : public Plugin,
// parameters[index] = value;
}

/**
Get the value of an internal state.
The host may call this function from any non-realtime context.
*/
String getState(const char* const key) const override
{
if (std::strcmp(key, "pedalboard") == 0)
return currentPedalboard;

return String();
}

/**
Change an internal state.
*/
void setState(const char*, const char*) override
void setState(const char* const key, const char* const value) override
{
if (std::strcmp(key, "pedalboard") == 0)
currentPedalboard = value;
}

/* --------------------------------------------------------------------------------------------------------
Expand All @@ -307,14 +337,15 @@ class DesktopPlugin : public Plugin,
{
firstTimeActivating = false;

if (envp != nullptr && shm.init() && run())
if (run())
startRunner(500);
}
else
{
shm.reset();
}

firstTimeProcessing = true;
numFramesInShmBuffer = numFramesInTmpBuffer = 0;
}

Expand Down Expand Up @@ -513,14 +544,21 @@ class DesktopPlugin : public Plugin,

void sampleRateChanged(double) override
{
if (jackd.isRunning())
{
stopRunner();
jackd.stop();
if (portBaseNum < 0 || shm.data == nullptr)
return;

if (run())
startRunner(500);
stopRunner();

if (processing && jackd.isRunning())
{
processing = false;
shm.stopWait();
}

jackd.stop();
shm.deinit();

firstTimeActivating = true;
}

// -------------------------------------------------------------------------------------------------------
Expand Down
40 changes: 30 additions & 10 deletions src/plugin/DesktopUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,19 @@ class DesktopUI : public UI,
buttonRefresh.setAbsolutePos(2 * scaleFactor, 2 * scaleFactor);
buttonRefresh.setSize(70 * scaleFactor, 26 * scaleFactor);

buttonOpenWebGui.setId(2);
buttonOpenWebGui.setLabel("Open in Web Browser");
buttonOpenWebGui.setFontScale(scaleFactor);
buttonOpenWebGui.setAbsolutePos(74 * scaleFactor, 2 * scaleFactor);
buttonOpenWebGui.setSize(150 * scaleFactor, 26 * scaleFactor);

buttonOpenUserFilesDir.setId(3);
buttonOpenUserFilesDir.setId(2);
buttonOpenUserFilesDir.setLabel("Open User Files Dir");
buttonOpenUserFilesDir.setFontScale(scaleFactor);
buttonOpenUserFilesDir.setAbsolutePos(226 * scaleFactor, 2 * scaleFactor);
buttonOpenUserFilesDir.setAbsolutePos(74 * scaleFactor, 2 * scaleFactor);
buttonOpenUserFilesDir.setSize(140 * scaleFactor, 26 * scaleFactor);

buttonOpenWebGui.setId(3);
buttonOpenWebGui.setLabel("Open in Web Browser");
buttonOpenWebGui.setFontScale(scaleFactor);
buttonOpenWebGui.setAbsolutePos(216 * scaleFactor, 2 * scaleFactor);
buttonOpenWebGui.setSize(150 * scaleFactor, 26 * scaleFactor);
buttonOpenWebGui.hide();

label = "MOD Desktop ";
label += getPluginFormatName();
label += " v" VERSION;
Expand Down Expand Up @@ -92,6 +93,13 @@ class DesktopUI : public UI,

if (value < 0.f)
{
if (webview != nullptr)
{
destroyWebView(webview);
webview = nullptr;
buttonOpenWebGui.hide();
}

switch (-d_roundToIntNegative(value))
{
case kErrorAppDirNotFound:
Expand All @@ -106,11 +114,16 @@ class DesktopUI : public UI,
error = "Error: Failed to start mod-ui";
errorDetail = "";
break;
case kErrorShmSetupFailed:
error = "Error initializing MOD Desktop plugin";
errorDetail = "Shared memory setup failed";
break;
case kErrorUndefined:
error = "Error initializing MOD Desktop plugin";
errorDetail = "";
break;
}

repaint();
return;
}
Expand All @@ -126,13 +139,20 @@ class DesktopUI : public UI,
{
destroyWebView(webview);
webview = nullptr;

buttonOpenWebGui.hide();
repaint();
}

port = d_roundToUnsignedInt(value);
DISTRHO_SAFE_ASSERT_RETURN(port != 0,);

port += kPortNumOffset;
d_stderr("webview port is %d", port);
webview = addWebView(getWindow().getNativeWindowHandle(), getScaleFactor(), port);

buttonOpenWebGui.show();
repaint();
}
}

Expand Down Expand Up @@ -182,10 +202,10 @@ class DesktopUI : public UI,
reloadWebView(webview);
break;
case 2:
openWebGui(port);
openUserFilesDir();
break;
case 3:
openUserFilesDir();
openWebGui(port);
break;
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/plugin/DistrhoPluginInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
#define DISTRHO_PLUGIN_IS_RT_SAFE 0
#define DISTRHO_PLUGIN_NUM_INPUTS 2
#define DISTRHO_PLUGIN_NUM_OUTPUTS 2
#define DISTRHO_PLUGIN_WANT_LATENCY 1
#define DISTRHO_PLUGIN_WANT_MIDI_INPUT 1
#define DISTRHO_PLUGIN_WANT_MIDI_OUTPUT 1
#define DISTRHO_PLUGIN_WANT_STATE 1
#define DISTRHO_PLUGIN_WANT_FULL_STATE 1
#define DISTRHO_UI_FILE_BROWSER 0
#define DISTRHO_UI_DEFAULT_WIDTH 1170
#define DISTRHO_UI_DEFAULT_HEIGHT 600
Expand All @@ -31,6 +33,7 @@ enum Error {
kErrorAppDirNotFound = 1,
kErrorJackdExecFailed,
kErrorModUiExecFailed,
kErrorShmSetupFailed,
kErrorUndefined
};

Expand Down
5 changes: 3 additions & 2 deletions src/plugin/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ BUILD_CXX_FLAGS += -pthread
LINK_FLAGS += -pthread

ifeq ($(MACOS),true)
LINK_FLAGS += -framework IOKit -framework WebKit
LINK_FLAGS += -framework CoreFoundation -framework IOKit -framework WebKit
else ifeq ($(WINDOWS),true)
LINK_FLAGS += -lwinmm
else ifeq ($(LINUX),true)
BUILD_CXX_FLAGS += $(shell $(PKG_CONFIG) --cflags Qt5Core) -std=gnu++14
BUILD_CXX_FLAGS += $(shell $(PKG_CONFIG) --cflags Qt5Core)
# -std=gnu++14
LINK_FLAGS += -ldl -lrt
endif

Expand Down
1 change: 1 addition & 0 deletions src/plugin/SharedMemory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ class SharedMemory
data->magic = 7331;
post();
wait();
data->magic = 1337;
}

bool process(float** output, const uint32_t offset)
Expand Down
Empty file removed src/plugin/WebViewQt.cpp
Empty file.
1 change: 0 additions & 1 deletion src/plugin/WebViewX11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,6 @@ static bool qt6webengine(const Window winId, const double scaleFactor, const cha
QWebEngineView_setUrl(webview, *qurl);
};


QApplication_exec();

dlclose(lib);
Expand Down
2 changes: 2 additions & 0 deletions src/plugin/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ char* const* getEvironment(const uint portBaseNum)
set_envp_value(envpl, L"LANG=en_US.UTF-8");
set_envp_value(envpl, L"MOD_DESKTOP=1");
set_envp_value(envpl, L"MOD_DESKTOP_PLUGIN=1");
set_envp_value(envpl, L"MOD_LOG=0");
set_envp_value(envpl, L"PYTHONUNBUFFERED=1");
#else
while (environ[envsize] != nullptr)
Expand All @@ -306,6 +307,7 @@ char* const* getEvironment(const uint portBaseNum)
set_envp_value(envp, "LANG=en_US.UTF-8");
set_envp_value(envp, "MOD_DESKTOP=1");
set_envp_value(envp, "MOD_DESKTOP_PLUGIN=1");
set_envp_value(envp, "MOD_LOG=0");
set_envp_value(envp, "PYTHONUNBUFFERED=1");
#endif

Expand Down
Loading

0 comments on commit 1348a5e

Please sign in to comment.