changeset 4711:a33facf19590

more work on seperating presets from legacy ui
author Tomasz Mon <desowin@gmail.com>
date Tue, 08 Jul 2008 15:35:48 +0200
parents c6c692d368b1
children 6584bba8de63
files src/audacious/equalizer_preset.c src/audacious/equalizer_preset.h src/audacious/legacy/ui_equalizer.c src/audacious/plugin.h src/audacious/pluginenum.c
diffstat 5 files changed, 107 insertions(+), 57 deletions(-) [+]
line wrap: on
line diff
--- a/src/audacious/equalizer_preset.c	Tue Jul 08 12:26:34 2008 +0900
+++ b/src/audacious/equalizer_preset.c	Tue Jul 08 15:35:48 2008 +0200
@@ -183,3 +183,58 @@
     return NULL;
 }
 
+void
+save_preset_file(EqualizerPreset *preset, const gchar * filename)
+{
+    RcFile *rcfile;
+    gint i;
+
+    rcfile = aud_rcfile_new();
+    aud_rcfile_write_float(rcfile, "Equalizer preset", "Preamp",
+                           preset->preamp);
+
+    for (i = 0; i < 10; i++) {
+        gchar tmp[7];
+        g_snprintf(tmp, sizeof(tmp), "Band%d", i);
+        aud_rcfile_write_float(rcfile, "Equalizer preset", tmp,
+                               preset->bands[i]);
+    }
+
+    aud_rcfile_write(rcfile, filename);
+    aud_rcfile_free(rcfile);
+}
+
+EqualizerPreset *
+equalizer_read_aud_preset(const gchar * filename)
+{
+    gfloat val;
+    gint i;
+    EqualizerPreset *preset = g_new0(EqualizerPreset, 1);
+    preset->name = g_strdup("");
+
+    RcFile *rcfile = aud_rcfile_open(filename);
+    if (rcfile == NULL)
+        return NULL;
+
+    if (aud_rcfile_read_float(rcfile, "Equalizer preset", "Preamp", &val))
+        preset->preamp = val;
+    for (i = 0; i < 10; i++) {
+        gchar tmp[7];
+        g_snprintf(tmp, sizeof(tmp), "Band%d", i);
+        if (aud_rcfile_read_float(rcfile, "Equalizer preset", tmp, &val))
+            preset->bands[i] = val;
+    }
+    aud_rcfile_free(rcfile);
+    return preset;
+}
+
+EqualizerPreset *
+load_preset_file(const gchar *filename)
+{
+    if (filename) {
+        EqualizerPreset *preset = equalizer_read_aud_preset(filename);
+        return preset;
+    }
+    return NULL;
+}
+
--- a/src/audacious/equalizer_preset.h	Tue Jul 08 12:26:34 2008 +0900
+++ b/src/audacious/equalizer_preset.h	Tue Jul 08 15:35:48 2008 +0200
@@ -20,6 +20,8 @@
 #ifndef AUDACIOUS_EQUALIZER_PRESET_H
 #define AUDACIOUS_EQUALIZER_PRESET_H
 
+#include "audacious/rcfile.h"
+
 struct _EqualizerPreset {
     gchar *name;
     gfloat preamp, bands[10];
@@ -32,5 +34,9 @@
 GList * equalizer_read_presets(const gchar * basename);
 void    equalizer_write_preset_file(GList * list, const gchar * basename);
 GList * import_winamp_eqf(VFSFile * file);
+void    save_preset_file(EqualizerPreset *preset, const gchar * filename);
+
+EqualizerPreset * equalizer_read_aud_preset(const gchar * filename);
+EqualizerPreset * load_preset_file(const gchar *filename);
 
 #endif
--- a/src/audacious/legacy/ui_equalizer.c	Tue Jul 08 12:26:34 2008 +0900
+++ b/src/audacious/legacy/ui_equalizer.c	Tue Jul 08 15:35:48 2008 +0200
@@ -173,6 +173,21 @@
 }
 
 static void
+equalizerwin_apply_preset(EqualizerPreset *preset)
+{
+    if (preset == NULL)
+       return;
+
+    gint i;
+
+    ui_skinned_equalizer_slider_set_position(equalizerwin_preamp, preset->preamp);
+    for (i = 0; i < 10; i++) {
+        ui_skinned_equalizer_slider_set_position(equalizerwin_bands[i], preset->bands[i]);
+    }
+    equalizerwin_eq_changed();
+}
+
+static void
 equalizerwin_on_pushed(void)
 {
     cfg.equalizer_active = UI_SKINNED_BUTTON(equalizerwin_on)->inside;
@@ -672,20 +687,13 @@
 }
 
 static void
-equalizerwin_read_aud_preset(RcFile * rcfile)
+equalizerwin_read_aud_preset(gchar * filename)
 {
-    gfloat val;
-    gint i;
-
-    if (aud_rcfile_read_float(rcfile, "Equalizer preset", "Preamp", &val))
-        ui_skinned_equalizer_slider_set_position(equalizerwin_preamp, val);
-    for (i = 0; i < 10; i++) {
-        gchar tmp[7];
-        g_snprintf(tmp, sizeof(tmp), "Band%d", i);
-        if (aud_rcfile_read_float(rcfile, "Equalizer preset", tmp, &val))
-            ui_skinned_equalizer_slider_set_position(equalizerwin_bands[i], val);
+    EqualizerPreset *preset = equalizer_read_aud_preset(filename);
+    if (preset) {
+        equalizerwin_apply_preset(preset);
+        equalizer_preset_free(preset);
     }
-    equalizerwin_eq_changed();
 }
 
 static void
@@ -831,18 +839,6 @@
     equalizerwin_delete_selected_presets(GTK_TREE_VIEW(data), "eq.auto_preset");
 }
 
-
-static void
-load_preset_file(const gchar *filename)
-{
-    RcFile *rcfile;
-
-    if ((rcfile = aud_rcfile_open(filename)) != NULL) {
-        equalizerwin_read_aud_preset(rcfile);
-        aud_rcfile_free(rcfile);
-    }
-}
-
 static VFSFile *
 open_vfs_file(const gchar *filename, const gchar *mode)
 {
@@ -892,27 +888,6 @@
 }
 
 static void
-save_preset_file(const gchar * filename)
-{
-    RcFile *rcfile;
-    gint i;
-
-    rcfile = aud_rcfile_new();
-    aud_rcfile_write_float(rcfile, "Equalizer preset", "Preamp",
-                           ui_skinned_equalizer_slider_get_position(equalizerwin_preamp));
-
-    for (i = 0; i < 10; i++) {
-        gchar tmp[7];
-        g_snprintf(tmp, sizeof(tmp), "Band%d", i);
-        aud_rcfile_write_float(rcfile, "Equalizer preset", tmp,
-                               ui_skinned_equalizer_slider_get_position(equalizerwin_bands[i]));
-    }
-
-    aud_rcfile_write(rcfile, filename);
-    aud_rcfile_free(rcfile);
-}
-
-static void
 save_winamp_file(const gchar * filename)
 {
     VFSFile *file;
@@ -1052,7 +1027,6 @@
 equalizerwin_load_auto_preset(const gchar * filename)
 {
     gchar *presetfilename, *directory;
-    RcFile *rcfile;
 
     g_return_if_fail(filename != NULL);
 
@@ -1062,11 +1036,9 @@
     presetfilename = g_strconcat(filename, ".", cfg.eqpreset_extension, NULL);
 
     /* First try to find a per file preset file */
-    if (strlen(cfg.eqpreset_extension) > 0 &&
-        (rcfile = aud_rcfile_open(presetfilename)) != NULL) {
+    if (strlen(cfg.eqpreset_extension) > 0) {
+        equalizerwin_read_aud_preset(presetfilename);
         g_free(presetfilename);
-        equalizerwin_read_aud_preset(rcfile);
-        aud_rcfile_free(rcfile);
         return;
     }
 
@@ -1078,10 +1050,8 @@
     g_free(directory);
 
     /* Try to find a per directory preset file */
-    if (strlen(cfg.eqpreset_default_file) > 0 &&
-        (rcfile = aud_rcfile_open(presetfilename)) != NULL) {
-        equalizerwin_read_aud_preset(rcfile);
-        aud_rcfile_free(rcfile);
+    if (strlen(cfg.eqpreset_default_file) > 0) {
+        equalizerwin_read_aud_preset(presetfilename);
     }
     else if (!equalizerwin_load_preset
              (equalizer_auto_presets, g_basename(filename))) {
@@ -1126,7 +1096,7 @@
         gtk_window_present(GTK_WINDOW(equalizerwin_load_window));
         return;
     }
-    
+
     equalizerwin_create_list_window(equalizer_presets,
                                     Q_("Load preset"),
                                     &equalizerwin_load_window,
@@ -1181,7 +1151,9 @@
     if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
     {
         file_uri = gtk_file_chooser_get_uri(GTK_FILE_CHOOSER(dialog));
-        load_preset_file(file_uri);
+        EqualizerPreset *preset = load_preset_file(file_uri);
+        equalizerwin_apply_preset(preset);
+        equalizer_preset_free(preset);
         g_free(file_uri);
     }
     gtk_widget_destroy(dialog);
@@ -1277,12 +1249,19 @@
     gchar *file_uri;
     gchar *songname;
     Playlist *playlist = playlist_get_active();
+    int i;
 
     dialog = make_filebrowser(Q_("Save equalizer preset"), TRUE);
     if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
     {
         file_uri = gtk_file_chooser_get_uri(GTK_FILE_CHOOSER(dialog));
-        save_preset_file(file_uri);
+        EqualizerPreset *preset = g_new0(EqualizerPreset, 1);
+        preset->name = g_strdup(file_uri);
+        preset->preamp = ui_skinned_equalizer_slider_get_position(equalizerwin_preamp);
+        for (i = 0; i < 10; i++)
+            preset->bands[i] = ui_skinned_equalizer_slider_get_position(equalizerwin_bands[i]);
+        save_preset_file(preset, file_uri);
+        equalizer_preset_free(preset);
         g_free(file_uri);
     }
 
--- a/src/audacious/plugin.h	Tue Jul 08 12:26:34 2008 +0900
+++ b/src/audacious/plugin.h	Tue Jul 08 15:35:48 2008 +0200
@@ -46,6 +46,7 @@
 #include "audacious/main.h"
 #include "audacious/preferences.h"
 #include "audacious/interface.h"
+#include "audacious/equalizer_preset.h"
 
 #define PLUGIN(x)         ((Plugin *)(x))
 #define INPUT_PLUGIN(x)   ((InputPlugin *)(x))
@@ -638,6 +639,9 @@
     GList *(*equalizer_read_presets)(const gchar * basename);
     void (*equalizer_write_preset_file)(GList * list, const gchar * basename);
     GList *(*import_winamp_eqf)(VFSFile * file);
+    void (*save_preset_file)(EqualizerPreset *preset, const gchar * filename);
+    EqualizerPreset *(*equalizer_read_aud_preset)(const gchar * filename);
+    EqualizerPreset *(*load_preset_file)(const gchar *filename);
 
     /* VFS endianess helper functions */
     gboolean (*vfs_fget_le16)(guint16 *value, VFSFile *stream);
@@ -1001,6 +1005,9 @@
 #define aud_equalizer_read_presets  _audvt->equalizer_read_presets
 #define aud_equalizer_write_preset_file _audvt->equalizer_write_preset_file
 #define aud_import_winamp_eqf       _audvt->import_winamp_eqf
+#define aud_save_preset_file        _audvt->save_preset_file
+#define aud_equalizer_read_aud_preset _audvt->equalizer_read_aud_preset
+#define aud_load_preset_file        _audvt->load_preset_file
 
 #include "audacious/auddrct.h"
 
--- a/src/audacious/pluginenum.c	Tue Jul 08 12:26:34 2008 +0900
+++ b/src/audacious/pluginenum.c	Tue Jul 08 15:35:48 2008 +0200
@@ -393,6 +393,9 @@
     .equalizer_read_presets = equalizer_read_presets,
     .equalizer_write_preset_file = equalizer_write_preset_file,
     .import_winamp_eqf = import_winamp_eqf,
+    .save_preset_file = save_preset_file,
+    .equalizer_read_aud_preset = equalizer_read_aud_preset,
+    .load_preset_file = load_preset_file,
 };
 
 /*****************************************************************/