Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable/Disable Menu items based on plugin loaded #45

Merged
merged 2 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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