Add AudioBackend::default_device_name().
authorCarl Hetherington <cth@carlh.net>
Thu, 25 Jul 2024 14:29:27 +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 73f57b50e3070a679526ac8b9f9aa5cfecfe9615..3cb2b8d4f708ab85055239c26132a3008b0b07fc 100644 (file)
@@ -106,6 +106,22 @@ AudioBackend::output_device_names()
 }
 
 
+optional<string>
+AudioBackend::default_device_name()
+{
+#if (RTAUDIO_VERSION_MAJOR >= 6)
+       return _rtaudio.getDeviceInfo(_rtaudio.getDefaultOutputDevice()).name;
+#else
+       try {
+               return _rtaudio.getDeviceInfo(_rtaudio.getDefaultOutputDevice()).name;
+       } catch (RtAudioError&) {
+               /* Never mind */
+       }
+#endif
+       return {};
+}
+
+
 void
 AudioBackend::abort_stream_if_running()
 {
index bb1c2048fd953e856d16562ba1cbaa9741cb313b..f2a44a5fb4bc0f06150492485541c8aa78447a12 100644 (file)
@@ -23,6 +23,7 @@
 LIBDCP_DISABLE_WARNINGS
 #include <RtAudio.h>
 LIBDCP_ENABLE_WARNINGS
+#include <boost/optional.hpp>
 
 
 
@@ -39,6 +40,7 @@ public:
        }
 
        std::vector<std::string> output_device_names();
+       boost::optional<std::string> default_device_name();
        void abort_stream_if_running();
        boost::optional<std::string> start_stream();
 
index da6dcbd16edf2aedb561d1cbefeee2d7fe2fed55..d97eeecc52a13d38f4357c364c82b0552b6d59d8 100644 (file)
@@ -912,20 +912,10 @@ SoundPage::sound_changed ()
 void
 SoundPage::sound_output_changed ()
 {
-       auto& audio = AudioBackend::instance()->rtaudio();
-
        auto const so = get_sound_output();
-       string default_device;
-#if (RTAUDIO_VERSION_MAJOR >= 6)
-       default_device = audio.getDeviceInfo(audio.getDefaultOutputDevice()).name;
-#else
-       try {
-               default_device = audio.getDeviceInfo(audio.getDefaultOutputDevice()).name;
-       } catch (RtAudioError&) {
-               /* Never mind */
-       }
-#endif
-       if (!so || *so == default_device) {
+       auto default_device = AudioBackend::instance()->default_device_name();
+
+       if (!so || so == default_device) {
                Config::instance()->unset_sound_output ();
        } else {
                Config::instance()->set_sound_output (*so);
@@ -948,15 +938,7 @@ SoundPage::config_changed ()
                configured_so = config->sound_output().get();
        } else {
                /* No configured output means we should use the default */
-#if (RTAUDIO_VERSION_MAJOR >= 6)
-               configured_so = audio.getDeviceInfo(audio.getDefaultOutputDevice()).name;
-#else
-               try {
-                       configured_so = audio.getDeviceInfo(audio.getDefaultOutputDevice()).name;
-               } catch (RtAudioError&) {
-                       /* Probably no audio devices at all */
-               }
-#endif
+               configured_so = AudioBackend::instance()->default_device_name();
        }
 
        if (configured_so && current_so != configured_so) {