From 7c33694c1a0f9bae8c258fb0908eba2210c27354 Mon Sep 17 00:00:00 2001 From: arcum42 Date: Sat, 25 Aug 2018 15:20:14 -0700 Subject: [PATCH] SPU2-X (Linux): Lets try this again. GTK 3 fixes. Volume slider added. Latency slider shows ms. Debug button disables and reenables. Various dialog box tweaks. --- plugins/spu2-x/src/Linux/Config.cpp | 95 ++++++++++++------- plugins/spu2-x/src/Linux/Config.h | 2 +- plugins/spu2-x/src/Linux/ConfigDebug.cpp | 19 ++-- plugins/spu2-x/src/Linux/ConfigSoundTouch.cpp | 52 ++++------ plugins/spu2-x/src/Linux/Dialogs.cpp | 36 +++++++ plugins/spu2-x/src/Linux/Dialogs.h | 9 +- 6 files changed, 133 insertions(+), 80 deletions(-) diff --git a/plugins/spu2-x/src/Linux/Config.cpp b/plugins/spu2-x/src/Linux/Config.cpp index 9d946becdc..0a75aecaf7 100644 --- a/plugins/spu2-x/src/Linux/Config.cpp +++ b/plugins/spu2-x/src/Linux/Config.cpp @@ -58,7 +58,7 @@ float VolumeAdjustBRdb; float VolumeAdjustSLdb; float VolumeAdjustSRdb; float VolumeAdjustLFEdb; -float VolumeAdjustFL; // linear coefs calcualted from decibels, +float VolumeAdjustFL; // linear coefs calculated from decibels, float VolumeAdjustC; float VolumeAdjustFR; float VolumeAdjustBL; @@ -81,6 +81,8 @@ static u32 SdlOutputAPI = 0; int numSpeakers = 0; int dplLevel = 0; +bool temp_debug_state; + /*****************************************************************************/ void ReadSettings() @@ -221,6 +223,27 @@ void debug_dialog() #if defined(__unix__) +// Format the slider with ms. +static gchar *cb_scale_format_ms(GtkScale *scale, gdouble value) +{ + return g_strdup_printf("%g ms (avg)", value); +} + +// Format the slider with a % sign. +static gchar *cb_scale_format_percent(GtkScale *scale, gdouble value) +{ + return g_strdup_printf("%g %%", value); +} + +// Disables and reenables the debug button. +static void cb_toggle_sensitivity(GtkWidget *widget, gpointer data) +{ + GtkButton *btn = static_cast(data); + + temp_debug_state = !temp_debug_state; + gtk_widget_set_sensitive(GTK_WIDGET(btn), temp_debug_state); +} + static void cb_adjust_latency(GtkComboBox *widget, gpointer data) { GtkRange *range = static_cast(data); @@ -234,14 +257,13 @@ void DisplayDialog() int return_value; GtkWidget *dialog; - GtkWidget *main_frame, *main_box; + GtkWidget *main_box; GtkWidget *mixing_frame, *mixing_box; GtkWidget *int_label, *int_box; GtkWidget *effects_check; GtkWidget *dealias_filter; - GtkWidget *debug_check; - GtkWidget *debug_button; + GtkWidget *debug_check, *debug_button, *debug_frame, *debug_box; GtkWidget *output_frame, *output_box; GtkWidget *mod_label, *mod_box; @@ -250,6 +272,7 @@ void DisplayDialog() GtkWidget *sdl_api_label, *sdl_api_box; #endif GtkWidget *latency_label, *latency_slide; + GtkWidget *volume_label, *volume_slide; GtkWidget *sync_label, *sync_box; GtkWidget *advanced_button; @@ -258,8 +281,8 @@ void DisplayDialog() "SPU2-X Config", NULL, /* parent window*/ (GtkDialogFlags)(GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT), - "OK", GTK_RESPONSE_ACCEPT, "Cancel", GTK_RESPONSE_REJECT, + "OK", GTK_RESPONSE_ACCEPT, NULL); int_label = gtk_label_new("Interpolation:"); @@ -309,13 +332,15 @@ void DisplayDialog() latency_label = gtk_label_new("Latency:"); const int min_latency = SynchMode == 0 ? LATENCY_MIN_TIMESTRETCH : LATENCY_MIN; -#if GTK_MAJOR_VERSION < 3 - latency_slide = gtk_hscale_new_with_range(min_latency, LATENCY_MAX, 5); -#else - latency_slide = gtk_scale_new_with_range(GTK_ORIENTATION_HORIZONTAL, min_latency, LATENCY_MAX, 5); -#endif + + latency_slide = spu2x_gtk_hscale_new_with_range(min_latency, LATENCY_MAX, 5); gtk_range_set_value(GTK_RANGE(latency_slide), SndOutLatencyMS); + volume_label = gtk_label_new("Volume:"); + + volume_slide = spu2x_gtk_hscale_new_with_range(0, 100, 5); + gtk_range_set_value(GTK_RANGE(volume_slide), FinalVolume * 100); + sync_label = gtk_label_new("Synchronization Mode:"); sync_box = gtk_combo_box_text_new(); gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(sync_box), "TimeStretch (Recommended)"); @@ -325,36 +350,30 @@ void DisplayDialog() advanced_button = gtk_button_new_with_label("Advanced..."); -#if GTK_MAJOR_VERSION < 3 - main_box = gtk_hbox_new(false, 5); -#else - main_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5); -#endif - main_frame = gtk_frame_new("SPU2-X Config"); - gtk_container_add(GTK_CONTAINER(main_frame), main_box); + main_box = spu2x_gtk_hbox_new(5); -#if GTK_MAJOR_VERSION < 3 - mixing_box = gtk_vbox_new(false, 5); -#else - mixing_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5); -#endif + mixing_box = spu2x_gtk_vbox_new(5); mixing_frame = gtk_frame_new("Mixing Settings:"); gtk_container_add(GTK_CONTAINER(mixing_frame), mixing_box); -#if GTK_MAJOR_VERSION < 3 - output_box = gtk_vbox_new(false, 5); -#else - output_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5); -#endif + + output_box = spu2x_gtk_vbox_new(5); output_frame = gtk_frame_new("Output Settings:"); + + debug_box = spu2x_gtk_vbox_new(5); + debug_frame = gtk_frame_new("Debug Settings:"); + + gtk_container_add(GTK_CONTAINER(debug_box), debug_check); + gtk_container_add(GTK_CONTAINER(debug_box), debug_button); + gtk_container_add(GTK_CONTAINER(debug_frame), debug_box); + gtk_container_add(GTK_CONTAINER(output_frame), output_box); gtk_container_add(GTK_CONTAINER(mixing_box), int_label); gtk_container_add(GTK_CONTAINER(mixing_box), int_box); gtk_container_add(GTK_CONTAINER(mixing_box), effects_check); gtk_container_add(GTK_CONTAINER(mixing_box), dealias_filter); - gtk_container_add(GTK_CONTAINER(mixing_box), debug_check); - gtk_container_add(GTK_CONTAINER(mixing_box), debug_button); + gtk_container_add(GTK_CONTAINER(mixing_box), debug_frame); gtk_container_add(GTK_CONTAINER(output_box), mod_label); gtk_container_add(GTK_CONTAINER(output_box), mod_box); @@ -368,20 +387,27 @@ void DisplayDialog() gtk_container_add(GTK_CONTAINER(output_box), sync_box); gtk_container_add(GTK_CONTAINER(output_box), latency_label); gtk_container_add(GTK_CONTAINER(output_box), latency_slide); + gtk_container_add(GTK_CONTAINER(output_box), volume_label); + gtk_container_add(GTK_CONTAINER(output_box), volume_slide); gtk_container_add(GTK_CONTAINER(output_box), advanced_button); - gtk_container_add(GTK_CONTAINER(main_box), mixing_frame); - gtk_container_add(GTK_CONTAINER(main_box), output_frame); + gtk_box_pack_start(GTK_BOX(main_box), mixing_frame, TRUE, TRUE, 5); + gtk_box_pack_start(GTK_BOX(main_box), output_frame, TRUE, TRUE, 5); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(effects_check), EffectsDisabled); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dealias_filter), postprocess_filter_dealias); - //FinalVolume; gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(debug_check), DebugEnabled); + gtk_widget_set_sensitive(GTK_WIDGET(debug_button), DebugEnabled); + temp_debug_state = DebugEnabled; - gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), main_frame); + gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), main_box); gtk_widget_show_all(dialog); + g_signal_connect(volume_slide, "format_value", G_CALLBACK(cb_scale_format_percent), volume_slide); + g_signal_connect(latency_slide, "format_value", G_CALLBACK(cb_scale_format_ms), latency_slide); g_signal_connect(sync_box, "changed", G_CALLBACK(cb_adjust_latency), latency_slide); + + g_signal_connect(debug_check, "clicked", G_CALLBACK(cb_toggle_sensitivity), debug_button); g_signal_connect_swapped(advanced_button, "clicked", G_CALLBACK(advanced_dialog), advanced_button); g_signal_connect_swapped(debug_button, "clicked", G_CALLBACK(debug_dialog), debug_button); @@ -394,7 +420,6 @@ void DisplayDialog() Interpolation = gtk_combo_box_get_active(GTK_COMBO_BOX(int_box)); EffectsDisabled = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(effects_check)); - //FinalVolume; if (gtk_combo_box_get_active(GTK_COMBO_BOX(mod_box)) != -1) OutputModule = gtk_combo_box_get_active(GTK_COMBO_BOX(mod_box)); @@ -433,7 +458,7 @@ void DisplayDialog() SDLOut->SetApiSettings(wxString(SDL_GetAudioDriver(SdlOutputAPI), wxConvUTF8)); } #endif - + FinalVolume = gtk_range_get_value(GTK_RANGE(volume_slide)) / 100; SndOutLatencyMS = gtk_range_get_value(GTK_RANGE(latency_slide)); if (gtk_combo_box_get_active(GTK_COMBO_BOX(sync_box)) != -1) diff --git a/plugins/spu2-x/src/Linux/Config.h b/plugins/spu2-x/src/Linux/Config.h index 54f2310a04..3be8397bb6 100644 --- a/plugins/spu2-x/src/Linux/Config.h +++ b/plugins/spu2-x/src/Linux/Config.h @@ -92,7 +92,7 @@ namespace SoundtouchCfg void ReadSettings(); void WriteSettings(); void DisplayDialog(); -}; +}; // namespace SoundtouchCfg void ReadSettings(); void WriteSettings(); diff --git a/plugins/spu2-x/src/Linux/ConfigDebug.cpp b/plugins/spu2-x/src/Linux/ConfigDebug.cpp index 5ddd77ff28..47f71a0ca4 100644 --- a/plugins/spu2-x/src/Linux/ConfigDebug.cpp +++ b/plugins/spu2-x/src/Linux/ConfigDebug.cpp @@ -161,7 +161,7 @@ void DisplayDialog() int return_value; GtkWidget *msg_box, *log_box, *dump_box, *main_box; - GtkWidget *msg_frame, *log_frame, *dump_frame, *main_frame; + GtkWidget *msg_frame, *log_frame, *dump_frame; GtkWidget *msg_console_check, *msg_key_check, *msg_voice_check, *msg_dma_check; GtkWidget *msg_autodma_check, *msg_overrun_check, *msg_cache_check; @@ -176,17 +176,14 @@ void DisplayDialog() "Spu2-X Config", NULL, // parent window (GtkDialogFlags)(GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT), - "OK", GTK_RESPONSE_ACCEPT, "Cancel", GTK_RESPONSE_REJECT, + "OK", GTK_RESPONSE_ACCEPT, NULL); - main_box = gtk_hbox_new(false, 5); - main_frame = gtk_frame_new("Spu2-X Config"); - gtk_container_add(GTK_CONTAINER(main_frame), main_box); + main_box = spu2x_gtk_hbox_new(5); // Message Section - - msg_box = gtk_vbox_new(false, 5); + msg_box = spu2x_gtk_vbox_new(5); msg_console_check = gtk_check_button_new_with_label("Show In Console"); msg_key_check = gtk_check_button_new_with_label("KeyOn/Off Events"); @@ -216,7 +213,7 @@ void DisplayDialog() gtk_container_add(GTK_CONTAINER(msg_frame), msg_box); // Log Section - log_box = gtk_vbox_new(false, 5); + log_box = spu2x_gtk_vbox_new(5); log_access_check = gtk_check_button_new_with_label("Log Register/DMA Actions"); log_dma_check = gtk_check_button_new_with_label("Log DMA Writes"); @@ -234,7 +231,7 @@ void DisplayDialog() gtk_container_add(GTK_CONTAINER(log_frame), log_box); // Dump Section - dump_box = gtk_vbox_new(false, 5); + dump_box = spu2x_gtk_vbox_new(5); dump_core_check = gtk_check_button_new_with_label("Dump Core and Voice State"); dump_mem_check = gtk_check_button_new_with_label("Dump Memory Contents"); @@ -258,7 +255,7 @@ void DisplayDialog() gtk_container_add(GTK_CONTAINER(main_box), dump_frame); // Add all our widgets, and show everything we've added to the dialog. - gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), main_frame); + gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), main_box); gtk_widget_show_all(dialog); return_value = gtk_dialog_run(GTK_DIALOG(dialog)); @@ -290,4 +287,4 @@ void DisplayDialog() { } #endif -} +} // namespace DebugConfig diff --git a/plugins/spu2-x/src/Linux/ConfigSoundTouch.cpp b/plugins/spu2-x/src/Linux/ConfigSoundTouch.cpp index fe5e786e6a..195e5189eb 100644 --- a/plugins/spu2-x/src/Linux/ConfigSoundTouch.cpp +++ b/plugins/spu2-x/src/Linux/ConfigSoundTouch.cpp @@ -87,7 +87,7 @@ void restore_defaults() void DisplayDialog() { int return_value; - GtkWidget *dialog, *main_label, *main_frame, *main_box; + GtkWidget *dialog, *main_label, *adv_box; GtkWidget *default_button; ReadSettings(); @@ -97,56 +97,44 @@ void DisplayDialog() "Advanced Settings", NULL, /* parent window*/ (GtkDialogFlags)(GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT), - "OK", GTK_RESPONSE_ACCEPT, "Cancel", GTK_RESPONSE_REJECT, + "OK", GTK_RESPONSE_ACCEPT, NULL); - main_label = gtk_label_new("These are advanced configuration options fine tuning time stretching behavior. Larger values are better for slowdown, while smaller values are better for speedup (more then 60 fps.). All options are in microseconds."); + main_label = gtk_label_new("These are advanced configuration options for fine tuning time stretching behavior. \nLarger values are better for slowdown, while smaller values are better for speedup (more then 60 fps.). \nAll options are in microseconds."); gtk_label_set_line_wrap(GTK_LABEL(main_label), true); default_button = gtk_button_new_with_label("Reset to Defaults"); seq_label = gtk_label_new("Sequence Length"); -#if GTK_MAJOR_VERSION < 3 - seq_slide = gtk_hscale_new_with_range(SequenceLen_Min, SequenceLen_Max, 2); -#else - seq_slide = gtk_scale_new_with_range(GTK_ORIENTATION_HORIZONTAL, SequenceLen_Min, SequenceLen_Max, 2); -#endif + seq_slide = spu2x_gtk_hscale_new_with_range(SequenceLen_Min, SequenceLen_Max, 2); gtk_range_set_value(GTK_RANGE(seq_slide), SequenceLenMS); seek_label = gtk_label_new("Seek Window Size"); -#if GTK_MAJOR_VERSION < 3 - seek_slide = gtk_hscale_new_with_range(SeekWindow_Min, SeekWindow_Max, 1); -#else - seek_slide = gtk_scale_new_with_range(GTK_ORIENTATION_HORIZONTAL, SeekWindow_Min, SeekWindow_Max, 1); -#endif + seek_slide = spu2x_gtk_hscale_new_with_range(SeekWindow_Min, SeekWindow_Max, 2); gtk_range_set_value(GTK_RANGE(seek_slide), SeekWindowMS); over_label = gtk_label_new("Overlap"); -#if GTK_MAJOR_VERSION < 3 - over_slide = gtk_hscale_new_with_range(Overlap_Min, Overlap_Max, 1); -#else - over_slide = gtk_scale_new_with_range(GTK_ORIENTATION_HORIZONTAL, Overlap_Min, Overlap_Max, 1); -#endif + over_slide = spu2x_gtk_hscale_new_with_range(Overlap_Min, Overlap_Max, 2); gtk_range_set_value(GTK_RANGE(over_slide), OverlapMS); - main_box = gtk_vbox_new(false, 5); - main_frame = gtk_frame_new("Spu2-X Config"); + adv_box = spu2x_gtk_vbox_new(5); - gtk_container_add(GTK_CONTAINER(main_box), default_button); - gtk_container_add(GTK_CONTAINER(main_box), seq_label); - gtk_container_add(GTK_CONTAINER(main_box), seq_slide); - gtk_container_add(GTK_CONTAINER(main_box), seek_label); - gtk_container_add(GTK_CONTAINER(main_box), seek_slide); - gtk_container_add(GTK_CONTAINER(main_box), over_label); - gtk_container_add(GTK_CONTAINER(main_box), over_slide); - gtk_container_add(GTK_CONTAINER(main_frame), main_box); + gtk_box_pack_start(GTK_BOX(adv_box), main_label, TRUE, TRUE, 0); + gtk_box_pack_start(GTK_BOX(adv_box), default_button, TRUE, TRUE, 5); - gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), main_label); - gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), main_frame); - gtk_widget_show_all(dialog); + gtk_box_pack_start(GTK_BOX(adv_box), seq_label, TRUE, TRUE, 0); + gtk_box_pack_start(GTK_BOX(adv_box), seq_slide, TRUE, TRUE, 5); + gtk_box_pack_start(GTK_BOX(adv_box), seek_label, TRUE, TRUE, 0); + gtk_box_pack_start(GTK_BOX(adv_box), seek_slide, TRUE, TRUE, 5); + + gtk_box_pack_start(GTK_BOX(adv_box), over_label, TRUE, TRUE, 0); + gtk_box_pack_start(GTK_BOX(adv_box), over_slide, TRUE, TRUE, 5); + + gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), adv_box); g_signal_connect_swapped(default_button, "clicked", G_CALLBACK(restore_defaults), default_button); + gtk_widget_show_all(dialog); return_value = gtk_dialog_run(GTK_DIALOG(dialog)); @@ -169,4 +157,4 @@ void restore_defaults() { } #endif -} +} // namespace SoundtouchCfg diff --git a/plugins/spu2-x/src/Linux/Dialogs.cpp b/plugins/spu2-x/src/Linux/Dialogs.cpp index 981ffe97e4..dff79589b6 100644 --- a/plugins/spu2-x/src/Linux/Dialogs.cpp +++ b/plugins/spu2-x/src/Linux/Dialogs.cpp @@ -64,6 +64,42 @@ void SysMessage(const wchar_t *fmt, ...) } #endif +GtkWidget *spu2x_gtk_hbox_new(int padding = 5) +{ +#if GTK_MAJOR_VERSION < 3 + return gtk_hbox_new(false, padding); +#else + return gtk_box_new(GTK_ORIENTATION_HORIZONTAL, padding); +#endif +} + +GtkWidget *spu2x_gtk_vbox_new(int padding = 5) +{ +#if GTK_MAJOR_VERSION < 3 + return gtk_vbox_new(false, padding); +#else + return gtk_box_new(GTK_ORIENTATION_VERTICAL, padding); +#endif +} + +GtkWidget *spu2x_gtk_hscale_new_with_range(double g_min, double g_max, int g_step = 5) +{ +#if GTK_MAJOR_VERSION < 3 + return gtk_hscale_new_with_range(g_min, g_max, g_step); +#else + return gtk_scale_new_with_range(GTK_ORIENTATION_HORIZONTAL, g_min, g_max, g_step); +#endif +} + +GtkWidget *spu2x_gtk_vscale_new_with_range(double g_min, double g_max, int g_step = 5) +{ +#if GTK_MAJOR_VERSION < 3 + return gtk_vscale_new_with_range(g_min, g_max, g_step); +#else + return gtk_scale_new_with_range(GTK_ORIENTATION_VERTICAL, g_min, g_max, g_step); +#endif +} + void DspUpdate() { } diff --git a/plugins/spu2-x/src/Linux/Dialogs.h b/plugins/spu2-x/src/Linux/Dialogs.h index ed9ebc1c69..1dabd7739e 100644 --- a/plugins/spu2-x/src/Linux/Dialogs.h +++ b/plugins/spu2-x/src/Linux/Dialogs.h @@ -26,7 +26,7 @@ namespace DebugConfig extern void ReadSettings(); extern void WriteSettings(); extern void DisplayDialog(); -} +} // namespace DebugConfig extern void CfgSetSettingsDir(const char *dir); extern void CfgSetLogDir(const char *dir); @@ -42,4 +42,11 @@ extern void CfgReadStr(const wchar_t *Section, const wchar_t *Name, wxString &Da extern int CfgReadInt(const wchar_t *Section, const wchar_t *Name, int Default); extern float CfgReadFloat(const wchar_t *Section, const wchar_t *Name, float Default); +#if defined(__unix__) +extern GtkWidget *spu2x_gtk_hbox_new(int padding); +extern GtkWidget *spu2x_gtk_vbox_new(int padding); +extern GtkWidget *spu2x_gtk_hscale_new_with_range(double g_min, double g_max, int g_step); +extern GtkWidget *spu2x_gtk_vscale_new_with_range(double g_min, double g_max, int g_step); +#endif + #endif