From 055e0ba576c7fed3dcaa4dfed643c4e1fc4d40e6 Mon Sep 17 00:00:00 2001 From: Tres Finocchiaro Date: Fri, 21 Feb 2025 00:56:04 -0500 Subject: [PATCH] Fix additional warnings when Carla is missing (#7722) Fix additional warnings when Carla is missing Adds new env var LMMS_EXCLUDE_LADSPA --------- Co-authored-by: Dalton Messmer --- cmake/linux/apprun-hooks/carla-hook.sh | 1 + include/PluginFactory.h | 1 + src/core/LadspaManager.cpp | 14 ++++++++++- src/core/PluginFactory.cpp | 34 +++++++++++++++++--------- 4 files changed, 38 insertions(+), 12 deletions(-) diff --git a/cmake/linux/apprun-hooks/carla-hook.sh b/cmake/linux/apprun-hooks/carla-hook.sh index 6f082d140..8cbe43d02 100644 --- a/cmake/linux/apprun-hooks/carla-hook.sh +++ b/cmake/linux/apprun-hooks/carla-hook.sh @@ -25,6 +25,7 @@ if command -v carla > /dev/null 2>&1; then else echo "[$ME] Carla does not appear to be installed, we'll remove it from the plugin listing." >&2 export "LMMS_EXCLUDE_PLUGINS=libcarla,${LMMS_EXCLUDE_PLUGINS}" + export "LMMS_EXCLUDE_LADSPA=libcarla,${LMMS_EXCLUDE_LADSPA}" fi # Additional workarounds for library conflicts diff --git a/include/PluginFactory.h b/include/PluginFactory.h index 126cb7d97..6ed0bc40b 100644 --- a/include/PluginFactory.h +++ b/include/PluginFactory.h @@ -61,6 +61,7 @@ public: ~PluginFactory() = default; static void setupSearchPaths(); + static QList getExcludePatterns(const char* envVar); /// Returns the singleton instance of PluginFactory. You won't need to call /// this directly, use pluginFactory instead. diff --git a/src/core/LadspaManager.cpp b/src/core/LadspaManager.cpp index 481b52a2e..5b94cac3f 100644 --- a/src/core/LadspaManager.cpp +++ b/src/core/LadspaManager.cpp @@ -28,6 +28,8 @@ #include #include #include +#include +#include #include @@ -45,6 +47,8 @@ LadspaManager::LadspaManager() // Make sure plugin search paths are set up PluginFactory::setupSearchPaths(); + QList excludePatterns = PluginFactory::getExcludePatterns("LMMS_EXCLUDE_LADSPA"); + QStringList ladspaDirectories = QString( getenv( "LADSPA_PATH" ) ). split( LADSPA_PATH_SEPERATOR ); ladspaDirectories += ConfigManager::inst()->ladspaDir().split( ',' ); @@ -67,7 +71,15 @@ LadspaManager::LadspaManager() QFileInfoList list = directory.entryInfoList(); for (const auto& f : list) { - if(!f.isFile() || f.fileName().right( 3 ).toLower() != + bool exclude = false; + for (const auto& pattern : excludePatterns) { + if (pattern.match(f.filePath()).hasMatch()) { + exclude = true; + break; + } + } + + if (exclude || !f.isFile() || f.fileName().right(3).toLower() != #ifdef LMMS_BUILD_WIN32 "dll" #else diff --git a/src/core/PluginFactory.cpp b/src/core/PluginFactory.cpp index 71bdfef45..38cd2dc58 100644 --- a/src/core/PluginFactory.cpp +++ b/src/core/PluginFactory.cpp @@ -249,38 +249,50 @@ void PluginFactory::discoverPlugins() m_descriptors = descriptors; } -// Filter plugins based on environment variable, e.g. export LMMS_EXCLUDE_PLUGINS="libcarla" -void PluginFactory::filterPlugins(QSet& files) { - // Get filter - QList excludedPatterns; - QString excludePatternString = std::getenv("LMMS_EXCLUDE_PLUGINS"); +// Builds QList based on environment variable envVar +QList PluginFactory::getExcludePatterns(const char* envVar) { + QList excludePatterns; + QString excludePatternString = std::getenv(envVar); if (!excludePatternString.isEmpty()) { QStringList patterns = excludePatternString.split(','); for (const QString& pattern : patterns) { + if (pattern.trimmed().isEmpty()) { + continue; + } QRegularExpression regex(pattern.trimmed()); - if (!pattern.trimmed().isEmpty() && regex.isValid()) { - excludedPatterns << regex; + if (regex.isValid()) { + excludePatterns << regex; } else { qWarning() << "Invalid regular expression:" << pattern; } } } + return excludePatterns; +} + +// Filter plugins based on environment variable, e.g. export LMMS_EXCLUDE_PLUGINS="libcarla" +void PluginFactory::filterPlugins(QSet& files) { + // Get filter + QList excludePatterns = getExcludePatterns("LMMS_EXCLUDE_PLUGINS"); + if (excludePatterns.isEmpty()) { + return; + } // Get files to remove QSet filesToRemove; for (const QFileInfo& fileInfo : files) { - bool excluded = false; + bool exclude = false; QString filePath = fileInfo.filePath(); - for (const QRegularExpression& pattern : excludedPatterns) { + for (const QRegularExpression& pattern : excludePatterns) { if (pattern.match(filePath).hasMatch()) { - excluded = true; + exclude = true; break; } } - if (excluded) { + if (exclude) { filesToRemove.insert(fileInfo); } }