Line data Source code
1 : /*
2 : * SPDX-License-Identifier: GPL-3.0-only
3 : * MuseScore-Studio-CLA-applies
4 : *
5 : * MuseScore Studio
6 : * Music Composition & Notation
7 : *
8 : * Copyright (C) 2026 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 : #include "knownaudiopluginsconfigurator.h"
23 :
24 : #include "global/serialization/json.h"
25 :
26 : #include "audio/common/audiotypes.h"
27 : #include "mpe/playbacksetupdata.h"
28 :
29 : using namespace mu::playback;
30 : using namespace muse::audioplugins;
31 :
32 0 : void KnownAudioPluginsConfigurator::init()
33 : {
34 0 : if (m_audioPluginConfiguration()) {
35 0 : PluginAttributes runtimeDefaults;
36 0 : runtimeDefaults.emplace(muse::audio::PLAYBACK_SETUP_DATA_ATTRIBUTE,
37 : muse::mpe::GENERIC_SETUP_DATA_STRING);
38 0 : m_audioPluginConfiguration()->setRuntimeAttributeDefaults(runtimeDefaults);
39 0 : }
40 :
41 : // app-specific migrations only; framework registers v0->v2
42 0 : if (m_migrationRegister()) {
43 : // v2 -> v3: hasNativeEditorSupport -> meta.attributes
44 0 : m_migrationRegister()->registerMigration(2, [](const muse::JsonArray& plugins) {
45 0 : const std::string nativeEditorKey = muse::audio::HAS_NATIVE_EDITOR_SUPPORT_ATTRIBUTE.toStdString();
46 0 : muse::JsonArray out;
47 0 : for (size_t i = 0; i < plugins.size(); ++i) {
48 0 : muse::JsonObject obj = plugins.at(i).toObject();
49 0 : muse::JsonObject meta = obj.value("meta").toObject();
50 0 : if (meta.contains(nativeEditorKey)) {
51 0 : muse::JsonObject attrs;
52 0 : if (meta.contains("attributes")) {
53 0 : attrs = meta.value("attributes").toObject();
54 : }
55 0 : const bool b = meta.value(nativeEditorKey).toBool();
56 0 : attrs.set(nativeEditorKey, b ? std::string("true") : std::string("false"));
57 0 : meta.set("attributes", attrs);
58 :
59 : // JsonObject has no remove(); rebuild without the legacy key.
60 0 : muse::JsonObject metaWithoutLegacy;
61 0 : for (const std::string& k : meta.keys()) {
62 0 : if (k == nativeEditorKey) {
63 0 : continue;
64 : }
65 0 : metaWithoutLegacy.set(k, meta.value(k));
66 0 : }
67 0 : obj.set("meta", metaWithoutLegacy);
68 0 : }
69 0 : out << obj;
70 0 : }
71 0 : return out;
72 0 : });
73 : }
74 0 : }
|