From 4e4d49ff70d9b317c23f0997a10519aee9666ec0 Mon Sep 17 00:00:00 2001 From: falkTX Date: Sat, 2 Oct 2021 18:02:16 +0100 Subject: [PATCH] Cleanup Signed-off-by: falkTX --- distrho/DistrhoPlugin.hpp | 3 +++ distrho/src/DistrhoPluginVST3.cpp | 29 +++++++++++++---------------- distrho/src/DistrhoUIVST3.cpp | 14 +++++--------- 3 files changed, 21 insertions(+), 25 deletions(-) diff --git a/distrho/DistrhoPlugin.hpp b/distrho/DistrhoPlugin.hpp index 34bfc857..edbdd659 100644 --- a/distrho/DistrhoPlugin.hpp +++ b/distrho/DistrhoPlugin.hpp @@ -634,6 +634,9 @@ struct MidiEvent { /** MIDI data.@n If size > kDataSize, dataExt is used (otherwise null). + + When dataExt is used, the event holder is responsible for + keeping the pointer valid during the entirity of the run function. */ uint8_t data[kDataSize]; const uint8_t* dataExt; diff --git a/distrho/src/DistrhoPluginVST3.cpp b/distrho/src/DistrhoPluginVST3.cpp index 5e1dd439..5ee5fd26 100644 --- a/distrho/src/DistrhoPluginVST3.cpp +++ b/distrho/src/DistrhoPluginVST3.cpp @@ -57,7 +57,6 @@ namespace std { #include /* TODO items: - * - base component refcount handling * - parameter enumeration as lists * - hide parameter outputs? * - hide program parameter? @@ -3074,9 +3073,9 @@ struct dpf_audio_processor : v3_audio_processor_cpp { struct dpf_component; -std::vector*> gComponentGarbage; +std::vector gComponentGarbage; -static v3_result handleUncleanComponent(ScopedPointer* const componentptr) +static v3_result handleUncleanComponent(dpf_component** const componentptr) { gComponentGarbage.push_back(componentptr); return V3_INVALID_ARG; @@ -3087,7 +3086,6 @@ static v3_result handleUncleanComponent(ScopedPointer* const comp struct dpf_component : v3_component_cpp { std::atomic_int refcounter; - ScopedPointer* self; ScopedPointer processor; #if DISTRHO_PLUGIN_HAS_UI ScopedPointer connection; // kConnectionPointComponent @@ -3097,9 +3095,8 @@ struct dpf_component : v3_component_cpp { v3_host_application** const hostContextFromFactory; v3_host_application** hostContextFromInitialize; - dpf_component(ScopedPointer* const s, v3_host_application** const h) + dpf_component(v3_host_application** const h) : refcounter(1), - self(s), hostContextFromFactory(h), hostContextFromInitialize(nullptr) { @@ -3208,7 +3205,7 @@ struct dpf_component : v3_component_cpp { static V3_API uint32_t unref_component(void* self) { - ScopedPointer* const componentptr = (ScopedPointer*)self; + dpf_component** const componentptr = (dpf_component**)self; dpf_component* const component = *componentptr; if (const int refcount = --component->refcounter) @@ -3281,7 +3278,7 @@ struct dpf_component : v3_component_cpp { if (component->hostContextFromFactory != nullptr) v3_cpp_obj_unref(component->hostContextFromFactory); - *(component->self) = nullptr; + delete component; delete componentptr; return 0; } @@ -3517,13 +3514,13 @@ struct dpf_factory : v3_plugin_factory_cpp { d_stdout("DPF notice: cleaning up previously undeleted components now"); - for (std::vector*>::iterator it = gComponentGarbage.begin(); + for (std::vector::iterator it = gComponentGarbage.begin(); it != gComponentGarbage.end(); ++it) { - ScopedPointer* const componentptr = *it; + dpf_component** const componentptr = *it; dpf_component* const component = *componentptr; component->cleanup(); - *(component->self) = nullptr; + delete component; delete componentptr; } @@ -3595,8 +3592,8 @@ struct dpf_factory : v3_plugin_factory_cpp { static V3_API v3_result create_instance(void* self, const v3_tuid class_id, const v3_tuid iid, void** instance) { d_stdout("dpf_factory::create_instance => %p %s %s %p", self, tuid2str(class_id), tuid2str(iid), instance); - DISTRHO_SAFE_ASSERT_RETURN(v3_tuid_match(class_id, *(v3_tuid*)&dpf_tuid_class) && - v3_tuid_match(iid, v3_component_iid), V3_NO_INTERFACE); + DISTRHO_SAFE_ASSERT_RETURN(v3_tuid_match(class_id, *(const v3_tuid*)&dpf_tuid_class) && + v3_tuid_match(iid, v3_component_iid), V3_NO_INTERFACE); dpf_factory* const factory = *(dpf_factory**)self; DISTRHO_SAFE_ASSERT_RETURN(factory != nullptr, V3_NOT_INITIALIZED); @@ -3606,9 +3603,9 @@ struct dpf_factory : v3_plugin_factory_cpp { if (factory->hostContext != nullptr) v3_cpp_obj_query_interface(factory->hostContext, v3_host_application_iid, &host); - ScopedPointer* const componentptr = new ScopedPointer; - *componentptr = new dpf_component(componentptr, host); - *instance = componentptr; + dpf_component** const componentptr = new dpf_component*; + *componentptr = new dpf_component(host); + *instance = static_cast(componentptr); return V3_OK; } diff --git a/distrho/src/DistrhoUIVST3.cpp b/distrho/src/DistrhoUIVST3.cpp index c0207976..6862208e 100644 --- a/distrho/src/DistrhoUIVST3.cpp +++ b/distrho/src/DistrhoUIVST3.cpp @@ -810,7 +810,6 @@ static const char* const kSupportedPlatforms[] = { struct dpf_plugin_view : v3_plugin_view_cpp { std::atomic_int refcounter; - dpf_plugin_view** const self; ScopedPointer connection; ScopedPointer scale; #ifdef DPF_VST3_USING_HOST_RUN_LOOP @@ -823,9 +822,8 @@ struct dpf_plugin_view : v3_plugin_view_cpp { double sampleRate; v3_plugin_frame** frame; - dpf_plugin_view(dpf_plugin_view** const s, v3_host_application** const h, void* const instance, const double sr) + dpf_plugin_view(v3_host_application** const h, void* const instance, const double sr) : refcounter(1), - self(s), host(h), instancePointer(instance), sampleRate(sr), @@ -916,8 +914,6 @@ struct dpf_plugin_view : v3_plugin_view_cpp { d_stdout("dpf_plugin_view::unref => %p | refcount is zero, deleting everything now!", self); - DISTRHO_SAFE_ASSERT_RETURN(viewptr == view->self, V3_INTERNAL_ERR); - if (view->connection != nullptr && view->connection->other) v3_cpp_obj(view->connection->other)->disconnect(view->connection->other, (v3_connection_point**)&view->connection); @@ -984,7 +980,7 @@ struct dpf_plugin_view : v3_plugin_view_cpp { #endif const float scaleFactor = view->scale != nullptr ? view->scale->scaleFactor : 0.0f; - view->uivst3 = new UIVst3((v3_plugin_view**)view->self, + view->uivst3 = new UIVst3((v3_plugin_view**)self, view->host, (uintptr_t)parent, scaleFactor, @@ -1107,8 +1103,8 @@ struct dpf_plugin_view : v3_plugin_view_cpp { const float scaleFactor = view->scale != nullptr ? view->scale->scaleFactor : 0.0f; UIExporter tmpUI(nullptr, 0, view->sampleRate, - nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, - view->instancePointer, scaleFactor); + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, + view->instancePointer, scaleFactor); rect->right = tmpUI.getWidth(); rect->bottom = tmpUI.getHeight(); return V3_OK; @@ -1185,7 +1181,7 @@ v3_plugin_view** dpf_plugin_view_create(v3_host_application** const host, const double sampleRate) { dpf_plugin_view** const viewptr = new dpf_plugin_view*; - *viewptr = new dpf_plugin_view(viewptr, host, instancePointer, sampleRate); + *viewptr = new dpf_plugin_view(host, instancePointer, sampleRate); return (v3_plugin_view**)static_cast(viewptr); }