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) 2023 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 : #pragma once
24 :
25 : #include "audiotypes.h"
26 : #include "soundfonttypes.h"
27 :
28 : namespace muse::audio {
29 0 : inline AudioResourceMeta makeReverbMeta()
30 : {
31 0 : AudioResourceMeta meta;
32 0 : meta.id = MUSE_REVERB_ID;
33 0 : meta.type = NATIVE_EFFECT_TYPE_NAME;
34 0 : meta.vendor = "Muse";
35 0 : meta.attributes.emplace(HAS_NATIVE_EDITOR_SUPPORT_ATTRIBUTE, u"true");
36 :
37 0 : return meta;
38 0 : }
39 :
40 0 : inline String audioResourceTypeToString(const muse::audioplugins::PluginType& metaType)
41 : {
42 0 : AudioResourceType type = resourceTypeFromString(metaType);
43 0 : auto search = RESOURCE_TYPE_MAP.find(type);
44 :
45 0 : if (search != RESOURCE_TYPE_MAP.end()) {
46 0 : return search->second;
47 : }
48 :
49 0 : return RESOURCE_TYPE_MAP.at(AudioResourceType::Undefined);
50 : }
51 :
52 0 : inline String audioSourceName(const AudioInputParams& params)
53 : {
54 0 : if (params.type() == AudioSourceType::MuseSampler) {
55 0 : return params.resourceMeta.attributeVal(u"museName");
56 : }
57 :
58 0 : if (isResourceType(params.resourceMeta, AudioResourceType::FluidSoundfont)) {
59 0 : const String& presetName = params.resourceMeta.attributeVal(synth::PRESET_NAME_ATTRIBUTE);
60 0 : if (!presetName.empty()) {
61 0 : return presetName;
62 : }
63 :
64 0 : const String& soundFontName = params.resourceMeta.attributeVal(synth::SOUNDFONT_NAME_ATTRIBUTE);
65 0 : if (!soundFontName.empty()) {
66 0 : return soundFontName;
67 : }
68 : }
69 :
70 0 : return String::fromStdString(params.resourceMeta.id);
71 : }
72 :
73 0 : inline String audioSourcePackName(const AudioInputParams& params)
74 : {
75 0 : if (params.type() == AudioSourceType::MuseSampler) {
76 0 : return params.resourceMeta.attributeVal(u"musePack");
77 : }
78 :
79 0 : return String();
80 : }
81 :
82 0 : inline String audioSourceCategoryName(const AudioInputParams& params)
83 : {
84 0 : if (params.type() == AudioSourceType::MuseSampler) {
85 0 : return params.resourceMeta.attributeVal(u"museCategory");
86 : }
87 :
88 0 : if (isResourceType(params.resourceMeta, AudioResourceType::FluidSoundfont)) {
89 0 : return params.resourceMeta.attributeVal(synth::SOUNDFONT_NAME_ATTRIBUTE);
90 : }
91 :
92 0 : return String::fromStdString(params.resourceMeta.id);
93 : }
94 :
95 0 : inline AudioFxCategories audioFxCategoriesFromString(const String& str)
96 : {
97 0 : if (str.empty()) {
98 0 : return {};
99 : }
100 :
101 0 : StringList list = str.split('|');
102 :
103 0 : AudioFxCategories result;
104 0 : for (const String& name : list) {
105 0 : result.insert(muse::key(AUDIO_FX_CATEGORY_TO_STRING_MAP, name, AudioFxCategory::FxOther));
106 : }
107 :
108 0 : return result;
109 0 : }
110 :
111 0 : inline bool isOnlineAudioResource(const AudioResourceMeta& meta)
112 : {
113 0 : return boolAttribute(meta, u"isOnline");
114 : }
115 : }
|