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