Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,12 @@ bool AsioAudioDriver::open(const Spec& spec, Spec* activeSpec)
return false;
}

const char* name = spec.deviceId.c_str();
AudioDeviceID deviceId = spec.deviceId;
if (deviceId == DEFAULT_DEVICE_ID) {
deviceId = defaultDevice();
}
Comment thread
RomanPudashkin marked this conversation as resolved.

const char* name = deviceId.c_str();
bool ok = s_adata.drivers->loadDriver(const_cast<char*>(name));
if (!ok) {
LOGE() << "failed load driver: " << name;
Expand Down
5 changes: 3 additions & 2 deletions src/framework/audio/main/internal/audiodrivercontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,16 +218,17 @@ void AudioDriverController::changeCurrentAudioApi(const std::string& name)
IAudioDriverPtr driver = createDriver(name);
setNewDriver(driver);
m_audioDriver->init();
LOGI() << "Used " << m_audioDriver->name() << " audio driver";
LOGI() << "Used audio driver: " << m_audioDriver->name();

// reset to default
IAudioDriver::Spec spec = defaultSpec();
spec.callback = m_callback;

if (!spec.deviceId.empty()) {
spec.deviceId = DEFAULT_DEVICE_ID;
m_audioDriver->open(spec, nullptr);
} else {
LOGW() << "no devices for " << name;
LOGW() << "No devices for " << name;
}

configuration()->setCurrentAudioApi(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "audiomidipreferencesmodel.h"

#include "translation.h"
#include "log.h"

using namespace mu::preferences;
Expand Down Expand Up @@ -50,6 +51,28 @@ void AudioMidiPreferencesModel::setCurrentAudioApiIndex(int index)
return;
}

std::string fallbackApi = audioDriverController()->currentAudioApi();

audioDriverController()->availableOutputDevicesChanged().onNotify(this, [this, fallbackApi]() {
audioDriverController()->availableOutputDevicesChanged().disconnect(this);

if (!audioDriverController()->availableOutputDevices().empty()) {
return;
}

auto promise = interactive()->warning(
muse::trc("preferences", "No audio devices available"),
muse::qtrc("preferences", "The selected audio driver does not have any available audio devices. "
"MuseScore Studio will use the default audio driver instead. "
"To use %1, please check your hardware settings and try again.")
.arg(QString::fromStdString(audioDriverController()->currentAudioApi())).toStdString());

promise.onResolve(this, [this, fallbackApi](const muse::IInteractive::Result&) {
audioDriverController()->changeCurrentAudioApi(fallbackApi);
emit currentAudioApiIndexChanged(currentAudioApiIndex());
});
Comment thread
RomanPudashkin marked this conversation as resolved.
}, Asyncable::Mode::SetReplace);

audioDriverController()->changeCurrentAudioApi(apiList.at(index));
emit currentAudioApiIndexChanged(index);
}
Expand Down Expand Up @@ -147,9 +170,11 @@ bool AudioMidiPreferencesModel::onlineSoundsSectionVisible() const

QVariantList AudioMidiPreferencesModel::midiInputDevices() const
{
std::vector<MidiDevice> devices = midiInPort()->availableDevices();

QVariantList result;
result.reserve(devices.size());

std::vector<MidiDevice> devices = midiInPort()->availableDevices();
for (const MidiDevice& device : devices) {
QVariantMap obj;
obj["value"] = QString::fromStdString(device.id);
Expand All @@ -163,9 +188,11 @@ QVariantList AudioMidiPreferencesModel::midiInputDevices() const

QVariantList AudioMidiPreferencesModel::midiOutputDevices() const
{
std::vector<MidiDevice> devices = midiOutPort()->availableDevices();

QVariantList result;
result.reserve(devices.size());

std::vector<MidiDevice> devices = midiOutPort()->availableDevices();
for (const MidiDevice& device : devices) {
QVariantMap obj;
obj["value"] = QString::fromStdString(device.id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@

#include "modularity/ioc.h"
#include "async/asyncable.h"

#include "audio/main/iaudioconfiguration.h"
#include "audio/iaudiodrivercontroller.h"
#include "midi/imidiconfiguration.h"
#include "midi/imidioutport.h"
#include "midi/imidiinport.h"
#include "playback/iplaybackconfiguration.h"
#include "global/iinteractive.h"

namespace mu::preferences {
class AudioMidiPreferencesModel : public QObject, public muse::Contextable, public muse::async::Asyncable
Expand Down Expand Up @@ -66,6 +68,7 @@ class AudioMidiPreferencesModel : public QObject, public muse::Contextable, publ
muse::ContextInject<muse::audio::IAudioDriverController> audioDriverController = { this };
muse::ContextInject<muse::midi::IMidiOutPort> midiOutPort = { this };
muse::ContextInject<muse::midi::IMidiInPort> midiInPort = { this };
muse::ContextInject<muse::IInteractive> interactive = { this };

public:
explicit AudioMidiPreferencesModel(QObject* parent = nullptr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ BaseSection {
ComboBoxWithTitle {
id: apiComboBox

title: qsTrc("preferences", "Audio API")
title: qsTrc("preferences", "Audio driver")
columnWidth: root.columnWidth

visible: root.audioApiList.length > 1
Expand Down
Loading