Browse Source

Add a little mutex just in case

Signed-off-by: falkTX <falktx@falktx.com>
tags/22.02
falkTX 3 years ago
parent
commit
d11db41c43
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
1 changed files with 20 additions and 4 deletions
  1. +20
    -4
      src/CardinalPlugin.cpp

+ 20
- 4
src/CardinalPlugin.cpp View File

@@ -32,6 +32,7 @@
#include <osdialog.h> #include <osdialog.h>
#include "PluginContext.hpp" #include "PluginContext.hpp"
#include "extra/Mutex.hpp"
namespace rack { namespace rack {
namespace plugin { namespace plugin {
@@ -123,6 +124,7 @@ class CardinalPlugin : public CardinalBasePlugin
// for base/context handling // for base/context handling
bool fIsActive; bool fIsActive;
rack::audio::Device* fCurrentDevice; rack::audio::Device* fCurrentDevice;
Mutex fDeviceMutex;
struct ScopedContext { struct ScopedContext {
ScopedContext(CardinalPlugin* const plugin) ScopedContext(CardinalPlugin* const plugin)
@@ -201,6 +203,7 @@ protected:
bool canAssignDevice() const noexcept override bool canAssignDevice() const noexcept override
{ {
const MutexLocker cml(fDeviceMutex);
return fCurrentDevice == nullptr; return fCurrentDevice == nullptr;
} }
@@ -208,11 +211,14 @@ protected:
{ {
DISTRHO_SAFE_ASSERT_RETURN(fCurrentDevice == nullptr,); DISTRHO_SAFE_ASSERT_RETURN(fCurrentDevice == nullptr,);
const MutexLocker cml(fDeviceMutex);
fCurrentDevice = dev; fCurrentDevice = dev;
} }
bool clearDevice(rack::audio::Device* const dev) noexcept override bool clearDevice(rack::audio::Device* const dev) noexcept override
{ {
const MutexLocker cml(fDeviceMutex);
if (fCurrentDevice != dev) if (fCurrentDevice != dev)
return false; return false;
@@ -298,14 +304,22 @@ protected:
fAudioBufferOut = new float[bufferSize]; fAudioBufferOut = new float[bufferSize];
std::memset(fAudioBufferIn, 0, sizeof(float)*bufferSize); std::memset(fAudioBufferIn, 0, sizeof(float)*bufferSize);
if (fCurrentDevice != nullptr)
fCurrentDevice->onStartStream();
{
const MutexLocker cml(fDeviceMutex);
if (fCurrentDevice != nullptr)
fCurrentDevice->onStartStream();
}
} }
void deactivate() override void deactivate() override
{ {
if (fCurrentDevice != nullptr)
fCurrentDevice->onStopStream();
{
const MutexLocker cml(fDeviceMutex);
if (fCurrentDevice != nullptr)
fCurrentDevice->onStopStream();
}
delete[] fAudioBufferIn; delete[] fAudioBufferIn;
delete[] fAudioBufferOut; delete[] fAudioBufferOut;
@@ -322,6 +336,8 @@ protected:
fContext->engine->stepBlock(frames); fContext->engine->stepBlock(frames);
*/ */
const MutexLocker cml(fDeviceMutex);
if (fCurrentDevice == nullptr) if (fCurrentDevice == nullptr)
{ {
if (outputs[0] != inputs[0]) if (outputs[0] != inputs[0])


Loading…
Cancel
Save