VST3: do not create persistent view to test has_editor()

This is a better variant of 05d2a0f4a4. Mainly becuase
some plugins crash when view->remove() is called for a
view that was never attached.
This commit is contained in:
Robin Gareus 2020-10-02 16:45:49 +02:00
parent 05d2a0f4a4
commit c069709939
No known key found for this signature in database
GPG key ID: A090BCE02CF57F04
2 changed files with 46 additions and 20 deletions

View file

@ -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<void, int, int> OnResizeView;
@ -152,6 +153,8 @@ private:
void terminate ();
IPlugView* try_create_view () const;
bool connect_components ();
bool disconnect_components ();

View file

@ -226,17 +226,7 @@ VST3Plugin::possible_output () const
bool
VST3Plugin::has_editor () const
{
IPlugView* view = const_cast<VST3PI*>(_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<IPlugView> (_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<IPlugView> (_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)