From 04053f53fb237a832c6fb0e1c0edd3b71be385a7 Mon Sep 17 00:00:00 2001 From: Tobias Doerffel Date: Sun, 19 Oct 2008 16:20:38 +0000 Subject: [PATCH] improved VST GUI embedding (closes #2167745) git-svn-id: https://lmms.svn.sf.net/svnroot/lmms/trunk/lmms@1780 0778d3d1-df1d-0410-868b-ea421aaaa00d --- ChangeLog | 11 +++ plugins/vst_base/vst_plugin.cpp | 83 +++++++++++-------- plugins/vst_base/vst_plugin.h | 22 +++-- .../vst_effect/vst_effect_control_dialog.cpp | 4 +- 4 files changed, 75 insertions(+), 45 deletions(-) diff --git a/ChangeLog b/ChangeLog index 51a9f17d7..2ae1447f1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2008-10-19 Tobias Doerffel + + * plugins/vst_base/vst_plugin.h: + * plugins/vst_base/vst_plugin.cpp: + * plugins/vst_effect/vst_effect_control_dialog.cpp: + improved VST GUI embedding (closes #2167745) + + * src/gui/track_container_view.cpp: + do not call method on deleted trackView but fetch pointer to track + before deleting trackView (fixes crash when removing a track) + 2008-10-18 Tobias Doerffel * src/gui/widgets/track_label_button.cpp: diff --git a/plugins/vst_base/vst_plugin.cpp b/plugins/vst_base/vst_plugin.cpp index 7d700e551..a1f579306 100644 --- a/plugins/vst_base/vst_plugin.cpp +++ b/plugins/vst_base/vst_plugin.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #ifdef LMMS_BUILD_LINUX @@ -50,6 +51,30 @@ #include "templates.h" +class vstSubWin : public QMdiSubWindow +{ +public: + vstSubWin( QWidget * _parent ) : + QMdiSubWindow( _parent ) + { + setAttribute( Qt::WA_DeleteOnClose, false ); + } + + virtual ~vstSubWin() + { + } + + virtual void closeEvent( QCloseEvent * e ) + { + // ignore close-events - for some reason otherwise the VST GUI + // remains hidden when re-opening + hide(); + e->ignore(); + } +} ; + + + vstPlugin::vstPlugin( const QString & _plugin ) : QObject(), @@ -116,8 +141,9 @@ vstPlugin::vstPlugin( const QString & _plugin ) : if( m_pluginWindowID ) { target->setFixedSize( m_pluginGeometry ); - engine::getMainWindow()->workspace()->addSubWindow( helper ) - ->setAttribute( Qt::WA_DeleteOnClose, FALSE ); + vstSubWin * sw = new vstSubWin( + engine::getMainWindow()->workspace() ); + sw->setWidget( helper ); helper->setWindowTitle( name() ); m_pluginWidget = helper; } @@ -133,32 +159,25 @@ vstPlugin::vstPlugin( const QString & _plugin ) : vstPlugin::~vstPlugin() { - if( m_pluginWidget != NULL && - m_pluginWidget->parentWidget() != NULL && - dynamic_cast( - m_pluginWidget->parentWidget() ) != NULL ) - { - delete m_pluginWidget->parentWidget(); - } + delete pluginWidget(); } -QWidget * vstPlugin::showEditor( QWidget * _parent ) +void vstPlugin::showEditor( QWidget * _parent ) { - if( m_pluginWidget != NULL ) + QWidget * w = pluginWidget(); + if( w ) { - if( m_pluginWidget->parentWidget() ) - { - m_pluginWidget->parentWidget()->show(); - } - return( m_pluginWidget ); + w->show(); + return; } + #ifdef LMMS_BUILD_LINUX if( m_pluginWindowID == 0 ) { - return( NULL ); + return; } m_pluginWidget = new QWidget( _parent ); @@ -166,23 +185,18 @@ QWidget * vstPlugin::showEditor( QWidget * _parent ) m_pluginWidget->setWindowTitle( name() ); if( _parent == NULL ) { - engine::getMainWindow()->workspace()->addSubWindow( - m_pluginWidget ) - ->setAttribute( Qt::WA_DeleteOnClose, FALSE ); + vstSubWin * sw = new vstSubWin( + engine::getMainWindow()->workspace() ); + sw->setWidget( m_pluginWidget ); } QX11EmbedContainer * xe = new QX11EmbedContainer( m_pluginWidget ); xe->embedClient( m_pluginWindowID ); xe->setFixedSize( m_pluginGeometry ); - //xe->setAutoDelete( FALSE ); xe->show(); #endif m_pluginWidget->show(); - - showUI(); - - return( m_pluginWidget ); } @@ -190,12 +204,10 @@ QWidget * vstPlugin::showEditor( QWidget * _parent ) void vstPlugin::hideEditor( void ) { - if( m_pluginWidget ) - m_pluginWidget->hide(); - return; - if( m_pluginWidget != NULL && m_pluginWidget->parentWidget() ) + QWidget * w = pluginWidget(); + if( w ) { - m_pluginWidget->parentWidget()->hide(); + w->hide(); } } @@ -208,18 +220,19 @@ void vstPlugin::loadSettings( const QDomElement & _this ) { if( _this.attribute( "guivisible" ).toInt() ) { - pluginWidget()->show(); + showEditor(); } else { - pluginWidget()->hide(); + hideEditor(); } } - const Sint32 num_params = _this.attribute( "numparams" ).toInt(); + + const int num_params = _this.attribute( "numparams" ).toInt(); if( num_params > 0 ) { QMap dump; - for( Sint32 i = 0; i < num_params; ++i ) + for( int i = 0; i < num_params; ++i ) { const QString key = "param" + QString::number( i ); @@ -278,7 +291,7 @@ const QMap & vstPlugin::parameterDump( void ) waitForMessage( IdVstParameterDump ); unlock(); - return( m_parameterDump ); + return m_parameterDump; } diff --git a/plugins/vst_base/vst_plugin.h b/plugins/vst_base/vst_plugin.h index 33c12149f..bd8061b17 100644 --- a/plugins/vst_base/vst_plugin.h +++ b/plugins/vst_base/vst_plugin.h @@ -47,27 +47,27 @@ public: virtual bool processMessage( const message & _m ); - QWidget * showEditor( QWidget * _parent = NULL ); + void showEditor( QWidget * _parent = NULL ); void hideEditor( void ); inline const QString & name( void ) const { - return( m_name ); + return m_name; } inline Sint32 version( void ) const { - return( m_version ); + return m_version; } inline const QString & vendorString( void ) const { - return( m_vendorString ); + return m_vendorString; } inline const QString & productString( void ) const { - return( m_productString ); + return m_productString; } const QMap & parameterDump( void ); @@ -76,8 +76,14 @@ public: inline QWidget * pluginWidget( void ) { - return( m_pluginWidget != NULL ? - m_pluginWidget->parentWidget() : NULL ); + if( m_pluginWidget ) + { + if( m_pluginWidget->parentWidget() ) + { + return m_pluginWidget->parentWidget(); + } + } + return m_pluginWidget; } virtual void loadSettings( const QDomElement & _this ); @@ -85,7 +91,7 @@ public: inline virtual QString nodeName( void ) const { - return( "vstplugin" ); + return "vstplugin"; } diff --git a/plugins/vst_effect/vst_effect_control_dialog.cpp b/plugins/vst_effect/vst_effect_control_dialog.cpp index 2dde3cdaf..59037b595 100644 --- a/plugins/vst_effect/vst_effect_control_dialog.cpp +++ b/plugins/vst_effect/vst_effect_control_dialog.cpp @@ -35,10 +35,10 @@ vstEffectControlDialog::vstEffectControlDialog( vstEffectControls * _ctl ) : effectControlDialog( _ctl ) { QVBoxLayout * l = new QVBoxLayout( this ); - QWidget * w = _ctl->m_effect->m_plugin->showEditor( this ); + _ctl->m_effect->m_plugin->showEditor( this ); + QWidget * w = _ctl->m_effect->m_plugin->pluginWidget(); if( w ) { - w->show(); l->addWidget( w ); } }