_sound_api->add(api.name(), new wxStringClientData(api.id()));
}
+ update_sound_outputs();
+
+ _sound->bind(&SoundPage::sound_changed, this);
+ _sound_api->bind(&SoundPage::sound_api_changed, this);
+ _sound_output->Bind(wxEVT_CHOICE, bind(&SoundPage::sound_output_changed, this));
+ _map->Changed.connect(bind(&SoundPage::map_changed, this, _1));
+ _reset_to_default->Bind(wxEVT_BUTTON, bind(&SoundPage::reset_to_default, this));
+}
+
+
+
+void
+SoundPage::update_sound_outputs()
+{
+ _sound_output->Clear();
auto& audio = _viewer->audio_backend();
for (unsigned int i = 0; i < audio.getDeviceCount(); ++i) {
try {
/* Something went wrong so let's just ignore that device */
}
}
-
- _sound->bind(&SoundPage::sound_changed, this);
- _sound_output->Bind (wxEVT_CHOICE, bind(&SoundPage::sound_output_changed, this));
- _map->Changed.connect (bind(&SoundPage::map_changed, this, _1));
- _reset_to_default->Bind (wxEVT_BUTTON, bind(&SoundPage::reset_to_default, this));
}
+
void
SoundPage::reset_to_default ()
{
Config::instance()->set_sound (_sound->GetValue ());
}
+
+void
+SoundPage::sound_api_changed()
+{
+ Config::instance()->set_sound_api(id_to_audio_api(get_sound_api()).id());
+ Config::instance()->unset_sound_output();
+}
+
+
void
SoundPage::sound_output_changed ()
{
}
}
+ update_sound_outputs();
+
auto const current_so = get_sound_output ();
optional<string> configured_so;
boost::optional<std::string> get_sound_api() const;
boost::optional<std::string> get_sound_output() const;
void sound_changed ();
+ void sound_api_changed();
void sound_output_changed ();
void setup_sensitivity ();
void map_changed (AudioMapping m);
void reset_to_default ();
+ void update_sound_outputs();
CheckBox* _sound;
Choice* _sound_api;
*/
+#include "audio_api.h"
#include "closed_captions_dialog.h"
#include "film_viewer.h"
#include "gl_video_view.h"
FilmViewer::FilmViewer (wxWindow* p)
- : _audio (DCPOMATIC_RTAUDIO_API)
+ : _audio(new RtAudio(id_to_audio_api(Config::instance()->sound_api()).rtaudio_id()))
, _closed_captions_dialog (new ClosedCaptionsDialog(p, this))
{
#if wxCHECK_VERSION(3, 1, 0)
return;
}
- if (p != Config::SOUND && p != Config::SOUND_OUTPUT) {
+ if (p != Config::SOUND && p != Config::SOUND_API && p != Config::SOUND_OUTPUT) {
return;
}
_audio->closeStream();
}
- if (Config::instance()->sound() && _audio.getDeviceCount() > 0) {
+ auto cleanup = [this]() {
+ _audio_channels = 0;
+ destroy_and_maybe_create_butler();
+ };
+
+ auto config = Config::instance();
+
+ if (!config->sound()) {
+ cleanup();
+ return;
+ }
+
+ auto configured_api = id_to_audio_api(config->sound_api()).rtaudio_id();
+
+ if (configured_api != _audio->getCurrentApi()) {
+ try {
+ delete _audio;
+ _audio = nullptr;
+ _audio = new RtAudio(configured_api);
+ } catch (RtAudioError& e) {
+ cleanup();
+ error_dialog (
+ _video_view->get(),
+ _("There was a problem starting audio playback. Please try another audio output device in Preferences."), std_to_wx(e.what())
+ );
+ return;
+ }
+ }
+
+ if (_audio->getDeviceCount() > 0) {
unsigned int st = 0;
- if (Config::instance()->sound_output()) {
+ if (config->sound_output()) {
while (st < _audio->getDeviceCount()) {
try {
- if (_audio.getDeviceInfo(st).name == Config::instance()->sound_output().get()) {
+ if (_audio->getDeviceInfo(st).name == config->sound_output().get()) {
break;
}
} catch (RtAudioError&) {
);
}
destroy_and_maybe_create_butler();
-
} else {
- _audio_channels = 0;
- destroy_and_maybe_create_butler();
+ cleanup();
}
}