diff --git a/source/backend/CarlaEngine.hpp b/source/backend/CarlaEngine.hpp index a2254e877..e5c17e7d4 100644 --- a/source/backend/CarlaEngine.hpp +++ b/source/backend/CarlaEngine.hpp @@ -24,12 +24,16 @@ struct CarlaOscData; #endif +// ----------------------------------------------------------------------- + CARLA_BACKEND_START_NAMESPACE #if 0 } /* Fix editor indentation */ #endif +// ----------------------------------------------------------------------- + /*! * @defgroup CarlaEngineAPI Carla Engine API * @@ -159,6 +163,8 @@ enum EngineControlEventType { kEngineControlEventTypeAllNotesOff = 5 }; +// ----------------------------------------------------------------------- + /*! * Engine control event. */ @@ -194,8 +200,6 @@ struct EngineMidiEvent { * Engine event. */ struct EngineEvent { - static const ushort kMaxInternalCount = 512; //!< Maximum pre-allocated events for rack and bridge modes - EngineEventType type; //!< Event Type; either Control or MIDI uint32_t time; //!< Time offset in frames uint8_t channel; //!< Channel, used for MIDI-related events @@ -214,6 +218,8 @@ struct EngineEvent { void fillFromMidiData(const uint8_t size, const uint8_t* const data) noexcept; }; +// ----------------------------------------------------------------------- + /*! * Engine options. */ @@ -1042,11 +1048,6 @@ protected: // ------------------------------------------------------------------- // Patchbay stuff - /*! - * Called from patchbayRefresh() after all rack ports are in place. - */ - void handleRackConnectionsRefresh(); - /*! * Virtual functions for handling MIDI ports in the rack patchbay. */ @@ -1054,8 +1055,6 @@ protected: virtual bool connectRackMidiOutPort(const int) { return false; } virtual bool disconnectRackMidiInPort(const int) { return false; } virtual bool disconnectRackMidiOutPort(const int) { return false; } - virtual uint getMidiConnectionsCount(const bool) { return 0; } - virtual uint getMidiConnectionPortId(const uint) { return 0; } // ------------------------------------------------------------------- @@ -1162,6 +1161,8 @@ public: /**@}*/ +// ----------------------------------------------------------------------- + CARLA_BACKEND_END_NAMESPACE #endif // CARLA_ENGINE_HPP_INCLUDED diff --git a/source/backend/CarlaPlugin.hpp b/source/backend/CarlaPlugin.hpp index 1ce205fe0..2a5d7a3e5 100644 --- a/source/backend/CarlaPlugin.hpp +++ b/source/backend/CarlaPlugin.hpp @@ -20,17 +20,23 @@ #include "CarlaBackend.h" +// ----------------------------------------------------------------------- // Avoid including extra libs here + typedef void* lo_address; typedef struct _NativePluginDescriptor NativePluginDescriptor; struct LADSPA_RDF_Descriptor; +// ----------------------------------------------------------------------- + CARLA_BACKEND_START_NAMESPACE #if 0 } /* Fix editor indentation */ #endif +// ----------------------------------------------------------------------- + /*! * @defgroup CarlaPluginAPI Carla Plugin API * @@ -899,6 +905,8 @@ protected: /**@}*/ +// ----------------------------------------------------------------------- + CARLA_BACKEND_END_NAMESPACE #endif // CARLA_PLUGIN_HPP_INCLUDED diff --git a/source/backend/engine/CarlaEngine.cpp b/source/backend/engine/CarlaEngine.cpp index 6a5fc6dd9..109c70b72 100644 --- a/source/backend/engine/CarlaEngine.cpp +++ b/source/backend/engine/CarlaEngine.cpp @@ -32,9 +32,9 @@ #include "CarlaEngineUtils.hpp" #include "CarlaStateUtils.hpp" -#include - -#ifdef HAVE_JUCE +#ifndef HAVE_JUCE +# include +#else # include "juce_audio_basics.h" using juce::FloatVectorOperations; #endif @@ -145,7 +145,7 @@ CarlaEngineEventPort::CarlaEngineEventPort(const CarlaEngine& engine, const bool carla_debug("CarlaEngineEventPort::CarlaEngineEventPort(%s)", bool2str(isInput)); if (fProcessMode == ENGINE_PROCESS_MODE_PATCHBAY) - fBuffer = new EngineEvent[EngineEvent::kMaxInternalCount]; + fBuffer = new EngineEvent[kMaxEngineEventInternalCount]; } CarlaEngineEventPort::~CarlaEngineEventPort() @@ -166,7 +166,7 @@ void CarlaEngineEventPort::initBuffer() if (fProcessMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK || fProcessMode == ENGINE_PROCESS_MODE_BRIDGE) fBuffer = fEngine.getInternalEventBuffer(fIsInput); else if (fProcessMode == ENGINE_PROCESS_MODE_PATCHBAY && ! fIsInput) - carla_zeroStruct(fBuffer, EngineEvent::kMaxInternalCount); + carla_zeroStruct(fBuffer, kMaxEngineEventInternalCount); } uint32_t CarlaEngineEventPort::getEventCount() const noexcept @@ -177,7 +177,7 @@ uint32_t CarlaEngineEventPort::getEventCount() const noexcept uint32_t i=0; - for (; i < EngineEvent::kMaxInternalCount; ++i) + for (; i < kMaxEngineEventInternalCount; ++i) { if (fBuffer[i].type == kEngineEventTypeNull) break; @@ -191,7 +191,7 @@ const EngineEvent& CarlaEngineEventPort::getEvent(const uint32_t index) noexcept CARLA_SAFE_ASSERT_RETURN(fIsInput, kFallbackEngineEvent); CARLA_SAFE_ASSERT_RETURN(fBuffer != nullptr, kFallbackEngineEvent); CARLA_SAFE_ASSERT_RETURN(fProcessMode != ENGINE_PROCESS_MODE_SINGLE_CLIENT && fProcessMode != ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS, kFallbackEngineEvent); - CARLA_SAFE_ASSERT_RETURN(index < EngineEvent::kMaxInternalCount, kFallbackEngineEvent); + CARLA_SAFE_ASSERT_RETURN(index < kMaxEngineEventInternalCount, kFallbackEngineEvent); return fBuffer[index]; } @@ -216,7 +216,7 @@ bool CarlaEngineEventPort::writeControlEvent(const uint32_t time, const uint8_t const float fixedValue(carla_fixValue(0.0f, 1.0f, value)); - for (uint32_t i=0; i < EngineEvent::kMaxInternalCount; ++i) + for (uint32_t i=0; i < kMaxEngineEventInternalCount; ++i) { if (fBuffer[i].type != kEngineEventTypeNull) continue; @@ -252,7 +252,7 @@ bool CarlaEngineEventPort::writeMidiEvent(const uint32_t time, const uint8_t cha CARLA_SAFE_ASSERT_RETURN(size > 0 && size <= EngineMidiEvent::kDataSize, false); CARLA_SAFE_ASSERT_RETURN(data != nullptr, false); - for (uint32_t i=0; i < EngineEvent::kMaxInternalCount; ++i) + for (uint32_t i=0; i < kMaxEngineEventInternalCount; ++i) { if (fBuffer[i].type != kEngineEventTypeNull) continue; @@ -586,8 +586,8 @@ bool CarlaEngine::init(const char* const clientName) case ENGINE_PROCESS_MODE_CONTINUOUS_RACK: pData->maxPluginNumber = MAX_RACK_PLUGINS; - pData->bufEvents.in = new EngineEvent[EngineEvent::kMaxInternalCount]; - pData->bufEvents.out = new EngineEvent[EngineEvent::kMaxInternalCount]; + pData->bufEvents.in = new EngineEvent[kMaxEngineEventInternalCount]; + pData->bufEvents.out = new EngineEvent[kMaxEngineEventInternalCount]; break; case ENGINE_PROCESS_MODE_PATCHBAY: @@ -596,8 +596,8 @@ bool CarlaEngine::init(const char* const clientName) case ENGINE_PROCESS_MODE_BRIDGE: pData->maxPluginNumber = 1; - pData->bufEvents.in = new EngineEvent[EngineEvent::kMaxInternalCount]; - pData->bufEvents.out = new EngineEvent[EngineEvent::kMaxInternalCount]; + pData->bufEvents.in = new EngineEvent[kMaxEngineEventInternalCount]; + pData->bufEvents.out = new EngineEvent[kMaxEngineEventInternalCount]; break; } diff --git a/source/backend/engine/CarlaEngineInternal.cpp b/source/backend/engine/CarlaEngineInternal.cpp index d3b5e1705..432230e75 100644 --- a/source/backend/engine/CarlaEngineInternal.cpp +++ b/source/backend/engine/CarlaEngineInternal.cpp @@ -17,7 +17,6 @@ #include "CarlaEngineInternal.hpp" #include "CarlaPlugin.hpp" - #include "CarlaMIDI.h" #ifndef HAVE_JUCE @@ -377,7 +376,7 @@ void EnginePatchbayBuffers::resize(const uint32_t /*bufferSize*/) // ----------------------------------------------------------------------- // InternalAudio -InternalAudio::InternalAudio() noexcept +EngineInternalAudio::EngineInternalAudio() noexcept : isReady(false), usePatchbay(false), inCount(0), @@ -386,17 +385,19 @@ InternalAudio::InternalAudio() noexcept rack = nullptr; } -InternalAudio::~InternalAudio() noexcept +EngineInternalAudio::~EngineInternalAudio() noexcept { CARLA_ASSERT(! isReady); CARLA_ASSERT(rack == nullptr); } -void InternalAudio::initPatchbay() noexcept +void EngineInternalAudio::initPatchbay() noexcept { if (usePatchbay) { CARLA_SAFE_ASSERT_RETURN(patchbay != nullptr,); + + // TODO } else { @@ -407,7 +408,7 @@ void InternalAudio::initPatchbay() noexcept } } -void InternalAudio::clear() +void EngineInternalAudio::clear() { isReady = false; inCount = 0; @@ -427,7 +428,7 @@ void InternalAudio::clear() } } -void InternalAudio::create(const uint32_t bufferSize) +void EngineInternalAudio::create(const uint32_t bufferSize) { if (usePatchbay) { @@ -443,7 +444,7 @@ void InternalAudio::create(const uint32_t bufferSize) isReady = true; } -void InternalAudio::resize(const uint32_t bufferSize) +void EngineInternalAudio::resize(const uint32_t bufferSize) { if (usePatchbay) { @@ -460,11 +461,11 @@ void InternalAudio::resize(const uint32_t bufferSize) // ----------------------------------------------------------------------- // InternalEvents -InternalEvents::InternalEvents() noexcept +EngineInternalEvents::EngineInternalEvents() noexcept : in(nullptr), out(nullptr) {} -InternalEvents::~InternalEvents() noexcept +EngineInternalEvents::~EngineInternalEvents() noexcept { CARLA_ASSERT(in == nullptr); CARLA_ASSERT(out == nullptr); @@ -473,24 +474,24 @@ InternalEvents::~InternalEvents() noexcept // ----------------------------------------------------------------------- // InternalTime -InternalTime::InternalTime() noexcept +EngineInternalTime::EngineInternalTime() noexcept : playing(false), frame(0) {} // ----------------------------------------------------------------------- // NextAction -NextAction::NextAction() noexcept +EngineNextAction::EngineNextAction() noexcept : opcode(kEnginePostActionNull), pluginId(0), value(0) {} -NextAction::~NextAction() noexcept +EngineNextAction::~EngineNextAction() noexcept { CARLA_ASSERT(opcode == kEnginePostActionNull); } -void NextAction::ready() noexcept +void EngineNextAction::ready() noexcept { mutex.lock(); mutex.unlock(); @@ -635,7 +636,7 @@ void CarlaEngineProtectedData::processRack(float* inBufReal[2], float* outBuf[2] FLOAT_CLEAR(outBuf[1], frames); // initialize event outputs (zero) - carla_zeroStruct(bufEvents.out, EngineEvent::kMaxInternalCount); + carla_zeroStruct(bufEvents.out, kMaxEngineEventInternalCount); bool processed = false; @@ -672,10 +673,10 @@ void CarlaEngineProtectedData::processRack(float* inBufReal[2], float* outBuf[2] else { // initialize event inputs from previous outputs - carla_copyStruct(bufEvents.in, bufEvents.out, EngineEvent::kMaxInternalCount); + carla_copyStruct(bufEvents.in, bufEvents.out, kMaxEngineEventInternalCount); // initialize event outputs (zero) - carla_zeroStruct(bufEvents.out, EngineEvent::kMaxInternalCount); + carla_zeroStruct(bufEvents.out, kMaxEngineEventInternalCount); } } diff --git a/source/backend/engine/CarlaEngineInternal.hpp b/source/backend/engine/CarlaEngineInternal.hpp index 6e756a8b7..08e1379cf 100644 --- a/source/backend/engine/CarlaEngineInternal.hpp +++ b/source/backend/engine/CarlaEngineInternal.hpp @@ -52,6 +52,11 @@ CARLA_BACKEND_START_NAMESPACE } // Fix editor indentation #endif +// ----------------------------------------------------------------------- +// Maximum pre-allocated events for rack and bridge modes + +const unsigned short kMaxEngineEventInternalCount = 512; + // ----------------------------------------------------------------------- // Rack Patchbay stuff @@ -104,6 +109,8 @@ struct EngineRackBuffers { ~EngineRackBuffers(); void clear(); void resize(const uint32_t bufferSize); + + CARLA_DECLARE_NON_COPY_STRUCT(EngineRackBuffers) }; // ----------------------------------------------------------------------- @@ -115,12 +122,14 @@ struct EnginePatchbayBuffers { ~EnginePatchbayBuffers(); void clear(); void resize(const uint32_t bufferSize); + + CARLA_DECLARE_NON_COPY_STRUCT(EnginePatchbayBuffers) }; // ----------------------------------------------------------------------- // InternalAudio -struct InternalAudio { +struct EngineInternalAudio { bool isReady; bool usePatchbay; @@ -132,34 +141,39 @@ struct InternalAudio { EnginePatchbayBuffers* patchbay; }; - InternalAudio() noexcept; - ~InternalAudio() noexcept; + EngineInternalAudio() noexcept; + ~EngineInternalAudio() noexcept; void initPatchbay() noexcept; void clear(); void create(const uint32_t bufferSize); void resize(const uint32_t bufferSize); + + CARLA_DECLARE_NON_COPY_STRUCT(EngineInternalAudio) }; // ----------------------------------------------------------------------- // InternalEvents -struct InternalEvents { +struct EngineInternalEvents { EngineEvent* in; EngineEvent* out; - InternalEvents() noexcept; - ~InternalEvents() noexcept; - void allocateEvents(); + EngineInternalEvents() noexcept; + ~EngineInternalEvents() noexcept; + + CARLA_DECLARE_NON_COPY_STRUCT(EngineInternalEvents) }; // ----------------------------------------------------------------------- // InternalTime -struct InternalTime { +struct EngineInternalTime { bool playing; uint64_t frame; - InternalTime() noexcept; + EngineInternalTime() noexcept; + + CARLA_DECLARE_NON_COPY_STRUCT(EngineInternalTime) }; // ----------------------------------------------------------------------- @@ -172,15 +186,17 @@ enum EnginePostAction { kEnginePostActionSwitchPlugins }; -struct NextAction { +struct EngineNextAction { EnginePostAction opcode; unsigned int pluginId; unsigned int value; CarlaMutex mutex; - NextAction() noexcept; - ~NextAction() noexcept; + EngineNextAction() noexcept; + ~EngineNextAction() noexcept; void ready() noexcept; + + CARLA_DECLARE_NON_COPY_STRUCT(EngineNextAction) }; // ----------------------------------------------------------------------- @@ -223,19 +239,25 @@ struct CarlaEngineProtectedData { EnginePluginData* plugins; #ifndef BUILD_BRIDGE - InternalAudio bufAudio; + EngineInternalAudio bufAudio; #endif - InternalEvents bufEvents; - InternalTime time; - NextAction nextAction; + EngineInternalEvents bufEvents; + EngineInternalTime time; + EngineNextAction nextAction; + + // ------------------------------------------------------------------- CarlaEngineProtectedData(CarlaEngine* const engine); ~CarlaEngineProtectedData() noexcept; + // ------------------------------------------------------------------- + void doPluginRemove() noexcept; void doPluginsSwitch() noexcept; void doNextPluginAction(const bool unlock) noexcept; + // ------------------------------------------------------------------- + #ifndef BUILD_BRIDGE // the base, where plugins run void processRack(float* inBufReal[2], float* outBuf[2], const uint32_t nframes, const bool isOffline); @@ -244,6 +266,8 @@ struct CarlaEngineProtectedData { void processRackFull(float** const inBuf, const uint32_t inCount, float** const outBuf, const uint32_t outCount, const uint32_t nframes, const bool isOffline); #endif + // ------------------------------------------------------------------- + class ScopedActionLock { public: @@ -257,6 +281,8 @@ struct CarlaEngineProtectedData { CARLA_DECLARE_NON_COPY_CLASS(ScopedActionLock) }; + // ------------------------------------------------------------------- + #ifdef CARLA_PROPER_CPP11_SUPPORT CarlaEngineProtectedData() = delete; CARLA_DECLARE_NON_COPY_STRUCT(CarlaEngineProtectedData) diff --git a/source/backend/engine/CarlaEngineJack.cpp b/source/backend/engine/CarlaEngineJack.cpp index ae7ef13d9..bf7d066c6 100644 --- a/source/backend/engine/CarlaEngineJack.cpp +++ b/source/backend/engine/CarlaEngineJack.cpp @@ -1122,7 +1122,7 @@ protected: float* outBuf[2] = { audioOut1, audioOut2 }; // initialize input events - carla_zeroStruct(pData->bufEvents.in, EngineEvent::kMaxInternalCount); + carla_zeroStruct(pData->bufEvents.in, kMaxEngineEventInternalCount); { uint32_t engineEventIndex = 0; @@ -1141,7 +1141,7 @@ protected: engineEvent.time = jackEvent.time; engineEvent.fillFromMidiData(static_cast(jackEvent.size), jackEvent.buffer); - if (engineEventIndex >= EngineEvent::kMaxInternalCount) + if (engineEventIndex >= kMaxEngineEventInternalCount) break; } } @@ -1153,7 +1153,7 @@ protected: { jackbridge_midi_clear_buffer(eventOut); - for (unsigned short i=0; i < EngineEvent::kMaxInternalCount; ++i) + for (unsigned short i=0; i < kMaxEngineEventInternalCount; ++i) { const EngineEvent& engineEvent(pData->bufEvents.out[i]); diff --git a/source/backend/engine/CarlaEngineJuce.cpp b/source/backend/engine/CarlaEngineJuce.cpp index e02408d41..93d6f1e08 100644 --- a/source/backend/engine/CarlaEngineJuce.cpp +++ b/source/backend/engine/CarlaEngineJuce.cpp @@ -439,7 +439,7 @@ protected: return runPendingRtEvents(); // initialize input events - carla_zeroStruct(pData->bufEvents.in, EngineEvent::kMaxInternalCount); + carla_zeroStruct(pData->bufEvents.in, kMaxEngineEventInternalCount); // TODO - get events from juce diff --git a/source/backend/engine/CarlaEngineNative.cpp b/source/backend/engine/CarlaEngineNative.cpp index 38a4654f6..5781fcf19 100644 --- a/source/backend/engine/CarlaEngineNative.cpp +++ b/source/backend/engine/CarlaEngineNative.cpp @@ -1059,8 +1059,8 @@ protected: // --------------------------------------------------------------- // initialize events - carla_zeroStruct(pData->bufEvents.in, EngineEvent::kMaxInternalCount); - carla_zeroStruct(pData->bufEvents.out, EngineEvent::kMaxInternalCount); + carla_zeroStruct(pData->bufEvents.in, kMaxEngineEventInternalCount); + carla_zeroStruct(pData->bufEvents.out, kMaxEngineEventInternalCount); // --------------------------------------------------------------- // events input (before processing) @@ -1068,7 +1068,7 @@ protected: { uint32_t engineEventIndex = 0; - for (uint32_t i=0; i < midiEventCount && engineEventIndex < EngineEvent::kMaxInternalCount; ++i) + for (uint32_t i=0; i < midiEventCount && engineEventIndex < kMaxEngineEventInternalCount; ++i) { const NativeMidiEvent& midiEvent(midiEvents[i]); EngineEvent& engineEvent(pData->bufEvents.in[engineEventIndex++]); @@ -1076,7 +1076,7 @@ protected: engineEvent.time = midiEvent.time; engineEvent.fillFromMidiData(midiEvent.size, midiEvent.data); - if (engineEventIndex >= EngineEvent::kMaxInternalCount) + if (engineEventIndex >= kMaxEngineEventInternalCount) break; } } @@ -1112,12 +1112,12 @@ protected: // --------------------------------------------------------------- // events output (after processing) - carla_zeroStruct(pData->bufEvents.in, EngineEvent::kMaxInternalCount); + carla_zeroStruct(pData->bufEvents.in, kMaxEngineEventInternalCount); { NativeMidiEvent midiEvent; - for (uint32_t i=0; i < EngineEvent::kMaxInternalCount; ++i) + for (uint32_t i=0; i < kMaxEngineEventInternalCount; ++i) { const EngineEvent& engineEvent(pData->bufEvents.out[i]); diff --git a/source/backend/engine/CarlaEngineRtAudio.cpp b/source/backend/engine/CarlaEngineRtAudio.cpp index 1e25526e6..31bfafb48 100644 --- a/source/backend/engine/CarlaEngineRtAudio.cpp +++ b/source/backend/engine/CarlaEngineRtAudio.cpp @@ -643,7 +643,7 @@ protected: FLOAT_CLEAR(fAudioBufOut[i], nframes); // initialize input events - carla_zeroStruct(pData->bufEvents.in, EngineEvent::kMaxInternalCount); + carla_zeroStruct(pData->bufEvents.in, kMaxEngineEventInternalCount); if (fMidiInEvents.mutex.tryLock()) { @@ -669,7 +669,7 @@ protected: engineEvent.fillFromMidiData(midiEvent.size, midiEvent.data); - if (engineEventIndex >= EngineEvent::kMaxInternalCount) + if (engineEventIndex >= kMaxEngineEventInternalCount) break; } diff --git a/source/backend/plugin/AuPlugin.cpp b/source/backend/plugin/AuPlugin.cpp index 3e417d97b..02e2d3107 100644 --- a/source/backend/plugin/AuPlugin.cpp +++ b/source/backend/plugin/AuPlugin.cpp @@ -15,7 +15,9 @@ * For a full copy of the GNU General Public License see the doc/GPL.txt file. */ -#include "CarlaPluginInternal.hpp" +#include "CarlaPlugin.hpp" +#include "CarlaEngine.hpp" +#include "CarlaUtils.hpp" CARLA_BACKEND_START_NAMESPACE diff --git a/source/backend/plugin/BridgePlugin.cpp b/source/backend/plugin/BridgePlugin.cpp index 47bbbeec6..be84cccbd 100644 --- a/source/backend/plugin/BridgePlugin.cpp +++ b/source/backend/plugin/BridgePlugin.cpp @@ -16,6 +16,7 @@ */ #include "CarlaPluginInternal.hpp" +#include "CarlaEngine.hpp" #ifndef BUILD_BRIDGE diff --git a/source/backend/plugin/CarlaPlugin.cpp b/source/backend/plugin/CarlaPlugin.cpp index 8d511fa1a..41c27392c 100644 --- a/source/backend/plugin/CarlaPlugin.cpp +++ b/source/backend/plugin/CarlaPlugin.cpp @@ -16,6 +16,7 @@ */ #include "CarlaPluginInternal.hpp" +#include "CarlaEngine.hpp" #include #include diff --git a/source/backend/plugin/CarlaPluginInternal.cpp b/source/backend/plugin/CarlaPluginInternal.cpp index 9096eb9ff..605907d4b 100644 --- a/source/backend/plugin/CarlaPluginInternal.cpp +++ b/source/backend/plugin/CarlaPluginInternal.cpp @@ -16,17 +16,566 @@ */ #include "CarlaPluginInternal.hpp" +#include "CarlaEngine.hpp" #include "CarlaLibCounter.hpp" #include +// ----------------------------------------------------------------------- + CARLA_BACKEND_START_NAMESPACE #if 0 } // Fix editor indentation #endif +// ------------------------------------------------------------------- +// Fallback data + +static const MidiProgramData kMidiProgramDataNull = { 0, 0, nullptr }; + +// ----------------------------------------------------------------------- +// PluginAudioPort + +PluginAudioPort::PluginAudioPort() noexcept + : rindex(0), + port(nullptr) {} + +PluginAudioPort::~PluginAudioPort() +{ + CARLA_ASSERT(port == nullptr); +} + +// ----------------------------------------------------------------------- +// PluginAudioData + +PluginAudioData::PluginAudioData() noexcept + : count(0), + ports(nullptr) {} + +PluginAudioData::~PluginAudioData() +{ + CARLA_ASSERT_INT(count == 0, count); + CARLA_ASSERT(ports == nullptr); +} + +void PluginAudioData::createNew(const uint32_t newCount) +{ + CARLA_ASSERT_INT(count == 0, count); + CARLA_ASSERT(ports == nullptr); + CARLA_ASSERT_INT(newCount > 0, newCount); + + if (ports != nullptr || newCount == 0) + return; + + ports = new PluginAudioPort[newCount]; + count = newCount; +} + +void PluginAudioData::clear() +{ + if (ports != nullptr) + { + for (uint32_t i=0; i < count; ++i) + { + if (ports[i].port != nullptr) + { + delete ports[i].port; + ports[i].port = nullptr; + } + } + + delete[] ports; + ports = nullptr; + } + + count = 0; +} + +void PluginAudioData::initBuffers() +{ + for (uint32_t i=0; i < count; ++i) + { + if (ports[i].port != nullptr) + ports[i].port->initBuffer(); + } +} + +// ----------------------------------------------------------------------- +// PluginCVPort + +PluginCVPort::PluginCVPort() noexcept + : rindex(0), + param(0), + port(nullptr) {} + +PluginCVPort::~PluginCVPort() +{ + CARLA_ASSERT(port == nullptr); +} + +// ----------------------------------------------------------------------- +// PluginCVData + +PluginCVData::PluginCVData() noexcept + : count(0), + ports(nullptr) {} + +PluginCVData::~PluginCVData() +{ + CARLA_ASSERT_INT(count == 0, count); + CARLA_ASSERT(ports == nullptr); +} + +void PluginCVData::createNew(const uint32_t newCount) +{ + CARLA_ASSERT_INT(count == 0, count); + CARLA_ASSERT(ports == nullptr); + CARLA_ASSERT_INT(newCount > 0, newCount); + + if (ports != nullptr || newCount == 0) + return; + + ports = new PluginCVPort[newCount]; + count = newCount; +} + +void PluginCVData::clear() +{ + if (ports != nullptr) + { + for (uint32_t i=0; i < count; ++i) + { + if (ports[i].port != nullptr) + { + delete ports[i].port; + ports[i].port = nullptr; + } + } + + delete[] ports; + ports = nullptr; + } + + count = 0; +} + +void PluginCVData::initBuffers() +{ + for (uint32_t i=0; i < count; ++i) + { + if (ports[i].port != nullptr) + ports[i].port->initBuffer(); + } +} + +// ----------------------------------------------------------------------- +// PluginEventData + +PluginEventData::PluginEventData() noexcept + : portIn(nullptr), + portOut(nullptr) {} + +PluginEventData::~PluginEventData() +{ + CARLA_ASSERT(portIn == nullptr); + CARLA_ASSERT(portOut == nullptr); +} + +void PluginEventData::clear() +{ + if (portIn != nullptr) + { + delete portIn; + portIn = nullptr; + } + + if (portOut != nullptr) + { + delete portOut; + portOut = nullptr; + } +} + +void PluginEventData::initBuffers() +{ + if (portIn != nullptr) + portIn->initBuffer(); + + if (portOut != nullptr) + portOut->initBuffer(); +} + +// ----------------------------------------------------------------------- +// PluginParameterData + +PluginParameterData::PluginParameterData() noexcept + : count(0), + data(nullptr), + ranges(nullptr), + special(nullptr) {} + +PluginParameterData::~PluginParameterData() +{ + CARLA_ASSERT_INT(count == 0, count); + CARLA_ASSERT(data == nullptr); + CARLA_ASSERT(ranges == nullptr); + CARLA_ASSERT(special == nullptr); +} + +void PluginParameterData::createNew(const uint32_t newCount, const bool withSpecial) +{ + CARLA_ASSERT_INT(count == 0, count); + CARLA_ASSERT(data == nullptr); + CARLA_ASSERT(ranges == nullptr); + CARLA_ASSERT(special == nullptr); + CARLA_ASSERT_INT(newCount > 0, newCount); + + if (data != nullptr || ranges != nullptr || newCount == 0) + return; + + data = new ParameterData[newCount]; + ranges = new ParameterRanges[newCount]; + count = newCount; + + if (withSpecial) + special = new SpecialParameterType[newCount]; +} + +void PluginParameterData::clear() +{ + if (data != nullptr) + { + delete[] data; + data = nullptr; + } + + if (ranges != nullptr) + { + delete[] ranges; + ranges = nullptr; + } + + if (special != nullptr) + { + delete[] special; + special = nullptr; + } + + count = 0; +} + +float PluginParameterData::getFixedValue(const uint32_t parameterId, const float& value) const +{ + CARLA_SAFE_ASSERT_RETURN(parameterId < count, 0.0f); + return ranges[parameterId].getFixedValue(value); +} + +// ----------------------------------------------------------------------- +// PluginProgramData + +PluginProgramData::PluginProgramData() noexcept + : count(0), + current(-1), + names(nullptr) {} + +PluginProgramData::~PluginProgramData() +{ + CARLA_ASSERT_INT(count == 0, count); + CARLA_ASSERT_INT(current == -1, current); + CARLA_ASSERT(names == nullptr); +} + +void PluginProgramData::createNew(const uint32_t newCount) +{ + CARLA_ASSERT_INT(count == 0, count); + CARLA_ASSERT_INT(current == -1, current); + CARLA_ASSERT(names == nullptr); + CARLA_ASSERT_INT(newCount > 0, newCount); + + if (names != nullptr || newCount == 0) + return; + + names = new ProgramName[newCount]; + count = newCount; + + for (uint32_t i=0; i < newCount; ++i) + names[i] = nullptr; +} + +void PluginProgramData::clear() +{ + if (names != nullptr) + { + for (uint32_t i=0; i < count; ++i) + { + if (names[i] != nullptr) + { + delete[] names[i]; + names[i] = nullptr; + } + } + + delete[] names; + names = nullptr; + } + + count = 0; + current = -1; +} + +// ----------------------------------------------------------------------- +// PluginMidiProgramData + +PluginMidiProgramData::PluginMidiProgramData() noexcept + : count(0), + current(-1), + data(nullptr) {} + +PluginMidiProgramData::~PluginMidiProgramData() +{ + CARLA_ASSERT_INT(count == 0, count); + CARLA_ASSERT_INT(current == -1, current); + CARLA_ASSERT(data == nullptr); +} + +void PluginMidiProgramData::createNew(const uint32_t newCount) +{ + CARLA_ASSERT_INT(count == 0, count); + CARLA_ASSERT_INT(current == -1, current); + CARLA_ASSERT(data == nullptr); + CARLA_ASSERT_INT(newCount > 0, newCount); + + if (data != nullptr || newCount == 0) + return; + + data = new MidiProgramData[newCount]; + count = newCount; + + for (uint32_t i=0; i < count; ++i) + { + data[i].bank = 0; + data[i].program = 0; + data[i].name = nullptr; + } +} + +void PluginMidiProgramData::clear() +{ + if (data != nullptr) + { + for (uint32_t i=0; i < count; ++i) + { + if (data[i].name != nullptr) + { + delete[] data[i].name; + data[i].name = nullptr; + } + } + + delete[] data; + data = nullptr; + } + + count = 0; + current = -1; +} + +const MidiProgramData& PluginMidiProgramData::getCurrent() const noexcept +{ + CARLA_SAFE_ASSERT_RETURN(current >= 0 && current < static_cast(count), kMidiProgramDataNull); + return data[current]; +} + +// ----------------------------------------------------------------------- + +CarlaPluginProtectedData::ExternalNotes::ExternalNotes() + : dataPool(32, 152), + data(dataPool) {} + +CarlaPluginProtectedData::ExternalNotes::~ExternalNotes() +{ + mutex.lock(); + data.clear(); + mutex.unlock(); +} + +void CarlaPluginProtectedData::ExternalNotes::append(const ExternalMidiNote& note) +{ + mutex.lock(); + data.append_sleepy(note); + mutex.unlock(); +} + +// ----------------------------------------------------------------------- + +CarlaPluginProtectedData::PostRtEvents::PostRtEvents() + : dataPool(128, 128), + data(dataPool), + dataPendingRT(dataPool) {} + +CarlaPluginProtectedData::PostRtEvents::~PostRtEvents() +{ + clear(); +} + +void CarlaPluginProtectedData::PostRtEvents::appendRT(const PluginPostRtEvent& event) +{ + dataPendingRT.append(event); +} + +void CarlaPluginProtectedData::PostRtEvents::trySplice() +{ + if (mutex.tryLock()) + { + dataPendingRT.spliceAppend(data); + mutex.unlock(); + } +} + +void CarlaPluginProtectedData::PostRtEvents::clear() +{ + mutex.lock(); + data.clear(); + dataPendingRT.clear(); + mutex.unlock(); +} + +// ----------------------------------------------------------------------- + +#ifndef BUILD_BRIDGE +CarlaPluginProtectedData::PostProc::PostProc() noexcept + : dryWet(1.0f), + volume(1.0f), + balanceLeft(-1.0f), + balanceRight(1.0f), + panning(0.0f) {} +#endif + +// ----------------------------------------------------------------------- + +CarlaPluginProtectedData::OSC::OSC(CarlaEngine* const engine, CarlaPlugin* const plugin) + : thread(engine, plugin) {} + +// ----------------------------------------------------------------------- + +CarlaPluginProtectedData::CarlaPluginProtectedData(CarlaEngine* const eng, const unsigned int idx, CarlaPlugin* const self) + : engine(eng), + client(nullptr), + id(idx), + hints(0x0), + options(0x0), + active(false), + enabled(false), + needsReset(false), + lib(nullptr), + uiLib(nullptr), + ctrlChannel(0), + extraHints(0x0), + patchbayClientId(0), + latency(0), + latencyBuffers(nullptr), + name(nullptr), + filename(nullptr), + iconName(nullptr), + identifier(nullptr), + osc(eng, self) {} + +CarlaPluginProtectedData::~CarlaPluginProtectedData() +{ + CARLA_SAFE_ASSERT(! needsReset); + + if (name != nullptr) + { + delete[] name; + name = nullptr; + } + + if (filename != nullptr) + { + delete[] filename; + filename = nullptr; + } + + if (iconName != nullptr) + { + delete[] iconName; + iconName = nullptr; + } + + if (identifier != nullptr) + { + delete[] identifier; + identifier = nullptr; + } + + { + // mutex MUST have been locked before + const bool lockMaster(masterMutex.tryLock()); + const bool lockSingle(singleMutex.tryLock()); + CARLA_SAFE_ASSERT(! lockMaster); + CARLA_SAFE_ASSERT(! lockSingle); + } + + if (client != nullptr) + { + if (client->isActive()) + { + // must not happen + carla_safe_assert("client->isActive()", __FILE__, __LINE__); + client->deactivate(); + } + + clearBuffers(); + + delete client; + client = nullptr; + } + + for (LinkedList::Itenerator it = custom.begin(); it.valid(); it.next()) + { + CustomData& cData(it.getValue()); + + if (cData.type != nullptr) + { + delete[] cData.type; + cData.type = nullptr; + } + else + carla_safe_assert("cData.type != nullptr", __FILE__, __LINE__); + + if (cData.key != nullptr) + { + delete[] cData.key; + cData.key = nullptr; + } + else + carla_safe_assert("cData.key != nullptr", __FILE__, __LINE__); + + if (cData.value != nullptr) + { + delete[] cData.value; + cData.value = nullptr; + } + else + carla_safe_assert("cData.value != nullptr", __FILE__, __LINE__); + } + + prog.clear(); + midiprog.clear(); + custom.clear(); + + // MUST have been locked before + masterMutex.unlock(); + singleMutex.unlock(); + + if (lib != nullptr) + libClose(); + + CARLA_ASSERT(uiLib == nullptr); +} + // ----------------------------------------------------------------------- // Buffer functions @@ -150,7 +699,7 @@ void* CarlaPluginProtectedData::uiLibSymbol(const char* const symbol) // ----------------------------------------------------------------------- // Settings functions -void CarlaPluginProtectedData::saveSetting(const unsigned int option, const bool yesNo) +void CarlaPluginProtectedData::saveSetting(const uint option, const bool yesNo) { CARLA_SAFE_ASSERT_RETURN(identifier != nullptr && identifier[0] != '\0',); @@ -193,7 +742,7 @@ void CarlaPluginProtectedData::saveSetting(const unsigned int option, const bool settings.endGroup(); } -unsigned int CarlaPluginProtectedData::loadSettings(const unsigned int options, const unsigned int availOptions) +uint CarlaPluginProtectedData::loadSettings(const uint options, const uint availOptions) { CARLA_SAFE_ASSERT_RETURN(identifier != nullptr && identifier[0] != '\0', 0x0); @@ -231,4 +780,6 @@ unsigned int CarlaPluginProtectedData::loadSettings(const unsigned int options, return newOptions; } +// ----------------------------------------------------------------------- + CARLA_BACKEND_END_NAMESPACE diff --git a/source/backend/plugin/CarlaPluginInternal.hpp b/source/backend/plugin/CarlaPluginInternal.hpp index 9c3f6d0a0..f0b3f7078 100644 --- a/source/backend/plugin/CarlaPluginInternal.hpp +++ b/source/backend/plugin/CarlaPluginInternal.hpp @@ -20,21 +20,20 @@ #include "CarlaPlugin.hpp" #include "CarlaPluginThread.hpp" -#include "CarlaEngine.hpp" -#include "CarlaBackendUtils.hpp" #include "CarlaOscUtils.hpp" #include "CarlaStateUtils.hpp" + #include "CarlaMutex.hpp" #include "RtLinkedList.hpp" +#include + #ifdef HAVE_JUCE # include "juce_audio_basics.h" using juce::FloatVectorOperations; #endif -#include - // ----------------------------------------------------------------------- #define CARLA_PROCESS_CONTINUE_CHECK if (! pData->enabled) { pData->engine->callback(ENGINE_CALLBACK_DEBUG, pData->id, 0, 0, 0.0f, "Processing while plugin is disabled!!"); return; } @@ -52,6 +51,8 @@ using juce::FloatVectorOperations; # define FLOAT_CLEAR(buf, frames) carla_zeroFloat(buf, frames) #endif +// ----------------------------------------------------------------------- + CARLA_BACKEND_START_NAMESPACE #if 0 @@ -59,9 +60,21 @@ CARLA_BACKEND_START_NAMESPACE #endif // ----------------------------------------------------------------------- +// Forward declarations of CarlaEngine classes + +class CarlaEngineAudioPort; +class CarlaEngineCVPort; +class CarlaEngineEventPort; +class CarlaEngineClient; + +// ----------------------------------------------------------------------- +// Maximum pre-allocated events for some plugin types const unsigned short kPluginMaxMidiEvents = 512; +// ----------------------------------------------------------------------- +// Extra plugin hints, hidden from backend + const unsigned int PLUGIN_EXTRA_HINT_HAS_MIDI_IN = 0x01; const unsigned int PLUGIN_EXTRA_HINT_HAS_MIDI_OUT = 0x02; const unsigned int PLUGIN_EXTRA_HINT_CAN_RUN_RACK = 0x04; @@ -96,6 +109,8 @@ struct PluginPostRtEvent { float value3; }; +// ----------------------------------------------------------------------- + struct ExternalMidiNote { int8_t channel; // invalid if -1 uint8_t note; // 0 to 127 @@ -108,14 +123,8 @@ struct PluginAudioPort { uint32_t rindex; CarlaEngineAudioPort* port; - PluginAudioPort() noexcept - : rindex(0), - port(nullptr) {} - - ~PluginAudioPort() - { - CARLA_ASSERT(port == nullptr); - } + PluginAudioPort() noexcept; + ~PluginAudioPort(); CARLA_DECLARE_NON_COPY_STRUCT(PluginAudioPort) }; @@ -124,57 +133,11 @@ struct PluginAudioData { uint32_t count; PluginAudioPort* ports; - PluginAudioData() noexcept - : count(0), - ports(nullptr) {} - - ~PluginAudioData() - { - CARLA_ASSERT_INT(count == 0, count); - CARLA_ASSERT(ports == nullptr); - } - - void createNew(const uint32_t newCount) - { - CARLA_ASSERT_INT(count == 0, count); - CARLA_ASSERT(ports == nullptr); - CARLA_ASSERT_INT(newCount > 0, newCount); - - if (ports != nullptr || newCount == 0) - return; - - ports = new PluginAudioPort[newCount]; - count = newCount; - } - - void clear() - { - if (ports != nullptr) - { - for (uint32_t i=0; i < count; ++i) - { - if (ports[i].port != nullptr) - { - delete ports[i].port; - ports[i].port = nullptr; - } - } - - delete[] ports; - ports = nullptr; - } - - count = 0; - } - - void initBuffers() - { - for (uint32_t i=0; i < count; ++i) - { - if (ports[i].port != nullptr) - ports[i].port->initBuffer(); - } - } + PluginAudioData() noexcept; + ~PluginAudioData(); + void createNew(const uint32_t newCount); + void clear(); + void initBuffers(); CARLA_DECLARE_NON_COPY_STRUCT(PluginAudioData) }; @@ -186,15 +149,8 @@ struct PluginCVPort { uint32_t param; CarlaEngineCVPort* port; - PluginCVPort() noexcept - : rindex(0), - param(0), - port(nullptr) {} - - ~PluginCVPort() - { - CARLA_ASSERT(port == nullptr); - } + PluginCVPort() noexcept; + ~PluginCVPort(); CARLA_DECLARE_NON_COPY_STRUCT(PluginCVPort) }; @@ -203,57 +159,11 @@ struct PluginCVData { uint32_t count; PluginCVPort* ports; - PluginCVData() noexcept - : count(0), - ports(nullptr) {} - - ~PluginCVData() - { - CARLA_ASSERT_INT(count == 0, count); - CARLA_ASSERT(ports == nullptr); - } - - void createNew(const uint32_t newCount) - { - CARLA_ASSERT_INT(count == 0, count); - CARLA_ASSERT(ports == nullptr); - CARLA_ASSERT_INT(newCount > 0, newCount); - - if (ports != nullptr || newCount == 0) - return; - - ports = new PluginCVPort[newCount]; - count = newCount; - } - - void clear() - { - if (ports != nullptr) - { - for (uint32_t i=0; i < count; ++i) - { - if (ports[i].port != nullptr) - { - delete ports[i].port; - ports[i].port = nullptr; - } - } - - delete[] ports; - ports = nullptr; - } - - count = 0; - } - - void initBuffers() - { - for (uint32_t i=0; i < count; ++i) - { - if (ports[i].port != nullptr) - ports[i].port->initBuffer(); - } - } + PluginCVData() noexcept; + ~PluginCVData(); + void createNew(const uint32_t newCount); + void clear(); + void initBuffers(); CARLA_DECLARE_NON_COPY_STRUCT(PluginCVData) }; @@ -264,39 +174,10 @@ struct PluginEventData { CarlaEngineEventPort* portIn; CarlaEngineEventPort* portOut; - PluginEventData() noexcept - : portIn(nullptr), - portOut(nullptr) {} - - ~PluginEventData() - { - CARLA_ASSERT(portIn == nullptr); - CARLA_ASSERT(portOut == nullptr); - } - - void clear() - { - if (portIn != nullptr) - { - delete portIn; - portIn = nullptr; - } - - if (portOut != nullptr) - { - delete portOut; - portOut = nullptr; - } - } - - void initBuffers() - { - if (portIn != nullptr) - portIn->initBuffer(); - - if (portOut != nullptr) - portOut->initBuffer(); - } + PluginEventData() noexcept; + ~PluginEventData(); + void clear(); + void initBuffers(); CARLA_DECLARE_NON_COPY_STRUCT(PluginEventData) }; @@ -317,67 +198,11 @@ struct PluginParameterData { ParameterRanges* ranges; SpecialParameterType* special; - PluginParameterData() noexcept - : count(0), - data(nullptr), - ranges(nullptr), - special(nullptr) {} - - ~PluginParameterData() - { - CARLA_ASSERT_INT(count == 0, count); - CARLA_ASSERT(data == nullptr); - CARLA_ASSERT(ranges == nullptr); - CARLA_ASSERT(special == nullptr); - } - - void createNew(const uint32_t newCount, const bool withSpecial) - { - CARLA_ASSERT_INT(count == 0, count); - CARLA_ASSERT(data == nullptr); - CARLA_ASSERT(ranges == nullptr); - CARLA_ASSERT(special == nullptr); - CARLA_ASSERT_INT(newCount > 0, newCount); - - if (data != nullptr || ranges != nullptr || newCount == 0) - return; - - data = new ParameterData[newCount]; - ranges = new ParameterRanges[newCount]; - count = newCount; - - if (withSpecial) - special = new SpecialParameterType[newCount]; - } - - void clear() - { - if (data != nullptr) - { - delete[] data; - data = nullptr; - } - - if (ranges != nullptr) - { - delete[] ranges; - ranges = nullptr; - } - - if (special != nullptr) - { - delete[] special; - special = nullptr; - } - - count = 0; - } - - float getFixedValue(const uint32_t parameterId, const float& value) const - { - CARLA_SAFE_ASSERT_RETURN(parameterId < count, 0.0f); - return ranges[parameterId].getFixedValue(value); - } + PluginParameterData() noexcept; + ~PluginParameterData(); + void createNew(const uint32_t newCount, const bool withSpecial); + void clear(); + float getFixedValue(const uint32_t parameterId, const float& value) const; CARLA_DECLARE_NON_COPY_STRUCT(PluginParameterData) }; @@ -391,55 +216,10 @@ struct PluginProgramData { int32_t current; ProgramName* names; - PluginProgramData() noexcept - : count(0), - current(-1), - names(nullptr) {} - - ~PluginProgramData() - { - CARLA_ASSERT_INT(count == 0, count); - CARLA_ASSERT_INT(current == -1, current); - CARLA_ASSERT(names == nullptr); - } - - void createNew(const uint32_t newCount) - { - CARLA_ASSERT_INT(count == 0, count); - CARLA_ASSERT_INT(current == -1, current); - CARLA_ASSERT(names == nullptr); - CARLA_ASSERT_INT(newCount > 0, newCount); - - if (names != nullptr || newCount == 0) - return; - - names = new ProgramName[newCount]; - count = newCount; - - for (uint32_t i=0; i < newCount; ++i) - names[i] = nullptr; - } - - void clear() - { - if (names != nullptr) - { - for (uint32_t i=0; i < count; ++i) - { - if (names[i] != nullptr) - { - delete[] names[i]; - names[i] = nullptr; - } - } - - delete[] names; - names = nullptr; - } - - count = 0; - current = -1; - } + PluginProgramData() noexcept; + ~PluginProgramData(); + void createNew(const uint32_t newCount); + void clear(); CARLA_DECLARE_NON_COPY_STRUCT(PluginProgramData) }; @@ -451,65 +231,11 @@ struct PluginMidiProgramData { int32_t current; MidiProgramData* data; - PluginMidiProgramData() noexcept - : count(0), - current(-1), - data(nullptr) {} - - ~PluginMidiProgramData() - { - CARLA_ASSERT_INT(count == 0, count); - CARLA_ASSERT_INT(current == -1, current); - CARLA_ASSERT(data == nullptr); - } - - void createNew(const uint32_t newCount) - { - CARLA_ASSERT_INT(count == 0, count); - CARLA_ASSERT_INT(current == -1, current); - CARLA_ASSERT(data == nullptr); - CARLA_ASSERT_INT(newCount > 0, newCount); - - if (data != nullptr || newCount == 0) - return; - - data = new MidiProgramData[newCount]; - count = newCount; - - for (uint32_t i=0; i < count; ++i) - { - data[i].bank = 0; - data[i].program = 0; - data[i].name = nullptr; - } - } - - void clear() - { - if (data != nullptr) - { - for (uint32_t i=0; i < count; ++i) - { - if (data[i].name != nullptr) - { - delete[] data[i].name; - data[i].name = nullptr; - } - } - - delete[] data; - data = nullptr; - } - - count = 0; - current = -1; - } - - const MidiProgramData& getCurrent() const - { - CARLA_ASSERT_INT2(current >= 0 && current < static_cast(count), current, count); - return data[current]; - } + PluginMidiProgramData() noexcept; + ~PluginMidiProgramData(); + void createNew(const uint32_t newCount); + void clear(); + const MidiProgramData& getCurrent() const noexcept; CARLA_DECLARE_NON_COPY_STRUCT(PluginMidiProgramData) }; @@ -565,23 +291,9 @@ struct CarlaPluginProtectedData { RtLinkedList::Pool dataPool; RtLinkedList data; - ExternalNotes() - : dataPool(32, 152), - data(dataPool) {} - - ~ExternalNotes() - { - mutex.lock(); - data.clear(); - mutex.unlock(); - } - - void append(const ExternalMidiNote& note) - { - mutex.lock(); - data.append_sleepy(note); - mutex.unlock(); - } + ExternalNotes(); + ~ExternalNotes(); + void append(const ExternalMidiNote& note); CARLA_DECLARE_NON_COPY_STRUCT(ExternalNotes) @@ -593,37 +305,11 @@ struct CarlaPluginProtectedData { RtLinkedList data; RtLinkedList dataPendingRT; - PostRtEvents() - : dataPool(128, 128), - data(dataPool), - dataPendingRT(dataPool) {} - - ~PostRtEvents() - { - clear(); - } - - void appendRT(const PluginPostRtEvent& event) - { - dataPendingRT.append(event); - } - - void trySplice() - { - if (mutex.tryLock()) - { - dataPendingRT.spliceAppend(data); - mutex.unlock(); - } - } - - void clear() - { - mutex.lock(); - data.clear(); - dataPendingRT.clear(); - mutex.unlock(); - } + PostRtEvents(); + ~PostRtEvents(); + void appendRT(const PluginPostRtEvent& event); + void trySplice(); + void clear(); CARLA_DECLARE_NON_COPY_STRUCT(PostRtEvents) @@ -637,12 +323,7 @@ struct CarlaPluginProtectedData { float balanceRight; float panning; - PostProc() noexcept - : dryWet(1.0f), - volume(1.0f), - balanceLeft(-1.0f), - balanceRight(1.0f), - panning(0.0f) {} + PostProc() noexcept; CARLA_DECLARE_NON_COPY_STRUCT(PostProc) @@ -653,8 +334,7 @@ struct CarlaPluginProtectedData { CarlaOscData data; CarlaPluginThread thread; - OSC(CarlaEngine* const engine, CarlaPlugin* const plugin) - : thread(engine, plugin) {} + OSC(CarlaEngine* const engine, CarlaPlugin* const plugin); #ifdef CARLA_PROPER_CPP11_SUPPORT OSC() = delete; @@ -662,126 +342,8 @@ struct CarlaPluginProtectedData { #endif } osc; - CarlaPluginProtectedData(CarlaEngine* const eng, const unsigned int idx, CarlaPlugin* const self) - : engine(eng), - client(nullptr), - id(idx), - hints(0x0), - options(0x0), - active(false), - enabled(false), - needsReset(false), - lib(nullptr), - uiLib(nullptr), - ctrlChannel(0), - extraHints(0x0), - patchbayClientId(0), - latency(0), - latencyBuffers(nullptr), - name(nullptr), - filename(nullptr), - iconName(nullptr), - identifier(nullptr), - osc(eng, self) {} - -#ifdef CARLA_PROPER_CPP11_SUPPORT - CarlaPluginProtectedData() = delete; - CARLA_DECLARE_NON_COPY_STRUCT(CarlaPluginProtectedData) -#endif - - ~CarlaPluginProtectedData() - { - CARLA_SAFE_ASSERT(! needsReset); - - if (name != nullptr) - { - delete[] name; - name = nullptr; - } - - if (filename != nullptr) - { - delete[] filename; - filename = nullptr; - } - - if (iconName != nullptr) - { - delete[] iconName; - iconName = nullptr; - } - - if (identifier != nullptr) - { - delete[] identifier; - identifier = nullptr; - } - - { - // mutex MUST have been locked before - const bool lockMaster(masterMutex.tryLock()); - const bool lockSingle(singleMutex.tryLock()); - CARLA_SAFE_ASSERT(! lockMaster); - CARLA_SAFE_ASSERT(! lockSingle); - } - - if (client != nullptr) - { - if (client->isActive()) - { - // must not happen - carla_safe_assert("client->isActive()", __FILE__, __LINE__); - client->deactivate(); - } - - clearBuffers(); - - delete client; - client = nullptr; - } - - for (LinkedList::Itenerator it = custom.begin(); it.valid(); it.next()) - { - CustomData& cData(it.getValue()); - - if (cData.type != nullptr) - { - delete[] cData.type; - cData.type = nullptr; - } - else - carla_safe_assert("cData.type != nullptr", __FILE__, __LINE__); - - if (cData.key != nullptr) - { - delete[] cData.key; - cData.key = nullptr; - } - else - carla_safe_assert("cData.key != nullptr", __FILE__, __LINE__); - - if (cData.value != nullptr) - { - delete[] cData.value; - cData.value = nullptr; - } - else - carla_safe_assert("cData.value != nullptr", __FILE__, __LINE__); - } - - prog.clear(); - midiprog.clear(); - custom.clear(); - - // MUST have been locked before - masterMutex.unlock(); - singleMutex.unlock(); - - if (lib != nullptr) - libClose(); - - CARLA_ASSERT(uiLib == nullptr); - } + CarlaPluginProtectedData(CarlaEngine* const eng, const unsigned int idx, CarlaPlugin* const self); + ~CarlaPluginProtectedData(); // ------------------------------------------------------------------- // Buffer functions @@ -811,8 +373,15 @@ struct CarlaPluginProtectedData { // ------------------------------------------------------------------- // Settings functions, see CarlaPlugin.cpp - void saveSetting(const unsigned int option, const bool yesNo); - unsigned int loadSettings(const unsigned int options, const unsigned int availOptions); + void saveSetting(const uint option, const bool yesNo); + uint loadSettings(const uint options, const uint availOptions); + + // ------------------------------------------------------------------- + +#ifdef CARLA_PROPER_CPP11_SUPPORT + CarlaPluginProtectedData() = delete; + CARLA_DECLARE_NON_COPY_STRUCT(CarlaPluginProtectedData) +#endif }; CARLA_BACKEND_END_NAMESPACE diff --git a/source/backend/plugin/CsoundPlugin.cpp b/source/backend/plugin/CsoundPlugin.cpp index ede9c7dc9..43f70e94c 100644 --- a/source/backend/plugin/CsoundPlugin.cpp +++ b/source/backend/plugin/CsoundPlugin.cpp @@ -16,6 +16,7 @@ */ #include "CarlaPluginInternal.hpp" +#include "CarlaEngine.hpp" //#define WANT_CSOUND 1 #ifdef WANT_CSOUND diff --git a/source/backend/plugin/DssiPlugin.cpp b/source/backend/plugin/DssiPlugin.cpp index 2f290ba36..39f0db9c0 100644 --- a/source/backend/plugin/DssiPlugin.cpp +++ b/source/backend/plugin/DssiPlugin.cpp @@ -16,6 +16,7 @@ */ #include "CarlaPluginInternal.hpp" +#include "CarlaEngine.hpp" #ifdef WANT_DSSI diff --git a/source/backend/plugin/FluidSynthPlugin.cpp b/source/backend/plugin/FluidSynthPlugin.cpp index 201cc5322..49b77b09e 100644 --- a/source/backend/plugin/FluidSynthPlugin.cpp +++ b/source/backend/plugin/FluidSynthPlugin.cpp @@ -16,6 +16,7 @@ */ #include "CarlaPluginInternal.hpp" +#include "CarlaEngine.hpp" #ifdef WANT_FLUIDSYNTH diff --git a/source/backend/plugin/JucePlugin.cpp b/source/backend/plugin/JucePlugin.cpp index 99412df9e..56353136f 100644 --- a/source/backend/plugin/JucePlugin.cpp +++ b/source/backend/plugin/JucePlugin.cpp @@ -16,6 +16,7 @@ */ #include "CarlaPluginInternal.hpp" +#include "CarlaEngine.hpp" #ifdef HAVE_JUCE diff --git a/source/backend/plugin/LadspaPlugin.cpp b/source/backend/plugin/LadspaPlugin.cpp index bb431681a..b870cf6f5 100644 --- a/source/backend/plugin/LadspaPlugin.cpp +++ b/source/backend/plugin/LadspaPlugin.cpp @@ -16,6 +16,7 @@ */ #include "CarlaPluginInternal.hpp" +#include "CarlaEngine.hpp" #ifdef WANT_LADSPA diff --git a/source/backend/plugin/LinuxSamplerPlugin.cpp b/source/backend/plugin/LinuxSamplerPlugin.cpp index e6856cb5e..975cd7df1 100644 --- a/source/backend/plugin/LinuxSamplerPlugin.cpp +++ b/source/backend/plugin/LinuxSamplerPlugin.cpp @@ -22,6 +22,7 @@ * - use CARLA_SAFE_ASSERT_RETURN with err */ #include "CarlaPluginInternal.hpp" +#include "CarlaEngine.hpp" #ifdef WANT_LINUXSAMPLER diff --git a/source/backend/plugin/Lv2Plugin.cpp b/source/backend/plugin/Lv2Plugin.cpp index 4165cf649..4f2ac5f96 100644 --- a/source/backend/plugin/Lv2Plugin.cpp +++ b/source/backend/plugin/Lv2Plugin.cpp @@ -16,6 +16,7 @@ */ #include "CarlaPluginInternal.hpp" +#include "CarlaEngine.hpp" #ifdef WANT_LV2 diff --git a/source/backend/plugin/NativePlugin.cpp b/source/backend/plugin/NativePlugin.cpp index 18eb7a409..5c3c2238f 100644 --- a/source/backend/plugin/NativePlugin.cpp +++ b/source/backend/plugin/NativePlugin.cpp @@ -16,6 +16,7 @@ */ #include "CarlaPluginInternal.hpp" +#include "CarlaEngine.hpp" #ifdef WANT_NATIVE diff --git a/source/backend/plugin/VstPlugin.cpp b/source/backend/plugin/VstPlugin.cpp index b3080f450..7a89d8177 100644 --- a/source/backend/plugin/VstPlugin.cpp +++ b/source/backend/plugin/VstPlugin.cpp @@ -16,6 +16,7 @@ */ #include "CarlaPluginInternal.hpp" +#include "CarlaEngine.hpp" #ifdef WANT_VST