Skip to content

Commit

Permalink
MIDI stubs
Browse files Browse the repository at this point in the history
Signed-off-by: falkTX <[email protected]>
  • Loading branch information
falkTX committed Mar 12, 2024
1 parent f389b85 commit 3bb00ba
Show file tree
Hide file tree
Showing 9 changed files with 377 additions and 106 deletions.
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ PAWPAW_PREFIX = $(PAWPAW_DIR)/targets/$(PAWPAW_TARGET)$(PAWPAW_SUFFIX)
# ---------------------------------------------------------------------------------------------------------------------
# List of files created by PawPaw bootstrap, to ensure we have run it at least once

BOOTSTRAP_FILES = $(PAWPAW_PREFIX)/bin/cxfreeze
BOOTSTRAP_FILES = $(PAWPAW_PREFIX)/bin/cxfreeze-quickstart
BOOTSTRAP_FILES += $(PAWPAW_PREFIX)/bin/jackd$(APP_EXT)
BOOTSTRAP_FILES += $(PAWPAW_PREFIX)/include/armadillo

Expand Down Expand Up @@ -144,6 +144,7 @@ TARGETS += build/pedalboards
TARGETS += build/VERSION
ifeq ($(WINDOWS),true)
TARGETS += build/jack/jack_dummy.dll
TARGETS += build/jack/jack_desktop.dll
TARGETS += build/jack/jack_portaudio.dll
TARGETS += build/jack/jack_winmme.dll
TARGETS += build/libjack64.dll
Expand Down Expand Up @@ -276,10 +277,13 @@ TARGETS += $(foreach PLUGIN,$(PLUGINS),$(call PLUGIN_STAMP,$(PLUGIN)))
# ---------------------------------------------------------------------------------------------------------------------

all: $(TARGETS)
$(MAKE) -C src/plugin

clean:
$(MAKE) clean -C src/DPF
$(MAKE) clean -C src/mod-host
$(MAKE) clean -C src/mod-ui/utils
$(MAKE) clean -C src/plugin
$(MAKE) clean -C src/systray
rm -rf build
rm -rf build-midi-merger
Expand Down Expand Up @@ -320,6 +324,9 @@ win64-app:
win64-bootstrap:
./src/PawPaw/bootstrap-mod.sh win64

win64-plugin:
./utils/run.sh win64 $(MAKE) -C src/plugin

win64-plugins:
$(MAKE) PAWPAW_TARGET=win64 plugins

Expand Down
96 changes: 87 additions & 9 deletions src/plugin/ChildProcess.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
#endif

#ifdef DISTRHO_OS_WINDOWS
# include <string>
# include <winsock2.h>
# include <windows.h>
#else
# include <cerrno>
# include <ctime>
Expand All @@ -27,6 +30,7 @@ START_NAMESPACE_DISTRHO
#if defined(DISTRHO_OS_MAC)
# define P "/Users/falktx/Source/MOD/mod-app/build/mod-desktop.app/Contents"
#elif defined(DISTRHO_OS_WINDOWS)
# define P "Z:\\home\\falktx\\Source\\MOD\\mod-app\\build"
#else
# define P "/home/falktx/Source/MOD/mod-app/build"
#endif
Expand All @@ -36,6 +40,7 @@ START_NAMESPACE_DISTRHO
class ChildProcess
{
#ifdef _WIN32
PROCESS_INFORMATION process = { INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE, 0, 0 };
#else
pid_t pid = -1;
#endif
Expand All @@ -53,6 +58,13 @@ class ChildProcess
bool start(const char* const args[])
{
// FIXME
#ifdef DISTRHO_OS_WINDOWS
const CHAR* const envp = (
"MOD_DATA_DIR=" P "\\data\0"
"MOD_FACTORY_PEDALBOARDS_DIR=" P "\\pedalboards\0"
"LV2_PATH=" P "\\plugins\0"
"\0");
#else
const char* const envp[] = {
"MOD_DESKTOP=1",
"LANG=en_US.UTF-8",
Expand All @@ -61,8 +73,7 @@ class ChildProcess
"JACK_DRIVER_DIR=" P "/MacOS/jack",
"MOD_DATA_DIR=/Users/falktx/Documents/MOD Desktop",
"MOD_FACTORY_PEDALBOARDS_DIR=" P "/Resources/pedalboards",
"LV2_PATH=" P "/PlugIns/LV2", // FIXME
#elif defined(DISTRHO_OS_WINDOWS)
"LV2_PATH=" P "/LV2",
#else
"LD_LIBRARY_PATH=" P,
"JACK_DRIVER_DIR=" P "/jack",
Expand All @@ -72,7 +83,35 @@ class ChildProcess
#endif
nullptr
};
#endif

#ifdef _WIN32
std::string cmd;

for (uint i = 0; args[i] != nullptr; ++i)
{
if (i != 0)
cmd += " ";

cmd += args[i];
}

STARTUPINFOA si = {};
si.cb = sizeof(si);

d_stdout("will start process with args '%s'", cmd.data());

return CreateProcessA(nullptr, // lpApplicationName
&cmd[0], // lpCommandLine
nullptr, // lpProcessAttributes
nullptr, // lpThreadAttributes
TRUE, // bInheritHandles
0, // CREATE_NO_WINDOW /*| CREATE_UNICODE_ENVIRONMENT*/, // dwCreationFlags
const_cast<LPSTR>(envp), // lpEnvironment
nullptr, // lpCurrentDirectory
&si, // lpStartupInfo
&process) != FALSE;
#else
const pid_t ret = pid = vfork();

switch (ret)
Expand All @@ -92,20 +131,57 @@ class ChildProcess
}

return ret > 0;
#endif
}

void stop(const uint32_t timeoutInMilliseconds = 2000)
{
const uint32_t timeout = d_gettime_ms() + timeoutInMilliseconds;
bool sendTerminate = true;

#ifdef _WIN32
if (process.hProcess == INVALID_HANDLE_VALUE)
return;

const PROCESS_INFORMATION oprocess = process;
process = { INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE, 0, 0 };

for (;;)
{
switch (WaitForSingleObject(oprocess.hProcess, 0))
{
case WAIT_OBJECT_0:
case WAIT_FAILED:
CloseHandle(oprocess.hThread);
CloseHandle(oprocess.hProcess);
return;
}

if (sendTerminate)
{
sendTerminate = false;
TerminateProcess(oprocess.hProcess, 15);
}
if (d_gettime_ms() < timeout)
{
d_msleep(5);
continue;
}
d_stderr("ChildProcess::stop() - timed out");
TerminateProcess(oprocess.hProcess, 9);
d_msleep(5);
CloseHandle(oprocess.hThread);
CloseHandle(oprocess.hProcess);
break;
}
#else
if (pid <= 0)
return;

const uint32_t timeout = d_gettime_ms() + timeoutInMilliseconds;
const pid_t opid = pid;
pid_t ret;
bool sendTerminate = true;
pid = -1;

for (;;)
for (pid_t ret;;)
{
try {
ret = ::waitpid(opid, nullptr, WNOHANG);
Expand All @@ -130,16 +206,17 @@ class ChildProcess
if (sendTerminate)
{
sendTerminate = false;
::kill(opid, SIGTERM);
kill(opid, SIGTERM);
}
if (d_gettime_ms() < timeout)
{
d_msleep(5);
continue;
}

d_stderr("ChildProcess::stop() - timed out");
::kill(opid, SIGKILL);
::waitpid(opid, nullptr, WNOHANG);
kill(opid, SIGKILL);
waitpid(opid, nullptr, WNOHANG);
break;

default:
Expand All @@ -157,6 +234,7 @@ class ChildProcess

break;
}
#endif
}

DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ChildProcess)
Expand Down
Loading

0 comments on commit 3bb00ba

Please sign in to comment.