From 5ca950998d4e4f8b7b32ac65fbf56f0f53bc42b4 Mon Sep 17 00:00:00 2001 From: falkTX Date: Sat, 2 Feb 2019 23:11:15 +0100 Subject: [PATCH] More NSM jack apps work, save, load and gui; water changes... Signed-off-by: falkTX --- source/backend/plugin/CarlaPluginJack.cpp | 53 ++++++++++++++++++- source/libjack/libjack.cpp | 2 +- source/modules/water/threads/ChildProcess.cpp | 15 ++++++ source/modules/water/threads/ChildProcess.h | 1 + 4 files changed, 69 insertions(+), 2 deletions(-) diff --git a/source/backend/plugin/CarlaPluginJack.cpp b/source/backend/plugin/CarlaPluginJack.cpp index 4bb968d06..f839a207e 100644 --- a/source/backend/plugin/CarlaPluginJack.cpp +++ b/source/backend/plugin/CarlaPluginJack.cpp @@ -90,6 +90,33 @@ public: return (uintptr_t)fProcess->getPID(); } + void sendTerminate() const noexcept + { + CARLA_SAFE_ASSERT_RETURN(fProcess != nullptr,); + + fProcess->terminate(); + } + +#ifdef HAVE_LIBLO + void nsmSave() + { + if (fOscClientAddress == nullptr) + return; + + lo_send_from(fOscClientAddress, fOscServer, LO_TT_IMMEDIATE, "/nsm/client/save", ""); + } + + void nsmShowGui(const bool yesNo) + { + if (fOscClientAddress == nullptr) + return; + + lo_send_from(fOscClientAddress, fOscServer, LO_TT_IMMEDIATE, + yesNo ? "/nsm/client/show_optional_gui" + : "/nsm/client/hide_optional_gui", ""); + } +#endif + protected: #ifdef HAVE_LIBLO static void _osc_error_handler(int num, const char* msg, const char* path) @@ -132,7 +159,7 @@ protected: method, message, smName, features); } - if (std::strcmp(path, "/reply") == 0) + else if (std::strcmp(path, "/reply") == 0) { CARLA_SAFE_ASSERT_RETURN(std::strcmp(types, "ss") == 0, 0); @@ -142,6 +169,20 @@ protected: carla_stdout("Got reply of '%s' as '%s'", method, message); } + else if (std::strcmp(path, "/nsm/client/gui_is_shown") == 0) + { + CARLA_SAFE_ASSERT_RETURN(std::strcmp(types, "") == 0, 0); + + kEngine->callback(ENGINE_CALLBACK_UI_STATE_CHANGED, kPlugin->getId(), 1, 0, 0.0f, nullptr); + } + + else if (std::strcmp(path, "/nsm/client/gui_is_hidden") == 0) + { + CARLA_SAFE_ASSERT_RETURN(std::strcmp(types, "") == 0, 0); + + kEngine->callback(ENGINE_CALLBACK_UI_STATE_CHANGED, kPlugin->getId(), 0, 0, 0.0f, nullptr); + } + return 0; } #endif @@ -362,6 +403,8 @@ public: fShmNonRtClientControl.writeOpcode(kPluginBridgeNonRtClientQuit); fShmNonRtClientControl.commitWrite(); + fBridgeThread.sendTerminate(); + if (! fTimedOut) waitForClient("stopping", 3000); } @@ -441,6 +484,10 @@ public: void prepareForSave() noexcept override { +#ifdef HAVE_LIBLO + fBridgeThread.nsmSave(); +#endif + { const CarlaMutexLocker _cml(fShmNonRtClientControl.mutex); @@ -517,6 +564,10 @@ public: CARLA_SAFE_ASSERT_RETURN(restartBridgeThread(),); } +#ifdef HAVE_LIBLO + fBridgeThread.nsmShowGui(yesNo); +#endif + const CarlaMutexLocker _cml(fShmNonRtClientControl.mutex); fShmNonRtClientControl.writeOpcode(yesNo ? kPluginBridgeNonRtClientShowUI : kPluginBridgeNonRtClientHideUI); diff --git a/source/libjack/libjack.cpp b/source/libjack/libjack.cpp index 8cf6e9271..268bd8368 100644 --- a/source/libjack/libjack.cpp +++ b/source/libjack/libjack.cpp @@ -943,7 +943,7 @@ bool CarlaJackAppClient::handleNonRtData() case kPluginBridgeNonRtClientPrepareForSave: { - if (fSessionManager == 1) // auto + if (fSessionManager == 1 && std::getenv("NSM_URL") == nullptr) // auto { struct sigaction sig; carla_zeroStruct(sig); diff --git a/source/modules/water/threads/ChildProcess.cpp b/source/modules/water/threads/ChildProcess.cpp index d1200296b..58a2f3cb8 100644 --- a/source/modules/water/threads/ChildProcess.cpp +++ b/source/modules/water/threads/ChildProcess.cpp @@ -125,6 +125,11 @@ public: return TerminateProcess (processInfo.hProcess, 0) != FALSE; } + bool terminateProcess() const noexcept + { + return TerminateProcess (processInfo.hProcess, 0) != FALSE; + } + uint32 getExitCode() const noexcept { DWORD exitCode = 0; @@ -238,6 +243,11 @@ public: return ::kill (childPID, SIGKILL) == 0; } + bool terminateProcess() const noexcept + { + return ::kill (childPID, SIGTERM) == 0; + } + uint32 getExitCode() const noexcept { if (childPID != 0) @@ -287,6 +297,11 @@ bool ChildProcess::kill() return activeProcess == nullptr || activeProcess->killProcess(); } +bool ChildProcess::terminate() +{ + return activeProcess == nullptr || activeProcess->terminateProcess(); +} + uint32 ChildProcess::getExitCode() const { return activeProcess != nullptr ? activeProcess->getExitCode() : 0; diff --git a/source/modules/water/threads/ChildProcess.h b/source/modules/water/threads/ChildProcess.h index cf38422c6..891322aa7 100644 --- a/source/modules/water/threads/ChildProcess.h +++ b/source/modules/water/threads/ChildProcess.h @@ -107,6 +107,7 @@ public: result in undefined behaviour. */ bool kill(); + bool terminate(); uint32 getPID() const noexcept;