Line data Source code
1 : /*
2 : * SPDX-License-Identifier: GPL-3.0-only
3 : * MuseScore-CLA-applies
4 : *
5 : * MuseScore
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 :
23 : #include "audiodriverfactory.h"
24 :
25 : #include "muse_framework_config.h"
26 :
27 : #ifdef MUSE_MODULE_AUDIO_JACK
28 : #include "audio/driver/platform/jack/jackaudiodriver.h"
29 : #endif
30 :
31 : #if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD)
32 : #include <QtEnvironmentVariables>
33 : #include "audio/driver/platform/lin/alsaaudiodriver.h"
34 : #ifdef MUSE_MODULE_AUDIO_PIPEWIRE
35 : #include "audio/driver/platform/lin/pwaudiodriver.h"
36 : #endif
37 : #endif
38 :
39 : #ifdef Q_OS_WIN
40 : #include "audio/driver/platform/win/wasapiaudiodriver.h"
41 : #ifdef MUSE_MODULE_AUDIO_ASIO
42 : #include "audio/driver/platform/win/asio/asioaudiodriver.h"
43 : #endif
44 : #endif
45 :
46 : #ifdef Q_OS_MACOS
47 : #include "audio/driver/platform/osx/osxaudiodriver.h"
48 : #include "audio/driver/platform/osx/osxdirectaudiodriver.h"
49 : #endif
50 :
51 : #ifdef Q_OS_WASM
52 : #include "audio/driver/platform/web/webaudiodriver.h"
53 : #endif
54 :
55 : #include "log.h"
56 :
57 : using namespace muse;
58 : using namespace muse::audio;
59 :
60 0 : std::vector<std::string> AudioDriverFactory::availableAudioDrivers() const
61 : {
62 0 : std::vector<std::string> names;
63 : #ifdef MUSE_MODULE_AUDIO_JACK
64 : names.push_back("JACK");
65 : return names;
66 : #endif
67 :
68 : #ifdef Q_OS_WIN
69 : names.push_back("WASAPI");
70 : #ifdef MUSE_MODULE_AUDIO_ASIO
71 : names.push_back("ASIO");
72 : #endif
73 :
74 : return names;
75 : #endif // Q_OS_WIN
76 :
77 : #if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD)
78 0 : names.push_back("ALSA");
79 0 : if (qEnvironmentVariableIsSet("MUSESCORE_FORCE_ALSA")) {
80 0 : return names;
81 : }
82 :
83 : #ifdef MUSE_MODULE_AUDIO_PIPEWIRE
84 : names.push_back("PipeWire");
85 : #endif
86 :
87 0 : return names;
88 : #endif // Q_OS_LINUX
89 :
90 : #ifdef Q_OS_MACOS
91 : names.push_back("CoreAudio");
92 : names.push_back("CoreAudioDirect");
93 : return names;
94 : #endif
95 :
96 : #ifdef Q_OS_WASM
97 : names.push_back("WASM");
98 : return names;
99 : #endif
100 0 : }
101 :
102 0 : IAudioDriverPtr AudioDriverFactory::createDriver(const std::string& name) const
103 : {
104 : #ifdef MUSE_MODULE_AUDIO_JACK
105 : LOGW() << "required: " << name << ", but is set MUSE_MODULE_AUDIO_JACK";
106 : return std::shared_ptr<IAudioDriver>(new JackAudioDriver());
107 : #endif
108 :
109 : #ifdef Q_OS_WIN
110 : if (name == "ASIO") {
111 : #ifdef MUSE_MODULE_AUDIO_ASIO
112 : return std::shared_ptr<IAudioDriver>(new AsioAudioDriver());
113 : #else
114 : LOGW() << "ASIO is required but is not available, WASAPI will be used";
115 : #endif
116 : }
117 :
118 : // required WASAPI or fallback
119 : return std::shared_ptr<IAudioDriver>(new WasapiAudioDriver());
120 : #endif
121 :
122 : #if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD)
123 0 : if (qEnvironmentVariableIsSet("MUSESCORE_FORCE_ALSA")) {
124 0 : if (name != "ALSA") {
125 0 : LOGW() << "required: " << name << ", but is set MUSESCORE_FORCE_ALSA";
126 : }
127 0 : return std::make_shared<AlsaAudioDriver>();
128 : }
129 :
130 0 : if (name == "PipeWire") {
131 : #ifdef MUSE_MODULE_AUDIO_PIPEWIRE
132 : auto driver = std::make_shared<PwAudioDriver>();
133 : if (driver->connectedToPwServer()) {
134 : return driver;
135 : } else {
136 : LOGE() << "PipeWire driver failed connected to server";
137 : }
138 : #else
139 0 : LOGW() << "PipeWire is required but is not available, ALSA will be used";
140 : #endif
141 : }
142 :
143 : // required ALSA or fallback
144 0 : return std::make_shared<AlsaAudioDriver>();
145 : #endif
146 :
147 : #ifdef Q_OS_MACOS
148 : if (name == "CoreAudioDirect") {
149 : return std::shared_ptr<IAudioDriver>(new OSXDirectAudioDriver());
150 : }
151 : return std::shared_ptr<IAudioDriver>(new OSXAudioDriver());
152 : #endif
153 :
154 : #ifdef Q_OS_WASM
155 : UNUSED(name);
156 : return std::shared_ptr<IAudioDriver>(new WebAudioDriver());
157 : #endif
158 : }
|