From 5e54425a359059e54aa5cdcaf39ea1988f6c6edc Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Thu, 3 Jun 2021 16:43:20 +0200 Subject: [PATCH] VST2: Consolidate support methods (close, unload) --- libs/ardour/linux_vst_support.cc | 32 ++++++++++------------------ libs/ardour/mac_vst_support.cc | 36 +++++++++++--------------------- 2 files changed, 23 insertions(+), 45 deletions(-) diff --git a/libs/ardour/linux_vst_support.cc b/libs/ardour/linux_vst_support.cc index cace4bd1e2..8903c7c965 100644 --- a/libs/ardour/linux_vst_support.cc +++ b/libs/ardour/linux_vst_support.cc @@ -267,6 +267,7 @@ vstfx_unload (VSTHandle* fhandle) if (fhandle->name) { free (fhandle->name); + fhandle->name = 0; } /*Don't need the plugin handle any more*/ @@ -339,30 +340,19 @@ void vstfx_close (VSTState* vstfx) vstfx->plugin->dispatcher (vstfx->plugin, effClose, 0, 0, 0, 0); } - if (vstfx->handle->plugincnt) + if (vstfx->handle->plugincnt) { vstfx->handle->plugincnt--; - - /*vstfx_unload will unload the dll if the instance count allows - - we need to do this because some plugins keep their own instance count - and (JUCE) manages the plugin UI in its own thread. When the plugins - internal instance count reaches zero, JUCE stops the UI thread and won't - restart it until the next time the library is loaded. If we don't unload - the lib JUCE will never restart*/ - - - if (vstfx->handle->plugincnt) - { - return; } - /*Valid plugin loaded - so we can unload it and 0 the pointer - to it. We can't free the handle here because we don't know what else - might need it. It should be / is freed when the plugin is deleted*/ + /* vstfx_unload will unload the dll if the instance count allows - + * we need to do this because some plugins keep their own instance count + * and (JUCE) manages the plugin UI in its own thread. When the plugins + * internal instance count reaches zero, JUCE stops the UI thread and won't + * restart it until the next time the library is loaded. If we don't unload + * the lib JUCE will never restart + */ + + vstfx_unload (vstfx->handle); - if (vstfx->handle->dll) - { - dlclose(vstfx->handle->dll); //dlclose keeps its own reference count - vstfx->handle->dll = 0; - } free(vstfx); } diff --git a/libs/ardour/mac_vst_support.cc b/libs/ardour/mac_vst_support.cc index e9a7f48951..45d23248e0 100644 --- a/libs/ardour/mac_vst_support.cc +++ b/libs/ardour/mac_vst_support.cc @@ -144,9 +144,7 @@ mac_vst_unload (VSTHandle* fhandle) { if (fhandle->plugincnt) { - /*Still have plugin instances - can't unload the library - - actually dlclose keeps an instance count anyway*/ - + /*Still have plugin instances - can't unload the library */ return -1; } @@ -163,6 +161,7 @@ mac_vst_unload (VSTHandle* fhandle) if (fhandle->name) { free (fhandle->name); + fhandle->name = 0; } /*Don't need the plugin handle any more*/ @@ -238,31 +237,20 @@ void mac_vst_close (VSTState* mac_vst) mac_vst->plugin->dispatcher (mac_vst->plugin, effClose, 0, 0, 0, 0); } - if (mac_vst->handle->plugincnt) + if (mac_vst->handle->plugincnt) { mac_vst->handle->plugincnt--; - - /*mac_vst_unload will unload the dll if the instance count allows - - we need to do this because some plugins keep their own instance count - and (JUCE) manages the plugin UI in its own thread. When the plugins - internal instance count reaches zero, JUCE stops the UI thread and won't - restart it until the next time the library is loaded. If we don't unload - the lib JUCE will never restart*/ - - - if (mac_vst->handle->plugincnt) - { - return; } - /*Valid plugin loaded - so we can unload it and 0 the pointer - to it. We can't free the handle here because we don't know what else - might need it. It should be / is freed when the plugin is deleted*/ + /* mac_vst_unload will unload the dll if the instance count allows - + * we need to do this because some plugins keep their own instance count + * and (JUCE) manages the plugin UI in its own thread. When the plugins + * internal instance count reaches zero, JUCE stops the UI thread and won't + * restart it until the next time the library is loaded. If we don't unload + * the lib JUCE will never restart + */ + + mac_vst_unload (mac_vst->handle); - if (mac_vst->handle->dll) - { - dlclose (mac_vst->handle->dll); //dlclose keeps its own reference count - mac_vst->handle->dll = 0; - } free (mac_vst); }