mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Smart Pointers: Add a new enum for indicating if a smart point should increment a reference count or not
This commit is contained in:
parent
8931d45fe9
commit
e68627c9ed
68 changed files with 243 additions and 160 deletions
|
|
@ -82,7 +82,7 @@ void VST3PluginFormatHeadless::findAllTypesForFile (OwnedArray<PluginDescription
|
|||
if (pluginFactory == nullptr)
|
||||
continue;
|
||||
|
||||
auto host = addVSTComSmartPtrOwner (new VST3HostContextHeadless());
|
||||
VSTComSmartPtr host { new VST3HostContextHeadless(), IncrementRef::yes };
|
||||
|
||||
for (const auto& d : DescriptionLister::findDescriptionsSlow (*host, *pluginFactory, File (file)))
|
||||
results.add (new PluginDescription (d));
|
||||
|
|
@ -111,7 +111,7 @@ void VST3PluginFormatHeadless::createPluginInstance (const PluginDescription& de
|
|||
PluginCreationCallback callback)
|
||||
{
|
||||
createVst3InstanceImpl<VST3PluginInstanceHeadless> (*this,
|
||||
becomeVSTComSmartPtrOwner (new VST3HostContextHeadless),
|
||||
{ new VST3HostContextHeadless(), IncrementRef::no },
|
||||
description,
|
||||
callback);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1096,7 +1096,7 @@ struct DLLHandle
|
|||
{
|
||||
if (factory == nullptr)
|
||||
if (auto* proc = (GetFactoryProc) getFunction (factoryFnName))
|
||||
factory = becomeVSTComSmartPtrOwner (proc());
|
||||
factory = VSTComSmartPtr (proc(), IncrementRef::no);
|
||||
|
||||
// The plugin NEEDS to provide a factory to be able to be called a VST3!
|
||||
// Most likely you are trying to load a 32-bit VST3 from a 64-bit host
|
||||
|
|
@ -1887,7 +1887,9 @@ class ParameterChanges final : public Vst::IParameterChanges
|
|||
|
||||
struct Entry
|
||||
{
|
||||
explicit Entry (std::unique_ptr<Queue> queue) : ptr (addVSTComSmartPtrOwner (queue.release())) {}
|
||||
explicit Entry (std::unique_ptr<Queue> queue)
|
||||
: ptr (queue.release(), IncrementRef::yes)
|
||||
{}
|
||||
|
||||
VSTComSmartPtr<Queue> ptr;
|
||||
Steinberg::int32 index = notInVector;
|
||||
|
|
@ -2632,7 +2634,7 @@ public:
|
|||
{
|
||||
if (trackInfoListener != nullptr)
|
||||
{
|
||||
auto l = addVSTComSmartPtrOwner (new TrackPropertiesAttributeList (properties));
|
||||
VSTComSmartPtr l { new TrackPropertiesAttributeList (properties), IncrementRef::yes };
|
||||
trackInfoListener->setChannelContextInfos (l.get());
|
||||
}
|
||||
}
|
||||
|
|
@ -2886,7 +2888,7 @@ public:
|
|||
|
||||
MemoryBlock getStateForPresetFile() const
|
||||
{
|
||||
auto memoryStream = becomeVSTComSmartPtrOwner (new MemoryStream());
|
||||
VSTComSmartPtr memoryStream { new MemoryStream(), IncrementRef::no };
|
||||
|
||||
if (memoryStream == nullptr || holder->component == nullptr)
|
||||
return {};
|
||||
|
|
@ -2905,7 +2907,8 @@ public:
|
|||
bool setStateFromPresetFile (const MemoryBlock& rawData) const
|
||||
{
|
||||
auto rawDataCopy = rawData;
|
||||
auto memoryStream = becomeVSTComSmartPtrOwner (new MemoryStream (rawDataCopy.getData(), (int) rawDataCopy.getSize()));
|
||||
VSTComSmartPtr memoryStream { new MemoryStream (rawDataCopy.getData(), (int) rawDataCopy.getSize()),
|
||||
IncrementRef::no };
|
||||
|
||||
if (memoryStream == nullptr || holder->component == nullptr)
|
||||
return false;
|
||||
|
|
@ -3042,7 +3045,7 @@ private:
|
|||
|
||||
if (mem.fromBase64Encoding (state->getAllSubText()))
|
||||
{
|
||||
auto stream = becomeVSTComSmartPtrOwner (new MemoryStream());
|
||||
VSTComSmartPtr stream { new MemoryStream(), IncrementRef::no };
|
||||
stream->setSize ((TSize) mem.getSize());
|
||||
mem.copyTo (stream->getData(), 0, mem.getSize());
|
||||
return stream;
|
||||
|
|
@ -3053,10 +3056,20 @@ private:
|
|||
}
|
||||
|
||||
CachedParamValues cachedParamValues;
|
||||
VSTComSmartPtr<ParameterChanges<HostToClientParamQueue>> inputParameterChanges = addVSTComSmartPtrOwner (new ParameterChanges<HostToClientParamQueue>);
|
||||
VSTComSmartPtr<ParameterChanges<ClientToHostParamQueue>> outputParameterChanges = addVSTComSmartPtrOwner (new ParameterChanges<ClientToHostParamQueue>);
|
||||
VSTComSmartPtr<MidiEventList> midiInputs = addVSTComSmartPtrOwner (new MidiEventList);
|
||||
VSTComSmartPtr<MidiEventList> midiOutputs = addVSTComSmartPtrOwner (new MidiEventList);
|
||||
VSTComSmartPtr<ParameterChanges<HostToClientParamQueue>> inputParameterChanges
|
||||
{
|
||||
new ParameterChanges<HostToClientParamQueue>,
|
||||
IncrementRef::yes
|
||||
};
|
||||
|
||||
VSTComSmartPtr<ParameterChanges<ClientToHostParamQueue>> outputParameterChanges
|
||||
{
|
||||
new ParameterChanges<ClientToHostParamQueue>,
|
||||
IncrementRef::yes
|
||||
};
|
||||
|
||||
VSTComSmartPtr<MidiEventList> midiInputs { new MidiEventList, IncrementRef::yes };
|
||||
VSTComSmartPtr<MidiEventList> midiOutputs { new MidiEventList, IncrementRef::yes };
|
||||
Vst::ProcessContext timingInfo; //< Only use this in processBlock()!
|
||||
bool isControllerInitialised = false, isActive = false, lastProcessBlockCallWasBypass = false;
|
||||
const bool hasMidiInput = getNumSingleDirectionBusesFor (holder->component.get(), MediaKind::event, Direction::input) > 0,
|
||||
|
|
|
|||
|
|
@ -173,8 +173,15 @@ public:
|
|||
source->release();
|
||||
}
|
||||
|
||||
VSTComSmartPtr (ObjectType* object, IncrementRef incrementRefCount) noexcept
|
||||
: source (object)
|
||||
{
|
||||
if (source != nullptr && incrementRefCount == IncrementRef::yes)
|
||||
source->addRef();
|
||||
}
|
||||
|
||||
VSTComSmartPtr (const VSTComSmartPtr& other) noexcept
|
||||
: VSTComSmartPtr (other.get(), true) {}
|
||||
: VSTComSmartPtr (other.get(), IncrementRef::yes) {}
|
||||
|
||||
template <typename Other, std::enable_if_t<! std::is_same_v<Other, ObjectType>, int> = 0>
|
||||
VSTComSmartPtr (const VSTComSmartPtr<Other>& other) noexcept
|
||||
|
|
@ -219,43 +226,10 @@ public:
|
|||
return factory->createInstance (uuid, ObjectType::iid, (void**) &source) == Steinberg::kResultOk;
|
||||
}
|
||||
|
||||
/** Increments refcount. */
|
||||
static auto addOwner (ObjectType* t)
|
||||
{
|
||||
return VSTComSmartPtr (t, true);
|
||||
}
|
||||
|
||||
/** Does not initially increment refcount; assumes t has a positive refcount. */
|
||||
static auto becomeOwner (ObjectType* t)
|
||||
{
|
||||
return VSTComSmartPtr (t, false);
|
||||
}
|
||||
|
||||
private:
|
||||
VSTComSmartPtr (ObjectType* object, bool autoAddRef) noexcept
|
||||
: source (object)
|
||||
{
|
||||
if (source != nullptr && autoAddRef)
|
||||
source->addRef();
|
||||
}
|
||||
|
||||
ObjectType* source = nullptr;
|
||||
};
|
||||
|
||||
/** Increments refcount. */
|
||||
template <class ObjectType>
|
||||
auto addVSTComSmartPtrOwner (ObjectType* t)
|
||||
{
|
||||
return VSTComSmartPtr<ObjectType>::addOwner (t);
|
||||
}
|
||||
|
||||
/** Does not initially increment refcount; assumes t has a positive refcount. */
|
||||
template <class ObjectType>
|
||||
auto becomeVSTComSmartPtrOwner (ObjectType* t)
|
||||
{
|
||||
return VSTComSmartPtr<ObjectType>::becomeOwner (t);
|
||||
}
|
||||
|
||||
// NOLINTEND(clang-analyzer-cplusplus.NewDelete)
|
||||
|
||||
JUCE_END_NO_SANITIZE
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue