Browse Source

Juce thread usage fixes

tags/1.9.4
falkTX 10 years ago
parent
commit
717495a42a
3 changed files with 53 additions and 43 deletions
  1. +13
    -14
      source/backend/CarlaStandalone.cpp
  2. +38
    -27
      source/plugin/carla-native-lv2.cpp
  3. +2
    -2
      source/utils/CarlaStringList.hpp

+ 13
- 14
source/backend/CarlaStandalone.cpp View File

@@ -40,6 +40,7 @@
using juce::initialiseJuce_GUI;
using juce::shutdownJuce_GUI;
using juce::MessageManager;
using juce::Thread;
#endif

namespace CB = CarlaBackend;
@@ -50,11 +51,11 @@ using CB::EngineOptions;

#if defined(HAVE_JUCE) && defined(CARLA_OS_LINUX)

class JuceMessageThread : public juce::Thread
class JuceMessageThread : public Thread
{
public:
JuceMessageThread()
: juce::Thread("JuceMessageThread"),
: Thread("JuceMessageThread"),
fInitialised(false)
{
}
@@ -70,31 +71,29 @@ public:

fInitialised = false;

startThread();
startThread(7);

while (! fInitialised)
Thread::sleep(1);
sleep(1);
}

void stop()
{
if (! fInitialised)
return;

stopThread(-1);
signalThreadShouldExit();
waitForThreadToExit(5000);
}

protected:
void run() override
{
fInitialised = true;
MessageManager* const msgMgr(MessageManager::getInstance());
CARLA_SAFE_ASSERT_RETURN(msgMgr != nullptr,);

if (MessageManager* const msgMgr = MessageManager::getInstance())
{
msgMgr->setCurrentThreadAsMessageThread();
msgMgr->setCurrentThreadAsMessageThread();
fInitialised = true;

for (; (! threadShouldExit()) && msgMgr->runDispatchLoopUntil(250);) {}
}
while ((! threadShouldExit()) && MessageManager::getInstance()->runDispatchLoopUntil(250))
{}

fInitialised = false;
}


+ 38
- 27
source/plugin/carla-native-lv2.cpp View File

@@ -18,9 +18,7 @@
#define CARLA_NATIVE_PLUGIN_LV2
#include "carla-native-base.cpp"

#include "juce_audio_basics.h"
#include "juce_gui_basics.h"

#include "CarlaMathUtils.hpp"
#include "CarlaString.hpp"

#include "lv2/atom.h"
@@ -36,8 +34,24 @@
#include "lv2/lv2_external_ui.h"
#include "lv2/lv2_programs.h"

using namespace juce;
#ifdef HAVE_JUCE

#include "juce_audio_basics.h"
#include "juce_gui_basics.h"

using juce::Array;
using juce::FloatVectorOperations;
using juce::JUCEApplicationBase;
using juce::MessageManager;
//using juce::MessageManagerLock;
using juce::Thread;

using juce::initialiseJuce_GUI;
using juce::shutdownJuce_GUI;

static Array<void*> gActivePlugins;

# ifdef CARLA_OS_LINUX
// -----------------------------------------------------------------------
// Juce Message Thread

@@ -57,17 +71,17 @@ public:
~JuceMessageThread()
{
signalThreadShouldExit();
JUCEApplication::quit();
JUCEApplicationBase::quit();
waitForThreadToExit(5000);
clearSingletonInstance();
}

void run()
void run() override
{
initialiseJuce_GUI();
fInitialised = true;

MessageManager::getInstance()->setCurrentThreadAsMessageThread();
fInitialised = true;

while ((! threadShouldExit()) && MessageManager::getInstance()->runDispatchLoopUntil(250))
{}
@@ -80,8 +94,9 @@ private:
};

juce_ImplementSingleton(JuceMessageThread)
# endif
#endif

static Array<void*> gActivePlugins;

// -----------------------------------------------------------------------
// LV2 descriptor functions
@@ -95,7 +110,9 @@ public:
: fHandle(nullptr),
fDescriptor(desc),
fMidiEventCount(0),
#ifdef HAVE_JUCE
fUiWasShown(false),
#endif
fIsProcessing(false),
fVolume(1.0f),
fDryWet(1.0f),
@@ -189,7 +206,9 @@ public:
~NativePlugin()
{
CARLA_ASSERT(fHandle == nullptr);
#ifdef HAVE_JUCE
CARLA_ASSERT(! fUiWasShown);
#endif

if (fHost.resourceDir != nullptr)
{
@@ -256,25 +275,19 @@ public:

fHandle = nullptr;

#ifdef HAVE_JUCE
if (fUiWasShown)
{
CARLA_SAFE_ASSERT_RETURN(gActivePlugins.contains(this),);

gActivePlugins.removeFirstMatchingValue(this);

JUCE_AUTORELEASEPOOL
{
MessageManagerLock mmLock;

if (gActivePlugins.size() == 0)
{
JuceMessageThread::deleteInstance();
shutdownJuce_GUI();
}
}
if (gActivePlugins.size() == 0)
JuceMessageThread::deleteInstance();

fUiWasShown = false;
}
#endif
}

void lv2_run(const uint32_t frames)
@@ -438,7 +451,7 @@ public:
{
FloatVectorOperations::multiply(fPorts.audioIns[i], fVolume*(1.0f-fDryWet), frames);
FloatVectorOperations::multiply(fPorts.audioOuts[i], fVolume*fDryWet, frames);
FloatVectorOperations::add(fPorts.audioOuts[i], fPorts.audioIns[i], frames);
FLOAT_ADD(fPorts.audioOuts[i], fPorts.audioIns[i], frames);
}
}
else if (fVolume != 1.0f)
@@ -643,16 +656,11 @@ protected:
{
if (fDescriptor->ui_show != nullptr)
{
#ifdef HAVE_JUCE
if (fDescriptor->hints & PLUGIN_NEEDS_UI_JUCE)
{
JUCE_AUTORELEASEPOOL
{
if (gActivePlugins.size() == 0)
{
initialiseJuce_GUI();
JuceMessageThread::getInstance();
}
}
if (gActivePlugins.size() == 0)
JuceMessageThread::getInstance();

fDescriptor->ui_show(fHandle, true);

@@ -660,6 +668,7 @@ protected:
gActivePlugins.add(this);
}
else
#endif
fDescriptor->ui_show(fHandle, true);
}

@@ -825,7 +834,9 @@ private:
NativeMidiEvent fMidiEvents[kMaxMidiEvents*2];
NativeTimeInfo fTimeInfo;

#ifdef HAVE_JUCE
bool fUiWasShown;
#endif
bool fIsProcessing;
float fVolume;
float fDryWet;


+ 2
- 2
source/utils/CarlaStringList.hpp View File

@@ -62,14 +62,14 @@ public:
return *this;
}

CharStringListPtr& operator=(const CharStringListPtr& ptr)
CharStringListPtr& operator=(const CharStringListPtr& ptr) noexcept
{
clear();
copy(ptr.charList);
return *this;
}

CharStringListPtr& operator=(const LinkedList<CarlaString>& list)
CharStringListPtr& operator=(const LinkedList<CarlaString>& list) noexcept
{
clear();
copy(list);


Loading…
Cancel
Save