From da4bd2a018dab547b50f37af6eb3fe7b7a37a9fb Mon Sep 17 00:00:00 2001 From: BearOso Date: Wed, 17 Mar 2021 17:43:27 -0500 Subject: [PATCH] Gtk: Make sound driver check a little simpler. --- gtk/src/gtk_config.h | 1 + gtk/src/gtk_preferences.cpp | 46 +++++---------------- gtk/src/gtk_s9x.cpp | 1 + gtk/src/gtk_sound.cpp | 80 ++++++++++++++----------------------- gtk/src/gtk_sound.h | 4 ++ 5 files changed, 46 insertions(+), 86 deletions(-) diff --git a/gtk/src/gtk_config.h b/gtk/src/gtk_config.h index ce856b43..2cad3946 100644 --- a/gtk/src/gtk_config.h +++ b/gtk/src/gtk_config.h @@ -127,6 +127,7 @@ class Snes9xConfig bool netplay_server_up; /* Operational */ + std::vector sound_drivers; int sound_driver; bool mute_sound; bool mute_sound_turbo; diff --git a/gtk/src/gtk_preferences.cpp b/gtk/src/gtk_preferences.cpp index e8989610..64e55f58 100644 --- a/gtk/src/gtk_preferences.cpp +++ b/gtk/src/gtk_preferences.cpp @@ -151,19 +151,10 @@ Snes9xPreferences::Snes9xPreferences(Snes9xConfig *config) combo_box_append("hw_accel", _("XVideo - Use hardware video blitter")); -#ifdef USE_PORTAUDIO - combo_box_append("sound_driver", _("PortAudio")); -#endif -#ifdef USE_OSS - combo_box_append("sound_driver", _("Open Sound System")); -#endif - combo_box_append("sound_driver", _("SDL")); -#ifdef USE_ALSA - combo_box_append("sound_driver", _("ALSA")); -#endif -#ifdef USE_PULSEAUDIO - combo_box_append("sound_driver", _("PulseAudio")); -#endif + for (auto &name : config->sound_drivers) + { + combo_box_append("sound_driver", name.c_str()); + } } Snes9xPreferences::~Snes9xPreferences () @@ -463,24 +454,6 @@ void Snes9xPreferences::move_settings_to_dialog() set_combo ("splash_background", config->splash_image); set_check ("force_enable_icons", config->enable_icons); - int num_sound_drivers = 0; -#ifdef USE_PORTAUDIO - num_sound_drivers++; -#endif -#ifdef USE_OSS - num_sound_drivers++; -#endif - num_sound_drivers++; // SDL is automatically there. -#ifdef USE_ALSA - num_sound_drivers++; -#endif -#ifdef USE_PULSEAUDIO - num_sound_drivers++; -#endif - - if (config->sound_driver >= num_sound_drivers) - config->sound_driver = 0; - set_combo ("sound_driver", config->sound_driver); show_widget("ntsc_alignment", config->scale_method == FILTER_NTSC); @@ -956,21 +929,20 @@ void Snes9xPreferences::clear_binding(const char *name) void Snes9xPreferences::bindings_to_dialog(int joypad) { - char name[256]; Binding *bindings = (Binding *)&pad[joypad].data; set_combo("control_combo", joypad); for (int i = 0; i < NUM_JOYPAD_LINKS; i++) { - bindings[i].to_string(name); - set_entry_text(b_links[i].button_name, name); + set_entry_text(b_links[i].button_name, bindings[i].as_string().c_str()); } - for (int i = NUM_JOYPAD_LINKS; b_links[i].button_name; i++) + auto shortcut_names = &b_links[NUM_JOYPAD_LINKS]; + + for (int i = 0; shortcut_names[i].button_name; i++) { - shortcut[i - NUM_JOYPAD_LINKS].to_string(name); - set_entry_text(b_links[i].button_name, name); + set_entry_text(shortcut_names[i].button_name, shortcut[i].as_string().c_str()); } } diff --git a/gtk/src/gtk_s9x.cpp b/gtk/src/gtk_s9x.cpp index 2513b1a1..4345e832 100644 --- a/gtk/src/gtk_s9x.cpp +++ b/gtk/src/gtk_s9x.cpp @@ -63,6 +63,7 @@ int main(int argc, char *argv[]) S9xLoadConfigFiles(argv, argc); gui_config = new Snes9xConfig(); + gui_config->sound_drivers = S9xGetSoundDriverNames(); S9xInitInputDevices(); diff --git a/gtk/src/gtk_sound.cpp b/gtk/src/gtk_sound.cpp index 110d4102..1a6d2d34 100644 --- a/gtk/src/gtk_sound.cpp +++ b/gtk/src/gtk_sound.cpp @@ -54,75 +54,57 @@ int S9xSoundPowerof2(int num) return (1 << num); } +std::vector S9xGetSoundDriverNames() +{ + std::vector names; + +#ifdef USE_PORTAUDIO + names.push_back("PortAudio"); +#endif +#ifdef USE_OSS + names.push_back("OSS"); +#endif +#ifdef USE_ALSA + names.push_back("ALSA"); +#endif +#ifdef USE_PULSEAUDIO + names.push_back("PulseAudio"); +#endif + names.push_back("SDL"); + + return names; +} + void S9xPortSoundInit() { - int pao_driver = 0; - int sdl_driver = 0; - int oss_driver = 0; - int alsa_driver = 0; - int pulse_driver = 0; - int max_driver = 0; - - driver = NULL; - -#ifdef USE_PORTAUDIO - sdl_driver++; - oss_driver++; - alsa_driver++; - pulse_driver++; - - max_driver++; -#endif - -#ifdef USE_OSS - sdl_driver++; - alsa_driver++; - pulse_driver++; - - max_driver++; -#endif - - /* SDL */ - alsa_driver++; - pulse_driver++; - - max_driver++; - -#ifdef USE_ALSA - max_driver++; - pulse_driver++; -#endif - -#ifdef USE_PULSEAUDIO - max_driver++; -#endif - - if (gui_config->sound_driver >= max_driver) + if (gui_config->sound_driver >= (int)gui_config->sound_drivers.size()) gui_config->sound_driver = 0; + auto &name = gui_config->sound_drivers[gui_config->sound_driver]; + #ifdef USE_PORTAUDIO - if (gui_config->sound_driver == pao_driver) + if (name == "PortAudio") driver = new S9xPortAudioSoundDriver(); #endif #ifdef USE_OSS - if (gui_config->sound_driver == oss_driver) + if (name == "OSS") driver = new S9xOSSSoundDriver(); #endif - if (gui_config->sound_driver == sdl_driver) - driver = new S9xSDLSoundDriver(); - #ifdef USE_ALSA - if (gui_config->sound_driver == alsa_driver) + if (name == "ALSA") driver = new S9xAlsaSoundDriver(); #endif #ifdef USE_PULSEAUDIO - if (gui_config->sound_driver == pulse_driver) + if (name == "PulseAudio") driver = new S9xPulseSoundDriver(); #endif + if (name == "SDL") + driver = new S9xSDLSoundDriver(); + if (driver != NULL) { driver->init(); diff --git a/gtk/src/gtk_sound.h b/gtk/src/gtk_sound.h index 25365075..df8f92b6 100644 --- a/gtk/src/gtk_sound.h +++ b/gtk/src/gtk_sound.h @@ -7,6 +7,9 @@ #ifndef __GTK_SOUND_H #define __GTK_SOUND_H +#include +#include + void S9xPortSoundInit(); void S9xPortSoundDeinit(); void S9xPortSoundReinit(); @@ -15,5 +18,6 @@ void S9xSoundStop(); int S9xSoundBase2log(int num); int S9xSoundPowerof2(int num); +std::vector S9xGetSoundDriverNames(); #endif /* __GTK_SOUND_H */