Skip to content

Commit

Permalink
Allow carla plugins to be conditionally skipped
Browse files Browse the repository at this point in the history
  • Loading branch information
tresf committed Feb 8, 2025
1 parent 6a0a4cd commit 3b3bd48
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cmake/linux/apprun-hooks/carla-hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ if command -v carla > /dev/null 2>&1; then
fi
done
else
echo "[$ME] Carla does not appear to be installed. That's OK, please ignore any related library errors." >&2
echo "[$ME] Carla does not appear to be installed, we'll remove it from the plugin listing.." >&2
export "LMMS_EXCLUDE_PLUGINS=*carla*,${LMMS_EXCLUDE_PLUGINS}"
fi

# Additional workarounds for library conflicts
Expand Down
2 changes: 2 additions & 0 deletions include/PluginFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ public slots:
QHash<QString, QString> m_errors;

static std::unique_ptr<PluginFactory> s_instance;

static QList<QRegularExpression> filterPlugins(QSet<QFileInfo>& files);
};

//Short-hand function
Expand Down
44 changes: 44 additions & 0 deletions src/core/PluginFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <QDebug>
#include <QDir>
#include <QLibrary>
#include <QRegularExpression>
#include <memory>
#include "lmmsconfig.h"

Expand Down Expand Up @@ -157,6 +158,9 @@ void PluginFactory::discoverPlugins()
#endif
}

// Apply any plugin filters from environment LMMS_EXCLUDE_PLUGINS
filterPlugins(files);

// Cheap dependency handling: zynaddsubfx needs ZynAddSubFxCore. By loading
// all libraries twice we ensure that libZynAddSubFxCore is found.
for (const QFileInfo& file : files)
Expand Down Expand Up @@ -245,7 +249,47 @@ void PluginFactory::discoverPlugins()
m_descriptors = descriptors;
}

// Filter plugins based on environment variable, e.g. export LMMS_EXCLUDE_PLUGINS="*carla*"
QSet<QFileInfo> filterPlugins(QSet<QFileInfo>& files) {
// Get filter
QList<QRegularExpression> excludedPatterns;
QString excludePatternString = std::getenv("LMMS_EXCLUDE_PLUGINS");

if (!excludePatternString.isEmpty()) {
QStringList patterns = excludePatternString.split(',');
for (const QString& pattern : patterns) {
QRegularExpression regex(pattern.trimmed());
if (!pattern.trimmed().isEmpty() && regex.isValid()) {
excludedPatterns << regex;
} else {
qWarning() << "Invalid regular expression:" << pattern;
}
}
}

// Get files to remove
QSet<QFileInfo> filesToRemove;
for (const QFileInfo& fileInfo : files) {
bool excluded = false;
QString filePath = fileInfo.filePath();

for (const QRegularExpression& pattern : excludedPatterns) {
if (pattern.match(filePath).hasMatch()) {
excluded = true;
break;
}
}

if (excluded) {
filesToRemove.insert(fileInfo);
}
}

// Remove them
for (const QFileInfo& fileInfo : filesToRemove) {
files.remove(fileInfo);
}
}

QString PluginFactory::PluginInfo::name() const
{
Expand Down

0 comments on commit 3b3bd48

Please sign in to comment.