Skip to content

Commit a2cb7e9

Browse files
lukas-wPhysSong
authored andcommitted
Fix VST sub-window creation glitches in project loading
Fixes bugs where during project loading (observed with VST effects), empty widgets and sub-windows would be left floating around. These were caused by inconsistencies between the way VST UIs were created when loading a project and when adding an effect in an existing project. In some situations, this caused createUI to be called twice, leaving over multiple empty widgets. This commit refactors some code in order to avoid creating unnecessary sub- windows, which aren't needed with VST effects, but were still created, usually being invisible. All sub-window related code was moved out of VstPlugin into vestige.cpp, which is the only place where sub-window VSTs are actually used. A new sub-class of VstPlugin, VstInstrumentPlugin, now handles VST sub-windows and is used by vestigeInstrument. "guivisible" attribute loading was moved out of VstPlugin as well and is now done in VstEffectControls' and vestigeInstrument's loadSettings method respectively. This causes some minor code duplication unfortunately. Closes #4110
1 parent 3e8120d commit a2cb7e9

File tree

7 files changed

+136
-126
lines changed

7 files changed

+136
-126
lines changed

plugins/VstEffect/VstEffectControlDialog.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
VstEffectControlDialog::VstEffectControlDialog( VstEffectControls * _ctl ) :
4646
EffectControlDialog( _ctl ),
4747
m_pluginWidget( NULL ),
48+
4849
m_plugin( NULL ),
4950
tbLabel( NULL )
5051
{
@@ -62,24 +63,18 @@ VstEffectControlDialog::VstEffectControlDialog( VstEffectControls * _ctl ) :
6263
embed_vst = m_plugin->embedMethod() != "none";
6364

6465
if (embed_vst) {
65-
m_plugin->createUI( nullptr, true );
66-
m_pluginWidget = m_plugin->pluginWidget( false );
67-
68-
#ifdef LMMS_BUILD_WIN32
69-
if( !m_pluginWidget )
70-
{
71-
m_pluginWidget = m_plugin->pluginWidget( false );
66+
if (! m_plugin->pluginWidget()) {
67+
m_plugin->createUI(nullptr);
7268
}
73-
#endif
74-
69+
m_pluginWidget = m_plugin->pluginWidget();
7570
}
7671
}
7772

7873
if ( m_plugin && (!embed_vst || m_pluginWidget) )
7974
{
8075
setWindowTitle( m_plugin->name() );
8176

82-
QPushButton * btn = new QPushButton( tr( "Show/hide" ) );
77+
QPushButton * btn = new QPushButton( tr( "Show/hide" ));
8378

8479
if (embed_vst) {
8580
btn->setCheckable( true );
@@ -95,6 +90,7 @@ VstEffectControlDialog::VstEffectControlDialog( VstEffectControls * _ctl ) :
9590
btn->setMaximumWidth( 78 );
9691
btn->setMinimumHeight( 24 );
9792
btn->setMaximumHeight( 24 );
93+
m_togglePluginButton = btn;
9894

9995
m_managePluginButton = new PixmapButton( this, "" );
10096
m_managePluginButton->setCheckable( false );
@@ -295,6 +291,14 @@ void VstEffectControlDialog::togglePluginUI( bool checked )
295291
return;
296292
}
297293

298-
m_plugin->toggleUI();
294+
if ( m_togglePluginButton->isChecked() != checked ) {
295+
m_togglePluginButton->setChecked( checked );
296+
}
297+
298+
if ( checked ) {
299+
m_plugin->showUI();
300+
} else {
301+
m_plugin->hideUI();
302+
}
299303
}
300304

plugins/VstEffect/VstEffectControlDialog.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class VstEffectControlDialog : public EffectControlDialog
5454
private:
5555
QWidget * m_pluginWidget;
5656

57+
QPushButton * m_togglePluginButton;
5758
PixmapButton * m_openPresetButton;
5859
PixmapButton * m_rolLPresetButton;
5960
PixmapButton * m_rolRPresetButton;
@@ -64,7 +65,7 @@ class VstEffectControlDialog : public EffectControlDialog
6465

6566
QLabel * tbLabel;
6667

67-
private slots:
68+
public slots:
6869
void togglePluginUI( bool checked );
6970
} ;
7071

plugins/VstEffect/VstEffectControls.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ VstEffectControls::VstEffectControls( VstEffect * _eff ) :
4040
m_subWindow( NULL ),
4141
knobFModel( NULL ),
4242
ctrHandle( NULL ),
43-
lastPosInMenu (0)
43+
lastPosInMenu (0),
44+
m_vstGuiVisible ( true )
4445
// m_presetLabel ( NULL )
4546
{
4647
}
@@ -64,6 +65,8 @@ void VstEffectControls::loadSettings( const QDomElement & _this )
6465
m_effect->m_pluginMutex.lock();
6566
if( m_effect->m_plugin != NULL )
6667
{
68+
m_vstGuiVisible = _this.attribute( "guivisible" ).toInt();
69+
6770
m_effect->m_plugin->loadSettings( _this );
6871

6972
const QMap<QString, QString> & dump = m_effect->m_plugin->parameterDump();
@@ -144,6 +147,15 @@ int VstEffectControls::controlCount()
144147

145148

146149

150+
EffectControlDialog *VstEffectControls::createView()
151+
{
152+
auto dialog = new VstEffectControlDialog( this );
153+
dialog->togglePluginUI( m_vstGuiVisible );
154+
return dialog;
155+
}
156+
157+
158+
147159

148160
void VstEffectControls::managePlugin( void )
149161
{

plugins/VstEffect/VstEffectControls.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,7 @@ class VstEffectControls : public EffectControls
5959

6060
virtual int controlCount();
6161

62-
virtual EffectControlDialog * createView()
63-
{
64-
return new VstEffectControlDialog( this );
65-
}
62+
virtual EffectControlDialog * createView();
6663

6764

6865
protected slots:
@@ -96,6 +93,7 @@ protected slots:
9693
friend class VstEffectControlDialog;
9794
friend class manageVSTEffectView;
9895

96+
bool m_vstGuiVisible;
9997
} ;
10098

10199

plugins/vestige/vestige.cpp

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
#include "vestige.h"
2626

27+
#include <memory>
28+
2729
#include <QDropEvent>
2830
#include <QMessageBox>
2931
#include <QPainter>
@@ -73,6 +75,57 @@ Plugin::Descriptor PLUGIN_EXPORT vestige_plugin_descriptor =
7375
}
7476

7577

78+
class vstSubWin : public QMdiSubWindow
79+
{
80+
public:
81+
vstSubWin( QWidget * _parent ) :
82+
QMdiSubWindow( _parent )
83+
{
84+
setAttribute( Qt::WA_DeleteOnClose, false );
85+
setWindowFlags( Qt::WindowCloseButtonHint );
86+
}
87+
88+
virtual ~vstSubWin()
89+
{
90+
}
91+
92+
virtual void closeEvent( QCloseEvent * e )
93+
{
94+
// ignore close-events - for some reason otherwise the VST GUI
95+
// remains hidden when re-opening
96+
hide();
97+
e->ignore();
98+
}
99+
};
100+
101+
102+
class VstInstrumentPlugin : public VstPlugin
103+
{
104+
public:
105+
using VstPlugin::VstPlugin;
106+
107+
void createUI( QWidget *parent ) override
108+
{
109+
Q_UNUSED(parent);
110+
VstPlugin::createUI( nullptr );
111+
if ( embedMethod() != "none" ) {
112+
m_pluginSubWindow.reset(new vstSubWin( gui->mainWindow()->workspace() ));
113+
m_pluginSubWindow->setWidget(pluginWidget());
114+
}
115+
}
116+
117+
/// Overwrite editor() to return the sub window instead of the embed widget
118+
/// itself. This makes toggleUI() and related functions toggle the
119+
/// sub window's visibility.
120+
QWidget* editor() override
121+
{
122+
return m_pluginSubWindow.get();
123+
}
124+
private:
125+
unique_ptr<QMdiSubWindow> m_pluginSubWindow;
126+
};
127+
128+
76129
QPixmap * VestigeInstrumentView::s_artwork = NULL;
77130
QPixmap * manageVestigeInstrumentView::s_artwork = NULL;
78131

@@ -127,6 +180,12 @@ void vestigeInstrument::loadSettings( const QDomElement & _this )
127180
{
128181
m_plugin->loadSettings( _this );
129182

183+
if ( _this.attribute( "guivisible" ).toInt() ) {
184+
m_plugin->showUI();
185+
} else {
186+
m_plugin->hideUI();
187+
}
188+
130189
const QMap<QString, QString> & dump = m_plugin->parameterDump();
131190
paramCount = dump.size();
132191
char paramStr[35];
@@ -267,7 +326,7 @@ void vestigeInstrument::loadFile( const QString & _file )
267326
}
268327

269328
m_pluginMutex.lock();
270-
m_plugin = new VstPlugin( m_pluginDLL );
329+
m_plugin = new VstInstrumentPlugin( m_pluginDLL );
271330
if( m_plugin->failed() )
272331
{
273332
m_pluginMutex.unlock();
@@ -278,6 +337,7 @@ void vestigeInstrument::loadFile( const QString & _file )
278337
return;
279338
}
280339

340+
m_plugin->createUI(nullptr);
281341
m_plugin->showUI();
282342

283343
if( set_ch_name )

0 commit comments

Comments
 (0)