From c0697099398e19ebe1bce619a0d06786aca5ae3a Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Fri, 2 Oct 2020 16:45:49 +0200 Subject: [PATCH] VST3: do not create persistent view to test has_editor() This is a better variant of 05d2a0f4a4816d. Mainly becuase some plugins crash when view->remove() is called for a view that was never attached. --- libs/ardour/ardour/vst3_plugin.h | 3 ++ libs/ardour/vst3_plugin.cc | 63 ++++++++++++++++++++++---------- 2 files changed, 46 insertions(+), 20 deletions(-) diff --git a/libs/ardour/ardour/vst3_plugin.h b/libs/ardour/ardour/vst3_plugin.h index 11431eb06d..70ebe85455 100644 --- a/libs/ardour/ardour/vst3_plugin.h +++ b/libs/ardour/ardour/vst3_plugin.h @@ -77,6 +77,7 @@ public: tresult PLUGIN_API resizeView (IPlugView* view, ViewRect* newSize) SMTG_OVERRIDE; /* GUI */ + bool has_editor () const; IPlugView* view (); void close_view (); PBD::Signal2 OnResizeView; @@ -152,6 +153,8 @@ private: void terminate (); + IPlugView* try_create_view () const; + bool connect_components (); bool disconnect_components (); diff --git a/libs/ardour/vst3_plugin.cc b/libs/ardour/vst3_plugin.cc index 32c37a8fea..39ce623c53 100644 --- a/libs/ardour/vst3_plugin.cc +++ b/libs/ardour/vst3_plugin.cc @@ -226,17 +226,7 @@ VST3Plugin::possible_output () const bool VST3Plugin::has_editor () const { - IPlugView* view = const_cast(_plug)->view (); - if (view){ -#ifdef PLATFORM_WINDOWS - return kResultOk == view->isPlatformTypeSupported ("HWND"); -#elif defined (__APPLE__) - return kResultOk == view->isPlatformTypeSupported ("NSView"); -#else - return kResultOk == view->isPlatformTypeSupported ("X11EmbedWindowID"); -#endif - } - return false; + return _plug->has_editor (); } Steinberg::IPlugView* @@ -1106,8 +1096,7 @@ VST3PI::unit_data () void VST3PI::terminate () { - close_view (); - + assert (!_view); /* disable all MIDI busses */ set_event_bus_state (false); @@ -2209,17 +2198,27 @@ VST3PI::save_state (RAMStream& stream) * GUI */ +IPlugView* +VST3PI::try_create_view () const +{ + IPlugView* view = _controller->createView (Vst::ViewType::kEditor); + if (!view) { + view = _controller->createView (0); + } + if (!view) { + view = FUnknownPtr (_controller); + if (view) { + view->addRef (); + } + } + return view; +} + IPlugView* VST3PI::view () { if (!_view) { - _view = _controller->createView (Vst::ViewType::kEditor); - if (!_view) { - _view = _controller->createView (0); - } - if (!_view) { - _view = FUnknownPtr (_controller); - } + _view = try_create_view (); if (_view) { _view->setFrame (this); } @@ -2239,6 +2238,30 @@ VST3PI::close_view () _view = 0; } +bool +VST3PI::has_editor () const +{ + IPlugView* view = _view; + if (!view){ + view = try_create_view (); + } + + bool rv = false; + if (view) { +#ifdef PLATFORM_WINDOWS + rv = kResultOk == view->isPlatformTypeSupported (kPlatformTypeHWND); +#elif defined (__APPLE__) + rv = kResultOk == view->isPlatformTypeSupported (kPlatformTypeNSView); +#else + rv = kResultOk == view->isPlatformTypeSupported (kPlatformTypeX11EmbedWindowID); +#endif + if (!_view) { + view->release (); + } + } + return rv; +} + #if SMTG_OS_LINUX void VST3PI::set_runloop (Linux::IRunLoop* run_loop)