diff --git a/host/main-window.cc b/host/main-window.cc index feee8a1..4442761 100644 --- a/host/main-window.cc +++ b/host/main-window.cc @@ -46,7 +46,9 @@ void MainWindow::createMenu() { QMenu *fileMenu = menuBar->addMenu(tr("File")); // TODO: fileMenu->addAction(tr("Load plugin")); - connect(fileMenu->addAction(tr("Load Native Plugin Preset")), + + _loadPluginPresetAction = fileMenu->addAction(tr("Load Native Plugin Preset")); + connect(_loadPluginPresetAction, &QAction::triggered, this, &MainWindow::loadNativePluginPreset); @@ -62,11 +64,15 @@ void MainWindow::createMenu() { &Application::quit); auto windowsMenu = menuBar->addMenu("Windows"); - connect(windowsMenu->addAction(tr("Show Parameters")), + + _showPluginParametersAction = windowsMenu->addAction(tr("Show Parameters")); + connect(_showPluginParametersAction, &QAction::triggered, this, &MainWindow::showPluginParametersWindow); - connect(windowsMenu->addAction(tr("Show Quick Controls")), + + _showPluginQuickControlsAction = windowsMenu->addAction(tr("Show Quick Controls")); + connect(_showPluginQuickControlsAction, &QAction::triggered, this, &MainWindow::showPluginQuickControlsWindow); @@ -76,11 +82,15 @@ void MainWindow::createMenu() { dialog.exec(); }); menuBar->addSeparator(); - connect(windowsMenu->addAction(tr("Toggle Plugin Window Visibility")), + + _togglePluginWindowVisibilityAction = windowsMenu->addAction(tr("Toggle Plugin Window Visibility")); + connect(_togglePluginWindowVisibilityAction, &QAction::triggered, this, &MainWindow::togglePluginWindowVisibility); - connect(windowsMenu->addAction(tr("Recreate Plugin Window")), + + _recreatePluginWindowAction = windowsMenu->addAction(tr("Recreate Plugin Window")); + connect(_recreatePluginWindowAction, &QAction::triggered, this, &MainWindow::recreatePluginWindow); @@ -88,6 +98,19 @@ void MainWindow::createMenu() { QMenu *helpMenu = menuBar->addMenu(tr("Help")); connect( helpMenu->addAction(tr("About")), &QAction::triggered, this, &MainWindow::showAboutDialog); + + updatePluginMenuItems(); + + assert(_application.engine()); + connect(&_application.engine()->pluginHost(), &PluginHost::pluginLoadedChanged, this, &MainWindow::updatePluginMenuItems); +} + +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() { diff --git a/host/main-window.hh b/host/main-window.hh index 1dcfa07..6bb2f85 100644 --- a/host/main-window.hh +++ b/host/main-window.hh @@ -41,11 +41,18 @@ private: void togglePluginWindowVisibility(); void recreatePluginWindow(); void showAboutDialog(); + void updatePluginMenuItems(bool pluginLoaded = false); Application &_application; QWindow *_pluginViewWindow = nullptr; QWidget *_pluginViewWidget = nullptr; + QAction *_loadPluginPresetAction = nullptr; + QAction *_showPluginParametersAction = nullptr; + QAction *_showPluginQuickControlsAction = nullptr; + QAction *_togglePluginWindowVisibilityAction = nullptr; + QAction *_recreatePluginWindowAction = nullptr; + PluginParametersWidget *_pluginParametersWidget = nullptr; PluginQuickControlsWidget *_pluginRemoteControlsWidget = nullptr; }; diff --git a/host/plugin-host.cc b/host/plugin-host.cc index fa45677..30d0540 100644 --- a/host/plugin-host.cc +++ b/host/plugin-host.cc @@ -147,12 +147,17 @@ bool PluginHost::load(const QString &path, int pluginIndex) { scanParams(); scanQuickControls(); + + pluginLoadedChanged(true); + return true; } void PluginHost::unload() { checkForMainThread(); + pluginLoadedChanged(false); + if (!_library.isLoaded()) return; @@ -1171,12 +1176,6 @@ void PluginHost::remoteControlsSuggestPage(clap_id page_id) noexcept { bool PluginHost::loadNativePluginPreset(const std::string &path) { checkForMainThread(); - if(!_plugin) - { - std::cerr << "called with a null clap_plugin pointer!" << std::endl; - return false; - } - if (!_plugin->canUsePresetLoad()) return false; 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: /////////////////////////