Add AudioBackend::output_device_names().
authorCarl Hetherington <cth@carlh.net>
Thu, 25 Jul 2024 14:28:46 +0000 (16:28 +0200)
committerCarl Hetherington <cth@carlh.net>
Fri, 26 Jul 2024 09:39:59 +0000 (11:39 +0200)
src/wx/audio_backend.cc
src/wx/audio_backend.h
src/wx/config_dialog.cc

index 351f0d78b090b8de5a4aeb4354ae83cf17fed49d..73f57b50e3070a679526ac8b9f9aa5cfecfe9615 100644 (file)
@@ -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<string>
+AudioBackend::output_device_names()
+{
+       vector<string> 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()
 {
index 91e8ccab56d970c22e76c1ce5f889e2edf9eef60..bb1c2048fd953e856d16562ba1cbaa9741cb313b 100644 (file)
@@ -38,6 +38,7 @@ public:
                return _rtaudio;
        }
 
+       std::vector<std::string> output_device_names();
        void abort_stream_if_running();
        boost::optional<std::string> start_stream();
 
index bbe2278ac84ba9fa83b7f8cd3081bc4639e5c0d7..da6dcbd16edf2aedb561d1cbefeee2d7fe2fed55 100644 (file)
@@ -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));