diff --git a/src/framework/audio/CMakeLists.txt b/src/framework/audio/CMakeLists.txt index 5445afdeaf528..8be5fe974abc5 100644 --- a/src/framework/audio/CMakeLists.txt +++ b/src/framework/audio/CMakeLists.txt @@ -85,6 +85,7 @@ set(MODULE_SRC ${CMAKE_CURRENT_LIST_DIR}/iaudiosource.h ${CMAKE_CURRENT_LIST_DIR}/synthtypes.h ${CMAKE_CURRENT_LIST_DIR}/audiotypes.h + ${CMAKE_CURRENT_LIST_DIR}/audioutils.h ${CMAKE_CURRENT_LIST_DIR}/iplayer.h ${CMAKE_CURRENT_LIST_DIR}/itracks.h ${CMAKE_CURRENT_LIST_DIR}/iaudiooutput.h diff --git a/src/framework/audio/audiotypes.h b/src/framework/audio/audiotypes.h index c9eba70fe37f7..52e98e39bd17b 100644 --- a/src/framework/audio/audiotypes.h +++ b/src/framework/audio/audiotypes.h @@ -161,17 +161,6 @@ using AudioResourceMetaSet = std::set; static const AudioResourceId MUSE_REVERB_ID("Muse Reverb"); -inline AudioResourceMeta makeReverbMeta() -{ - AudioResourceMeta meta; - meta.id = MUSE_REVERB_ID; - meta.type = AudioResourceType::MusePlugin; - meta.vendor = "Muse"; - meta.hasNativeEditorSupport = true; - - return meta; -} - enum class AudioPluginType { Undefined = -1, Instrument, @@ -186,22 +175,6 @@ struct AudioPluginInfo { int errorCode = 0; }; -inline AudioPluginType audioPluginTypeFromCategoriesString(const String& categoriesStr) -{ - static const std::map STRING_TO_PLUGIN_TYPE_MAP = { - { u"Fx", AudioPluginType::Fx }, - { u"Instrument", AudioPluginType::Instrument }, - }; - - for (auto it = STRING_TO_PLUGIN_TYPE_MAP.cbegin(); it != STRING_TO_PLUGIN_TYPE_MAP.cend(); ++it) { - if (categoriesStr.contains(it->first)) { - return it->second; - } - } - - return AudioPluginType::Undefined; -} - enum class AudioFxType { Undefined = -1, VstFx, diff --git a/src/framework/audio/audioutils.h b/src/framework/audio/audioutils.h new file mode 100644 index 0000000000000..ffd4026a7c7cf --- /dev/null +++ b/src/framework/audio/audioutils.h @@ -0,0 +1,57 @@ +/* + * SPDX-License-Identifier: GPL-3.0-only + * MuseScore-CLA-applies + * + * MuseScore + * Music Composition & Notation + * + * Copyright (C) 2023 MuseScore BVBA and others + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef MU_AUDIO_AUDIOUTILS_H +#define MU_AUDIO_AUDIOUTILS_H + +#include "audiotypes.h" + +namespace mu::audio { +inline AudioResourceMeta makeReverbMeta() +{ + AudioResourceMeta meta; + meta.id = MUSE_REVERB_ID; + meta.type = AudioResourceType::MusePlugin; + meta.vendor = "Muse"; + meta.hasNativeEditorSupport = true; + + return meta; +} + +inline AudioPluginType audioPluginTypeFromCategoriesString(const String& categoriesStr) +{ + static const std::vector > STRING_TO_PLUGIN_TYPE_LIST = { + { u"Instrument", AudioPluginType::Instrument }, + { u"Fx", AudioPluginType::Fx }, + }; + + for (auto it = STRING_TO_PLUGIN_TYPE_LIST.cbegin(); it != STRING_TO_PLUGIN_TYPE_LIST.cend(); ++it) { + if (categoriesStr.contains(it->first)) { + return it->second; + } + } + + return AudioPluginType::Undefined; +} +} + +#endif // MU_AUDIO_AUDIOUTILS_H diff --git a/src/framework/audio/internal/fx/musefxresolver.cpp b/src/framework/audio/internal/fx/musefxresolver.cpp index 49188e446b092..5eb165e9a0a1e 100644 --- a/src/framework/audio/internal/fx/musefxresolver.cpp +++ b/src/framework/audio/internal/fx/musefxresolver.cpp @@ -24,7 +24,7 @@ #include "reverb/reverbprocessor.h" -#include "log.h" +#include "audio/audioutils.h" using namespace mu::audio; using namespace mu::audio::fx; diff --git a/src/framework/audio/internal/plugins/knownaudiopluginsregister.cpp b/src/framework/audio/internal/plugins/knownaudiopluginsregister.cpp index 69878dfba4485..fd3bc784a76c7 100644 --- a/src/framework/audio/internal/plugins/knownaudiopluginsregister.cpp +++ b/src/framework/audio/internal/plugins/knownaudiopluginsregister.cpp @@ -22,6 +22,7 @@ #include "knownaudiopluginsregister.h" +#include "audioutils.h" #include "serialization/json.h" #include "log.h" diff --git a/src/framework/audio/internal/plugins/registeraudiopluginsscenario.cpp b/src/framework/audio/internal/plugins/registeraudiopluginsscenario.cpp index 75ec4174ec8a8..fcd29ce045044 100644 --- a/src/framework/audio/internal/plugins/registeraudiopluginsscenario.cpp +++ b/src/framework/audio/internal/plugins/registeraudiopluginsscenario.cpp @@ -24,6 +24,7 @@ #include +#include "audioutils.h" #include "audioerrors.h" #include "translation.h" #include "log.h" diff --git a/src/framework/audio/tests/CMakeLists.txt b/src/framework/audio/tests/CMakeLists.txt index d4e20d3d4b4a6..e44549d7a22ff 100644 --- a/src/framework/audio/tests/CMakeLists.txt +++ b/src/framework/audio/tests/CMakeLists.txt @@ -32,6 +32,7 @@ set(MODULE_TEST_SRC ${CMAKE_CURRENT_LIST_DIR}/knownaudiopluginsregistertest.cpp ${CMAKE_CURRENT_LIST_DIR}/registeraudiopluginsscenariotest.cpp + ${CMAKE_CURRENT_LIST_DIR}/audioutilstest.cpp ) set(MODULE_TEST_LINK audio) diff --git a/src/framework/audio/tests/audioutilstest.cpp b/src/framework/audio/tests/audioutilstest.cpp new file mode 100644 index 0000000000000..f09d41c7a7fc4 --- /dev/null +++ b/src/framework/audio/tests/audioutilstest.cpp @@ -0,0 +1,51 @@ +/* + * SPDX-License-Identifier: GPL-3.0-only + * MuseScore-CLA-applies + * + * MuseScore + * Music Composition & Notation + * + * Copyright (C) 2023 MuseScore BVBA and others + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include + +#include "audio/audioutils.h" + +using namespace mu::audio; + +namespace mu::audio { +class Audio_AudioUtilsTest : public ::testing::Test +{ +public: +}; +} + +TEST_F(Audio_AudioUtilsTest, AudioPluginTypeFromCategoriesString) +{ + EXPECT_EQ(AudioPluginType::Fx, audioPluginTypeFromCategoriesString(u"Fx|Delay")); + EXPECT_EQ(AudioPluginType::Fx, audioPluginTypeFromCategoriesString(u"Test|Fx")); + + EXPECT_EQ(AudioPluginType::Instrument, audioPluginTypeFromCategoriesString(u"Instrument|Test")); + EXPECT_EQ(AudioPluginType::Instrument, audioPluginTypeFromCategoriesString(u"Test|Instrument")); + + //! NOTE: "Instrument" has the highest priority for compatibility reasons + EXPECT_EQ(AudioPluginType::Instrument, audioPluginTypeFromCategoriesString(u"Instrument|Fx|Test")); + EXPECT_EQ(AudioPluginType::Instrument, audioPluginTypeFromCategoriesString(u"Fx|Instrument|Test")); + + EXPECT_EQ(AudioPluginType::Undefined, audioPluginTypeFromCategoriesString(u"Test")); + EXPECT_EQ(AudioPluginType::Undefined, audioPluginTypeFromCategoriesString(u"FX|Test")); + EXPECT_EQ(AudioPluginType::Undefined, audioPluginTypeFromCategoriesString(u"INSTRUMENT|Test")); +} diff --git a/src/playback/internal/playbackcontroller.cpp b/src/playback/internal/playbackcontroller.cpp index a3d0c97e9442b..b83c8ca35191f 100644 --- a/src/playback/internal/playbackcontroller.cpp +++ b/src/playback/internal/playbackcontroller.cpp @@ -23,6 +23,7 @@ #include "playbacktypes.h" +#include "audio/audioutils.h" #include "containers.h" #include "defer.h" #include "log.h"