From fabfb7f312da762fbf0dd57059171ea889c85661 Mon Sep 17 00:00:00 2001 From: falkTX Date: Sun, 14 Apr 2019 13:18:56 +0900 Subject: [PATCH] Offline/freewheel callback for our fake libjack Signed-off-by: falkTX --- source/libjack/libjack.cpp | 33 ++++++++++++++++++++++++--------- source/utils/CarlaMutex.hpp | 14 +++++++++----- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/source/libjack/libjack.cpp b/source/libjack/libjack.cpp index 8185c0894..baff041be 100644 --- a/source/libjack/libjack.cpp +++ b/source/libjack/libjack.cpp @@ -512,7 +512,8 @@ bool CarlaJackAppClient::handleRtData() JackClientState* const jclient(it.getValue(nullptr)); CARLA_SAFE_ASSERT_CONTINUE(jclient != nullptr); - jclient->bufferSizeCb(fServer.bufferSize, jclient->bufferSizeCbPtr); + if (jclient->bufferSizeCb != nullptr) + jclient->bufferSizeCb(fServer.bufferSize, jclient->bufferSizeCbPtr); } delete[] fAudioTmpBuf; @@ -536,16 +537,31 @@ bool CarlaJackAppClient::handleRtData() JackClientState* const jclient(it.getValue(nullptr)); CARLA_SAFE_ASSERT_CONTINUE(jclient != nullptr); - jclient->sampleRateCb(static_cast(fServer.sampleRate), jclient->sampleRateCbPtr); + if (jclient->sampleRateCb != nullptr) + jclient->sampleRateCb(static_cast(fServer.sampleRate), jclient->sampleRateCbPtr); } } } break; - case kPluginBridgeRtClientSetOnline: - // TODO inform changes - fIsOffline = fShmRtClientControl.readBool(); - //offlineModeChanged(fIsOffline); - break; + case kPluginBridgeRtClientSetOnline: { + const bool offline = fShmRtClientControl.readBool(); + + if (fIsOffline != offline) + { + const CarlaMutexLocker cml(fRealtimeThreadMutex); + + fIsOffline = offline; + + for (LinkedList::Itenerator it = fClients.begin2(); it.valid(); it.next()) + { + JackClientState* const jclient(it.getValue(nullptr)); + CARLA_SAFE_ASSERT_CONTINUE(jclient != nullptr); + + if (jclient->freewheelCb != nullptr) + jclient->freewheelCb(offline ? 1 : 0, jclient->freewheelCbPtr); + } + } + } break; case kPluginBridgeRtClientControlEventParameter: case kPluginBridgeRtClientControlEventMidiBank: @@ -593,8 +609,7 @@ bool CarlaJackAppClient::handleRtData() // TODO tell client of xrun in case buffersize does not match - // FIXME - lock if offline - const CarlaMutexTryLocker cmtl(fRealtimeThreadMutex); + const CarlaMutexTryLocker cmtl(fRealtimeThreadMutex, fIsOffline); if (cmtl.wasLocked()) { diff --git a/source/utils/CarlaMutex.hpp b/source/utils/CarlaMutex.hpp index ae7725185..73466b40b 100644 --- a/source/utils/CarlaMutex.hpp +++ b/source/utils/CarlaMutex.hpp @@ -66,9 +66,9 @@ public: /* * Lock the mutex. */ - void lock() const noexcept + bool lock() const noexcept { - pthread_mutex_lock(&fMutex); + return (pthread_mutex_lock(&fMutex) == 0); } /* @@ -143,12 +143,12 @@ public: /* * Lock the mutex. */ - void lock() const noexcept + bool lock() const noexcept { #ifdef CARLA_OS_WIN - EnterCriticalSection(&fSection); + return (EnterCriticalSection(&fSection) != FALSE); #else - pthread_mutex_lock(&fMutex); + return (pthread_mutex_lock(&fMutex) == 0); #endif } @@ -304,6 +304,10 @@ public: : fMutex(mutex), fLocked(mutex.tryLock()) {} + CarlaScopeTryLocker(const Mutex& mutex, const bool forceLock) noexcept + : fMutex(mutex), + fLocked(forceLock ? mutex.lock() : mutex.tryLock()) {} + ~CarlaScopeTryLocker() noexcept { if (fLocked)