Skip to content

Fix audio plugins scanner#67

Merged
RomanPudashkin merged 4 commits into
musescore:mainfrom
RomanPudashkin:fix_audio_plugins_scanner
May 29, 2026
Merged

Fix audio plugins scanner#67
RomanPudashkin merged 4 commits into
musescore:mainfrom
RomanPudashkin:fix_audio_plugins_scanner

Conversation

@RomanPudashkin
Copy link
Copy Markdown
Contributor

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 29, 2026

Review Change Stack

Warning

Review limit reached

@RomanPudashkin, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 43 minutes and 57 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: b0cec156-b7fa-4fe7-8540-ab4404b53c53

📥 Commits

Reviewing files that changed from the base of the PR and between b57150f and c6d7806.

📒 Files selected for processing (4)
  • framework/audioplugins/internal/registeraudiopluginsscenario.cpp
  • framework/audioplugins/internal/registeraudiopluginsscenario.h
  • framework/audioplugins/iregisteraudiopluginsscenario.h
  • framework/audioplugins/tests/registeraudiopluginsscenariotest.cpp
📝 Walkthrough

Walkthrough

This PR refactors the audio plugin registration and scanning system. The primary change is a return-type swap between two methods: updatePluginsRegistry() now returns void instead of Ret, while registerNewPlugins() now returns Ret instead of void. The registration layer now conditionally persists plugin data only when changes occur. The VST scanner switches to set-based path deduplication to eliminate duplicate plugin paths from multiple sources. Comprehensive tests verify the new behavior, including handling of incompatible plugins and multi-component VST3 scenarios. The header include guard is modernized to use #pragma once.

🚥 Pre-merge checks | ✅ 2 | ❌ 3

❌ Failed checks (2 warnings, 1 inconclusive)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description only contains links to the upstream issue and MuseScore PR without completing the required template sections or providing context about the changes. Complete the PR template by adding a description of changes, checking relevant boxes, and confirming CLA signature and code quality guidelines compliance.
Docstring Coverage ⚠️ Warning Docstring coverage is 13.64% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Fix audio plugins scanner' is vague and does not clearly describe the specific technical changes or the problem being fixed. Provide a more specific title that describes what was fixed, such as 'Prevent duplicate VST paths and avoid unnecessary plugin reloads' or 'Optimize plugin scanning and registration logic'.
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes address the core issue #33454 by avoiding unnecessary plugin reloads through optimized scanning and registration logic with path deduplication.
Out of Scope Changes check ✅ Passed All changes are in scope: VST scanner optimization, plugin registration logic improvements, and include header modernization directly addressing the linked issue.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
framework/audioplugins/internal/knownaudiopluginsregister.cpp (1)

245-258: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Shared path can be dropped while other plugin IDs still reference it.

For a multi-component VST, several IDs share one .vst3 path. muse::remove(m_pluginPaths, pair.second.path) unconditionally erases that path when the first ID is unregistered, so a subsequently still-registered sibling ID would report exists(path) == false. The current updatePluginsRegistry() flow unregisters all IDs of a missing path together, so this is latent today, but the public method is unsafe for partial unregistration. Also, the inner loop scans the whole map though resourceId is the unique key.

🐛 Look up by key and only drop the path when no sibling references it
     for (const AudioResourceId& resourceId : resourceIds) {
         if (!exists(resourceId)) {
             continue;
         }
 
-        for (const auto& pair : m_pluginInfoMap) {
-            if (pair.first == resourceId) {
-                muse::remove(m_pluginPaths, pair.second.path);
-            }
-        }
-
-        m_pluginInfoMap.erase(resourceId);
+        auto it = m_pluginInfoMap.find(resourceId);
+        const io::path_t path = it->second.path;
+        m_pluginInfoMap.erase(it);
+
+        const bool pathStillUsed = std::any_of(m_pluginInfoMap.cbegin(), m_pluginInfoMap.cend(),
+                                               [&path](const auto& p) { return p.second.path == path; });
+        if (!pathStillUsed) {
+            muse::remove(m_pluginPaths, path);
+        }
         changed = true;
     }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@framework/audioplugins/internal/knownaudiopluginsregister.cpp` around lines
245 - 258, When erasing a plugin by resourceId, don't scan the whole
m_pluginInfoMap or unconditionally remove its path; instead locate the entry via
m_pluginInfoMap.find(resourceId), then before calling
muse::remove(m_pluginPaths, pair.second.path) check whether any other entries in
m_pluginInfoMap (excluding resourceId) reference the same pair.second.path and
only remove the path if no sibling references remain; update the removal logic
in the block that uses exists(resourceId), m_pluginInfoMap, m_pluginPaths and
muse::remove so you do a key lookup, conditional path removal based on remaining
references, then erase(resourceId) and set changed = true.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@framework/audioplugins/internal/registeraudiopluginsscenario.cpp`:
- Around line 60-68: The loop currently pushes path onto result.newPluginPaths
whenever knownPluginsRegister()->exists(path) is false, which allows duplicates;
change the logic to first attempt to insert each scanned path into scannedPaths
and only if that insertion reports it was newly inserted (i.e., first time seen)
and the path is not already known, then append to result.newPluginPaths; update
the loop around scannerRegister()->scanners() / scanner->scanPlugins(progress)
to use the insert result (or an explicit contains check on scannedPaths) before
pushing to result.newPluginPaths so each unknown path is added exactly once and
processPluginsRegistration() won't be invoked multiple times for the same path.

In `@framework/audioplugins/tests/registeraudiopluginsscenariotest.cpp`:
- Around line 337-338: Replace the strict ON_CALL matching of scanPlugins() with
a wildcard matcher to accept the default nullptr or any Progress*; specifically
update the mock stub for IAudioPluginsScanner::scanPlugins so it uses the
underscore matcher (_) instead of the no-argument form, ensuring
RegisterAudioPluginsScenario::updatePluginsRegistry (which calls
scanner->scanPlugins(progress)) will match both nullptr and non-null Progress*
values.

---

Outside diff comments:
In `@framework/audioplugins/internal/knownaudiopluginsregister.cpp`:
- Around line 245-258: When erasing a plugin by resourceId, don't scan the whole
m_pluginInfoMap or unconditionally remove its path; instead locate the entry via
m_pluginInfoMap.find(resourceId), then before calling
muse::remove(m_pluginPaths, pair.second.path) check whether any other entries in
m_pluginInfoMap (excluding resourceId) reference the same pair.second.path and
only remove the path if no sibling references remain; update the removal logic
in the block that uses exists(resourceId), m_pluginInfoMap, m_pluginPaths and
muse::remove so you do a key lookup, conditional path removal based on remaining
references, then erase(resourceId) and set changed = true.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 5e04595f-0873-447d-ad8c-b044780a74aa

📥 Commits

Reviewing files that changed from the base of the PR and between 98c8f70 and b57150f.

📒 Files selected for processing (7)
  • framework/audioplugins/internal/knownaudiopluginsregister.cpp
  • framework/audioplugins/internal/registeraudiopluginsscenario.cpp
  • framework/audioplugins/internal/registeraudiopluginsscenario.h
  • framework/audioplugins/iregisteraudiopluginsscenario.h
  • framework/audioplugins/tests/registeraudiopluginsscenariotest.cpp
  • framework/vst/internal/vstpluginsscanner.cpp
  • framework/vst/internal/vstpluginsscanner.h

Comment on lines +60 to 68
for (const IAudioPluginsScannerPtr& scanner : scannerRegister()->scanners()) {
for (const io::path_t& path : scanner->scanPlugins(progress)) {
if (!knownPluginsRegister()->exists(path)) {
result.newPluginPaths.push_back(path);
}

scannedPaths.insert(path);
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

newPluginPaths can still contain duplicates, defeating the PR's dedup goal.

scannedPaths deduplicates, but the decision to append to result.newPluginPaths is gated only on knownPluginsRegister()->exists(path). If the same not-yet-known path is returned by more than one scanner (or twice by one), it is pushed multiple times, so processPluginsRegistration() spawns a subprocess for it more than once. This contradicts the stated objective of ensuring scanPlugins() does not return duplicate paths.

🐛 Gate on first insertion into the dedup set
     for (const IAudioPluginsScannerPtr& scanner : scannerRegister()->scanners()) {
         for (const io::path_t& path : scanner->scanPlugins(progress)) {
-            if (!knownPluginsRegister()->exists(path)) {
-                result.newPluginPaths.push_back(path);
-            }
-
-            scannedPaths.insert(path);
+            if (!scannedPaths.insert(path).second) {
+                continue;
+            }
+
+            if (!knownPluginsRegister()->exists(path)) {
+                result.newPluginPaths.push_back(path);
+            }
         }
     }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@framework/audioplugins/internal/registeraudiopluginsscenario.cpp` around
lines 60 - 68, The loop currently pushes path onto result.newPluginPaths
whenever knownPluginsRegister()->exists(path) is false, which allows duplicates;
change the logic to first attempt to insert each scanned path into scannedPaths
and only if that insertion reports it was newly inserted (i.e., first time seen)
and the path is not already known, then append to result.newPluginPaths; update
the loop around scannerRegister()->scanners() / scanner->scanPlugins(progress)
to use the insert result (or an explicit contains check on scannedPaths) before
pushing to result.newPluginPaths so each unknown path is added exactly once and
processPluginsRegistration() won't be invoked multiple times for the same path.

Comment thread framework/audioplugins/tests/registeraudiopluginsscenariotest.cpp Outdated
@RomanPudashkin RomanPudashkin force-pushed the fix_audio_plugins_scanner branch from b57150f to c6d7806 Compare May 29, 2026 12:21
@RomanPudashkin RomanPudashkin merged commit 1a4095c into musescore:main May 29, 2026
3 checks passed
@RomanPudashkin RomanPudashkin deleted the fix_audio_plugins_scanner branch May 29, 2026 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Start VST scan at every program startup

1 participant