[GTK3] Get color correction & highpass from config

This commit is contained in:
Maximilian Mader 2019-09-26 16:22:30 +02:00
parent eca563dfde
commit f68472f1c3
Signed by: Max
GPG Key ID: F71D56A3151C4FB3
3 changed files with 93 additions and 5 deletions

View File

@ -631,8 +631,8 @@ static void run(UserData *user_data) {
GB_set_pixels_output(&gb, get_current_buffer());
GB_set_rgb_encode_callback(&gb, rgb_encode);
// GB_set_sample_rate(&gb, have_aspec.freq);
// GB_set_color_correction_mode(&gb, configuration.color_correction_mode);
// GB_set_highpass_filter_mode(&gb, configuration.highpass_mode);
GB_set_color_correction_mode(&gb, get_color_correction_mode());
GB_set_highpass_filter_mode(&gb, get_highpass_mode());
GB_set_rewind_length(&gb, config.rewind_duration);
// GB_set_update_input_hint_callback(&gb, handle_events);
// GB_apu_set_sample_callback(&gb, gb_audio_callback);

View File

@ -23,6 +23,7 @@ void print_config(config_t *config) {
}
void load_config_from_key_file(config_t *config, GKeyFile *key_file) {
g_print("Loading config from key file\n");
GError *error = NULL;
gchar *group_name;
@ -48,6 +49,7 @@ void load_config_from_key_file(config_t *config, GKeyFile *key_file) {
}
void save_config_to_key_file(config_t *config, GKeyFile *key_file) {
g_print("Saving config to key file\n");
GError *error = NULL;
gchar *group_name;
@ -62,8 +64,11 @@ void save_config_to_key_file(config_t *config, GKeyFile *key_file) {
if (config->member != NULL) { \
g_key_file_set_##key_type(key_file, group_name, #member, config->member); \
} \
else { \
GError *error = NULL; \
else if (g_key_file_has_key(key_file, group_name, #member, &error)) { \
if (error != NULL) { \
g_printerr("%s\n", error->message); \
g_clear_error(&error); \
} \
g_key_file_remove_key(key_file, group_name, #member, &error); \
if (error != NULL) { \
g_printerr("%s\n", error->message); \
@ -144,6 +149,8 @@ void free_settings(void) {
}
enum menubar_override get_show_menubar(void) {
if (config.menubar_override == NULL) goto default_value;
if (g_strcmp0(config.menubar_override, "show") == 0) {
return MENUBAR_SHOW;
}
@ -151,7 +158,9 @@ enum menubar_override get_show_menubar(void) {
return MENUBAR_HIDE;
}
return MENUBAR_AUTO;
// This should not happen
g_warning("Unknown menubar setting: %s\nFalling back to “Auto”\n", config.menubar_override);
default_value: return MENUBAR_AUTO;
}
void set_show_menubar(enum menubar_override value) {
@ -168,6 +177,78 @@ void set_show_menubar(enum menubar_override value) {
}
}
GB_color_correction_mode_t get_color_correction_mode(void) {
if (config.color_correction_id == NULL) goto default_value;
if (g_strcmp0(config.color_correction_id, "disabled") == 0) {
return GB_COLOR_CORRECTION_DISABLED;
}
else if (g_strcmp0(config.color_correction_id, "correct_color_curves") == 0) {
return GB_COLOR_CORRECTION_CORRECT_CURVES;
}
else if (g_strcmp0(config.color_correction_id, "emulate_hardware") == 0) {
return GB_COLOR_CORRECTION_EMULATE_HARDWARE;
}
else if (g_strcmp0(config.color_correction_id, "preserve_brightness") == 0) {
return GB_COLOR_CORRECTION_PRESERVE_BRIGHTNESS;
}
// This should not happen
g_warning("Unknown color correction mode: %s\nFalling back to “Emulate Hardware”\n", config.color_correction_id);
default_value: return GB_COLOR_CORRECTION_EMULATE_HARDWARE;
}
void set_color_correction_mode(GB_color_correction_mode_t mode) {
switch (mode) {
case GB_COLOR_CORRECTION_DISABLED:
config.color_correction_id = "disabled";
break;
case GB_COLOR_CORRECTION_CORRECT_CURVES:
config.color_correction_id = "correct_color_curves";
break;
case GB_COLOR_CORRECTION_EMULATE_HARDWARE:
config.color_correction_id = "emulate_hardware";
break;
case GB_COLOR_CORRECTION_PRESERVE_BRIGHTNESS:
config.color_correction_id = "preserve_brightness";
break;
}
}
GB_highpass_mode_t get_highpass_mode(void) {
if (config.high_pass_filter_id == NULL) goto default_value;
if (g_strcmp0(config.high_pass_filter_id, "disabled") == 0) {
return GB_HIGHPASS_OFF;
}
else if (g_strcmp0(config.high_pass_filter_id, "emulate_hardware") == 0) {
return GB_HIGHPASS_ACCURATE;
}
else if (g_strcmp0(config.high_pass_filter_id, "preserve_waveform") == 0) {
return GB_HIGHPASS_REMOVE_DC_OFFSET;
}
// This should not happen
g_warning("Unknown highpass mode: %s\nFalling back to “Accurate”\n", config.high_pass_filter_id);
default_value: return GB_HIGHPASS_ACCURATE;
}
void set_highpass_mode(GB_highpass_mode_t mode) {
switch (mode) {
case GB_HIGHPASS_OFF:
config.high_pass_filter_id = "disabled";
break;
case GB_HIGHPASS_MAX:
g_warning("GB_HIGHPASS_MAX is not a valid highpass mode, falling back to “Accurate”.\n");
case GB_HIGHPASS_ACCURATE:
config.high_pass_filter_id = "emulate_hardware";
break;
case GB_HIGHPASS_REMOVE_DC_OFFSET:
config.high_pass_filter_id = "preserve_waveform";
break;
}
}
G_MODULE_EXPORT void on_highpass_filter_changed(GtkWidget *w, gpointer user_data_gptr) {
GtkComboBox *box = GTK_COMBO_BOX(w);
g_print("New value: %s\n", gtk_combo_box_get_active_id(box));

View File

@ -2,6 +2,7 @@
#define settings_h
#include <gtk/gtk.h>
#include <Core/gb.h>
#define SETTINGS_FILE "sameboy-gtk3-settings.ini"
@ -72,4 +73,10 @@ void free_settings(void);
enum menubar_override get_show_menubar(void);
void set_show_menubar(enum menubar_override);
GB_color_correction_mode_t get_color_correction_mode(void);
void set_color_correction_mode(GB_color_correction_mode_t);
GB_highpass_mode_t get_highpass_mode(void);
void set_highpass_mode(GB_highpass_mode_t);
#endif /* settings_h */