Gtk: Make sound driver check a little simpler.

This commit is contained in:
BearOso 2021-03-17 17:43:27 -05:00
parent ebe96e91de
commit da4bd2a018
5 changed files with 46 additions and 86 deletions

View File

@ -127,6 +127,7 @@ class Snes9xConfig
bool netplay_server_up;
/* Operational */
std::vector<std::string> sound_drivers;
int sound_driver;
bool mute_sound;
bool mute_sound_turbo;

View File

@ -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());
}
}

View File

@ -63,6 +63,7 @@ int main(int argc, char *argv[])
S9xLoadConfigFiles(argv, argc);
gui_config = new Snes9xConfig();
gui_config->sound_drivers = S9xGetSoundDriverNames();
S9xInitInputDevices();

View File

@ -54,75 +54,57 @@ int S9xSoundPowerof2(int num)
return (1 << num);
}
std::vector<std::string> S9xGetSoundDriverNames()
{
std::vector<std::string> 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();

View File

@ -7,6 +7,9 @@
#ifndef __GTK_SOUND_H
#define __GTK_SOUND_H
#include <vector>
#include <string>
void S9xPortSoundInit();
void S9xPortSoundDeinit();
void S9xPortSoundReinit();
@ -15,5 +18,6 @@ void S9xSoundStop();
int S9xSoundBase2log(int num);
int S9xSoundPowerof2(int num);
std::vector<std::string> S9xGetSoundDriverNames();
#endif /* __GTK_SOUND_H */