Preferences: show spin to select max fps

This commit is contained in:
Duilio Protti 2016-06-23 17:35:26 -03:00
parent c6b4aa5b4b
commit acd19cbb80
10 changed files with 172 additions and 768 deletions

View File

@ -23,8 +23,7 @@ libinfinite_la_SOURCES = \
renderer.cc renderer.h\
compute.c compute.h \
display.c display.h \
infconfig.c infconfig.h\
config-dialog.c config-dialog.h\
prefs.c prefs.h\
effects.c effects.h\
cputest.c cputest.h\
mmx.h types.h
@ -32,4 +31,3 @@ libinfinite_la_SOURCES = \
INCLUDES = -I$(top_srcdir)/src -I$(top_builddir)
EXTRA_DIST = infinite_states

View File

@ -18,7 +18,7 @@
#include "config.h"
#include "compute.h"
#include "infconfig.h"
#include "prefs.h"
#ifdef MMX_DETECTION
#include "mmx.h"
#endif

View File

@ -1,256 +0,0 @@
#include "config.h"
#include "config-dialog.h"
#include "infconfig.h"
ConfigDialog *config_dialog_new(void)
{
ConfigDialog *config_win;
GtkTooltips *tooltips;
GtkWidget *window_main;
GtkWidget *vbox_main;
GtkWidget *label_scale_factor;
GtkWidget *hscale_scale_factor;
GtkWidget *frame_general;
GtkWidget *table_general;
GtkWidget *label_effect;
GtkWidget *label_palette;
GtkWidget *label_fps;
GtkWidget *checkbutton_show_title;
GtkWidget *hscale_effect;
GtkWidget *hscale_palette;
GtkObject *spinbutton_fps_adj;
GtkWidget *spinbutton_fps;
GtkWidget *hbuttonbox_main;
GtkWidget *button_ok;
GtkWidget *button_cancel;
GtkWidget *button_apply;
window_main = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_object_set_data(GTK_OBJECT(window_main), "window_main", window_main);
gtk_window_set_title(GTK_WINDOW(window_main), "Infinity Configuration");
gtk_window_set_type_hint(GTK_WINDOW(window_main), GDK_WINDOW_TYPE_HINT_DIALOG);
vbox_main = gtk_vbox_new(FALSE, 0);
gtk_widget_ref(vbox_main);
gtk_object_set_data_full(GTK_OBJECT(window_main), "vbox_main", vbox_main,
(GtkDestroyNotify)gtk_widget_unref);
gtk_widget_show(vbox_main);
gtk_container_add(GTK_CONTAINER(window_main), vbox_main);
gtk_container_set_border_width(GTK_CONTAINER(vbox_main), 2);
frame_general = gtk_frame_new("Parameters");
gtk_widget_ref(frame_general);
gtk_object_set_data_full(GTK_OBJECT(window_main), "frame_general", frame_general,
(GtkDestroyNotify)gtk_widget_unref);
gtk_widget_show(frame_general);
gtk_box_pack_start(GTK_BOX(vbox_main), frame_general, TRUE, TRUE, 0);
gtk_container_set_border_width(GTK_CONTAINER(frame_general), 2);
table_general = gtk_table_new(5, 3, FALSE);
gtk_widget_ref(table_general);
gtk_object_set_data_full(GTK_OBJECT(window_main), "table_general", table_general,
(GtkDestroyNotify)gtk_widget_unref);
gtk_widget_show(table_general);
gtk_container_add(GTK_CONTAINER(frame_general), table_general);
gtk_container_set_border_width(GTK_CONTAINER(table_general), 2);
gtk_table_set_row_spacings(GTK_TABLE(table_general), 2);
gtk_table_set_col_spacings(GTK_TABLE(table_general), 2);
label_effect = gtk_label_new("Effect period:");
gtk_widget_ref(label_effect);
gtk_object_set_data_full(GTK_OBJECT(window_main), "label_effect", label_effect,
(GtkDestroyNotify)gtk_widget_unref);
gtk_widget_show(label_effect);
gtk_table_attach(GTK_TABLE(table_general), label_effect, 0, 1, 0, 1,
(GtkAttachOptions)(GTK_FILL),
(GtkAttachOptions)(0), 0, 0);
gtk_misc_set_alignment(GTK_MISC(label_effect), 0, 0.5);
gtk_misc_set_padding(GTK_MISC(label_effect), 1, 0);
label_palette = gtk_label_new("Palette period:");
gtk_widget_ref(label_palette);
gtk_object_set_data_full(GTK_OBJECT(window_main), "label_palette", label_palette,
(GtkDestroyNotify)gtk_widget_unref);
gtk_widget_show(label_palette);
gtk_table_attach(GTK_TABLE(table_general), label_palette, 0, 1, 1, 2,
(GtkAttachOptions)(GTK_FILL),
(GtkAttachOptions)(0), 0, 0);
gtk_misc_set_alignment(GTK_MISC(label_palette), 0, 0.5);
gtk_misc_set_padding(GTK_MISC(label_palette), 1, 0);
label_scale_factor = gtk_label_new("Scale Factor");
gtk_widget_ref(label_scale_factor);
gtk_object_set_data_full(GTK_OBJECT(window_main), "label_scale_factor", label_scale_factor,
(GtkDestroyNotify)gtk_widget_unref);
gtk_widget_show(label_scale_factor);
gtk_table_attach(GTK_TABLE(table_general), label_scale_factor, 0, 1, 2, 3,
(GtkAttachOptions)(GTK_FILL),
(GtkAttachOptions)(0), 0, 0);
gtk_misc_set_alignment(GTK_MISC(label_scale_factor), 0, 0.5);
gtk_misc_set_padding(GTK_MISC(label_scale_factor), 1, 0);
label_fps = gtk_label_new("Maximum Frames per Second:");
gtk_widget_ref(label_fps);
gtk_object_set_data_full(GTK_OBJECT(window_main), "label_fps", label_fps,
(GtkDestroyNotify)gtk_widget_unref);
gtk_widget_show(label_fps);
gtk_table_attach(GTK_TABLE(table_general), label_fps, 0, 1, 3, 4,
(GtkAttachOptions)(GTK_FILL),
(GtkAttachOptions)(0), 0, 0);
gtk_misc_set_alignment(GTK_MISC(label_fps), 0, 0.5);
gtk_misc_set_padding(GTK_MISC(label_fps), 1, 0);
checkbutton_show_title = gtk_check_button_new_with_label("Show current play title");
gtk_widget_ref(checkbutton_show_title);
gtk_object_set_data_full(GTK_OBJECT(window_main), "checkbutton_show_title", checkbutton_show_title,
(GtkDestroyNotify)gtk_widget_unref);
gtk_widget_show(checkbutton_show_title);
gtk_table_attach(GTK_TABLE(table_general), checkbutton_show_title, 0, 1, 4, 5,
(GtkAttachOptions)(GTK_FILL),
(GtkAttachOptions)(0), 0, 0);
tooltips = gtk_tooltips_new();
gtk_tooltips_set_tip(tooltips, checkbutton_show_title,
"Check it if you want to see the current play "
"title on the Infinity's title bar", NULL);
//spinbutton_fps_adj = gtk_adjustment_new (30, 5, 150, 1, 10, 0);
spinbutton_fps_adj = gtk_adjustment_new(config_get_fps(), 5, 150, 1, 10, 0);
spinbutton_fps = gtk_spin_button_new(GTK_ADJUSTMENT(spinbutton_fps_adj), 1, 0);
gtk_widget_ref(spinbutton_fps);
gtk_object_set_data_full(GTK_OBJECT(window_main), "spinbutton_fps", spinbutton_fps,
(GtkDestroyNotify)gtk_widget_unref);
gtk_widget_show(spinbutton_fps);
gtk_table_attach(GTK_TABLE(table_general), spinbutton_fps, 2, 3, 3, 4,
(GtkAttachOptions)(0),
(GtkAttachOptions)(0), 0, 0);
gtk_spin_button_set_update_policy(GTK_SPIN_BUTTON(spinbutton_fps), GTK_UPDATE_IF_VALID);
hscale_effect = gtk_hscale_new(GTK_ADJUSTMENT(gtk_adjustment_new(100, 50, 400, 0, 0, 0)));
gtk_widget_ref(hscale_effect);
gtk_object_set_data_full(GTK_OBJECT(window_main), "hscale_effect", hscale_effect,
(GtkDestroyNotify)gtk_widget_unref);
gtk_widget_show(hscale_effect);
gtk_table_attach(GTK_TABLE(table_general), hscale_effect, 1, 3, 0, 1,
(GtkAttachOptions)(GTK_EXPAND | GTK_FILL),
(GtkAttachOptions)(0), 0, 0);
gtk_scale_set_value_pos(GTK_SCALE(hscale_effect), GTK_POS_LEFT);
gtk_scale_set_digits(GTK_SCALE(hscale_effect), 0);
gtk_tooltips_set_tip(tooltips, hscale_effect,
"Time to change between an effect and the "
"next one, in milliseconds.", NULL);
hscale_palette = gtk_hscale_new(GTK_ADJUSTMENT(gtk_adjustment_new(100, 50, 400, 0, 0, 0)));
gtk_widget_ref(hscale_palette);
gtk_object_set_data_full(GTK_OBJECT(window_main), "hscale_palette", hscale_palette,
(GtkDestroyNotify)gtk_widget_unref);
gtk_widget_show(hscale_palette);
gtk_table_attach(GTK_TABLE(table_general), hscale_palette, 1, 3, 1, 2,
(GtkAttachOptions)(GTK_EXPAND | GTK_FILL),
(GtkAttachOptions)(0), 0, 0);
gtk_scale_set_value_pos(GTK_SCALE(hscale_palette), GTK_POS_LEFT);
gtk_scale_set_digits(GTK_SCALE(hscale_palette), 0);
gtk_tooltips_set_tip(tooltips, hscale_palette,
"Time to change between a color and the "
"next one, in milliseconds.", NULL);
hscale_scale_factor = gtk_hscale_new(GTK_ADJUSTMENT(gtk_adjustment_new(1, 1, 2, 0, 0, 0)));
gtk_widget_ref(hscale_scale_factor);
gtk_object_set_data_full(GTK_OBJECT(window_main), "hscale_scale_factor", hscale_scale_factor,
(GtkDestroyNotify)gtk_widget_unref);
gtk_widget_show(hscale_scale_factor);
gtk_table_attach(GTK_TABLE(table_general), hscale_scale_factor, 1, 3, 2, 3,
(GtkAttachOptions)(GTK_EXPAND | GTK_FILL),
(GtkAttachOptions)(0), 0, 0);
gtk_scale_set_value_pos(GTK_SCALE(hscale_scale_factor), GTK_POS_LEFT);
gtk_scale_set_digits(GTK_SCALE(hscale_scale_factor), 0);
gtk_tooltips_set_tip(tooltips, hscale_scale_factor,
"Change only if the system doesn't have "
"enough power to show the screen at "
"a reasonably speed/size relation.", NULL);
hbuttonbox_main = gtk_hbutton_box_new();
gtk_widget_ref(hbuttonbox_main);
gtk_object_set_data_full(GTK_OBJECT(window_main), "hbuttonbox_main", hbuttonbox_main,
(GtkDestroyNotify)gtk_widget_unref);
gtk_widget_show(hbuttonbox_main);
gtk_box_pack_start(GTK_BOX(vbox_main), hbuttonbox_main, FALSE, TRUE, 0);
gtk_container_set_border_width(GTK_CONTAINER(hbuttonbox_main), 2);
gtk_button_box_set_layout(GTK_BUTTON_BOX(hbuttonbox_main), GTK_BUTTONBOX_END);
button_ok = gtk_button_new_with_label("Ok");
gtk_widget_ref(button_ok);
gtk_object_set_data_full(GTK_OBJECT(window_main), "button_ok", button_ok,
(GtkDestroyNotify)gtk_widget_unref);
gtk_widget_show(button_ok);
gtk_container_add(GTK_CONTAINER(hbuttonbox_main), button_ok);
GTK_WIDGET_SET_FLAGS(button_ok, GTK_CAN_DEFAULT);
gtk_tooltips_set_tip(tooltips, button_ok,
"For to toggle to fullscreen mode, select "
"the Infinity plugin window, and press "
"the Tab key. Pressing Tab again will return "
"to window mode.", NULL);
button_cancel = gtk_button_new_with_label("Cancel");
gtk_widget_ref(button_cancel);
gtk_object_set_data_full(GTK_OBJECT(window_main), "button_cancel", button_cancel,
(GtkDestroyNotify)gtk_widget_unref);
gtk_widget_show(button_cancel);
gtk_container_add(GTK_CONTAINER(hbuttonbox_main), button_cancel);
GTK_WIDGET_SET_FLAGS(button_cancel, GTK_CAN_DEFAULT);
button_apply = gtk_button_new_with_label("Apply");
gtk_widget_ref(button_apply);
gtk_object_set_data_full(GTK_OBJECT(window_main), "button_apply", button_apply,
(GtkDestroyNotify)gtk_widget_unref);
gtk_widget_show(button_apply);
gtk_container_add(GTK_CONTAINER(hbuttonbox_main), button_apply);
GTK_WIDGET_SET_FLAGS(button_apply, GTK_CAN_DEFAULT);
gtk_widget_grab_default(button_cancel);
config_win = g_new0(ConfigDialog, 1);
config_win->window_main = window_main;
config_win->hscale_effect = hscale_effect;
config_win->hscale_palette = hscale_palette;
config_win->hscale_scale_factor = hscale_scale_factor;
config_win->spinbutton_fps = spinbutton_fps;
config_win->checkbutton_show_title = checkbutton_show_title;
config_win->button_ok = button_ok;
config_win->button_cancel = button_cancel;
config_win->button_apply = button_apply;
gtk_tooltips_enable(tooltips);
return config_win;
}
void config_dialog_destroy(ConfigDialog *dialog)
{
g_return_if_fail(dialog != NULL);
g_free(dialog);
}
void config_dialog_show(ConfigDialog *dialog)
{
g_return_if_fail(dialog != NULL);
gtk_window_present(GTK_WINDOW(dialog->window_main));
}
void config_dialog_hide(ConfigDialog *dialog)
{
g_return_if_fail(dialog != NULL);
gtk_widget_hide(dialog->window_main);
}

View File

@ -1,34 +0,0 @@
#ifndef __CONFIG_DIALOG_H__
#define __CONFIG_DIALOG_H__
#include <gtk/gtk.h>
/**
* Here we have all the widgets of config dialog we need to interact to.
*/
typedef struct {
GtkWidget * window_main;
/* General stuff */
GtkWidget * hscale_effect; /**< GtkHScale */
GtkWidget * hscale_palette; /**< GtkHScale */
GtkWidget * hscale_scale_factor; /**< GtkHScale */
GtkWidget * spinbutton_fps; /**< GtkSpinButton */
GtkWidget * checkbutton_show_title; /** GtkCheckButton */
/* Buttons */
GtkWidget * button_ok; /**< GtkButton */
GtkWidget * button_cancel; /**< GtkButton */
GtkWidget * button_apply; /**< GtkButton */
} ConfigDialog;
ConfigDialog *config_dialog_new(void);
void config_dialog_destroy(ConfigDialog *dialog);
void config_dialog_show(ConfigDialog *dialog);
void config_dialog_hide(ConfigDialog *dialog);
#endif

View File

@ -20,7 +20,7 @@
#include "config.h"
#include "display.h"
#include "infconfig.h"
#include "prefs.h"
#define wrap(a) (a < 0 ? 0 : (a > 255 ? 255 : a))
#define assign_max(p, a) (*p <= a ? *p = a : 0)

View File

@ -1,443 +0,0 @@
#include <string.h>
#include <gtk/gtk.h>
#include <glib.h>
#include <fcntl.h>
#include "config.h"
#include "infconfig.h"
#include "config-dialog.h"
#define DEFAULT_WIDTH 512
#define DEFAULT_HEIGHT 288
#define DEFAULT_TIME_EFFECT 100
#define DEFAULT_TIME_PALETTE 100
#define DEFAULT_SCALE_FACTOR 1
#define DEFAULT_FPS 15
#define DEFAULT_SHOW_TITLE TRUE
#define INFINITY_CONFIG_DIR "/.audacious/infinity"
#define INFINITY_CONFIG_FILE (INFINITY_CONFIG_DIR "/infinity.ini")
typedef struct t_config {
gint32 x, y;
gint32 xres;
gint32 yres;
gint32 sres;
gint32 teff;
gint32 tcol;
gint32 fps;
gboolean show_title;
} t_config;
static t_config config = { -1, -1, 0, 0, 0, 0, 0, 0, DEFAULT_SHOW_TITLE };
static ConfigDialog *configure_dialog = NULL;
/*
* Here we save values selected on configure dialog, but which
* have not been yet applied, so on cancel click we just forget
* them.
*/
static t_config temp_config;
/*
*
* Private functions
*
*/
/*
* Callbacks for config_plugin_config_window
*/
static void scale_value_changed(GtkWidget *widget, gpointer data)
{
temp_config.sres = ((gint32)(GTK_ADJUSTMENT(widget)->value));
}
static void teff_value_changed(GtkWidget *widget, gpointer data)
{
temp_config.teff = ((gint32)(GTK_ADJUSTMENT(widget)->value));
}
static void tcol_value_changed(GtkWidget *widget, gpointer data)
{
temp_config.tcol = ((gint32)(GTK_ADJUSTMENT(widget)->value));
}
static void on_fps_changed(GtkWidget *widget, gpointer data)
{
gint32 value;
value = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(configure_dialog->spinbutton_fps));
temp_config.fps = value;
g_message("fps changed to %d", value);
}
static void on_show_title_toggled(GtkWidget *widget, gpointer data)
{
temp_config.show_title = !temp_config.show_title;
}
/*static gboolean check_cfg_version (ConfigFile *f)
* {
* gchar *vstr;
*
* if (xmms_cfg_read_string (f, "infinity", "version", &vstr))
* if (!strcmp (vstr, PACKAGE_VERSION))
* return TRUE;
* return FALSE;
*
* return TRUE;
* }*/
static void sync_options()
{
/*g_message ("Synchronizing options: sres %d, teff %d, tcol %d, fps %d",
* temp_config.sres, temp_config.teff, temp_config.tcol, temp_config.fps);*/
config_set_sres(temp_config.sres);
config_set_teff(temp_config.teff);
config_set_tcol(temp_config.tcol);
config_set_fps(temp_config.fps);
config_set_show_title(temp_config.show_title);
}
static void apply_clicked(GtkWidget *w, GtkWidget *window)
{
g_message("Applying changes ...");
sync_options();
config_plugin_save_prefs();
}
static void ok_clicked(GtkWidget *w, GtkWidget *window)
{
apply_clicked(w, window);
config_dialog_hide(configure_dialog);
}
static void cancel_clicked(GtkWidget *w, GtkWidget *window)
{
g_message("Cancelling changes...");
config_dialog_hide(configure_dialog);
}
static void on_config_dialog_destroy(GtkWidget *widget, gpointer data)
{
config_dialog_destroy(configure_dialog);
configure_dialog = NULL;
}
/*
* This function set widgets on configure dialog according with
* saved values. This way after cancel on a configure dialog, if
* we reopen it we get the saved values.
*/
static void set_config_values(ConfigDialog *config_dialog)
{
GtkAdjustment *teadj, *tcadj, *scale_adj;
g_return_if_fail(configure_dialog != NULL);
teadj = gtk_range_get_adjustment(GTK_RANGE(config_dialog->hscale_effect));
gtk_adjustment_set_value(teadj, config_get_teff());
tcadj = gtk_range_get_adjustment(GTK_RANGE(config_dialog->hscale_palette));
gtk_adjustment_set_value(tcadj, config_get_tcol());
scale_adj = gtk_range_get_adjustment(GTK_RANGE(config_dialog->hscale_scale_factor));
gtk_adjustment_set_value(scale_adj, config_get_sres());
gtk_spin_button_set_value(GTK_SPIN_BUTTON(config_dialog->spinbutton_fps), config_get_fps());
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(config_dialog->checkbutton_show_title), config_get_show_title());
/* Memorize current values */
temp_config.sres = config_get_sres();
temp_config.teff = config_get_teff();
temp_config.tcol = config_get_tcol();
temp_config.fps = config_get_fps();
temp_config.show_title = config_get_show_title();
}
static void connect_callbacks(ConfigDialog *configure_dialog)
{
GtkAdjustment *teadj, *tcadj, *scale_adj;
g_return_if_fail(configure_dialog != NULL);
gtk_signal_connect(GTK_OBJECT(configure_dialog->window_main), "destroy",
GTK_SIGNAL_FUNC(on_config_dialog_destroy), NULL);
teadj = gtk_range_get_adjustment(GTK_RANGE(configure_dialog->hscale_effect));
tcadj = gtk_range_get_adjustment(GTK_RANGE(configure_dialog->hscale_palette));
scale_adj = gtk_range_get_adjustment(GTK_RANGE(configure_dialog->hscale_scale_factor));
gtk_signal_connect(GTK_OBJECT(teadj), "value-changed",
GTK_SIGNAL_FUNC(teff_value_changed), NULL);
gtk_signal_connect(GTK_OBJECT(tcadj), "value-changed",
GTK_SIGNAL_FUNC(tcol_value_changed), NULL);
gtk_signal_connect(GTK_OBJECT(scale_adj), "value-changed",
GTK_SIGNAL_FUNC(scale_value_changed), NULL);
gtk_signal_connect(GTK_OBJECT(configure_dialog->spinbutton_fps), "changed",
GTK_SIGNAL_FUNC(on_fps_changed), NULL);
gtk_signal_connect(GTK_OBJECT(configure_dialog->checkbutton_show_title), "toggled",
GTK_SIGNAL_FUNC(on_show_title_toggled), NULL);
gtk_signal_connect(GTK_OBJECT(configure_dialog->button_ok), "clicked",
GTK_SIGNAL_FUNC(ok_clicked), NULL);
gtk_signal_connect(GTK_OBJECT(configure_dialog->button_cancel), "clicked",
GTK_SIGNAL_FUNC(cancel_clicked), NULL);
gtk_signal_connect(GTK_OBJECT(configure_dialog->button_apply), "clicked",
GTK_SIGNAL_FUNC(apply_clicked), NULL);
}
/*
*
* Public functions
*
*/
void config_plugin_load_prefs(void)
{
gint value;
GKeyFile *kf;
gchar *config_file_path;
gboolean error, must_update, config_file_usable;
kf = g_key_file_new();
config_file_path = g_strconcat(g_get_home_dir(), INFINITY_CONFIG_FILE, NULL);
config_file_usable = g_key_file_load_from_file(kf, config_file_path, G_KEY_FILE_KEEP_COMMENTS, NULL);
error = must_update = FALSE;
if (config_file_usable) {
if (TRUE) {
//TODO if (check_cfg_version (f)) {
// g_message("version Ok");
if ((value = g_key_file_get_integer(kf, "Preferences", "xres", NULL)) > 0)
config_set_xres(value);
else
error = TRUE;
if ((value = g_key_file_get_integer(kf, "Preferences", "yres", NULL)) > 0)
config_set_yres(value);
else
error = TRUE;
if ((value = g_key_file_get_integer(kf, "Preferences", "teff", NULL)) > 0)
config_set_teff(value);
else
error = TRUE;
if ((value = g_key_file_get_integer(kf, "Preferences", "tcol", NULL)) > 0)
config_set_tcol(value);
else
error = TRUE;
if ((value = g_key_file_get_integer(kf, "Preferences", "sres", NULL)) > 0)
config_set_sres(value);
else
error = TRUE;
if ((value = g_key_file_get_integer(kf, "Preferences", "fps", NULL)) > 0)
config_set_fps(value);
else
error = TRUE;
//config_set_show_title (g_key_file_get_boolean (kf, "Preferences", "show_title", NULL));
/* FIXME for now these are not used */
//xmms_cfg_read_int (f, "infinity", "xorig", &value);
//config_set_x (value);
//xmms_cfg_read_int (f, "infinity", "yorig", &value);
//config_set_y (value);
} else {
config_set_default_values();
must_update = TRUE;
}
} else {
config_set_default_values();
must_update = TRUE;
}
g_free(config_file_path);
g_key_file_free(kf);
if (error || must_update) {
if (error)
g_message("Fixing errors on Infinity's configure file...");
else
g_message("Updating Infinity's configure file...");
config_plugin_save_prefs();
}
}
void config_plugin_save_prefs(void)
{
gchar *config_file_path, *config_dir_path;
GKeyFile *kf;
gboolean ok;
gchar *preferences;
gsize length;
kf = g_key_file_new();
config_dir_path = g_strconcat(g_get_home_dir(), INFINITY_CONFIG_DIR, NULL);
config_file_path = g_strconcat(g_get_home_dir(), INFINITY_CONFIG_FILE, NULL);
ok = g_key_file_load_from_file(kf, config_file_path, G_KEY_FILE_KEEP_COMMENTS, NULL);
if (!ok) {
g_message("Infinity plugin .ini file not found");
if (!g_file_test(config_dir_path, G_FILE_TEST_EXISTS)) {
g_message("Creating Infinity plugin config directory '%s'", INFINITY_CONFIG_DIR);
if (g_mkdir_with_parents(config_dir_path, S_IRWXU) != 0) {
g_warning("Cannot save preferences: unable to create directory '%s'", config_dir_path);
g_free(config_file_path);
g_free(config_dir_path);
g_key_file_free(kf);
return;
}
}
}
if (!config_is_initialized())
config_set_default_values();
//g_key_file_set_value (kf, "Preferences", "version", PACKAGE_VERSION);
g_key_file_set_integer(kf, "Preferences", "xres", config_get_xres());
g_key_file_set_integer(kf, "Preferences", "yres", config_get_yres());
g_key_file_set_integer(kf, "Preferences", "teff", config_get_teff());
g_key_file_set_integer(kf, "Preferences", "tcol", config_get_tcol());
g_key_file_set_integer(kf, "Preferences", "sres", config_get_sres());
g_key_file_set_integer(kf, "Preferences", "fps", config_get_fps());
//g_key_file_set_boolean (kf, "Preferences", "show_title", config_get_show_title());
preferences = g_key_file_to_data(kf, &length, NULL);
ok = g_file_set_contents(config_file_path, preferences, length, NULL);
if (!ok)
g_warning("Error saving preferences");
g_free(preferences);
g_free(config_file_path);
g_free(config_dir_path);
g_key_file_free(kf);
}
void config_set_default_values(void)
{
config_set_x(20);
config_set_y(10);
config_set_xres(DEFAULT_WIDTH);
config_set_yres(DEFAULT_HEIGHT);
config_set_teff(DEFAULT_TIME_EFFECT);
config_set_tcol(DEFAULT_TIME_PALETTE);
config_set_sres(DEFAULT_SCALE_FACTOR);
config_set_fps(DEFAULT_FPS);
config_set_show_title(DEFAULT_SHOW_TITLE);
}
gboolean config_is_initialized(void)
{
/* FIXME mhm, ugly thing... */
//return ((config.x > -1) && (config.y > -1) &&
return (config.xres != 0) && (config.yres != 0) &&
(config.sres != 0) && (config.teff != 0) &&
(config.tcol != 0) && (config.fps != 0);
}
void config_plugin_config_window(void)
{
if (configure_dialog) {
set_config_values(configure_dialog);
config_dialog_show(configure_dialog);
return;
}
config_plugin_load_prefs();
if (!config_is_initialized())
config_set_default_values();
configure_dialog = config_dialog_new();
set_config_values(configure_dialog);
connect_callbacks(configure_dialog);
config_dialog_show(configure_dialog);
}
void config_set_x(gint32 value)
{
config.x = value;
}
void config_set_y(gint32 value)
{
config.y = value;
}
void config_set_xres(gint32 value)
{
config.xres = value;
}
void config_set_yres(gint32 value)
{
config.yres = value;
}
void config_set_teff(gint32 value)
{
config.teff = value;
}
void config_set_tcol(gint32 value)
{
config.tcol = value;
}
void config_set_sres(gint32 value)
{
config.sres = value;
}
void config_set_fps(gint32 value)
{
config.fps = value;
}
void config_set_show_title(gboolean value)
{
config.show_title = value;
}
gint32 config_get_x(void)
{
return config.x;
}
gint32 config_get_y(void)
{
return config.y;
}
gint32 config_get_xres(void)
{
return config.xres;
}
gint32 config_get_yres(void)
{
return config.yres;
}
gint32 config_get_teff(void)
{
return config.teff;
}
gint32 config_get_tcol(void)
{
return config.tcol;
}
gint32 config_get_sres(void)
{
return config.sres;
}
gint32 config_get_fps(void)
{
return config.fps;
}
gboolean config_get_show_title(void)
{
return config.show_title;
}

View File

@ -23,28 +23,34 @@
#include <string.h>
#include <libaudcore/plugin.h>
#include <libaudcore/preferences.h>
#include <gtk/gtk.h>
#include <libaudcore/runtime.h>
#include <glib/gi18n.h>
extern "C" {
#include "config.h"
#include "infconfig.h"
#include "prefs.h"
#include "renderer.h"
}
static const char about_text[] =
"Infinity Visualization Plugin for Audacious\n\n"
"Version " PACKAGE_VERSION "\n\n"
"Infinity " PACKAGE_VERSION "\n\n"
"Julien Carme, Duilio Protti\n\n"
"https://github.com/dprotti/infinity-plugin";
static const PreferencesWidget prefs_fps[] = {
WidgetLabel ("<b>Maximum Frames per Second</b>"),
WidgetSpin ("Rate:", WidgetInt (CFGID, "max_fps"), {10, 120, 1, "fps"})
};
static const PreferencesWidget prefs_widgets[] = {
WidgetLabel ("<b>Coming soon...</b>")
WidgetBox ({{prefs_fps}}),
//WidgetSeparator (),
//WidgetBox ({{...}})
};
static const PluginPreferences preferences = {{prefs_widgets}};
class InfinityPlugin : VisPlugin {
public:
static constexpr PluginInfo info = {
"Infinity",
@ -57,13 +63,12 @@ public:
bool init ();
void cleanup ();
//void * get_gtk_widget ();
void clear ();
void render_multi_pcm (const float * pcm, int channels);
};
private:
void load_settings ();
};
EXPORT InfinityPlugin aud_plugin_instance;
@ -82,23 +87,48 @@ bool InfinityPlugin::init(void)
"- Enter:\tswitch to interactive mode.\n\t\t(works only if infinity was configured with --enable-debug option)\n"
"- F11:\t\tscreenshot.\n"
"- F12:\t\tchange palette.");
config_plugin_load_prefs();
load_settings();
renderer_init();
return TRUE;
}
void InfinityPlugin::clear ()
{
g_message("TODO implement clear()");
g_message("[Infinity] clear()");
}
void InfinityPlugin::cleanup(void)
{
g_message("cleanup()");
config_plugin_save_prefs();
g_message("[Infinity] cleanup()");
config_save_prefs();
renderer_finish();
}
void InfinityPlugin::render_multi_pcm (const float * pcm, int channels) {
renderer_render_multi_pcm(pcm, channels);
}
static const char * const defaults[] = {
"width", "512",
"height", "288",
"effect_time", "100",
"palette_time", "100",
"scale_factor", "1",
"max_fps", "15",
"show_title", "true"
};
void InfinityPlugin::load_settings(void)
{
aud_config_set_defaults (CFGID, defaults);
config_set_x(20);
config_set_y(10);
config_set_xres(aud_get_int(CFGID, "width"));
config_set_yres(aud_get_int(CFGID, "height"));
config_set_teff(aud_get_int(CFGID, "effect_time"));
config_set_tcol(aud_get_int(CFGID, "palette_time"));
config_set_sres(aud_get_int(CFGID, "scale_factor"));
config_set_fps(aud_get_int(CFGID, "max_fps"));
config_set_show_title(aud_get_bool(CFGID, "show_title"));
}

121
src/prefs.c Normal file
View File

@ -0,0 +1,121 @@
#include <string.h>
#include <glib.h>
#include "config.h"
#include "prefs.h"
typedef struct t_config {
gint32 x, y;
gint32 xres;
gint32 yres;
gint32 sres;
gint32 teff;
gint32 tcol;
gint32 fps;
gboolean show_title;
} t_config;
static t_config config;
void config_save_prefs(void)
{
// TODO until it gets repaired, plugin forgets its window size when quit
g_message("TODO config_save_prefs()");
}
gboolean config_is_initialized(void)
{
return (config.xres != 0) && (config.yres != 0) &&
(config.sres != 0) && (config.teff != 0) &&
(config.tcol != 0) && (config.fps != 0);
}
void config_set_x(gint32 value)
{
config.x = value;
}
void config_set_y(gint32 value)
{
config.y = value;
}
void config_set_xres(gint32 value)
{
config.xres = value;
}
void config_set_yres(gint32 value)
{
config.yres = value;
}
void config_set_teff(gint32 value)
{
config.teff = value;
}
void config_set_tcol(gint32 value)
{
config.tcol = value;
}
void config_set_sres(gint32 value)
{
config.sres = value;
}
void config_set_fps(gint32 value)
{
config.fps = value;
}
void config_set_show_title(gboolean value)
{
config.show_title = value;
}
gint32 config_get_x(void)
{
return config.x;
}
gint32 config_get_y(void)
{
return config.y;
}
gint32 config_get_xres(void)
{
return config.xres;
}
gint32 config_get_yres(void)
{
return config.yres;
}
gint32 config_get_teff(void)
{
return config.teff;
}
gint32 config_get_tcol(void)
{
return config.tcol;
}
gint32 config_get_sres(void)
{
return config.sres;
}
gint32 config_get_fps(void)
{
return config.fps;
}
gboolean config_get_show_title(void)
{
return config.show_title;
}

View File

@ -19,6 +19,7 @@
#include <glib.h>
#define CFGID "infinity"
/*
* This structure is intended to be used for every module
@ -38,14 +39,7 @@ typedef struct _t_screen_parameters {
} t_screen_parameters;
/*
* Read user preferences from ~/.xmms/config file
*/
void config_plugin_load_prefs(void);
void config_plugin_save_prefs(void);
void config_set_default_values(void);
void config_save_prefs(void);
/*
* \return TRUE if config_plugin_load_prefs() or
@ -53,12 +47,6 @@ void config_set_default_values(void);
*/
gboolean config_is_initialized(void);
/*
* Open a window to let the user choose and
* save your options.
*/
void config_plugin_config_window(void);
void config_set_x(gint32 value);
void config_set_y(gint32 value);
void config_set_xres(gint32 value);

View File

@ -34,7 +34,7 @@
extern "C" {
#include "config.h"
#include "renderer.h"
#include "infconfig.h"
#include "prefs.h"
#include "effects.h"
#include "display.h"
@ -230,7 +230,7 @@ static gint32 event_filter(const SDL_Event *event)
}
break;
case SDL_QUIT:
config_plugin_save_prefs();
config_save_prefs();
break;
default:
break;