Skip to content

Commit

Permalink
Vst: Fix widget deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
lukas-w committed Nov 10, 2017
1 parent 6fd38fe commit a8311a7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 28 deletions.
29 changes: 5 additions & 24 deletions plugins/VstEffect/VstEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ Plugin::Descriptor PLUGIN_EXPORT vsteffect_plugin_descriptor =
VstEffect::VstEffect( Model * _parent,
const Descriptor::SubPluginFeatures::Key * _key ) :
Effect( &vsteffect_plugin_descriptor, _parent, _key ),
m_plugin( NULL ),
m_pluginMutex(),
m_key( *_key ),
m_vstControls( this )
Expand All @@ -73,7 +72,6 @@ VstEffect::VstEffect( Model * _parent,

VstEffect::~VstEffect()
{
closePlugin();
}


Expand Down Expand Up @@ -128,44 +126,27 @@ void VstEffect::openPlugin( const QString & _plugin )
VstPlugin::tr( "Loading plugin" ),
VstPlugin::tr( "Please wait while loading VST plugin..." ),
PLUGIN_NAME::getIconPixmap( "logo", 24, 24 ), 0 );
m_pluginMutex.lock();
m_plugin = new VstPlugin( _plugin );

QMutexLocker ml( &m_pluginMutex ); Q_UNUSED( ml );
m_plugin.reset(new VstPlugin( _plugin ));
if( m_plugin->failed() )
{
m_pluginMutex.unlock();
closePlugin();
m_plugin.reset(nullptr);
delete tf;
collectErrorForUI( VstPlugin::tr( "The VST plugin %1 could not be loaded." ).arg( _plugin ) );
return;
}

VstPlugin::connect( Engine::getSong(), SIGNAL( tempoChanged( bpm_t ) ), m_plugin, SLOT( setTempo( bpm_t ) ) );
VstPlugin::connect( Engine::getSong(), SIGNAL( tempoChanged( bpm_t ) ), m_plugin.data(), SLOT( setTempo( bpm_t ) ) );
m_plugin->setTempo( Engine::getSong()->getTempo() );

m_pluginMutex.unlock();

delete tf;

m_key.attributes["file"] = _plugin;
}



void VstEffect::closePlugin()
{
m_pluginMutex.lock();
if( m_plugin && m_plugin->pluginWidget() != NULL )
{
delete m_plugin->pluginWidget();
}
delete m_plugin;
m_plugin = NULL;
m_pluginMutex.unlock();
}





extern "C"
{
Expand Down
7 changes: 4 additions & 3 deletions plugins/VstEffect/VstEffect.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@
#ifndef _VST_EFFECT_H
#define _VST_EFFECT_H

#include <QMutex>
#include <QtCore/QMutex>
#include <QtCore/QSharedPointer>

#include "Effect.h"
#include "VstPlugin.h"
#include "VstEffectControlDialog.h"
#include "VstEffectControls.h"

class VstPlugin;

class VstEffect : public Effect
{
Expand All @@ -58,7 +59,7 @@ class VstEffect : public Effect
void openPlugin( const QString & _plugin );
void closePlugin();

VstPlugin * m_plugin;
QSharedPointer<VstPlugin> m_plugin;
QMutex m_pluginMutex;
EffectKey m_key;

Expand Down
3 changes: 2 additions & 1 deletion plugins/VstEffect/VstEffectControlDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <QObject>
#include <QPainter>
#include <QLabel>
#include <QSharedPointer>


class VstEffectControls;
Expand Down Expand Up @@ -59,7 +60,7 @@ class VstEffectControlDialog : public EffectControlDialog
PixmapButton * m_managePluginButton;
PixmapButton * m_savePresetButton;

VstPlugin * m_plugin;
QSharedPointer<VstPlugin> m_plugin;

QLabel * tbLabel;

Expand Down
2 changes: 2 additions & 0 deletions plugins/vst_base/VstPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ VstPlugin::VstPlugin( const QString & _plugin ) :

VstPlugin::~VstPlugin()
{
delete m_pluginSubWindow;
delete m_pluginWidget;
}


Expand Down

0 comments on commit a8311a7

Please sign in to comment.