From c2e9918c8ab402c04b29c54ae72ad2f88e48e635 Mon Sep 17 00:00:00 2001 From: Mike Choi Date: Thu, 3 Jan 2013 19:28:47 +0100 Subject: [PATCH] VST Automation: crash prevention Fixed destuctors for various types of VST automation panel removal. Automated signals correct disconection on panel removal. When you load new VST plugin in the place of old one, while automation is already connected and active there, this should not result in LMMS crash or reuse of that old automation connections and automation window destructor should not leave zombie VST plugins on application exit. Signed-off-by: Tobias Doerffel --- plugins/vestige/vestige.cpp | 102 +++++++++++++++++++---- plugins/vestige/vestige.h | 1 + plugins/vst_effect/VstEffectControls.cpp | 78 +++++++++++++---- plugins/vst_effect/VstEffectControls.h | 1 + 4 files changed, 151 insertions(+), 31 deletions(-) diff --git a/plugins/vestige/vestige.cpp b/plugins/vestige/vestige.cpp index 46630d740..514d93f1e 100644 --- a/plugins/vestige/vestige.cpp +++ b/plugins/vestige/vestige.cpp @@ -117,13 +117,14 @@ void vestigeInstrument::loadSettings( const QDomElement & _this ) m_plugin->loadSettings( _this ); const QMap & dump = m_plugin->parameterDump(); - int paramCount = (dump).size(); + paramCount = dump.size(); char paramStr[35]; - vstKnobs = new knob *[paramCount]; - knobFModel = new FloatModel *[paramCount]; + vstKnobs = new knob *[ paramCount ]; + knobFModel = new FloatModel *[ paramCount ]; QStringList list1; QWidget * widget = new QWidget(); - for (int i = 0; i < paramCount; i++) { + for( int i = 0; i < paramCount; i++ ) + { sprintf( paramStr, "param%d", i); list1 = dump[paramStr].split(":"); @@ -167,9 +168,10 @@ void vestigeInstrument::saveSettings( QDomDocument & _doc, QDomElement & _this ) m_plugin->saveSettings( _doc, _this ); if (knobFModel != NULL) { const QMap & dump = m_plugin->parameterDump(); - int paramCount = (dump).size(); + paramCount = dump.size(); char paramStr[35]; - for (int i = 0; i < paramCount; i++) { + for( int i = 0; i < paramCount; i++ ) + { if (knobFModel[i]->isAutomated() || knobFModel[i]->getControllerConnection()) { sprintf( paramStr, "param%d", i); knobFModel[i]->saveSettings( _doc, _this, paramStr ); @@ -223,7 +225,10 @@ void vestigeInstrument::loadFile( const QString & _file ) InstrumentTrack::tr( "Default preset" ); m_pluginMutex.unlock(); - closePlugin(); + if ( m_plugin != NULL ) + { + closePlugin(); + } m_pluginDLL = _file; textFloat * tf = textFloat::displayMessage( @@ -308,6 +313,51 @@ bool vestigeInstrument::handleMidiEvent( const midiEvent & _me, void vestigeInstrument::closePlugin( void ) { + // disconnect all signals + if( knobFModel != NULL ) + { + for( int i = 0; i < paramCount; i++ ) + { + delete knobFModel[ i ]; + delete vstKnobs[ i ]; + } + } + + if( vstKnobs != NULL ) + { + delete [] vstKnobs; + vstKnobs = NULL; + } + + if( knobFModel != NULL ) + { + delete [] knobFModel; + knobFModel = NULL; + } + + if( m_scrollArea != NULL ) + { +// delete m_scrollArea; + m_scrollArea = NULL; + } + + if( m_subWindow != NULL ) + { + m_subWindow->setAttribute( Qt::WA_DeleteOnClose ); + m_subWindow->close(); + + if( m_subWindow != NULL ) + { + delete m_subWindow; + } + m_subWindow = NULL; + } + + if( p_subWindow != NULL ) + { + p_subWindow = NULL; + } + m_pluginMutex.lock(); if( m_plugin ) { @@ -832,23 +882,24 @@ manageVestigeInstrumentView::manageVestigeInstrumentView( Instrument * _instrume l->addWidget( m_syncButton, 0, 0, 1, 2, Qt::AlignLeft ); const QMap & dump = m_vi->m_plugin->parameterDump(); - int paramCount = (dump).size(); + m_vi->paramCount = dump.size(); bool isVstKnobs = true; if (m_vi->vstKnobs == NULL) { - m_vi->vstKnobs = new knob *[paramCount]; + m_vi->vstKnobs = new knob *[ m_vi->paramCount ]; isVstKnobs = false; } if (m_vi->knobFModel == NULL) { - m_vi->knobFModel = new FloatModel *[paramCount]; + m_vi->knobFModel = new FloatModel *[ m_vi->paramCount ]; } char paramStr[35]; QStringList list1; if (isVstKnobs == false) { - for (int i = 0; i < paramCount; i++) { + for( int i = 0; i < m_vi->paramCount; i++ ) + { sprintf( paramStr, "param%d", i); list1 = dump[paramStr].split(":"); @@ -865,15 +916,19 @@ manageVestigeInstrumentView::manageVestigeInstrumentView( Instrument * _instrume } int i = 0; - for (int lrow = 0+1; lrow < (int(paramCount / 10) + 1)+1; lrow++) { - for (int lcolumn = 0; lcolumn < 10; lcolumn++) { - if (i < paramCount) + for( int lrow = 1; lrow < ( int( m_vi->paramCount / 10 ) + 1 ) + 1; lrow++ ) + { + for( int lcolumn = 0; lcolumn < 10; lcolumn++ ) + { + if( i < m_vi->paramCount ) + { l->addWidget( m_vi->vstKnobs[i], lrow, lcolumn, Qt::AlignCenter ); + } i++; } } - l->setRowStretch( (int(paramCount / 10) + 1), 1 ); + l->setRowStretch( ( int( m_vi->paramCount / 10) + 1), 1 ); l->setColumnStretch( 10, 1 ); widget->setLayout(l); @@ -911,10 +966,25 @@ void manageVestigeInstrumentView::syncPlugin( void ) manageVestigeInstrumentView::~manageVestigeInstrumentView() { + if( m_vi->knobFModel != NULL ) + { + for( int i = 0; i < m_vi->paramCount; i++ ) + { + delete m_vi->knobFModel[ i ]; + delete m_vi->vstKnobs[ i ]; + } + } + if (m_vi->vstKnobs != NULL) { delete []m_vi->vstKnobs; m_vi->vstKnobs = NULL; } + + if( m_vi->knobFModel != NULL ) + { + delete [] m_vi->knobFModel; + m_vi->knobFModel = NULL; + } if (m_vi->m_scrollArea != NULL) { delete m_vi->m_scrollArea; @@ -929,6 +999,8 @@ manageVestigeInstrumentView::~manageVestigeInstrumentView() delete m_vi->m_subWindow; m_vi->m_subWindow = NULL; } + + m_vi->p_subWindow = NULL; } diff --git a/plugins/vestige/vestige.h b/plugins/vestige/vestige.h index 632b6dee6..0320fe4b6 100644 --- a/plugins/vestige/vestige.h +++ b/plugins/vestige/vestige.h @@ -92,6 +92,7 @@ private: knob ** vstKnobs; FloatModel ** knobFModel; QObject * p_subWindow; + int paramCount; friend class VestigeInstrumentView; diff --git a/plugins/vst_effect/VstEffectControls.cpp b/plugins/vst_effect/VstEffectControls.cpp index 866c8c4ed..abd22c5ee 100644 --- a/plugins/vst_effect/VstEffectControls.cpp +++ b/plugins/vst_effect/VstEffectControls.cpp @@ -69,13 +69,14 @@ void VstEffectControls::loadSettings( const QDomElement & _this ) m_effect->m_plugin->loadSettings( _this ); const QMap & dump = m_effect->m_plugin->parameterDump(); - int paramCount = (dump).size(); + paramCount = dump.size(); char paramStr[35]; - vstKnobs = new knob *[paramCount]; - knobFModel = new FloatModel *[paramCount]; + vstKnobs = new knob *[ paramCount ]; + knobFModel = new FloatModel *[ paramCount ]; QStringList list1; QWidget * widget = new QWidget(); - for (int i = 0; i < paramCount; i++) { + for( int i = 0; i < paramCount; i++ ) + { sprintf( paramStr, "param%d", i); list1 = dump[paramStr].split(":"); @@ -120,13 +121,15 @@ void VstEffectControls::saveSettings( QDomDocument & _doc, QDomElement & _this ) m_effect->m_plugin->saveSettings( _doc, _this ); if (knobFModel != NULL) { const QMap & dump = m_effect->m_plugin->parameterDump(); - int paramCount = (dump).size(); + paramCount = dump.size(); char paramStr[35]; - for (int i = 0; i < paramCount; i++) + for( int i = 0; i < paramCount; i++ ) + { if (knobFModel[i]->isAutomated() || knobFModel[i]->getControllerConnection()) { sprintf( paramStr, "param%d", i); knobFModel[i]->saveSettings( _doc, _this, paramStr ); } + } } } m_effect->m_pluginMutex.unlock(); @@ -321,17 +324,17 @@ manageVSTEffectView::manageVSTEffectView( VstEffect * _eff, VstEffectControls * l->addWidget( m_syncButton, 0, 0, 1, 2, Qt::AlignLeft ); const QMap & dump = m_effect->m_plugin->parameterDump(); - int paramCount = (dump).size(); + m_vi->paramCount = dump.size(); bool isVstKnobs = true, isKnobFModel = true; if (m_vi->vstKnobs == NULL) { - m_vi->vstKnobs = new knob *[paramCount]; + m_vi->vstKnobs = new knob *[ m_vi->paramCount ]; isVstKnobs = false; } if (m_vi->knobFModel == NULL) { - m_vi->knobFModel = new FloatModel *[paramCount]; + m_vi->knobFModel = new FloatModel *[ m_vi->paramCount ]; isKnobFModel = false; } @@ -339,7 +342,8 @@ manageVSTEffectView::manageVSTEffectView( VstEffect * _eff, VstEffectControls * QStringList list1; if (isVstKnobs == false) { - for (int i = 0; i < paramCount; i++) { + for( int i = 0; i < m_vi->paramCount; i++ ) + { sprintf( paramStr, "param%d", i); list1 = dump[paramStr].split(":"); @@ -356,15 +360,19 @@ manageVSTEffectView::manageVSTEffectView( VstEffect * _eff, VstEffectControls * } int i = 0; - for (int lrow = 0+1; lrow < (int(paramCount / 10) + 1)+1; lrow++) { - for (int lcolumn = 0; lcolumn < 10; lcolumn++) { - if (i < paramCount) + for( int lrow = 1; lrow < ( int( m_vi->paramCount / 10 ) + 1 ) + 1; lrow++ ) + { + for( int lcolumn = 0; lcolumn < 10; lcolumn++ ) + { + if( i < m_vi->paramCount ) + { l->addWidget( m_vi->vstKnobs[i], lrow, lcolumn, Qt::AlignCenter ); + } i++; } } - l->setRowStretch( (int(paramCount / 10) + 1), 1 ); + l->setRowStretch( ( int( m_vi->paramCount / 10 ) + 1 ), 1 ); l->setColumnStretch( 10, 1 ); widget->setLayout(l); @@ -418,8 +426,46 @@ void manageVSTEffectView::setParameter( void ) manageVSTEffectView::~manageVSTEffectView() { - delete m_vi2->m_subWindow; - m_vi2->m_subWindow = NULL; + if( m_vi2->knobFModel != NULL ) + { + for( int i = 0; i < m_vi2->paramCount; i++ ) + { + delete m_vi2->knobFModel[ i ]; + delete m_vi2->vstKnobs[ i ]; + } + } + + if( m_vi2->vstKnobs != NULL ) + { + delete [] m_vi2->vstKnobs; + m_vi2->vstKnobs = NULL; + } + + if( m_vi2->knobFModel != NULL ) + { + delete [] m_vi2->knobFModel; + m_vi2->knobFModel = NULL; + } + + if( m_vi2->m_scrollArea != NULL ) + { + delete m_vi2->m_scrollArea; + m_vi2->m_scrollArea = NULL; + } + + if( m_vi2->m_subWindow != NULL ) + { + m_vi2->m_subWindow->setAttribute( Qt::WA_DeleteOnClose ); + m_vi2->m_subWindow->close(); + + if( m_vi2->m_subWindow != NULL ) + { + delete m_vi2->m_subWindow; + } + m_vi2->m_subWindow = NULL; + } + //delete m_vi2->m_subWindow; + //m_vi2->m_subWindow = NULL; } diff --git a/plugins/vst_effect/VstEffectControls.h b/plugins/vst_effect/VstEffectControls.h index a56c54fcc..1c92cfefe 100644 --- a/plugins/vst_effect/VstEffectControls.h +++ b/plugins/vst_effect/VstEffectControls.h @@ -88,6 +88,7 @@ private: QScrollArea * m_scrollArea; FloatModel ** knobFModel; knob ** vstKnobs; + int paramCount; QObject * ctrHandle;