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 : #include "musesampleractioncontroller.h"
23 :
24 : #include "global/translation.h"
25 :
26 : #include "rcommand/actiontocommand.h"
27 :
28 : #include "../musesamplercommands.h"
29 :
30 : #include "log.h"
31 :
32 : using namespace muse::musesampler;
33 :
34 0 : void MuseSamplerActionController::init(std::weak_ptr<MuseSamplerResolver> resolver)
35 : {
36 0 : m_museSamplerResolver = resolver;
37 :
38 0 : commandDispatcher()->onRequest(this, MUSESAMPLER_CHECK_COMMAND, [this]() { checkMuseSampler(); return muse::make_ok(); });
39 0 : commandDispatcher()->onRequest(this, MUSESAMPLER_RELOAD_COMMAND, [this]() { reloadMuseSampler(); return muse::make_ok(); });
40 :
41 : // compat
42 : {
43 : using namespace muse::rcommand;
44 : static const std::vector<ActionToCommand> actionToCommands = {
45 0 : { "musesampler-check", MUSESAMPLER_CHECK_COMMAND, {} },
46 : { "musesampler-reload", MUSESAMPLER_RELOAD_COMMAND, {} }
47 0 : };
48 :
49 0 : rcommand::registerActionToCommand(this, actionToCommands, commandDispatcher(), dispatcher());
50 : }
51 0 : }
52 :
53 0 : void MuseSamplerActionController::checkMuseSampler()
54 : {
55 0 : std::shared_ptr<MuseSamplerResolver> resolver = m_museSamplerResolver.lock();
56 0 : if (!resolver) {
57 0 : return;
58 : }
59 :
60 0 : const Version& libVersion = resolver->version();
61 0 : String libVersionStr = libVersion.toString();
62 :
63 0 : if (configuration()->shouldShowBuildNumber() && resolver->buildNumber() >= 0) {
64 0 : libVersionStr += u"." + String::number(resolver->buildNumber());
65 : }
66 :
67 0 : String status;
68 :
69 0 : if (resolver->isLoaded()) {
70 0 : status = muse::mtrc("musesampler", "MuseSampler library is detected, version %1")
71 0 : .arg(libVersionStr);
72 0 : } else if (resolver->initFailed()) {
73 0 : status = muse::mtrc("musesampler", "MuseSampler library could not be initialized, version %1")
74 0 : .arg(libVersionStr);
75 0 : } else if (!libVersion.isNull() && libVersion < configuration()->minSupportedVersion()) {
76 0 : status = muse::mtrc("musesampler", "Installed MuseSampler library is not supported, version %1")
77 0 : .arg(libVersionStr);
78 : } else {
79 0 : status = muse::mtrc("musesampler", "MuseSampler library is not found");
80 : }
81 :
82 0 : interactive()->info(status.toStdString(), std::string());
83 0 : }
84 :
85 0 : void MuseSamplerActionController::reloadMuseSampler()
86 : {
87 0 : std::shared_ptr<MuseSamplerResolver> resolver = m_museSamplerResolver.lock();
88 0 : if (resolver && resolver->reloadAllInstruments()) {
89 0 : interactive()->error("", std::string("Could not reload MuseSampler library"));
90 : }
91 0 : }
|