-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Start of DPF-based plugin Signed-off-by: falkTX <falktx@falktx.com> * Deal with any buffer size Signed-off-by: falkTX <falktx@falktx.com> * Pass host sample rate into jack Signed-off-by: falkTX <falktx@falktx.com> * Auto-start mod-ui as well Signed-off-by: falkTX <falktx@falktx.com> * Cleanup, split files Signed-off-by: falkTX <falktx@falktx.com> * macos plugin details Signed-off-by: falkTX <falktx@falktx.com> * More mac details Signed-off-by: falkTX <falktx@falktx.com> * MIDI stubs Signed-off-by: falkTX <falktx@falktx.com> * working MIDI Signed-off-by: falkTX <falktx@falktx.com> * Add com.apple.security.device.audio-input to entitlements Signed-off-by: falkTX <falktx@falktx.com> * update pawpaw Signed-off-by: falkTX <falktx@falktx.com> * Deal with some UI details Signed-off-by: falkTX <falktx@falktx.com> * x11 webview Signed-off-by: falkTX <falktx@falktx.com> * continue plugin tweaks Signed-off-by: falkTX <falktx@falktx.com> * Less hacky approach Signed-off-by: falkTX <falktx@falktx.com> * Start of multi-instance details Signed-off-by: falkTX <falktx@falktx.com> * Dynamic path handling on Linux too Signed-off-by: falkTX <falktx@falktx.com> * Make it versioned Signed-off-by: falkTX <falktx@falktx.com> * Use jack2 fork Signed-off-by: falkTX <falktx@falktx.com> * force CI rebuild Signed-off-by: falkTX <falktx@falktx.com> * win32 details Signed-off-by: falkTX <falktx@falktx.com> * more linux details Signed-off-by: falkTX <falktx@falktx.com> * even more linux details, qt6 variant, gtk-free usage Signed-off-by: falkTX <falktx@falktx.com> * Put the rest of the linux embed webview details in place Signed-off-by: falkTX <falktx@falktx.com> --------- Signed-off-by: falkTX <falktx@falktx.com>
- Loading branch information
Showing
35 changed files
with
3,735 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule PawPaw
updated
23 files
Submodule mod-host
updated
from 8ac6a8 to c6a567
Submodule mod-ui
updated
from 059578 to a1e043
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,279 @@ | ||
// SPDX-FileCopyrightText: 2023-2024 MOD Audio UG | ||
// SPDX-License-Identifier: AGPL-3.0-or-later | ||
|
||
#pragma once | ||
|
||
#include "extra/Sleep.hpp" | ||
#include "Time.hpp" | ||
|
||
#if defined(DISTRHO_OS_MAC) | ||
#elif defined(DISTRHO_OS_WINDOWS) | ||
#else | ||
#endif | ||
|
||
#ifdef DISTRHO_OS_WINDOWS | ||
# include <string> | ||
# include <winsock2.h> | ||
# include <windows.h> | ||
#else | ||
# include <cerrno> | ||
# include <ctime> | ||
# include <signal.h> | ||
# include <sys/wait.h> | ||
#endif | ||
|
||
// #include <sys/time.h> | ||
|
||
START_NAMESPACE_DISTRHO | ||
|
||
// ----------------------------------------------------------------------------------------------------------- | ||
|
||
class ChildProcess | ||
{ | ||
#ifdef _WIN32 | ||
PROCESS_INFORMATION process = { INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE, 0, 0 }; | ||
#else | ||
pid_t pid = -1; | ||
#endif | ||
|
||
public: | ||
ChildProcess() | ||
{ | ||
} | ||
|
||
~ChildProcess() | ||
{ | ||
stop(); | ||
} | ||
|
||
#ifdef _WIN32 | ||
bool start(const char* const args[], const WCHAR* const envp) | ||
#else | ||
bool start(const char* const args[], char* const* const envp = nullptr) | ||
#endif | ||
{ | ||
#ifdef _WIN32 | ||
std::string cmd; | ||
|
||
for (uint i = 0; args[i] != nullptr; ++i) | ||
{ | ||
if (i != 0) | ||
cmd += " "; | ||
|
||
if (std::strchr(args[i], ' ') != nullptr) | ||
{ | ||
cmd += "\""; | ||
cmd += args[i]; | ||
cmd += "\""; | ||
} | ||
else | ||
{ | ||
cmd += args[i]; | ||
} | ||
} | ||
|
||
wchar_t wcmd[PATH_MAX]; | ||
if (MultiByteToWideChar(CP_UTF8, 0, cmd.data(), -1, wcmd, PATH_MAX) <= 0) | ||
return false; | ||
|
||
STARTUPINFOW si = {}; | ||
si.cb = sizeof(si); | ||
|
||
d_stdout("will start process with args '%s'", cmd.data()); | ||
|
||
return CreateProcessW(nullptr, // lpApplicationName | ||
wcmd, // lpCommandLine | ||
nullptr, // lpProcessAttributes | ||
nullptr, // lpThreadAttributes | ||
TRUE, // bInheritHandles | ||
/* CREATE_NO_WINDOW | */ CREATE_UNICODE_ENVIRONMENT, // dwCreationFlags | ||
const_cast<LPWSTR>(envp), // lpEnvironment | ||
nullptr, // lpCurrentDirectory | ||
&si, // lpStartupInfo | ||
&process) != FALSE; | ||
#else | ||
const pid_t ret = pid = vfork(); | ||
|
||
switch (ret) | ||
{ | ||
// child process | ||
case 0: | ||
if (envp != nullptr) | ||
execve(args[0], const_cast<char* const*>(args), envp); | ||
else | ||
execvp(args[0], const_cast<char* const*>(args)); | ||
|
||
d_stderr2("exec failed: %d:%s", errno, std::strerror(errno)); | ||
_exit(1); | ||
break; | ||
|
||
// error | ||
case -1: | ||
d_stderr2("vfork() failed: %d:%s", errno, std::strerror(errno)); | ||
break; | ||
} | ||
|
||
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 pid_t opid = pid; | ||
pid = -1; | ||
|
||
for (pid_t ret;;) | ||
{ | ||
try { | ||
ret = ::waitpid(opid, nullptr, WNOHANG); | ||
} DISTRHO_SAFE_EXCEPTION_BREAK("waitpid"); | ||
|
||
switch (ret) | ||
{ | ||
case -1: | ||
if (errno == ECHILD) | ||
{ | ||
// success, child doesn't exist | ||
return; | ||
} | ||
else | ||
{ | ||
d_stderr("ChildProcess::stop() - waitpid failed: %d:%s", errno, std::strerror(errno)); | ||
return; | ||
} | ||
break; | ||
|
||
case 0: | ||
if (sendTerminate) | ||
{ | ||
sendTerminate = false; | ||
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); | ||
break; | ||
|
||
default: | ||
if (ret == opid) | ||
{ | ||
// success | ||
return; | ||
} | ||
else | ||
{ | ||
d_stderr("ChildProcess::stop() - got wrong pid %i (requested was %i)", int(ret), int(opid)); | ||
return; | ||
} | ||
} | ||
|
||
break; | ||
} | ||
#endif | ||
} | ||
|
||
bool isRunning() | ||
{ | ||
#ifdef _WIN32 | ||
if (process.hProcess == INVALID_HANDLE_VALUE) | ||
return false; | ||
|
||
if (WaitForSingleObject(process.hProcess, 0) == WAIT_FAILED) | ||
{ | ||
const PROCESS_INFORMATION oprocess = process; | ||
process = { INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE, 0, 0 }; | ||
CloseHandle(oprocess.hThread); | ||
CloseHandle(oprocess.hProcess); | ||
return false; | ||
} | ||
|
||
return true; | ||
#else | ||
if (pid <= 0) | ||
return false; | ||
|
||
const pid_t ret = ::waitpid(pid, nullptr, WNOHANG); | ||
|
||
if (ret == pid || (ret == -1 && errno == ECHILD)) | ||
{ | ||
pid = 0; | ||
return false; | ||
} | ||
|
||
return true; | ||
#endif | ||
} | ||
|
||
#ifndef _WIN32 | ||
void signal(const int sig) | ||
{ | ||
if (pid > 0) | ||
kill(pid, sig); | ||
} | ||
#endif | ||
|
||
void terminate() | ||
{ | ||
#ifdef _WIN32 | ||
if (process.hProcess != INVALID_HANDLE_VALUE) | ||
TerminateProcess(process.hProcess, 15); | ||
#else | ||
if (pid > 0) | ||
kill(pid, SIGTERM); | ||
#endif | ||
} | ||
|
||
DISTRHO_DECLARE_NON_COPYABLE(ChildProcess) | ||
}; | ||
|
||
// ----------------------------------------------------------------------------------------------------------- | ||
|
||
END_NAMESPACE_DISTRHO |
Oops, something went wrong.