Skip to content

Commit 3273c98

Browse files
committed
now the driver controller is used everywhere, instead of the driver directlyy
1 parent a589794 commit 3273c98

13 files changed

+299
-113
lines changed

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()->changeAudioDriver(apiList.at(index));
53+
audioDriverController()->changeCurrentAudioApi(apiList.at(index));
5454
emit currentAudioApiIndexChanged(index);
5555
}
5656

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

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

src/appshell/view/preferences/commonaudioapiconfigurationmodel.cpp

Lines changed: 32 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
#include "commonaudioapiconfigurationmodel.h"
2424

25+
#include "global/translation.h"
26+
2527
#include "audio/common/audiotypes.h"
2628

2729
#include "log.h"
@@ -36,51 +38,45 @@ CommonAudioApiConfigurationModel::CommonAudioApiConfigurationModel(QObject* pare
3638

3739
void CommonAudioApiConfigurationModel::load()
3840
{
39-
auto subscribeOnDriver = [this]() {
40-
audioDriver()->availableOutputDevicesChanged().onNotify(this, [this]() {
41-
emit deviceListChanged();
42-
emit currentDeviceIdChanged();
43-
});
44-
45-
audioDriver()->outputDeviceChanged().onNotify(this, [this]() {
46-
emit currentDeviceIdChanged();
47-
emit sampleRateChanged();
48-
emit bufferSizeListChanged();
49-
emit bufferSizeChanged();
50-
});
51-
52-
audioDriver()->outputDeviceSampleRateChanged().onNotify(this, [this]() {
53-
emit sampleRateChanged();
54-
});
55-
56-
audioDriver()->outputDeviceBufferSizeChanged().onNotify(this, [this]() {
57-
emit bufferSizeChanged();
58-
});
59-
};
60-
61-
audioDriverController()->audioDriverChanged().onNotify(this, [this, subscribeOnDriver]() {
41+
audioDriverController()->currentAudioApiChanged().onNotify(this, [this]() {
6242
emit deviceListChanged();
6343
emit currentDeviceIdChanged();
6444
emit sampleRateChanged();
6545
emit bufferSizeListChanged();
6646
emit bufferSizeChanged();
47+
});
48+
49+
audioDriverController()->availableOutputDevicesChanged().onNotify(this, [this]() {
50+
emit deviceListChanged();
51+
emit currentDeviceIdChanged();
52+
});
6753

68-
subscribeOnDriver();
54+
audioDriverController()->outputDeviceChanged().onNotify(this, [this]() {
55+
emit currentDeviceIdChanged();
56+
emit sampleRateChanged();
57+
emit bufferSizeListChanged();
58+
emit bufferSizeChanged();
6959
});
7060

71-
subscribeOnDriver();
61+
audioDriverController()->outputDeviceSampleRateChanged().onNotify(this, [this]() {
62+
emit sampleRateChanged();
63+
});
64+
65+
audioDriverController()->outputDeviceBufferSizeChanged().onNotify(this, [this]() {
66+
emit bufferSizeChanged();
67+
});
7268
}
7369

7470
QString CommonAudioApiConfigurationModel::currentDeviceId() const
7571
{
76-
return QString::fromStdString(audioDriver()->outputDevice());
72+
return QString::fromStdString(audioDriverController()->outputDevice());
7773
}
7874

7975
QVariantList CommonAudioApiConfigurationModel::deviceList() const
8076
{
8177
QVariantList result;
8278

83-
AudioDeviceList devices = audioDriver()->availableOutputDevices();
79+
AudioDeviceList devices = audioDriverController()->availableOutputDevices();
8480
for (const AudioDevice& device : devices) {
8581
QVariantMap obj;
8682
obj["value"] = QString::fromStdString(device.id);
@@ -94,19 +90,23 @@ QVariantList CommonAudioApiConfigurationModel::deviceList() const
9490

9591
void CommonAudioApiConfigurationModel::deviceSelected(const QString& deviceId)
9692
{
97-
audioDriverController()->selectOutputDevice(deviceId.toStdString());
93+
bool ok = audioDriverController()->selectOutputDevice(deviceId.toStdString());
94+
if (!ok) {
95+
interactive()->error("",
96+
muse::trc("appshell/preferences", "The driver for this device could not be opened."));
97+
}
9898
}
9999

100100
unsigned int CommonAudioApiConfigurationModel::bufferSize() const
101101
{
102-
unsigned int val = audioDriver()->activeSpec().output.samplesPerChannel;
102+
unsigned int val = audioDriverController()->activeSpec().output.samplesPerChannel;
103103
return val;
104104
}
105105

106106
QList<unsigned int> CommonAudioApiConfigurationModel::bufferSizeList() const
107107
{
108108
QList<unsigned int> result;
109-
std::vector<unsigned int> bufferSizes = audioDriver()->availableOutputDeviceBufferSizes();
109+
std::vector<unsigned int> bufferSizes = audioDriverController()->availableOutputDeviceBufferSizes();
110110

111111
for (unsigned int bufferSize : bufferSizes) {
112112
result << bufferSize;
@@ -122,13 +122,13 @@ void CommonAudioApiConfigurationModel::bufferSizeSelected(const QString& bufferS
122122

123123
unsigned int CommonAudioApiConfigurationModel::sampleRate() const
124124
{
125-
return audioDriver()->activeSpec().output.sampleRate;
125+
return audioDriverController()->activeSpec().output.sampleRate;
126126
}
127127

128128
QList<unsigned int> CommonAudioApiConfigurationModel::sampleRateList() const
129129
{
130130
QList<unsigned int> result;
131-
std::vector<unsigned int> sampleRates = audioDriver()->availableOutputDeviceSampleRates();
131+
std::vector<unsigned int> sampleRates = audioDriverController()->availableOutputDeviceSampleRates();
132132

133133
for (unsigned int sampleRate : sampleRates) {
134134
result << sampleRate;
@@ -141,8 +141,3 @@ void CommonAudioApiConfigurationModel::sampleRateSelected(const QString& sampleR
141141
{
142142
audioDriverController()->changeSampleRate(sampleRateStr.toInt());
143143
}
144-
145-
muse::audio::IAudioDriverPtr CommonAudioApiConfigurationModel::audioDriver() const
146-
{
147-
return audioDriverController()->audioDriver();
148-
}

src/appshell/view/preferences/commonaudioapiconfigurationmodel.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
#include "audio/main/iaudioconfiguration.h"
3131
#include "audio/iaudiodrivercontroller.h"
32+
#include "global/iinteractive.h"
3233

3334
namespace mu::appshell {
3435
class CommonAudioApiConfigurationModel : public QObject, public muse::Injectable, public muse::async::Asyncable
@@ -46,6 +47,7 @@ class CommonAudioApiConfigurationModel : public QObject, public muse::Injectable
4647

4748
muse::Inject<muse::audio::IAudioConfiguration> audioConfiguration = { this };
4849
muse::Inject<muse::audio::IAudioDriverController> audioDriverController = { this };
50+
muse::Inject<muse::IInteractive> interactive = { this };
4951

5052
public:
5153
explicit CommonAudioApiConfigurationModel(QObject* parent = nullptr);
@@ -73,8 +75,5 @@ class CommonAudioApiConfigurationModel : public QObject, public muse::Injectable
7375

7476
void bufferSizeChanged();
7577
void bufferSizeListChanged();
76-
77-
private:
78-
muse::audio::IAudioDriverPtr audioDriver() const;
7978
};
8079
}

src/framework/audio/common/audiotypes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ static constexpr samples_t MINIMUM_BUFFER_SIZE = 128;
8080
#endif
8181

8282
static constexpr samples_t MAXIMUM_BUFFER_SIZE = 4096;
83+
static constexpr samples_t DEFAULT_BUFFER_SIZE = 1024;
8384

8485
struct OutputSpec {
8586
sample_rate_t sampleRate = 0;

src/framework/audio/driver/platform/win/asio/asioaudiodriver.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,7 @@ bool AsioAudioDriver::open(const Spec& spec, Spec* activeSpec)
412412

413413
bool AsioAudioDriver::doOpen(const AudioDeviceID& device, const Spec& spec, Spec* activeSpec)
414414
{
415+
LOGI() << "try open: " << device;
415416
const char* name = device.c_str();
416417
bool ok = s_adata.drivers.loadDriver(const_cast<char*>(name));
417418
if (!ok) {
@@ -427,7 +428,7 @@ bool AsioAudioDriver::doOpen(const AudioDeviceID& device, const Spec& spec, Spec
427428

428429
LOGI() << "asioVersion: " << s_adata.driverInfo.asioVersion
429430
<< " driverVersion: " << s_adata.driverInfo.driverVersion
430-
<< " name: " << s_adata.driverInfo.name;
431+
<< " driverName: " << s_adata.driverInfo.name;
431432

432433
// Get device metrics
433434
AsioData::DeviceMetrics& metrics = s_adata.deviceMetrics;
@@ -534,7 +535,9 @@ bool AsioAudioDriver::doOpen(const AudioDeviceID& device, const Spec& spec, Spec
534535
void AsioAudioDriver::close()
535536
{
536537
m_running = false;
537-
m_thread.join();
538+
if (m_thread.joinable()) {
539+
m_thread.join();
540+
}
538541

539542
ASIODisposeBuffers();
540543

@@ -676,7 +679,7 @@ bool AsioAudioDriver::selectOutputDevice(const AudioDeviceID& id)
676679

677680
//! NOTE We are trying to open a new device with the default value;
678681
//! it is not known what it was before.
679-
spec.output.samplesPerChannel = 1024;
682+
spec.output.samplesPerChannel = DEFAULT_BUFFER_SIZE;
680683
result = open(spec, nullptr);
681684
}
682685

src/framework/audio/iaudiodrivercontroller.h

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,34 @@ class IAudioDriverController : MODULE_EXPORT_INTERFACE
3434
public:
3535
virtual ~IAudioDriverController() = default;
3636

37+
// Api
38+
virtual std::vector<std::string> availableAudioApiList() const = 0;
39+
3740
virtual std::string currentAudioApi() const = 0;
38-
virtual IAudioDriverPtr audioDriver() const = 0;
39-
virtual void changeAudioDriver(const std::string& name) = 0;
40-
virtual async::Notification audioDriverChanged() const = 0;
41+
virtual void changeCurrentAudioApi(const std::string& name) = 0;
42+
virtual async::Notification currentAudioApiChanged() const = 0;
4143

42-
virtual std::vector<std::string> availableAudioApiList() const = 0;
44+
// Current driver operation
45+
virtual AudioDeviceList availableOutputDevices() const = 0;
46+
virtual async::Notification availableOutputDevicesChanged() const = 0;
47+
48+
virtual bool open(const IAudioDriver::Spec& spec, IAudioDriver::Spec* activeSpec) = 0;
49+
virtual void close() = 0;
50+
virtual bool isOpened() const = 0;
4351

44-
virtual void selectOutputDevice(const std::string& deviceId) = 0;
52+
virtual const IAudioDriver::Spec& activeSpec() const = 0;
53+
virtual async::Channel<IAudioDriver::Spec> activeSpecChanged() const = 0;
54+
55+
virtual AudioDeviceID outputDevice() const = 0;
56+
virtual bool selectOutputDevice(const std::string& deviceId) = 0;
57+
virtual async::Notification outputDeviceChanged() const = 0;
58+
59+
virtual std::vector<unsigned int> availableOutputDeviceBufferSizes() const = 0;
4560
virtual void changeBufferSize(samples_t samples) = 0;
61+
virtual async::Notification outputDeviceBufferSizeChanged() const = 0;
62+
63+
virtual std::vector<unsigned int> availableOutputDeviceSampleRates() const = 0;
4664
virtual void changeSampleRate(sample_rate_t sampleRate) = 0;
65+
virtual async::Notification outputDeviceSampleRateChanged() const = 0;
4766
};
4867
}

src/framework/audio/main/iaudioconfiguration.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class IAudioConfiguration : MODULE_EXPORT_INTERFACE
3939

4040
virtual AudioEngineConfig engineConfig() const = 0;
4141

42+
virtual std::string defaultAudioApi() const = 0;
4243
virtual std::string currentAudioApi() const = 0;
4344
virtual void setCurrentAudioApi(const std::string& name) = 0;
4445
virtual async::Notification currentAudioApiChanged() const = 0;

src/framework/audio/main/internal/audioconfiguration.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ void AudioConfiguration::onWorkerConfigChanged()
108108
rpcChannel()->send(rpc::make_notification(rpc::Method::EngineConfigChanged, rpc::RpcPacker::pack(engineConfig())));
109109
}
110110

111+
std::string AudioConfiguration::defaultAudioApi() const
112+
{
113+
return settings()->defaultValue(AUDIO_API_KEY).toString();
114+
}
115+
111116
std::string AudioConfiguration::currentAudioApi() const
112117
{
113118
return settings()->value(AUDIO_API_KEY).toString();

src/framework/audio/main/internal/audioconfiguration.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class AudioConfiguration : public IAudioConfiguration, public Injectable
4545
AudioEngineConfig engineConfig() const override;
4646
void onWorkerConfigChanged();
4747

48+
std::string defaultAudioApi() const override;
4849
std::string currentAudioApi() const override;
4950
void setCurrentAudioApi(const std::string& name) override;
5051
async::Notification currentAudioApiChanged() const override;

0 commit comments

Comments
 (0)