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) 2025 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 "generalsoundfontcontroller.h"
24 :
25 : #include "global/io/path.h"
26 :
27 : #include "audio/common/rpc/rpcpacker.h"
28 :
29 : using namespace muse;
30 : using namespace muse::audio;
31 : using namespace muse::audio::rpc;
32 : using namespace muse::audio::synth;
33 :
34 0 : void GeneralSoundFontController::loadSoundFonts()
35 : {
36 0 : configuration()->soundFontDirectoriesChanged().onReceive(this, [this](const io::paths_t&) {
37 0 : doLoadSoundFonts();
38 0 : });
39 :
40 0 : doLoadSoundFonts();
41 0 : }
42 :
43 0 : void GeneralSoundFontController::doLoadSoundFonts()
44 : {
45 0 : TRACEFUNC;
46 :
47 0 : static const std::vector<std::string> filters = { "*.sf2", "*.sf3" };
48 0 : io::paths_t dirs = configuration()->soundFontDirectories();
49 :
50 0 : std::vector<io::path_t> paths;
51 0 : for (const io::path_t& dir : dirs) {
52 0 : RetVal<io::paths_t> soundFonts = fileSystem()->scanFiles(dir, filters);
53 0 : if (!soundFonts.ret) {
54 0 : LOGE() << soundFonts.ret.toString();
55 0 : continue;
56 : }
57 :
58 0 : paths.insert(paths.end(), soundFonts.val.begin(), soundFonts.val.end());
59 0 : }
60 :
61 0 : loadSoundFonts(paths);
62 0 : }
63 :
64 0 : void GeneralSoundFontController::loadSoundFonts(const std::vector<io::path_t>& paths)
65 : {
66 0 : std::vector<synth::SoundFontUri> uris;
67 0 : uris.reserve(paths.size());
68 0 : for (const io::path_t& p : paths) {
69 0 : uris.push_back(synth::SoundFontUri::fromLocalFile(p));
70 : }
71 0 : channel()->send(rpc::make_request(rpc::GLOBAL_CTX_ID, MsgCode::LoadSoundFonts, RpcPacker::pack(uris)));
72 0 : }
73 :
74 0 : void GeneralSoundFontController::addSoundFont(const synth::SoundFontUri& uri)
75 : {
76 0 : channel()->send(rpc::make_request(rpc::GLOBAL_CTX_ID, MsgCode::AddSoundFont, RpcPacker::pack(uri)));
77 0 : }
|