LCOV - code coverage report
Current view: top level - muse/framework/vst/internal - vstmodulesrepository.cpp Coverage Total Hit
Test: filtered_coverage.info Lines: 0.0 % 77 0
Test Date: 2026-11-05 04:07:02

            Line data    Source code
       1              : /*
       2              :  * SPDX-License-Identifier: GPL-3.0-only
       3              :  * MuseScore-CLA-applies
       4              :  *
       5              :  * MuseScore Studio
       6              :  * Music Composition & Notation
       7              :  *
       8              :  * Copyright (C) 2021 MuseScore Limited and others
       9              :  *
      10              :  * This program is free software: you can redistribute it and/or modify
      11              :  * it under the terms of the GNU General Public License version 3 as
      12              :  * published by the Free Software Foundation.
      13              :  *
      14              :  * This program is distributed in the hope that it will be useful,
      15              :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      16              :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      17              :  * GNU General Public License for more details.
      18              :  *
      19              :  * You should have received a copy of the GNU General Public License
      20              :  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
      21              :  */
      22              : 
      23              : #include "vstmodulesrepository.h"
      24              : 
      25              : using namespace muse;
      26              : using namespace muse::vst;
      27              : 
      28            0 : void VstModulesRepository::init()
      29              : {
      30            0 :     ONLY_MAIN_THREAD(threadSecurer);
      31              : 
      32            0 :     PluginContextFactory::instance().setPluginContext(&m_pluginContext);
      33            0 : }
      34              : 
      35            0 : void VstModulesRepository::deInit()
      36              : {
      37            0 :     for (auto& pair : m_modules) {
      38            0 :         pair.second.reset();
      39              :     }
      40              : 
      41            0 :     PluginContextFactory::instance().setPluginContext(nullptr);
      42            0 : }
      43              : 
      44            0 : bool VstModulesRepository::exists(const muse::audio::AudioResourceId& resourceId) const
      45              : {
      46            0 :     ONLY_AUDIO_THREAD(threadSecurer);
      47              : 
      48            0 :     std::lock_guard lock(m_mutex);
      49              : 
      50            0 :     return knownPlugins()->exists(resourceId);
      51            0 : }
      52              : 
      53            0 : PluginModulePtr VstModulesRepository::pluginModule(const muse::audio::AudioResourceId& resourceId) const
      54              : {
      55            0 :     ONLY_AUDIO_OR_MAIN_THREAD(threadSecurer);
      56              : 
      57            0 :     std::lock_guard lock(m_mutex);
      58              : 
      59            0 :     auto search = m_modules.find(resourceId);
      60              : 
      61            0 :     if (search != m_modules.end()) {
      62            0 :         return search->second;
      63              :     }
      64              : 
      65            0 :     return nullptr;
      66            0 : }
      67              : 
      68            0 : void VstModulesRepository::addPluginModule(const muse::audio::AudioResourceId& resourceId)
      69              : {
      70            0 :     ONLY_MAIN_THREAD(threadSecurer);
      71              : 
      72            0 :     std::lock_guard lock(m_mutex);
      73              : 
      74            0 :     auto search = m_modules.find(resourceId);
      75            0 :     if (search != m_modules.end()) {
      76            0 :         return;
      77              :     }
      78              : 
      79            0 :     loadGuard()->beginLoad(resourceId);
      80            0 :     PluginModulePtr module = createModule(knownPlugins()->pluginPath(resourceId));
      81            0 :     loadGuard()->endLoad(resourceId);
      82              : 
      83            0 :     if (!module) {
      84            0 :         return;
      85              :     }
      86              : 
      87            0 :     m_modules.emplace(resourceId, std::move(module));
      88            0 : }
      89              : 
      90            0 : void VstModulesRepository::removePluginModule(const muse::audio::AudioResourceId& resourceId)
      91              : {
      92            0 :     ONLY_MAIN_THREAD(threadSecurer);
      93              : 
      94            0 :     std::lock_guard lock(m_mutex);
      95              : 
      96            0 :     auto search = m_modules.find(resourceId);
      97            0 :     if (search == m_modules.end()) {
      98            0 :         return;
      99              :     }
     100              : 
     101            0 :     m_modules.erase(search);
     102            0 : }
     103              : 
     104            0 : muse::audio::AudioResourceMetaList VstModulesRepository::instrumentModulesMeta() const
     105              : {
     106            0 :     ONLY_AUDIO_THREAD(threadSecurer);
     107              : 
     108            0 :     std::lock_guard lock(m_mutex);
     109              : 
     110            0 :     return modulesMetaList(PluginType::Instrument);
     111            0 : }
     112              : 
     113            0 : muse::audio::AudioResourceMetaList VstModulesRepository::fxModulesMeta() const
     114              : {
     115            0 :     ONLY_AUDIO_THREAD(threadSecurer);
     116              : 
     117            0 :     std::lock_guard lock(m_mutex);
     118              : 
     119            0 :     return modulesMetaList(PluginType::Fx);
     120            0 : }
     121              : 
     122            0 : void VstModulesRepository::refresh()
     123              : {
     124            0 : }
     125              : 
     126            0 : muse::audio::AudioResourceMetaList VstModulesRepository::modulesMetaList(PluginType type) const
     127              : {
     128            0 :     auto infoAccepted = [type](const audioplugins::AudioPluginInfo& info) {
     129            0 :         if (info.meta.type != muse::vst::AUDIO_RESOURCE_TYPE_NAME
     130            0 :             || info.state != audioplugins::AudioPluginState::Validated) {
     131            0 :             return false;
     132              :         }
     133            0 :         const String& categories = info.meta.attributeVal(muse::vst::CATEGORIES_ATTRIBUTE);
     134            0 :         const bool isInstrument = categories.contains(muse::vst::INSTRUMENT_CATEGORY);
     135            0 :         return type == PluginType::Instrument ? isInstrument : !isInstrument;
     136            0 :     };
     137              : 
     138            0 :     audioplugins::AudioPluginInfoList infoList = knownPlugins()->pluginInfoList(infoAccepted);
     139            0 :     muse::audio::AudioResourceMetaList result;
     140            0 :     result.reserve(infoList.size());
     141              : 
     142              :     // bridge the cache-domain PluginMeta to its engine-domain twin field-wise
     143            0 :     for (const audioplugins::AudioPluginInfo& info : infoList) {
     144            0 :         muse::audio::AudioResourceMeta meta;
     145            0 :         meta.id = info.meta.id;
     146            0 :         meta.vendor = info.meta.vendor;
     147            0 :         meta.attributes = info.meta.attributes;
     148            0 :         meta.type = info.meta.type;
     149            0 :         result.push_back(std::move(meta));
     150            0 :     }
     151              : 
     152            0 :     return result;
     153            0 : }
        

Generated by: LCOV version 2.0-1