diff --git a/host/main-window.cc b/host/main-window.cc index 79cc827..4442761 100644 --- a/host/main-window.cc +++ b/host/main-window.cc @@ -99,15 +99,18 @@ void MainWindow::createMenu() { connect( helpMenu->addAction(tr("About")), &QAction::triggered, this, &MainWindow::showAboutDialog); - updateMenuItems(); + updatePluginMenuItems(); + + assert(_application.engine()); + connect(&_application.engine()->pluginHost(), &PluginHost::pluginLoadedChanged, this, &MainWindow::updatePluginMenuItems); } -void MainWindow::updateMenuItems() { - _loadPluginPresetAction->setEnabled(_pluginLoaded); - _showPluginParametersAction->setEnabled(_pluginLoaded); - _showPluginQuickControlsAction->setEnabled(_pluginLoaded); - _togglePluginWindowVisibilityAction->setEnabled(_pluginLoaded); - _recreatePluginWindowAction->setEnabled(_pluginLoaded); +void MainWindow::updatePluginMenuItems(bool const pluginLoaded /* = false */ ) { + _loadPluginPresetAction->setEnabled(pluginLoaded); + _showPluginParametersAction->setEnabled(pluginLoaded); + _showPluginQuickControlsAction->setEnabled(pluginLoaded); + _togglePluginWindowVisibilityAction->setEnabled(pluginLoaded); + _recreatePluginWindowAction->setEnabled(pluginLoaded); } void MainWindow::showSettingsDialog() { @@ -137,11 +140,6 @@ void MainWindow::resizePluginView(int width, int height) { adjustSize(); } -void MainWindow::onPluginLoadChange(bool const i_pluginLoaded) { - _pluginLoaded = i_pluginLoaded; - updateMenuItems(); -} - void MainWindow::loadNativePluginPreset() { auto file = QFileDialog::getOpenFileName(this, tr("Load Plugin Native Preset")); if (file.isEmpty()) diff --git a/host/main-window.hh b/host/main-window.hh index 260407e..6bb2f85 100644 --- a/host/main-window.hh +++ b/host/main-window.hh @@ -25,7 +25,6 @@ public: void showPluginParametersWindow(); void showPluginQuickControlsWindow(); void resizePluginView(int width, int height); - void onPluginLoadChange(bool i_pluginLoaded); void showPluginWindow() { _pluginViewWidget->show(); } @@ -42,7 +41,7 @@ private: void togglePluginWindowVisibility(); void recreatePluginWindow(); void showAboutDialog(); - void updateMenuItems(); + void updatePluginMenuItems(bool pluginLoaded = false); Application &_application; QWindow *_pluginViewWindow = nullptr; @@ -54,8 +53,6 @@ private: QAction *_togglePluginWindowVisibilityAction = nullptr; QAction *_recreatePluginWindowAction = nullptr; - bool _pluginLoaded = false; - PluginParametersWidget *_pluginParametersWidget = nullptr; PluginQuickControlsWidget *_pluginRemoteControlsWidget = nullptr; }; diff --git a/host/plugin-host.cc b/host/plugin-host.cc index 175f826..30d0540 100644 --- a/host/plugin-host.cc +++ b/host/plugin-host.cc @@ -148,7 +148,7 @@ bool PluginHost::load(const QString &path, int pluginIndex) { scanParams(); scanQuickControls(); - Application::instance().mainWindow()->onPluginLoadChange(true); + pluginLoadedChanged(true); return true; } @@ -156,7 +156,7 @@ bool PluginHost::load(const QString &path, int pluginIndex) { void PluginHost::unload() { checkForMainThread(); - Application::instance().mainWindow()->onPluginLoadChange(false); + pluginLoadedChanged(false); if (!_library.isLoaded()) return; diff --git a/host/plugin-host.hh b/host/plugin-host.hh index 7f36db7..0a69fa9 100644 --- a/host/plugin-host.hh +++ b/host/plugin-host.hh @@ -92,6 +92,7 @@ signals: void quickControlsPagesChanged(); void quickControlsSelectedPageChanged(); void paramAdjusted(clap_id paramId); + void pluginLoadedChanged(bool pluginLoaded); protected: /////////////////////////