Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix VST effect bugs #4294

Merged
merged 11 commits into from
May 30, 2018
55 changes: 37 additions & 18 deletions plugins/VstEffect/VstEffectControlDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@
#include <QToolBar>
#include <QLabel>


VstEffectControlDialog::VstEffectControlDialog( VstEffectControls * _ctl ) :
EffectControlDialog( _ctl ),
m_pluginWidget( NULL ),

m_plugin( NULL ),
tbLabel( NULL )
{
Expand All @@ -62,39 +62,34 @@ VstEffectControlDialog::VstEffectControlDialog( VstEffectControls * _ctl ) :
embed_vst = m_plugin->embedMethod() != "none";

if (embed_vst) {
m_plugin->createUI( nullptr, true );
m_pluginWidget = m_plugin->pluginWidget( false );

#ifdef LMMS_BUILD_WIN32
if( !m_pluginWidget )
{
m_pluginWidget = m_plugin->pluginWidget( false );
if (m_plugin->hasEditor() && ! m_plugin->pluginWidget()) {
m_plugin->createUI(this);
}
#endif

m_pluginWidget = m_plugin->pluginWidget();
}
}

if ( m_plugin && (!embed_vst || m_pluginWidget) )
if (m_plugin)
{
setWindowTitle( m_plugin->name() );

QPushButton * btn = new QPushButton( tr( "Show/hide" ) );
QPushButton * btn = new QPushButton( tr( "Show/hide" ));

if (embed_vst) {
btn->setCheckable( true );
btn->setChecked( true );
connect( btn, SIGNAL( toggled( bool ) ),
SLOT( togglePluginUI( bool ) ) );
} else {
connect( btn, SIGNAL( clicked( bool ) ),
SLOT( togglePluginUI( bool ) ) );
connect( btn, SIGNAL( clicked() ),
m_plugin.data(), SLOT( toggleUI() ) );
}

btn->setMinimumWidth( 78 );
btn->setMaximumWidth( 78 );
btn->setMinimumHeight( 24 );
btn->setMaximumHeight( 24 );
m_togglePluginButton = btn;

m_managePluginButton = new PixmapButton( this, "" );
m_managePluginButton->setCheckable( false );
Expand Down Expand Up @@ -223,7 +218,7 @@ VstEffectControlDialog::VstEffectControlDialog( VstEffectControls * _ctl ) :

int newSize = 0;

if (embed_vst) {
if (m_pluginWidget) {
newSize = m_pluginWidget->width() + 20;
}
newSize = std::max(newSize, 250);
Expand All @@ -239,7 +234,7 @@ VstEffectControlDialog::VstEffectControlDialog( VstEffectControls * _ctl ) :
l->addItem( new QSpacerItem( newSize - 20, 30, QSizePolicy::Fixed,
QSizePolicy::Fixed ), 1, 0 );
l->addWidget( resize, 2, 0, 1, 1, Qt::AlignCenter );
if (embed_vst) {
if (m_pluginWidget) {
l->addWidget( m_pluginWidget, 3, 0, 1, 1, Qt::AlignCenter );
}
l->setRowStretch( 5, 1 );
Expand Down Expand Up @@ -278,12 +273,28 @@ void VstEffectControlDialog::paintEvent( QPaintEvent * )
}
}

void VstEffectControlDialog::showEvent(QShowEvent *_se)
{
EffectControlDialog::showEvent( _se );
// Workaround for a (unexplained) bug where on project-load the effect
// control window has size 0 and would only restore to the proper size upon
// moving the window or interacting with it.
if (parentWidget()) {
parentWidget()->adjustSize();
}
}




VstEffectControlDialog::~VstEffectControlDialog()
{
//delete m_pluginWidget;
#if !(QT_VERSION < 0x050000 && defined(LMMS_BUILD_LINUX))
if (m_pluginWidget && layout()) {
layout()->removeWidget(m_pluginWidget);
m_pluginWidget->setParent(nullptr);
}
#endif
}


Expand All @@ -295,6 +306,14 @@ void VstEffectControlDialog::togglePluginUI( bool checked )
return;
}

m_plugin->toggleUI();
if ( m_togglePluginButton->isChecked() != checked ) {
m_togglePluginButton->setChecked( checked );
}

if ( checked ) {
m_plugin->showUI();
} else {
m_plugin->hideUI();
}
}

4 changes: 3 additions & 1 deletion plugins/VstEffect/VstEffectControlDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ class VstEffectControlDialog : public EffectControlDialog

protected:
virtual void paintEvent( QPaintEvent * _pe );
virtual void showEvent( QShowEvent* _se ) override;

private:
QWidget * m_pluginWidget;

QPushButton * m_togglePluginButton;
PixmapButton * m_openPresetButton;
PixmapButton * m_rolLPresetButton;
PixmapButton * m_rolRPresetButton;
Expand All @@ -64,7 +66,7 @@ class VstEffectControlDialog : public EffectControlDialog

QLabel * tbLabel;

private slots:
public slots:
void togglePluginUI( bool checked );
} ;

Expand Down
19 changes: 15 additions & 4 deletions plugins/VstEffect/VstEffectControls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ VstEffectControls::VstEffectControls( VstEffect * _eff ) :
m_subWindow( NULL ),
knobFModel( NULL ),
ctrHandle( NULL ),
lastPosInMenu (0)
lastPosInMenu (0),
m_vstGuiVisible ( true )
// m_presetLabel ( NULL )
{
}
Expand All @@ -64,6 +65,8 @@ void VstEffectControls::loadSettings( const QDomElement & _this )
m_effect->m_pluginMutex.lock();
if( m_effect->m_plugin != NULL )
{
m_vstGuiVisible = _this.attribute( "guivisible" ).toInt();

m_effect->m_plugin->loadSettings( _this );

const QMap<QString, QString> & dump = m_effect->m_plugin->parameterDump();
Expand Down Expand Up @@ -138,8 +141,16 @@ void VstEffectControls::saveSettings( QDomDocument & _doc, QDomElement & _this )

int VstEffectControls::controlCount()
{
return m_effect->m_plugin != NULL &&
m_effect->m_plugin->hasEditor() ? 1 : 0;
return m_effect->m_plugin != NULL ? 1 : 0;
}



EffectControlDialog *VstEffectControls::createView()
{
auto dialog = new VstEffectControlDialog( this );
dialog->togglePluginUI( m_vstGuiVisible );
return dialog;
}


Expand Down Expand Up @@ -306,7 +317,7 @@ manageVSTEffectView::manageVSTEffectView( VstEffect * _eff, VstEffectControls *
m_vi->m_subWindow->setWidget(m_vi->m_scrollArea);
m_vi->m_subWindow->setWindowTitle( _eff->m_plugin->name() + tr( " - VST parameter control" ) );
m_vi->m_subWindow->setWindowIcon( PLUGIN_NAME::getIconPixmap( "logo" ) );
//m_vi->m_subWindow->setAttribute(Qt::WA_DeleteOnClose);
m_vi->m_subWindow->setAttribute(Qt::WA_DeleteOnClose, false);


l->setContentsMargins( 20, 10, 10, 10 );
Expand Down
6 changes: 2 additions & 4 deletions plugins/VstEffect/VstEffectControls.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@ class VstEffectControls : public EffectControls

virtual int controlCount();

virtual EffectControlDialog * createView()
{
return new VstEffectControlDialog( this );
}
virtual EffectControlDialog * createView();


protected slots:
Expand Down Expand Up @@ -96,6 +93,7 @@ protected slots:
friend class VstEffectControlDialog;
friend class manageVSTEffectView;

bool m_vstGuiVisible;
} ;


Expand Down
64 changes: 63 additions & 1 deletion plugins/vestige/vestige.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

#include "vestige.h"

#include <memory>

#include <QDropEvent>
#include <QMessageBox>
#include <QPainter>
Expand Down Expand Up @@ -73,6 +75,59 @@ Plugin::Descriptor PLUGIN_EXPORT vestige_plugin_descriptor =
}


class vstSubWin : public QMdiSubWindow
{
public:
vstSubWin( QWidget * _parent ) :
QMdiSubWindow( _parent )
{
setAttribute( Qt::WA_DeleteOnClose, false );
setWindowFlags( Qt::WindowCloseButtonHint );
}

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();
}
};


class VstInstrumentPlugin : public VstPlugin
{
public:
using VstPlugin::VstPlugin;

void createUI( QWidget *parent ) override
{
Q_UNUSED(parent);
if ( embedMethod() != "none" ) {
m_pluginSubWindow.reset(new vstSubWin( gui->mainWindow()->workspace() ));
VstPlugin::createUI( m_pluginSubWindow.get() );
m_pluginSubWindow->setWidget(pluginWidget());
} else {
VstPlugin::createUI( nullptr );
}
}

/// Overwrite editor() to return the sub window instead of the embed widget
/// itself. This makes toggleUI() and related functions toggle the
/// sub window's visibility.
QWidget* editor() override
{
return m_pluginSubWindow.get();
}
private:
unique_ptr<QMdiSubWindow> m_pluginSubWindow;
};


QPixmap * VestigeInstrumentView::s_artwork = NULL;
QPixmap * manageVestigeInstrumentView::s_artwork = NULL;

Expand Down Expand Up @@ -127,6 +182,12 @@ void vestigeInstrument::loadSettings( const QDomElement & _this )
{
m_plugin->loadSettings( _this );

if ( _this.attribute( "guivisible" ).toInt() ) {
m_plugin->showUI();
} else {
m_plugin->hideUI();
}

const QMap<QString, QString> & dump = m_plugin->parameterDump();
paramCount = dump.size();
char paramStr[35];
Expand Down Expand Up @@ -267,7 +328,7 @@ void vestigeInstrument::loadFile( const QString & _file )
}

m_pluginMutex.lock();
m_plugin = new VstPlugin( m_pluginDLL );
m_plugin = new VstInstrumentPlugin( m_pluginDLL );
if( m_plugin->failed() )
{
m_pluginMutex.unlock();
Expand All @@ -278,6 +339,7 @@ void vestigeInstrument::loadFile( const QString & _file )
return;
}

m_plugin->createUI(nullptr);
m_plugin->showUI();

if( set_ch_name )
Expand Down
Loading