diff --git a/source/backend/plugin/CarlaPluginInternal.cpp b/source/backend/plugin/CarlaPluginInternal.cpp index 83acd4dc7..be34a9b52 100644 --- a/source/backend/plugin/CarlaPluginInternal.cpp +++ b/source/backend/plugin/CarlaPluginInternal.cpp @@ -56,13 +56,9 @@ void PluginAudioData::createNew(const uint32_t newCount) CARLA_SAFE_ASSERT_RETURN(newCount > 0,); ports = new PluginAudioPort[newCount]; - count = newCount; + carla_zeroStruct(ports, newCount); - for (uint32_t i=0; i < count; ++i) - { - ports[i].rindex = 0; - ports[i].port = nullptr; - } + count = newCount; } void PluginAudioData::clear() noexcept @@ -114,14 +110,9 @@ void PluginCVData::createNew(const uint32_t newCount) CARLA_SAFE_ASSERT_RETURN(newCount > 0,); ports = new PluginCVPort[newCount]; - count = newCount; + carla_zeroStruct(ports, newCount); - for (uint32_t i=0; i < count; ++i) - { - ports[i].rindex = 0; - ports[i].param = 0; - ports[i].port = nullptr; - } + count = newCount; } void PluginCVData::clear() noexcept @@ -215,31 +206,26 @@ void PluginParameterData::createNew(const uint32_t newCount, const bool withSpec CARLA_SAFE_ASSERT_RETURN(special == nullptr,); CARLA_SAFE_ASSERT_RETURN(newCount > 0,); - data = new ParameterData[newCount]; - ranges = new ParameterRanges[newCount]; - count = newCount; - - if (withSpecial) - special = new SpecialParameterType[newCount]; + data = new ParameterData[newCount]; + carla_zeroStruct(data, newCount); for (uint32_t i=0; i < newCount; ++i) { - data[i].type = PARAMETER_UNKNOWN; - data[i].hints = 0x0; data[i].index = PARAMETER_NULL; data[i].rindex = PARAMETER_NULL; data[i].midiCC = -1; - data[i].midiChannel = 0; - ranges[i].def = 0.0f; - ranges[i].min = 0.0f; - ranges[i].max = 0.0f; - ranges[i].step = 0.0f; - ranges[i].stepSmall = 0.0f; - ranges[i].stepLarge = 0.0f; - - if (withSpecial) - special[i] = PARAMETER_SPECIAL_NULL; } + + ranges = new ParameterRanges[newCount]; + carla_zeroStruct(ranges, newCount); + + if (withSpecial) + { + special = new SpecialParameterType[newCount]; + carla_zeroStruct(special, newCount); + } + + count = newCount; } void PluginParameterData::clear() noexcept @@ -293,12 +279,11 @@ void PluginProgramData::createNew(const uint32_t newCount) CARLA_SAFE_ASSERT_RETURN(names == nullptr,); CARLA_SAFE_ASSERT_RETURN(newCount > 0,); - names = new ProgramName[newCount]; + names = new ProgramName[newCount]; + carla_zeroStruct(names, newCount); + count = newCount; current = -1; - - for (uint32_t i=0; i < newCount; ++i) - names[i] = nullptr; } void PluginProgramData::clear() noexcept @@ -318,7 +303,7 @@ void PluginProgramData::clear() noexcept names = nullptr; } - count = 0; + count = 0; current = -1; } @@ -344,16 +329,11 @@ void PluginMidiProgramData::createNew(const uint32_t newCount) CARLA_SAFE_ASSERT_RETURN(data == nullptr,); CARLA_SAFE_ASSERT_RETURN(newCount > 0,); - data = new MidiProgramData[newCount]; + data = new MidiProgramData[newCount]; + carla_zeroStruct(data, newCount); + count = newCount; current = -1; - - for (uint32_t i=0; i < count; ++i) - { - data[i].bank = 0; - data[i].program = 0; - data[i].name = nullptr; - } } void PluginMidiProgramData::clear() noexcept @@ -373,7 +353,7 @@ void PluginMidiProgramData::clear() noexcept data = nullptr; } - count = 0; + count = 0; current = -1; } @@ -392,9 +372,7 @@ CarlaPlugin::ProtectedData::ExternalNotes::ExternalNotes() noexcept CarlaPlugin::ProtectedData::ExternalNotes::~ExternalNotes() noexcept { - mutex.lock(); - data.clear(); - mutex.unlock(); + clear(); } void CarlaPlugin::ProtectedData::ExternalNotes::appendNonRT(const ExternalMidiNote& note) noexcept @@ -404,6 +382,13 @@ void CarlaPlugin::ProtectedData::ExternalNotes::appendNonRT(const ExternalMidiNo mutex.unlock(); } +void CarlaPlugin::ProtectedData::ExternalNotes::clear() noexcept +{ + mutex.lock(); + data.clear(); + mutex.unlock(); +} + // ----------------------------------------------------------------------- // ProtectedData::PostRtEvents diff --git a/source/backend/plugin/CarlaPluginInternal.hpp b/source/backend/plugin/CarlaPluginInternal.hpp index 1ef38c0b9..687d9df65 100644 --- a/source/backend/plugin/CarlaPluginInternal.hpp +++ b/source/backend/plugin/CarlaPluginInternal.hpp @@ -24,11 +24,10 @@ #include "CarlaOscUtils.hpp" #include "CarlaStateUtils.hpp" +#include "CarlaMIDI.h" #include "CarlaMutex.hpp" #include "RtLinkedList.hpp" -#include "CarlaMIDI.h" - // ----------------------------------------------------------------------- #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; } @@ -42,7 +41,7 @@ CARLA_BACKEND_START_NAMESPACE #endif // ----------------------------------------------------------------------- -// Forward declarations of CarlaEngine classes +// Forward declarations of CarlaEngine port classes class CarlaEngineAudioPort; class CarlaEngineCVPort; @@ -124,7 +123,7 @@ struct PluginAudioData { struct PluginCVPort { uint32_t rindex; - uint32_t param; + uint32_t param; // FIXME is this needed? CarlaEngineCVPort* port; }; @@ -158,11 +157,11 @@ struct PluginEventData { // ----------------------------------------------------------------------- enum SpecialParameterType { - PARAMETER_SPECIAL_NULL = 0, - PARAMETER_SPECIAL_LATENCY = 1, - PARAMETER_SPECIAL_SAMPLE_RATE = 2, - PARAMETER_SPECIAL_LV2_FREEWHEEL = 3, - PARAMETER_SPECIAL_LV2_TIME = 4 + PARAMETER_SPECIAL_NULL = 0, + PARAMETER_SPECIAL_FREEWHEEL = 1, + PARAMETER_SPECIAL_LATENCY = 2, + PARAMETER_SPECIAL_SAMPLE_RATE = 3, + PARAMETER_SPECIAL_TIME = 4 }; struct PluginParameterData { @@ -258,11 +257,11 @@ struct CarlaPlugin::ProtectedData { PluginMidiProgramData midiprog; LinkedList custom; - StateSave stateSave; - CarlaMutex masterMutex; // global master lock CarlaMutex singleMutex; // small lock used only in processSingle() + StateSave stateSave; + struct ExternalNotes { CarlaMutex mutex; RtLinkedList::Pool dataPool; @@ -271,6 +270,7 @@ struct CarlaPlugin::ProtectedData { ExternalNotes() noexcept; ~ExternalNotes() noexcept; void appendNonRT(const ExternalMidiNote& note) noexcept; + void clear() noexcept; CARLA_DECLARE_NON_COPY_STRUCT(ExternalNotes) diff --git a/source/backend/plugin/Lv2Plugin.cpp b/source/backend/plugin/Lv2Plugin.cpp index 932bef6b6..f3ab31f25 100644 --- a/source/backend/plugin/Lv2Plugin.cpp +++ b/source/backend/plugin/Lv2Plugin.cpp @@ -1979,11 +1979,11 @@ public: } else if (LV2_IS_PORT_DESIGNATION_FREEWHEELING(portDesignation)) { - pData->param.special[j] = PARAMETER_SPECIAL_LV2_FREEWHEEL; + pData->param.special[j] = PARAMETER_SPECIAL_FREEWHEEL; } else if (LV2_IS_PORT_DESIGNATION_TIME(portDesignation)) { - pData->param.special[j] = PARAMETER_SPECIAL_LV2_TIME; + pData->param.special[j] = PARAMETER_SPECIAL_TIME; } else { @@ -2031,7 +2031,7 @@ public: } else if (LV2_IS_PORT_DESIGNATION_TIME(portDesignation)) { - pData->param.special[j] = PARAMETER_SPECIAL_LV2_TIME; + pData->param.special[j] = PARAMETER_SPECIAL_TIME; } else { @@ -2073,7 +2073,7 @@ public: pData->param.ranges[j].stepLarge = stepLarge; // Start parameters in their default values (except freewheel, which is off by default) - if (pData->param.data[j].type == PARAMETER_INPUT && pData->param.special[j] == PARAMETER_SPECIAL_LV2_FREEWHEEL) + if (pData->param.data[j].type == PARAMETER_INPUT && pData->param.special[j] == PARAMETER_SPECIAL_FREEWHEEL) fParamBuffers[j] = min; else fParamBuffers[j] = def; @@ -2574,7 +2574,7 @@ public: { if (pData->param.data[k].type != PARAMETER_INPUT) continue; - if (pData->param.special[k] != PARAMETER_SPECIAL_LV2_TIME) + if (pData->param.special[k] != PARAMETER_SPECIAL_TIME) continue; doPostRt = false; @@ -3581,7 +3581,7 @@ public: { for (uint32_t k=0; k < pData->param.count; ++k) { - if (pData->param.data[k].type == PARAMETER_INPUT && pData->param.special[k] == PARAMETER_SPECIAL_LV2_FREEWHEEL) + if (pData->param.data[k].type == PARAMETER_INPUT && pData->param.special[k] == PARAMETER_SPECIAL_FREEWHEEL) { fParamBuffers[k] = isOffline ? pData->param.ranges[k].max : pData->param.ranges[k].min; pData->postponeRtEvent(kPluginPostRtEventParameterChange, static_cast(k), 1, fParamBuffers[k]);