From 13e7437a5f08f898b876213b18ac341fb0610546 Mon Sep 17 00:00:00 2001 From: falkTX Date: Fri, 22 Mar 2024 08:28:57 +0100 Subject: [PATCH] Add debug logs for plugin init, send midi out to keep active Signed-off-by: falkTX --- src/plugin/DesktopPlugin.cpp | 34 ++++++++++++++++++++++++++++++++-- src/plugin/SharedMemory.hpp | 19 +++++++++++++------ 2 files changed, 45 insertions(+), 8 deletions(-) diff --git a/src/plugin/DesktopPlugin.cpp b/src/plugin/DesktopPlugin.cpp index 0c5e54d..a66ff4e 100644 --- a/src/plugin/DesktopPlugin.cpp +++ b/src/plugin/DesktopPlugin.cpp @@ -65,6 +65,7 @@ class DesktopPlugin : public Plugin, if (availablePortNum == 0) { + d_stderr("MOD Desktop: Failed to find available ports"); parameters[kParameterBasePortNumber] = portBaseNum = -kErrorShmSetupFailed; return; } @@ -73,12 +74,14 @@ class DesktopPlugin : public Plugin, if (envp == nullptr) { + d_stderr("MOD Desktop: Failed to init environment"); parameters[kParameterBasePortNumber] = portBaseNum = -kErrorAppDirNotFound; return; } if (! shm.init(availablePortNum)) { + d_stderr("MOD Desktop: Failed to init shared memory"); parameters[kParameterBasePortNumber] = portBaseNum = -kErrorShmSetupFailed; return; } @@ -86,6 +89,8 @@ class DesktopPlugin : public Plugin, portBaseNum = availablePortNum; setupResampler(getSampleRate()); + + d_stderr("MOD Desktop: Initial init ok"); } ~DesktopPlugin() @@ -130,6 +135,7 @@ class DesktopPlugin : public Plugin, if (shm.data == nullptr && ! shm.init(portBaseNum)) { + d_stderr("MOD Desktop: Failed to init shared memory inside runner"); parameters[kParameterBasePortNumber] = portBaseNum = -kErrorShmSetupFailed; return false; } @@ -138,6 +144,7 @@ class DesktopPlugin : public Plugin, { if (startingJackd) { + d_stderr("MOD Desktop: Failed to get jackd to run"); startingJackd = false; parameters[kParameterBasePortNumber] = portBaseNum = -kErrorJackdExecFailed; return false; @@ -164,8 +171,12 @@ class DesktopPlugin : public Plugin, startingJackd = true; if (jackd.start(jackd_args, envp)) + { + d_stderr("MOD Desktop: jackd exec ok"); return true; - + } + + d_stderr("MOD Desktop: Failed to start jackd"); parameters[kParameterBasePortNumber] = portBaseNum = -kErrorJackdExecFailed; return false; } @@ -184,6 +195,7 @@ class DesktopPlugin : public Plugin, { if (startingModUI) { + d_stderr("MOD Desktop: Failed to get mod-ui to run"); startingModUI = false; parameters[kParameterBasePortNumber] = portBaseNum = -kErrorModUiExecFailed; return false; @@ -199,13 +211,21 @@ class DesktopPlugin : public Plugin, startingModUI = true; if (mod_ui.start(mod_ui_args, envp)) + { + d_stderr("MOD Desktop: mod-ui exec ok"); return true; + } + d_stderr("MOD Desktop: Failed to start jackd"); parameters[kParameterBasePortNumber] = portBaseNum = -kErrorModUiExecFailed; return false; } - startingModUI = false; + if (startingModUI) + { + d_stderr("MOD Desktop: Runner setup ok"); + startingModUI = false; + } parameters[kParameterBasePortNumber] = portBaseNum; return true; @@ -492,6 +512,16 @@ class DesktopPlugin : public Plugin, audioBufferOut.read(outputs, frames); + for (uint32_t i = 0; i < frames; i += 32) + { + MidiEvent midiEvent = { + i, 1, { 0xFE, 0, 0, 0 }, nullptr + }; + + if (! writeMidiEvent(midiEvent)) + break; + } + #if 0 // FIXME not quite right, crashes if (getBufferSize() != frames) diff --git a/src/plugin/SharedMemory.hpp b/src/plugin/SharedMemory.hpp index 08c5ea1..3e28b81 100644 --- a/src/plugin/SharedMemory.hpp +++ b/src/plugin/SharedMemory.hpp @@ -7,6 +7,7 @@ #ifdef DISTRHO_OS_WINDOWS #else +# include # include # include # ifdef DISTRHO_OS_MAC @@ -16,7 +17,6 @@ # include # include # else -# include # include # include # include @@ -122,7 +122,10 @@ class SharedMemory const HANDLE testshm = OpenFileMappingA(FILE_MAP_ALL_ACCESS, FALSE, shmName); if (testshm == nullptr) + { + d_stderr("SharedMemory::canInit(%u) - true", portBaseNum); return true; + } CloseHandle(testshm); #else @@ -130,11 +133,15 @@ class SharedMemory const int testshmfd = shm_open(shmName, O_RDONLY, 0); if (testshmfd < 0) + { + d_stderr("SharedMemory::canInit(%u) - true", portBaseNum); return true; + } close(testshmfd); #endif + d_stderr("SharedMemory::canInit(%u) - false", portBaseNum); return false; } @@ -160,10 +167,10 @@ class SharedMemory #else std::snprintf(shmName, 31, "/mod-desktop-shm-%d", portBaseNum); - shmfd = shm_open(shmName, O_CREAT|O_EXCL|O_RDWR, 0600); - DISTRHO_SAFE_ASSERT_RETURN(shmfd >= 0, false); + shmfd = shm_open(shmName, O_CREAT|O_EXCL|O_RDWR, 0666); + DISTRHO_CUSTOM_SAFE_ASSERT_RETURN(std::strerror(errno), shmfd >= 0, false); - DISTRHO_SAFE_ASSERT_RETURN(ftruncate(shmfd, static_cast(kDataSize)) == 0, fail_deinit()); + DISTRHO_CUSTOM_SAFE_ASSERT_RETURN(std::strerror(errno), ftruncate(shmfd, static_cast(kDataSize)) == 0, fail_deinit()); #ifdef MAP_LOCKED ptr = mmap(nullptr, kDataSize, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_LOCKED, shmfd, 0); @@ -172,8 +179,8 @@ class SharedMemory { ptr = mmap(nullptr, kDataSize, PROT_READ|PROT_WRITE, MAP_SHARED, shmfd, 0); } - DISTRHO_SAFE_ASSERT_RETURN(ptr != nullptr, fail_deinit()); - DISTRHO_SAFE_ASSERT_RETURN(ptr != MAP_FAILED, fail_deinit()); + DISTRHO_CUSTOM_SAFE_ASSERT_RETURN(std::strerror(errno), ptr != nullptr, fail_deinit()); + DISTRHO_CUSTOM_SAFE_ASSERT_RETURN(std::strerror(errno), ptr != MAP_FAILED, fail_deinit()); #ifndef MAP_LOCKED mlock(ptr, kDataSize);