Skip to content

Commit

Permalink
Merge pull request #45 from NatureIsFrequency/PluginMenuItems
Browse files Browse the repository at this point in the history
Enable/Disable Menu items based on plugin loaded
  • Loading branch information
abique authored Feb 12, 2024
2 parents 4c4c7f1 + 7017523 commit ff98954
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 11 deletions.
33 changes: 28 additions & 5 deletions host/main-window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -76,18 +82,35 @@ 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);

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() {
Expand Down
7 changes: 7 additions & 0 deletions host/main-window.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
11 changes: 5 additions & 6 deletions host/plugin-host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions host/plugin-host.hh
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ signals:
void quickControlsPagesChanged();
void quickControlsSelectedPageChanged();
void paramAdjusted(clap_id paramId);
void pluginLoadedChanged(bool pluginLoaded);

protected:
/////////////////////////
Expand Down

0 comments on commit ff98954

Please sign in to comment.