diff --git a/host/main-window.cc b/host/main-window.cc index feee8a1..79cc827 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,16 @@ void MainWindow::createMenu() { QMenu *helpMenu = menuBar->addMenu(tr("Help")); connect( helpMenu->addAction(tr("About")), &QAction::triggered, this, &MainWindow::showAboutDialog); + + updateMenuItems(); +} + +void MainWindow::updateMenuItems() { + _loadPluginPresetAction->setEnabled(_pluginLoaded); + _showPluginParametersAction->setEnabled(_pluginLoaded); + _showPluginQuickControlsAction->setEnabled(_pluginLoaded); + _togglePluginWindowVisibilityAction->setEnabled(_pluginLoaded); + _recreatePluginWindowAction->setEnabled(_pluginLoaded); } void MainWindow::showSettingsDialog() { @@ -117,6 +137,11 @@ 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 1dcfa07..260407e 100644 --- a/host/main-window.hh +++ b/host/main-window.hh @@ -25,6 +25,7 @@ public: void showPluginParametersWindow(); void showPluginQuickControlsWindow(); void resizePluginView(int width, int height); + void onPluginLoadChange(bool i_pluginLoaded); void showPluginWindow() { _pluginViewWidget->show(); } @@ -41,11 +42,20 @@ private: void togglePluginWindowVisibility(); void recreatePluginWindow(); void showAboutDialog(); + void updateMenuItems(); Application &_application; QWindow *_pluginViewWindow = nullptr; QWidget *_pluginViewWidget = nullptr; + QAction *_loadPluginPresetAction = nullptr; + QAction *_showPluginParametersAction = nullptr; + QAction *_showPluginQuickControlsAction = nullptr; + 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 fa45677..175f826 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(); + + Application::instance().mainWindow()->onPluginLoadChange(true); + return true; } void PluginHost::unload() { checkForMainThread(); + Application::instance().mainWindow()->onPluginLoadChange(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;