From 7a368ededd104d642cb6a4d735df58905903243c Mon Sep 17 00:00:00 2001 From: Brandon Wright Date: Mon, 20 Nov 2017 13:06:13 -0600 Subject: [PATCH] Add GTK+ preferences for dynamic rate control. --- gtk/src/gtk_builder_window.cpp | 7 ++- gtk/src/gtk_builder_window.h | 4 +- gtk/src/gtk_config.cpp | 12 ++++++ gtk/src/gtk_preferences.cpp | 4 ++ gtk/src/snes9x.ui | 78 +++++++++++++++++++++++++++++++--- 5 files changed, 94 insertions(+), 11 deletions(-) diff --git a/gtk/src/gtk_builder_window.cpp b/gtk/src/gtk_builder_window.cpp index 50d08113..4c739318 100644 --- a/gtk/src/gtk_builder_window.cpp +++ b/gtk/src/gtk_builder_window.cpp @@ -226,7 +226,7 @@ GtkBuilderWindow::set_combo (const char *name, unsigned char value) } void -GtkBuilderWindow::set_spin (const char *name, unsigned int value) +GtkBuilderWindow::set_spin (const char *name, double value) { gtk_spin_button_set_value (GTK_SPIN_BUTTON (get_widget (name)), (double) value); @@ -260,11 +260,10 @@ GtkBuilderWindow::get_window (void) return GTK_WINDOW (window); } -unsigned int +double GtkBuilderWindow::get_spin (const char *name) { - return (unsigned int) - gtk_spin_button_get_value (GTK_SPIN_BUTTON (get_widget (name))); + return gtk_spin_button_get_value (GTK_SPIN_BUTTON (get_widget (name))); } int diff --git a/gtk/src/gtk_builder_window.h b/gtk/src/gtk_builder_window.h index 2fe0d02b..9ef9a0d7 100644 --- a/gtk/src/gtk_builder_window.h +++ b/gtk/src/gtk_builder_window.h @@ -30,13 +30,13 @@ class GtkBuilderWindow unsigned char get_combo (const char *name); void combo_box_append (const char *name, const char *value); void combo_box_append (GtkComboBox *combo, const char *value); - unsigned int get_spin (const char *name); + double get_spin (const char *name); float get_slider (const char *name); void set_check (const char *name, unsigned char value); void set_entry_value (const char *name, unsigned int value); void set_entry_text (const char *name, const char *text); void set_combo (const char *name, unsigned char value); - void set_spin (const char *name, unsigned int value); + void set_spin (const char *name, double value); void set_slider (const char *name, float value); int has_focus (const char *widget); diff --git a/gtk/src/gtk_config.cpp b/gtk/src/gtk_config.cpp index b4db218c..3c37482d 100644 --- a/gtk/src/gtk_config.cpp +++ b/gtk/src/gtk_config.cpp @@ -253,6 +253,8 @@ Snes9xConfig::load_defaults (void) Settings.FrameTime = Settings.FrameTimeNTSC; Settings.BlockInvalidVRAMAccessMaster = TRUE; Settings.SoundSync = 1; + Settings.DynamicRateControl = 0; + Settings.DynamicRateLimit = 1000; Settings.HDMATimingHack = 100; Settings.ApplyCheats = 1; @@ -402,6 +404,8 @@ Snes9xConfig::save_config_file (void) xml_out_int (xml, "sound_driver", sound_driver); xml_out_int (xml, "sound_input_rate", sound_input_rate); xml_out_int (xml, "sound_sync", Settings.SoundSync); + xml_out_int (xml, "dynamic_rate_control", Settings.DynamicRateControl); + xml_out_int (xml, "dynamic_rate_limit", Settings.DynamicRateLimit); /* Snes9X core-stored variables */ xml_out_int (xml, "transparency", Settings.Transparency); @@ -664,6 +668,14 @@ Snes9xConfig::set_option (const char *name, const char *value) { Settings.ReverseStereo = atoi (value); } + else if (!strcasecmp (name, "dynamic_rate_control")) + { + Settings.DynamicRateControl = atoi (value); + } + else if (!strcasecmp (name, "dynamic_rate_limit")) + { + Settings.DynamicRateLimit = atoi (value); + } else if (!strcasecmp (name, "gaussian_interpolation")) { } diff --git a/gtk/src/gtk_preferences.cpp b/gtk/src/gtk_preferences.cpp index ec66c495..2ff70968 100644 --- a/gtk/src/gtk_preferences.cpp +++ b/gtk/src/gtk_preferences.cpp @@ -661,6 +661,8 @@ Snes9xPreferences::move_settings_to_dialog (void) set_spin ("sound_buffer_size", config->sound_buffer_size); set_slider ("sound_input_rate", config->sound_input_rate); set_check ("sync_sound", Settings.SoundSync); + set_check ("dynamic_rate_control", Settings.DynamicRateControl); + set_spin ("dynamic_rate_limit", Settings.DynamicRateLimit / 100000.0); set_spin ("rewind_buffer_size", config->rewind_buffer_size); set_spin ("rewind_granularity", config->rewind_granularity); @@ -816,6 +818,8 @@ Snes9xPreferences::get_settings_from_dialog (void) Settings.SoundSync = get_check ("sync_sound"); config->mute_sound = get_check ("mute_sound_check"); config->mute_sound_turbo = get_check ("mute_sound_turbo_check"); + Settings.DynamicRateControl = get_check ("dynamic_rate_control"); + Settings.DynamicRateLimit = (uint32) (get_spin ("dynamic_rate_limit") * 100000); store_ntsc_settings (); config->ntsc_scanline_intensity = get_combo ("ntsc_scanline_intensity"); diff --git a/gtk/src/snes9x.ui b/gtk/src/snes9x.ui index 465adba8..12af4edd 100644 --- a/gtk/src/snes9x.ui +++ b/gtk/src/snes9x.ui @@ -150,6 +150,13 @@ 0.01 0.10000000000000001 + + 0.001 + 0.100 + 0.010 + 0.001 + 0.010 + -1 1 @@ -4008,6 +4015,23 @@ 1 + + + + Dynamic rate control + True + True + False + Adjust input rate automatically + True + + + False + False + 2 + + + Mute sound output @@ -4021,7 +4045,7 @@ False False - 2 + 3 @@ -4037,7 +4061,7 @@ False False - 3 + 4 @@ -4053,14 +4077,14 @@ False False - 4 + 5 True False - 4 + 5 2 10 5 @@ -4135,6 +4159,50 @@ GTK_FILL + + + True + False + 0 + Dynamic rate limit: + + + 4 + 5 + GTK_FILL + GTK_FILL + + + + + True + False + + + True + True + False + False + True + True + 3 + dynamic_rate_adjustment + + + False + False + 0 + + + + + 1 + 4 + 5 + GTK_FILL + GTK_FILL + + True @@ -4229,7 +4297,7 @@ False True - 5 + 6