diff --git a/src/framework/audio/internal/plugins/knownaudiopluginsregister.cpp b/src/framework/audio/internal/plugins/knownaudiopluginsregister.cpp index 0d4ec357f1947..69878dfba4485 100644 --- a/src/framework/audio/internal/plugins/knownaudiopluginsregister.cpp +++ b/src/framework/audio/internal/plugins/knownaudiopluginsregister.cpp @@ -187,7 +187,14 @@ mu::Ret KnownAudioPluginsRegister::registerPlugin(const AudioPluginInfo& info) return false; } - m_pluginInfoMap[info.meta.id] = info; + auto it = m_pluginInfoMap.find(info.meta.id); + if (it != m_pluginInfoMap.end()) { + IF_ASSERT_FAILED(it->second.path != info.path) { + return false; + } + } + + m_pluginInfoMap.emplace(info.meta.id, info); m_pluginPaths.insert(info.path); Ret ret = writePluginsInfo(); @@ -204,10 +211,13 @@ mu::Ret KnownAudioPluginsRegister::unregisterPlugin(const AudioResourceId& resou return make_ok(); } - AudioPluginInfo info = m_pluginInfoMap[resourceId]; + for (const auto& pair : m_pluginInfoMap) { + if (pair.first == resourceId) { + mu::remove(m_pluginPaths, pair.second.path); + } + } - mu::remove(m_pluginInfoMap, resourceId); - mu::remove(m_pluginPaths, info.path); + m_pluginInfoMap.erase(resourceId); Ret ret = writePluginsInfo(); return ret; diff --git a/src/framework/audio/internal/plugins/knownaudiopluginsregister.h b/src/framework/audio/internal/plugins/knownaudiopluginsregister.h index 102b8de1f0aeb..6063d9c7d854a 100644 --- a/src/framework/audio/internal/plugins/knownaudiopluginsregister.h +++ b/src/framework/audio/internal/plugins/knownaudiopluginsregister.h @@ -51,7 +51,7 @@ class KnownAudioPluginsRegister : public IKnownAudioPluginsRegister Ret writePluginsInfo(); bool m_loaded = false; - std::map m_pluginInfoMap; + std::multimap m_pluginInfoMap; std::set m_pluginPaths; }; } diff --git a/src/framework/audio/tests/knownaudiopluginsregistertest.cpp b/src/framework/audio/tests/knownaudiopluginsregistertest.cpp index 1c7690919901c..f202ca7e53f9a 100644 --- a/src/framework/audio/tests/knownaudiopluginsregistertest.cpp +++ b/src/framework/audio/tests/knownaudiopluginsregistertest.cpp @@ -212,13 +212,28 @@ TEST_F(Audio_KnownAudioPluginsRegisterTest, PluginInfoList) // [THEN] The plugin successfully registered EXPECT_TRUE(ret); + // [GIVEN] Same plugin (with the same resourceId) is installed in a different location + AudioPluginInfo duplicatedPluginInfo = newPluginInfo; + duplicatedPluginInfo.path = "/another/path/to/new/plugin/plugin.vst"; + expectedPluginInfoList.push_back(duplicatedPluginInfo); + + // [THEN] All the plugins will be written to the file + expectedNewPluginsData = pluginInfoListToJson(expectedPluginInfoList); + EXPECT_CALL(*m_fileSystem, writeFile(m_knownAudioPluginsFilePath, expectedNewPluginsData)) + .WillOnce(Return(mu::make_ok())); + + // [WHEN] Register it + ret = m_knownPlugins->registerPlugin(duplicatedPluginInfo); + + // [THEN] The duplicated plugin successfully registered + EXPECT_TRUE(ret); + actualPluginInfoList = m_knownPlugins->pluginInfoList(); EXPECT_EQ(expectedPluginInfoList.size(), actualPluginInfoList.size()); for (const AudioPluginInfo& actualInfo : actualPluginInfoList) { EXPECT_TRUE(mu::contains(expectedPluginInfoList, actualInfo)); EXPECT_TRUE(m_knownPlugins->exists(actualInfo.path)); EXPECT_TRUE(m_knownPlugins->exists(actualInfo.meta.id)); - EXPECT_EQ(actualInfo.path, m_knownPlugins->pluginPath(actualInfo.meta.id)); } // [GIVEN] We want to unregister the first plugin in the list diff --git a/src/framework/global/containers.h b/src/framework/global/containers.h index 6493b1acaeff9..7e1675412d0fb 100644 --- a/src/framework/global/containers.h +++ b/src/framework/global/containers.h @@ -216,6 +216,12 @@ inline bool contains(const std::map& m, const K& k) return m.find(k) != m.cend(); } +template +inline bool contains(const std::multimap& m, const K& k) +{ + return m.find(k) != m.cend(); +} + template inline bool contains(const std::unordered_map& m, const K& k) {