Skip to content

Commit 0d2d5ee

Browse files
committed
Added ability to change audio drivers without restarting
1 parent f3de3f7 commit 0d2d5ee

25 files changed

+271
-277
lines changed

CMakeLists.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,6 @@ option(MUE_ENABLE_ENGRAVING_RENDER_DEBUG "Enable rendering debug" OFF)
131131
option(MUE_ENABLE_ENGRAVING_LD_ACCESS "Enable diagnostic engraving check layout data access" OFF)
132132
option(MUE_ENABLE_ENGRAVING_LD_PASSES "Enable engraving layout by passes" OFF)
133133

134-
if (OS_IS_LIN)
135-
option(MUSE_PIPEWIRE_AUDIO_DRIVER "Use PipeWire audio driver" OFF) # Turns ON on CI
136-
elseif (OS_IS_FBSD)
137-
option(MUSE_PIPEWIRE_AUDIO_DRIVER "Use PipeWire audio driver" OFF)
138-
endif()
139-
140134
###########################################
141135
# Setup Configure
142136
###########################################

ninja_build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ function do_build() {
102102
-DMUSE_MODULE_GLOBAL_LOGGER_DEBUGLEVEL="${MUSESCORE_DEBUGLEVEL_ENABLED}" \
103103
-DMUSE_MODULE_VST="${MUSESCORE_BUILD_VST_MODULE}" \
104104
-DMUSE_MODULE_NETWORK_WEBSOCKET="${MUSESCORE_BUILD_WEBSOCKET}" \
105-
-DMUSE_PIPEWIRE_AUDIO_DRIVER="${MUSESCORE_BUILD_PIPEWIRE_AUDIO_DRIVER}" \
105+
-DMUSE_MODULE_AUDIO_PIPEWIRE="${MUSESCORE_BUILD_PIPEWIRE_AUDIO_DRIVER}" \
106106
-DCMAKE_SKIP_RPATH="${MUSESCORE_NO_RPATH}" \
107107
-DMUSE_COMPILE_USE_UNITY="${MUSESCORE_COMPILE_USE_UNITY}"
108108

src/appshell/qml/Preferences/internal/AudioApiSection.qml

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ BaseSection {
3939
ComboBoxWithTitle {
4040
id: apiComboBox
4141

42-
property int initialIndex: -1
43-
4442
title: qsTrc("appshell/preferences", "Audio API")
4543
columnWidth: root.columnWidth
4644

@@ -56,25 +54,6 @@ BaseSection {
5654
onValueEdited: function(newIndex, newValue) {
5755
root.currentAudioApiIndexChangeRequested(newIndex)
5856
}
59-
60-
onCurrentIndexChanged: {
61-
if (apiComboBox.initialIndex !== -1) {
62-
restartRequiredLabel.visible = apiComboBox.currentIndex !== apiComboBox.initialIndex
63-
}
64-
}
65-
66-
Component.onCompleted: {
67-
apiComboBox.initialIndex = apiComboBox.currentIndex
68-
}
69-
}
70-
71-
StyledTextLabel {
72-
id: restartRequiredLabel
73-
74-
anchors.verticalCenter: parent.verticalCenter
75-
76-
text: qsTrc("appshell/preferences", "Restart required")
77-
visible: false
7857
}
7958
}
8059

src/appshell/view/preferences/audiomidipreferencesmodel.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ void AudioMidiPreferencesModel::setCurrentAudioApiIndex(int index)
5050
return;
5151
}
5252

53-
audioDriverController()->setCurrentAudioApi(apiList.at(index));
53+
audioDriverController()->changeAudioDriver(apiList.at(index));
5454
emit currentAudioApiIndexChanged(index);
5555
}
5656

@@ -108,7 +108,7 @@ void AudioMidiPreferencesModel::init()
108108
emit onlineSoundsShowProgressBarModeChanged();
109109
});
110110

111-
audioDriverController()->currentAudioApiChanged().onNotify(this, [this]() {
111+
audioDriverController()->audioDriverChanged().onNotify(this, [this]() {
112112
emit currentAudioApiIndexChanged(currentAudioApiIndex());
113113
});
114114

src/appshell/view/preferences/commonaudioapiconfigurationmodel.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ QVariantList CommonAudioApiConfigurationModel::deviceList() const
7979

8080
void CommonAudioApiConfigurationModel::deviceSelected(const QString& deviceId)
8181
{
82-
audioConfiguration()->setAudioOutputDeviceId(deviceId.toStdString());
82+
audioDriverController()->selectOutputDevice(deviceId.toStdString());
8383
}
8484

8585
unsigned int CommonAudioApiConfigurationModel::bufferSize() const
@@ -102,7 +102,7 @@ QList<unsigned int> CommonAudioApiConfigurationModel::bufferSizeList() const
102102

103103
void CommonAudioApiConfigurationModel::bufferSizeSelected(const QString& bufferSizeStr)
104104
{
105-
audioConfiguration()->setDriverBufferSize(bufferSizeStr.toInt());
105+
audioDriverController()->changeBufferSize(bufferSizeStr.toInt());
106106
}
107107

108108
unsigned int CommonAudioApiConfigurationModel::sampleRate() const
@@ -124,7 +124,7 @@ QList<unsigned int> CommonAudioApiConfigurationModel::sampleRateList() const
124124

125125
void CommonAudioApiConfigurationModel::sampleRateSelected(const QString& sampleRateStr)
126126
{
127-
audioConfiguration()->setSampleRate(sampleRateStr.toInt());
127+
audioDriverController()->changeSampleRate(sampleRateStr.toInt());
128128
}
129129

130130
muse::audio::IAudioDriverPtr CommonAudioApiConfigurationModel::audioDriver() const

src/framework/audio/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ else ()
8181
find_package(ALSA REQUIRED)
8282
set(MODULE_INCLUDE_PRIVATE ${MODULE_INCLUDE_PRIVATE} ${ALSA_INCLUDE_DIRS} )
8383
set(MODULE_LINK ${MODULE_LINK} ${ALSA_LIBRARIES} pthread )
84-
if (MUSE_PIPEWIRE_AUDIO_DRIVER)
84+
if (MUSE_MODULE_AUDIO_PIPEWIRE)
8585
pkg_check_modules(PipeWire libpipewire-0.3)
8686
if (PipeWire_FOUND)
8787
message(STATUS "Found Pipewire: ${PipeWire_LIBRARIES}")
@@ -91,7 +91,6 @@ else ()
9191
)
9292
set(MODULE_INCLUDE ${MODULE_INCLUDE} ${PipeWire_INCLUDE_DIRS} )
9393
set(MODULE_LINK ${MODULE_LINK} ${PipeWire_LIBRARIES})
94-
set(MODULE_DEF ${MODULE_DEF} -DMUSE_PIPEWIRE_AUDIO_DRIVER)
9594
else()
9695
message(WARNING "Pipewire development files not found.\nPipewire support is disabled from the build.")
9796
endif()

src/framework/audio/common/audiotypes.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737

3838
#include "mpe/events.h"
3939

40+
#include "log.h"
41+
4042
namespace muse::audio {
4143
using msecs_t = int64_t;
4244
using secs_t = muse::secs_t;
@@ -404,7 +406,16 @@ struct AudioSignalsNotifier {
404406
}
405407
}
406408

407-
AudioSignalChanges audioSignalChanges;
409+
//! NOTE It would be nice if the driver callback was called in one thread.
410+
//! But some drivers, for example PipeWire, use queues
411+
//! And then the callback can be called in different threads.
412+
//! If a score is open, we will change the audio API (change the driver)
413+
//! then the number of threads used may increase...
414+
//! Channels allow 10 threads by default. Here we're increasing that to the maximum...
415+
//! If this is not enough, then we need to make sure that the callback is called in one thread,
416+
//! or use something else here instead of channels, some kind of queues.
417+
const int _max_threads = 100;
418+
AudioSignalChanges audioSignalChanges = AudioSignalChanges(_max_threads);
408419

409420
private:
410421
static constexpr volume_dbfs_t PRESSURE_MINIMAL_VALUABLE_DIFF = volume_dbfs_t::make(2.5f);

src/framework/audio/driver/audio_driver.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ elseif(OS_IS_LIN OR OS_IS_FBSD)
7676
${CMAKE_CURRENT_LIST_DIR}/platform/lin/audiodeviceslistener.cpp
7777
${CMAKE_CURRENT_LIST_DIR}/platform/lin/audiodeviceslistener.h
7878
)
79-
if (MUSE_PIPEWIRE_AUDIO_DRIVER)
79+
if (MUSE_MODULE_AUDIO_PIPEWIRE)
8080
# this is conditionally added to module source if
8181
# pipewire is actually found on the system
8282
set(PW_AUDIO_DRIVER_SRC

src/framework/audio/driver/platform/lin/alsaaudiodriver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ void AlsaAudioDriver::init()
128128

129129
std::string AlsaAudioDriver::name() const
130130
{
131-
return "MUAUDIO(ALSA)";
131+
return "ALSA";
132132
}
133133

134134
bool AlsaAudioDriver::open(const Spec& spec, Spec* activeSpec)

src/framework/audio/driver/platform/lin/pwaudiodriver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ void PwAudioDriver::init()
614614
LOGD() << "Running with version " << pw_get_library_version();
615615
}
616616

617-
std::string PwAudioDriver::name() const { return "MUAUDIO(PipeWire)"; }
617+
std::string PwAudioDriver::name() const { return "PipeWire"; }
618618

619619
bool PwAudioDriver::open(const Spec& spec, Spec* activeSpec)
620620
{

0 commit comments

Comments
 (0)