diff --git a/source/backend/engine/CarlaEngine.cpp b/source/backend/engine/CarlaEngine.cpp index 443629430..252e40c31 100644 --- a/source/backend/engine/CarlaEngine.cpp +++ b/source/backend/engine/CarlaEngine.cpp @@ -648,7 +648,7 @@ bool CarlaEngine::close() void CarlaEngine::idle() { - CARLA_ASSERT(kData->plugins != nullptr); + CARLA_ASSERT(kData->plugins != nullptr); // this one too maybe CARLA_ASSERT(kData->nextAction.opcode == kEnginePostActionNull); // TESTING, remove later CARLA_ASSERT(kData->nextPluginId == kData->maxPluginNumber); // TESTING, remove later diff --git a/source/backend/plugin/BridgePlugin.cpp b/source/backend/plugin/BridgePlugin.cpp index 796ad5833..42ebe6c16 100644 --- a/source/backend/plugin/BridgePlugin.cpp +++ b/source/backend/plugin/BridgePlugin.cpp @@ -142,6 +142,9 @@ public: kData->singleMutex.lock(); kData->masterMutex.lock(); + if (kData->client != nullptr && kData->client->isActive()) + kData->client->deactivate(); + if (kData->active) { deactivate(); diff --git a/source/backend/plugin/CarlaPlugin.cpp b/source/backend/plugin/CarlaPlugin.cpp index af1079027..1bb0644da 100644 --- a/source/backend/plugin/CarlaPlugin.cpp +++ b/source/backend/plugin/CarlaPlugin.cpp @@ -227,7 +227,7 @@ unsigned int CarlaPluginProtectedData::loadSettings(const unsigned int options, unsigned int newOptions = 0x0; -#define CHECK_AND_SET_OPTION(STR, BIT) \ + #define CHECK_AND_SET_OPTION(STR, BIT) \ if ((availOptions & BIT) != 0 || BIT == PLUGIN_OPTION_FORCE_STEREO) \ { \ if (settings.contains(STR)) \ @@ -249,7 +249,7 @@ unsigned int CarlaPluginProtectedData::loadSettings(const unsigned int options, CHECK_AND_SET_OPTION("SendPitchbend", PLUGIN_OPTION_SEND_PITCHBEND); CHECK_AND_SET_OPTION("SendAllSoundOff", PLUGIN_OPTION_SEND_ALL_SOUND_OFF); -#undef CHECK_AND_SET_OPTION + #undef CHECK_AND_SET_OPTION settings.endGroup(); diff --git a/source/backend/plugin/CarlaPluginInternal.hpp b/source/backend/plugin/CarlaPluginInternal.hpp index e52555316..3435b98eb 100644 --- a/source/backend/plugin/CarlaPluginInternal.hpp +++ b/source/backend/plugin/CarlaPluginInternal.hpp @@ -360,10 +360,10 @@ struct PluginPostRtEvent { value2(-1), value3(0.0f) {} -#if 1//def DEBUG - CARLA_DECLARE_NON_COPY_STRUCT_WITH_LEAK_DETECTOR(PluginPostRtEvent) -#else +#ifndef DEBUG CARLA_DECLARE_NON_COPY_STRUCT(PluginPostRtEvent) +#else + CARLA_DECLARE_NON_COPY_STRUCT_WITH_LEAK_DETECTOR(PluginPostRtEvent) #endif }; @@ -379,10 +379,10 @@ struct ExternalMidiNote { note(0), velo(0) {} -#if 1//def DEBUG - CARLA_DECLARE_NON_COPY_STRUCT_WITH_LEAK_DETECTOR(ExternalMidiNote) -#else +#ifndef DEBUG CARLA_DECLARE_NON_COPY_STRUCT(ExternalMidiNote) +#else + CARLA_DECLARE_NON_COPY_STRUCT_WITH_LEAK_DETECTOR(ExternalMidiNote) #endif }; @@ -574,6 +574,8 @@ struct CarlaPluginProtectedData { if (client != nullptr) { + CARLA_ASSERT(! client->isActive()); + if (client->isActive()) client->deactivate(); diff --git a/source/backend/plugin/DssiPlugin.cpp b/source/backend/plugin/DssiPlugin.cpp index 3ffd788aa..6879eeb4d 100644 --- a/source/backend/plugin/DssiPlugin.cpp +++ b/source/backend/plugin/DssiPlugin.cpp @@ -68,6 +68,9 @@ public: kData->singleMutex.lock(); kData->masterMutex.lock(); + if (kData->client != nullptr && kData->client->isActive()) + kData->client->deactivate(); + if (kData->active) { deactivate(); diff --git a/source/backend/plugin/FluidSynthPlugin.cpp b/source/backend/plugin/FluidSynthPlugin.cpp index 66ef7d12d..7b42dc848 100644 --- a/source/backend/plugin/FluidSynthPlugin.cpp +++ b/source/backend/plugin/FluidSynthPlugin.cpp @@ -96,6 +96,9 @@ public: kData->singleMutex.lock(); kData->masterMutex.lock(); + if (kData->client != nullptr && kData->client->isActive()) + kData->client->deactivate(); + if (kData->active) { deactivate(); diff --git a/source/backend/plugin/LadspaPlugin.cpp b/source/backend/plugin/LadspaPlugin.cpp index cb0215ed2..1b25b0687 100644 --- a/source/backend/plugin/LadspaPlugin.cpp +++ b/source/backend/plugin/LadspaPlugin.cpp @@ -50,6 +50,9 @@ public: kData->singleMutex.lock(); kData->masterMutex.lock(); + if (kData->client != nullptr && kData->client->isActive()) + kData->client->deactivate(); + if (kData->active) { deactivate(); diff --git a/source/backend/plugin/LinuxSamplerPlugin.cpp b/source/backend/plugin/LinuxSamplerPlugin.cpp index 96ba8876e..157071f18 100644 --- a/source/backend/plugin/LinuxSamplerPlugin.cpp +++ b/source/backend/plugin/LinuxSamplerPlugin.cpp @@ -185,6 +185,9 @@ public: kData->singleMutex.lock(); kData->masterMutex.lock(); + if (kData->client != nullptr && kData->client->isActive()) + kData->client->deactivate(); + if (kData->active) { deactivate(); diff --git a/source/backend/plugin/Lv2Plugin.cpp b/source/backend/plugin/Lv2Plugin.cpp index b760ce6b8..8eb3f5328 100644 --- a/source/backend/plugin/Lv2Plugin.cpp +++ b/source/backend/plugin/Lv2Plugin.cpp @@ -17,13 +17,15 @@ #include "CarlaPluginInternal.hpp" +#define WANT_LV2 #ifdef WANT_LV2 #include "CarlaPluginGui.hpp" -#include "../engine/CarlaEngineOsc.hpp" #include "CarlaLv2Utils.hpp" #include "Lv2AtomQueue.hpp" +#include "../engine/CarlaEngineOsc.hpp" + #include extern "C" { @@ -234,7 +236,7 @@ struct Lv2PluginEventData { CARLA_ASSERT_INT(count == 0, count); CARLA_ASSERT(data == nullptr); CARLA_ASSERT(ctrl == nullptr); - CARLA_ASSERT(ctrlIndex == 0); + CARLA_ASSERT_INT(ctrlIndex == 0, ctrlIndex); } void createNew(const uint32_t newCount) @@ -242,7 +244,7 @@ struct Lv2PluginEventData { CARLA_ASSERT_INT(count == 0, count); CARLA_ASSERT(data == nullptr); CARLA_ASSERT(ctrl == nullptr); - CARLA_ASSERT(ctrlIndex == 0); + CARLA_ASSERT_INT(ctrlIndex == 0, ctrlIndex); CARLA_ASSERT_INT(newCount > 0, newCount); if (data != nullptr || newCount == 0) @@ -446,6 +448,9 @@ public: kData->singleMutex.lock(); kData->masterMutex.lock(); + if (kData->client != nullptr && kData->client->isActive()) + kData->client->deactivate(); + if (kData->active) { deactivate(); diff --git a/source/backend/plugin/NativePlugin.cpp b/source/backend/plugin/NativePlugin.cpp index 8450dd70c..e66a514d4 100644 --- a/source/backend/plugin/NativePlugin.cpp +++ b/source/backend/plugin/NativePlugin.cpp @@ -213,6 +213,9 @@ public: kData->singleMutex.lock(); kData->masterMutex.lock(); + if (kData->client != nullptr && kData->client->isActive()) + kData->client->deactivate(); + CARLA_ASSERT(! fIsProcessing); if (kData->active) diff --git a/source/backend/plugin/Vst3Plugin.cpp b/source/backend/plugin/Vst3Plugin.cpp index db578da21..5d16b0ed6 100644 --- a/source/backend/plugin/Vst3Plugin.cpp +++ b/source/backend/plugin/Vst3Plugin.cpp @@ -38,6 +38,9 @@ public: kData->singleMutex.lock(); kData->masterMutex.lock(); + + if (kData->client != nullptr && kData->client->isActive()) + kData->client->deactivate(); } // ------------------------------------------------------------------- diff --git a/source/backend/plugin/VstPlugin.cpp b/source/backend/plugin/VstPlugin.cpp index 3458f0721..402b41a85 100644 --- a/source/backend/plugin/VstPlugin.cpp +++ b/source/backend/plugin/VstPlugin.cpp @@ -94,6 +94,9 @@ public: kData->singleMutex.lock(); kData->masterMutex.lock(); + if (kData->client != nullptr && kData->client->isActive()) + kData->client->deactivate(); + CARLA_ASSERT(! fIsProcessing); if (kData->active) diff --git a/source/utils/CarlaJuceUtils.hpp b/source/utils/CarlaJuceUtils.hpp index d14f91b15..9c5f93a26 100644 --- a/source/utils/CarlaJuceUtils.hpp +++ b/source/utils/CarlaJuceUtils.hpp @@ -1,19 +1,18 @@ /* * Carla misc utils imported from Juce source code - * Copyright (C) 2004-11 Raw Material Software Ltd. + * Copyright (c) 2013 Raw Material Software Ltd. * Copyright (C) 2013 Filipe Coelho * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or any later version. + * Permission to use, copy, modify, and/or distribute this software for any purpose with + * or without fee is hereby granted, provided that the above copyright notice and this + * permission notice appear in all copies. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * For a full copy of the GNU General Public License see the GPL.txt file + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD + * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN + * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER + * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #ifndef __CARLA_JUCE_UTILS_HPP__ @@ -75,7 +74,7 @@ private: \ it can check whether there are any left-over instances that may have been leaked. To use it, use the CARLA_LEAK_DETECTOR macro as a simple way to put one in your - class declaration. Have a look through the juce codebase for examples, it's used + class declaration. Have a look through the carla codebase for examples, it's used in most of the classes. */ template @@ -83,15 +82,8 @@ class LeakedObjectDetector { public: //============================================================================== - LeakedObjectDetector() - { - ++(getCounter().numObjects); - } - - LeakedObjectDetector(const LeakedObjectDetector&) - { - ++(getCounter().numObjects); - } + LeakedObjectDetector() noexcept { ++(getCounter().numObjects); } + LeakedObjectDetector (const LeakedObjectDetector&) noexcept { ++(getCounter().numObjects); } ~LeakedObjectDetector() { @@ -119,7 +111,7 @@ private: class LeakCounter { public: - LeakCounter() + LeakCounter() noexcept { numObjects = 0; } @@ -141,7 +133,7 @@ private: } } - int numObjects; + volatile int numObjects; }; static const char* getLeakedObjectClassName() @@ -149,7 +141,7 @@ private: return OwnerClass::getLeakedObjectClassName(); } - static LeakCounter& getCounter() + static LeakCounter& getCounter() noexcept { static LeakCounter counter; return counter; @@ -158,7 +150,7 @@ private: #define CARLA_LEAK_DETECTOR(OwnerClass) \ friend class LeakedObjectDetector; \ - static const char* getLeakedObjectClassName() { return #OwnerClass; } \ + static const char* getLeakedObjectClassName() noexcept { return #OwnerClass; } \ LeakedObjectDetector CARLA_JOIN_MACRO (leakDetector, __LINE__); @@ -205,13 +197,13 @@ class ScopedPointer public: //============================================================================== /** Creates a ScopedPointer containing a null pointer. */ - ScopedPointer() + ScopedPointer() noexcept : object(nullptr) { } /** Creates a ScopedPointer that owns the specified object. */ - ScopedPointer(ObjectType* const objectToTakePossessionOf) + ScopedPointer(ObjectType* const objectToTakePossessionOf) noexcept : object(objectToTakePossessionOf) { } @@ -222,7 +214,7 @@ public: the pointer from the other object to this one, and the other object is reset to be a null pointer. */ - ScopedPointer(ScopedPointer& objectToTransferFrom) + ScopedPointer(ScopedPointer& objectToTransferFrom) noexcept : object(objectToTransferFrom.object) { objectToTransferFrom.object = nullptr; @@ -283,33 +275,28 @@ public: //============================================================================== /** Returns the object that this ScopedPointer refers to. */ - operator ObjectType*() const { return object; } + operator ObjectType*() const noexcept { return object; } /** Returns the object that this ScopedPointer refers to. */ - ObjectType* get() const { return object; } + ObjectType* get() const noexcept { return object; } /** Returns the object that this ScopedPointer refers to. */ - ObjectType& operator*() const { return *object; } + ObjectType& operator*() const noexcept { return *object; } /** Lets you access methods and properties of the object that this ScopedPointer refers to. */ - ObjectType* operator->() const { return object; } + ObjectType* operator->() const noexcept { return object; } //============================================================================== /** Removes the current object from this ScopedPointer without deleting it. This will return the current object, and set the ScopedPointer to a null pointer. */ - ObjectType* release() - { - ObjectType* const o = object; - object = nullptr; - return o; - } + ObjectType* release() noexcept { ObjectType* const o = object; object = nullptr; return o; } //============================================================================== /** Swaps this object with that of another ScopedPointer. The two objects simply exchange their pointers. */ - void swapWith(ScopedPointer& other) + void swapWith(ScopedPointer& other) noexcept { // Two ScopedPointers should never be able to refer to the same object - if // this happens, you must have done something dodgy! @@ -323,17 +310,14 @@ private: ObjectType* object; // (Required as an alternative to the overloaded & operator). - const ScopedPointer* getAddress() const - { - return this; - } + const ScopedPointer* getAddress() const { return this; } #if ! defined(CARLA_CC_MSVC) // (MSVC can't deal with multiple copy constructors) - /* These are private to stop people accidentally copying a const ScopedPointer (the compiler - would let you do so by implicitly casting the source to its raw object pointer). + /* The copy constructors are private to stop people accidentally copying a const ScopedPointer + (the compiler would let you do so by implicitly casting the source to its raw object pointer). - A side effect of this is that you may hit a puzzling compiler error when you write something - like this: + A side effect of this is that in a compiler that doesn't support C++11, you may hit an + error when you write something like this: ScopedPointer m = new MyClass(); // Compile error: copy constructor is private. @@ -342,12 +326,10 @@ private: ScopedPointer m (new MyClass()); // Compiles OK - It's good practice to always use the latter form when writing your object declarations anyway, - rather than writing them as assignments and assuming (or hoping) that the compiler will be - smart enough to replace your construction + assignment with a single constructor. + It's probably best to use the latter form when writing your object declarations anyway, as + this is a better representation of the code that you actually want the compiler to produce. */ - ScopedPointer(const ScopedPointer&); - ScopedPointer& operator=(const ScopedPointer&); + CARLA_DECLARE_NON_COPYABLE(ScopedPointer) #endif };