Add AudioBackend::device_output_channels().
authorCarl Hetherington <cth@carlh.net>
Thu, 25 Jul 2024 14:29:49 +0000 (16:29 +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 3cb2b8d4f708ab85055239c26132a3008b0b07fc..9c8b1c386d032da4ea140cf33918d93461ad739d 100644 (file)
@@ -24,6 +24,9 @@
 
 using std::string;
 using std::vector;
+using boost::optional;
+
+
 AudioBackend* AudioBackend::_instance = nullptr;
 
 
@@ -122,6 +125,33 @@ AudioBackend::default_device_name()
 }
 
 
+optional<int>
+AudioBackend::device_output_channels(string name)
+{
+#if (RTAUDIO_VERSION_MAJOR >= 6)
+       for (auto device_id: _rtaudio.getDeviceIds()) {
+               auto info = audio.getDeviceInfo(device_id);
+               if (info.name == name) {
+                       return info.outputChannels;
+               }
+       }
+#else
+       for (unsigned int i = 0; i < _rtaudio.getDeviceCount(); ++i) {
+               try {
+                       auto info = _rtaudio.getDeviceInfo(i);
+                       if (info.name == name) {
+                               return info.outputChannels;
+                       }
+               } catch (RtAudioError&) {
+                       /* Never mind */
+               }
+       }
+#endif
+
+       return {};
+}
+
+
 void
 AudioBackend::abort_stream_if_running()
 {
index f2a44a5fb4bc0f06150492485541c8aa78447a12..aa4adf13ce25000c14240d6970e2c44b57ac1ad0 100644 (file)
@@ -41,6 +41,8 @@ public:
 
        std::vector<std::string> output_device_names();
        boost::optional<std::string> default_device_name();
+       boost::optional<int> device_output_channels(std::string name);
+
        void abort_stream_if_running();
        boost::optional<std::string> start_stream();
 
index d97eeecc52a13d38f4357c364c82b0552b6d59d8..12e914742aeae0343ecfe97ce4d4439650b19448 100644 (file)
@@ -964,28 +964,7 @@ SoundPage::config_changed ()
        apis[RtAudio::LINUX_OSS]      = _("OSS");
        apis[RtAudio::RTAUDIO_DUMMY]  = _("Dummy");
 
-       int channels = 0;
-       if (configured_so) {
-#if (RTAUDIO_VERSION_MAJOR >= 6)
-               for (auto device_id: audio.getDeviceIds()) {
-                       auto info = audio.getDeviceInfo(device_id);
-                       if (info.name == *configured_so && info.outputChannels > 0) {
-                               channels = info.outputChannels;
-                       }
-               }
-#else
-               for (unsigned int i = 0; i < audio.getDeviceCount(); ++i) {
-                       try {
-                               auto info = audio.getDeviceInfo(i);
-                               if (info.name == *configured_so && info.outputChannels > 0) {
-                                       channels = info.outputChannels;
-                               }
-                       } catch (RtAudioError&) {
-                               /* Never mind */
-                       }
-               }
-#endif
-       }
+       int const channels = configured_so ? AudioBackend::instance()->device_output_channels(*configured_so).get_value_or(0) : 0;
 
        _sound_output_details->SetLabel (
                wxString::Format(_("%d channels on %s"), channels, apis[audio.getCurrentApi()])