From 91ad46eea043673b188f5b5d4be49d66e0b7ba0d Mon Sep 17 00:00:00 2001 From: Cerapter Date: Fri, 24 Aug 2018 15:51:28 +0200 Subject: [PATCH] Fixed a Windows bug where there was no way to get back to the default audio device. --- aoapplication.h | 2 +- aoblipplayer.cpp | 3 ++- aomusicplayer.cpp | 3 ++- aooptionsdialog.cpp | 19 +++++++++++++++++++ aooptionsdialog.h | 2 ++ aosfxplayer.cpp | 3 ++- courtroom.cpp | 22 +++++++++++++++------- 7 files changed, 43 insertions(+), 11 deletions(-) diff --git a/aoapplication.h b/aoapplication.h index c5ab2bc..fe5a478 100644 --- a/aoapplication.h +++ b/aoapplication.h @@ -265,7 +265,7 @@ private: const int CCCC_RELEASE = 1; const int CCCC_MAJOR_VERSION = 3; - const int CCCC_MINOR_VERSION = 0; + const int CCCC_MINOR_VERSION = 1; QString current_theme = "default"; diff --git a/aoblipplayer.cpp b/aoblipplayer.cpp index ed8a8d7..0ea0897 100644 --- a/aoblipplayer.cpp +++ b/aoblipplayer.cpp @@ -29,7 +29,8 @@ void AOBlipPlayer::blip_tick() HSTREAM f_stream = m_stream_list[f_cycle]; - BASS_ChannelSetDevice(f_stream, BASS_GetDevice()); + if (ao_app->get_audio_output_device() != "Default") + BASS_ChannelSetDevice(f_stream, BASS_GetDevice()); BASS_ChannelPlay(f_stream, false); } diff --git a/aomusicplayer.cpp b/aomusicplayer.cpp index f69128c..9e76358 100644 --- a/aomusicplayer.cpp +++ b/aomusicplayer.cpp @@ -21,7 +21,8 @@ void AOMusicPlayer::play(QString p_song) this->set_volume(m_volume); - BASS_ChannelSetDevice(m_stream, BASS_GetDevice()); + if (ao_app->get_audio_output_device() != "Default") + BASS_ChannelSetDevice(m_stream, BASS_GetDevice()); BASS_ChannelPlay(m_stream, false); } diff --git a/aooptionsdialog.cpp b/aooptionsdialog.cpp index 3d6d5d6..7d307dd 100644 --- a/aooptionsdialog.cpp +++ b/aooptionsdialog.cpp @@ -211,6 +211,11 @@ AOOptionsDialog::AOOptionsDialog(QWidget *parent, AOApplication *p_ao_app) : QDi int a = 0; BASS_DEVICEINFO info; + if (needs_default_audiodev()) + { + AudioDeviceCombobox->addItem("Default"); + } + for (a = 0; BASS_GetDeviceInfo(a, &info); a++) { AudioDeviceCombobox->addItem(info.name); @@ -339,3 +344,17 @@ void AOOptionsDialog::discard_pressed() { done(0); } + +#if (defined (_WIN32) || defined (_WIN64)) +bool AOOptionsDialog::needs_default_audiodev() +{ + return true; +} +#elif (defined (LINUX) || defined (__linux__)) +bool AOOptionsDialog::needs_default_audiodev() +{ + return false; +} +#else +#error This operating system is not supported. +#endif diff --git a/aooptionsdialog.h b/aooptionsdialog.h index 7d09f21..a48bff9 100644 --- a/aooptionsdialog.h +++ b/aooptionsdialog.h @@ -79,6 +79,8 @@ private: QLabel *BlankBlipsLabel; QDialogButtonBox *SettingsButtons; + bool needs_default_audiodev(); + signals: public slots: diff --git a/aosfxplayer.cpp b/aosfxplayer.cpp index 667005d..df26ddf 100644 --- a/aosfxplayer.cpp +++ b/aosfxplayer.cpp @@ -23,7 +23,8 @@ void AOSfxPlayer::play(QString p_sfx, QString p_char) set_volume(m_volume); - BASS_ChannelSetDevice(m_stream, BASS_GetDevice()); + if (ao_app->get_audio_output_device() != "Default") + BASS_ChannelSetDevice(m_stream, BASS_GetDevice()); BASS_ChannelPlay(m_stream, false); } diff --git a/courtroom.cpp b/courtroom.cpp index dce4186..3b9930b 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -19,15 +19,23 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() int a = 0; BASS_DEVICEINFO info; - for (a = 0; BASS_GetDeviceInfo(a, &info); a++) + if (ao_app->get_audio_output_device() == "Default") { - if (ao_app->get_audio_output_device() == info.name) + BASS_Init(-1, 48000, BASS_DEVICE_LATENCY, 0, NULL); + BASS_PluginLoad("bassopus.dll", BASS_UNICODE); + } + else + { + for (a = 0; BASS_GetDeviceInfo(a, &info); a++) { - BASS_SetDevice(a); - BASS_Init(a, 48000, BASS_DEVICE_LATENCY, 0, NULL); - BASS_PluginLoad("bassopus.dll", BASS_UNICODE); - qDebug() << info.name << "was set as the default audio output device."; - break; + if (ao_app->get_audio_output_device() == info.name) + { + BASS_SetDevice(a); + BASS_Init(a, 48000, BASS_DEVICE_LATENCY, 0, NULL); + BASS_PluginLoad("bassopus.dll", BASS_UNICODE); + qDebug() << info.name << "was set as the default audio output device."; + break; + } } }