From b7c8deccc16c7efc8f6544f17d35557178880a7c Mon Sep 17 00:00:00 2001 From: falkTX Date: Thu, 11 Sep 2014 16:50:18 +0100 Subject: [PATCH] Init (fake) juce events if using custom plugin entries (for LMMS) --- source/backend/engine/CarlaEngineNative.cpp | 25 +++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/source/backend/engine/CarlaEngineNative.cpp b/source/backend/engine/CarlaEngineNative.cpp index 0cff3823d..d5ee7b5f6 100644 --- a/source/backend/engine/CarlaEngineNative.cpp +++ b/source/backend/engine/CarlaEngineNative.cpp @@ -38,6 +38,14 @@ #include "juce_audio_basics.h" +#if defined(CARLA_OS_MAC) || defined(CARLA_OS_WIN) +# include "juce_gui_basics.h" +#else +namespace juce { +# include "juce_events/messages/juce_Initialisation.h" +} // namespace juce +#endif + using juce::File; using juce::FloatVectorOperations; using juce::MemoryOutputStream; @@ -46,6 +54,9 @@ using juce::String; using juce::XmlDocument; using juce::XmlElement; +static bool gNeedsJuceHandling = false; +static int gJuceReferenceCounter = 0; + CARLA_BACKEND_START_NAMESPACE // ----------------------------------------------------------------------- @@ -561,6 +572,11 @@ public: { carla_debug("CarlaEngineNative::CarlaEngineNative()"); + CARLA_SAFE_ASSERT_INT(gJuceReferenceCounter >= 0, gJuceReferenceCounter); + + if (gNeedsJuceHandling && ++gJuceReferenceCounter == 1) + juce::initialiseJuce_GUI(); + carla_zeroChar(fTmpBuf, STR_MAX+1); // set-up engine @@ -610,6 +626,9 @@ public: pData->graph.destroy(); + if (gNeedsJuceHandling && --gJuceReferenceCounter == 0) + juce::shutdownJuce_GUI(); + carla_debug("CarlaEngineNative::~CarlaEngineNative() - END"); } @@ -1583,6 +1602,9 @@ CARLA_EXPORT const NativePluginDescriptor* carla_get_native_rack_plugin(); const NativePluginDescriptor* carla_get_native_rack_plugin() { + // if this is called then we're running as special plugin + gNeedsJuceHandling = true; + CARLA_BACKEND_USE_NAMESPACE; return &carlaRackDesc; } @@ -1591,6 +1613,9 @@ CARLA_EXPORT const NativePluginDescriptor* carla_get_native_patchbay_plugin(); const NativePluginDescriptor* carla_get_native_patchbay_plugin() { + // if this is called then we're running as special plugin + gNeedsJuceHandling = true; + CARLA_BACKEND_USE_NAMESPACE; return &carlaPatchbayDesc; }