From 5fc64dfcf121d785de3445d10fa7510a30c55965 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 25 Jul 2024 16:28:46 +0200 Subject: Add AudioBackend::output_device_names(). --- src/wx/audio_backend.cc | 31 +++++++++++++++++++++++++++++++ src/wx/audio_backend.h | 1 + src/wx/config_dialog.cc | 22 ++-------------------- 3 files changed, 34 insertions(+), 20 deletions(-) diff --git a/src/wx/audio_backend.cc b/src/wx/audio_backend.cc index 351f0d78b..73f57b50e 100644 --- a/src/wx/audio_backend.cc +++ b/src/wx/audio_backend.cc @@ -22,6 +22,8 @@ #include "audio_backend.h" +using std::string; +using std::vector; AudioBackend* AudioBackend::_instance = nullptr; @@ -75,6 +77,35 @@ AudioBackend::instance() } +vector +AudioBackend::output_device_names() +{ + vector names; + +#if (RTAUDIO_VERSION_MAJOR >= 6) + for (auto device_id: audio.getDeviceIds()) { + auto dev = audio.getDeviceInfo(device_id); + if (dev.outputChannels > 0) { + names.push_back(dev.name); + } + } +#else + for (unsigned int i = 0; i < _rtaudio.getDeviceCount(); ++i) { + try { + auto dev = _rtaudio.getDeviceInfo(i); + if (dev.probed && dev.outputChannels > 0) { + names.push_back(dev.name); + } + } catch (RtAudioError&) { + /* Something went wrong so let's just ignore that device */ + } + } +#endif + + return names; +} + + void AudioBackend::abort_stream_if_running() { diff --git a/src/wx/audio_backend.h b/src/wx/audio_backend.h index 91e8ccab5..bb1c2048f 100644 --- a/src/wx/audio_backend.h +++ b/src/wx/audio_backend.h @@ -38,6 +38,7 @@ public: return _rtaudio; } + std::vector output_device_names(); void abort_stream_if_running(); boost::optional start_stream(); diff --git a/src/wx/config_dialog.cc b/src/wx/config_dialog.cc index bbe2278ac..da6dcbd16 100644 --- a/src/wx/config_dialog.cc +++ b/src/wx/config_dialog.cc @@ -881,27 +881,9 @@ SoundPage::setup () font.SetPointSize (font.GetPointSize() - 1); _sound_output_details->SetFont (font); - auto& audio = AudioBackend::instance()->rtaudio(); - -#if (RTAUDIO_VERSION_MAJOR >= 6) - for (auto device_id: audio.getDeviceIds()) { - auto dev = audio.getDeviceInfo(device_id); - if (dev.outputChannels > 0) { - _sound_output->Append(std_to_wx(dev.name)); - } + for (auto name: AudioBackend::instance()->output_device_names()) { + _sound_output->Append(std_to_wx(name)); } -#else - for (unsigned int i = 0; i < audio.getDeviceCount(); ++i) { - try { - auto dev = audio.getDeviceInfo (i); - if (dev.probed && dev.outputChannels > 0) { - _sound_output->Append (std_to_wx (dev.name)); - } - } catch (RtAudioError&) { - /* Something went wrong so let's just ignore that device */ - } - } -#endif _sound->bind(&SoundPage::sound_changed, this); _sound_output->Bind (wxEVT_CHOICE, bind(&SoundPage::sound_output_changed, this)); -- cgit v1.2.3