1643
|
1 /* Audacious - Cross-platform multimedia player
|
|
2 * Copyright (C) 2005-2006 Audacious development team.
|
|
3 *
|
|
4 * BMP - Cross-platform multimedia player
|
|
5 * Copyright (C) 2003-2004 BMP development team.
|
|
6 *
|
|
7 * Based on XMMS:
|
|
8 * Copyright (C) 1998-2003 XMMS development team.
|
|
9 *
|
|
10 * This program is free software; you can redistribute it and/or modify
|
|
11 * it under the terms of the GNU General Public License as published by
|
|
12 * the Free Software Foundation; either version 2 of the License, or
|
|
13 * (at your option) any later version.
|
|
14 *
|
|
15 * This program is distributed in the hope that it will be useful,
|
|
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
18 * GNU General Public License for more details.
|
|
19 *
|
|
20 * You should have received a copy of the GNU General Public License
|
|
21 * along with this program; if not, write to the Free Software
|
|
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
23 */
|
|
24
|
|
25 #ifdef HAVE_CONFIG_H
|
|
26 # include "config.h"
|
|
27 #endif
|
|
28
|
|
29 #include "equalizer.h"
|
1644
|
30 #include "playlist.h"
|
1643
|
31
|
|
32 #include <glib.h>
|
|
33 #include <glib/gi18n.h>
|
|
34 #include <gtk/gtk.h>
|
|
35 #include <stdio.h>
|
|
36 #include <math.h>
|
|
37 #include <string.h>
|
|
38
|
1644
|
39 #include "audacious/platform/smartinclude.h"
|
|
40 #include "audacious/widgets/widgetcore.h"
|
|
41 #include "audacious/dock.h"
|
|
42 #include "audacious/hints.h"
|
|
43 #include "audacious/input.h"
|
|
44 #include "audacious/main.h"
|
|
45 #include "audacious/playlist.h"
|
|
46 #include "audacious/util.h"
|
|
47 #include "audacious/output.h"
|
1643
|
48
|
|
49 #include "libaudacious/rcfile.h"
|
|
50 #include "libaudacious/vfs.h"
|
|
51
|
1644
|
52 #include "audacious/images/audacious_eq.xpm"
|
1643
|
53
|
|
54 enum PresetViewCols {
|
|
55 PRESET_VIEW_COL_NAME,
|
|
56 PRESET_VIEW_N_COLS
|
|
57 };
|
|
58
|
|
59 enum {
|
|
60 EQUALIZER_PRESETS_LOAD_PRESET,
|
|
61 EQUALIZER_PRESETS_LOAD_AUTOPRESET,
|
|
62 EQUALIZER_PRESETS_LOAD_DEFAULT,
|
|
63 EQUALIZER_PRESETS_LOAD_ZERO,
|
|
64 EQUALIZER_PRESETS_LOAD_FROM_FILE,
|
|
65 EQUALIZER_PRESETS_LOAD_FROM_WINAMPFILE,
|
|
66 EQUALIZER_PRESETS_IMPORT_WINAMPFILE,
|
|
67 EQUALIZER_PRESETS_SAVE_PRESET,
|
|
68 EQUALIZER_PRESETS_SAVE_AUTOPRESET,
|
|
69 EQUALIZER_PRESETS_SAVE_DEFAULT,
|
|
70 EQUALIZER_PRESETS_SAVE_TO_FILE,
|
|
71 EQUALIZER_PRESETS_SAVE_TO_WINAMPFILE,
|
|
72 EQUALIZER_PRESETS_DELETE_PRESET,
|
|
73 EQUALIZER_PRESETS_DELETE_AUTOPRESET
|
|
74 };
|
|
75
|
|
76
|
|
77 struct _EqualizerPreset {
|
|
78 gchar *name;
|
|
79 gfloat preamp, bands[10];
|
|
80 };
|
|
81
|
|
82 typedef struct _EqualizerPreset EqualizerPreset;
|
|
83
|
|
84
|
|
85 GtkWidget *equalizerwin;
|
|
86
|
|
87 static GtkWidget *equalizerwin_load_window = NULL;
|
|
88 static GtkWidget *equalizerwin_load_auto_window = NULL;
|
|
89 static GtkWidget *equalizerwin_save_window = NULL;
|
|
90 static GtkWidget *equalizerwin_save_entry;
|
|
91 static GtkWidget *equalizerwin_save_auto_window = NULL;
|
|
92 static GtkWidget *equalizerwin_save_auto_entry;
|
|
93 static GtkWidget *equalizerwin_delete_window = NULL;
|
|
94 static GtkWidget *equalizerwin_delete_auto_window = NULL;
|
|
95
|
|
96 static GdkPixmap *equalizerwin_bg;
|
|
97 static GdkGC *equalizerwin_gc;
|
|
98
|
|
99 static GList *equalizerwin_wlist = NULL;
|
|
100
|
|
101 static GtkAccelGroup *equalizerwin_accel;
|
|
102
|
|
103 static TButton *equalizerwin_on, *equalizerwin_auto;
|
|
104
|
|
105 static PButton *equalizerwin_presets, *equalizerwin_shade;
|
|
106 PButton *equalizerwin_close;
|
|
107 static EqGraph *equalizerwin_graph;
|
|
108 static EqSlider *equalizerwin_preamp, *equalizerwin_bands[10];
|
|
109 static HSlider *equalizerwin_volume, *equalizerwin_balance;
|
|
110
|
|
111 static GtkItemFactory *equalizerwin_presets_menu;
|
|
112
|
|
113 static GList *equalizer_presets = NULL, *equalizer_auto_presets = NULL;
|
|
114
|
|
115
|
|
116 static void equalizerwin_presets_menu_cb(gpointer cb_data, guint action,
|
|
117 GtkWidget * w);
|
|
118
|
|
119 static GtkItemFactoryEntry equalizerwin_presets_menu_entries[] = {
|
|
120 {N_("/Load"), NULL, NULL, 0, "<Branch>", NULL},
|
|
121 {N_("/Load/Preset"), NULL, equalizerwin_presets_menu_cb,
|
|
122 EQUALIZER_PRESETS_LOAD_PRESET, "<Item>", NULL},
|
|
123 {N_("/Load/Auto-load preset"), NULL, equalizerwin_presets_menu_cb,
|
|
124 EQUALIZER_PRESETS_LOAD_AUTOPRESET, "<Item>", NULL},
|
|
125 {N_("/Load/Default"), NULL, equalizerwin_presets_menu_cb,
|
|
126 EQUALIZER_PRESETS_LOAD_DEFAULT, "<Item>", NULL},
|
|
127 {"/Load/-", NULL, NULL, 0, "<Separator>", NULL},
|
|
128 {N_("/Load/Zero"), NULL, equalizerwin_presets_menu_cb,
|
|
129 EQUALIZER_PRESETS_LOAD_ZERO, "<Item>", NULL},
|
|
130 {"/Load/-", NULL, NULL, 0, "<Separator>", NULL},
|
|
131 {N_("/Load/From file"), NULL, equalizerwin_presets_menu_cb,
|
|
132 EQUALIZER_PRESETS_LOAD_FROM_FILE, "<Item>", NULL},
|
|
133 {N_("/Load/From WinAMP EQF file"), NULL, equalizerwin_presets_menu_cb,
|
|
134 EQUALIZER_PRESETS_LOAD_FROM_WINAMPFILE, "<Item>", NULL},
|
|
135 {N_("/Import"), NULL, NULL, 0, "<Branch>", NULL},
|
|
136 {N_("/Import/WinAMP Presets"), NULL, equalizerwin_presets_menu_cb,
|
|
137 EQUALIZER_PRESETS_IMPORT_WINAMPFILE, "<Item>", NULL},
|
|
138 {N_("/Save"), NULL, NULL, 0, "<Branch>", NULL},
|
|
139 {N_("/Save/Preset"), NULL, equalizerwin_presets_menu_cb,
|
|
140 EQUALIZER_PRESETS_SAVE_PRESET, "<Item>", NULL},
|
|
141 {N_("/Save/Auto-load preset"), NULL, equalizerwin_presets_menu_cb,
|
|
142 EQUALIZER_PRESETS_SAVE_AUTOPRESET, "<Item>", NULL},
|
|
143 {N_("/Save/Default"), NULL, equalizerwin_presets_menu_cb,
|
|
144 EQUALIZER_PRESETS_SAVE_DEFAULT, "<Item>", NULL},
|
|
145 {"/Save/-", NULL, NULL, 0, "<Separator>", NULL},
|
|
146 {N_("/Save/To file"), NULL, equalizerwin_presets_menu_cb,
|
|
147 EQUALIZER_PRESETS_SAVE_TO_FILE, "<Item>", NULL},
|
|
148 {N_("/Save/To WinAMP EQF file"), NULL, equalizerwin_presets_menu_cb,
|
|
149 EQUALIZER_PRESETS_SAVE_TO_WINAMPFILE, "<Item>", NULL},
|
|
150 {N_("/Delete"), NULL, NULL, 0, "<Branch>", NULL},
|
|
151 {N_("/Delete/Preset"), NULL, equalizerwin_presets_menu_cb,
|
|
152 EQUALIZER_PRESETS_DELETE_PRESET, "<Item>", NULL},
|
|
153 {N_("/Delete/Auto-load preset"), NULL, equalizerwin_presets_menu_cb,
|
|
154 EQUALIZER_PRESETS_DELETE_AUTOPRESET, "<Item>", NULL},
|
|
155 };
|
|
156
|
|
157 static gint equalizerwin_presets_menu_entries_num =
|
|
158 G_N_ELEMENTS(equalizerwin_presets_menu_entries);
|
|
159
|
|
160
|
|
161 EqualizerPreset *
|
|
162 equalizer_preset_new(const gchar * name)
|
|
163 {
|
|
164 EqualizerPreset *preset = g_new0(EqualizerPreset, 1);
|
|
165 preset->name = g_strdup(name);
|
|
166 return preset;
|
|
167 }
|
|
168
|
|
169 void
|
|
170 equalizer_preset_free(EqualizerPreset * preset)
|
|
171 {
|
|
172 if (!preset)
|
|
173 return;
|
|
174
|
|
175 g_free(preset->name);
|
|
176 g_free(preset);
|
|
177 }
|
|
178
|
|
179
|
|
180 static void
|
|
181 equalizerwin_set_shape_mask(void)
|
|
182 {
|
|
183 GdkBitmap *mask;
|
|
184
|
|
185 if (cfg.show_wm_decorations)
|
|
186 return;
|
|
187
|
|
188 mask = skin_get_mask(bmp_active_skin, SKIN_MASK_EQ + cfg.equalizer_shaded);
|
|
189 gtk_widget_shape_combine_mask(equalizerwin, mask, 0, 0);
|
|
190 }
|
|
191
|
|
192
|
|
193 void
|
|
194 equalizerwin_set_shade_menu_cb(gboolean shaded)
|
|
195 {
|
|
196 cfg.equalizer_shaded = shaded;
|
|
197
|
|
198 equalizerwin_set_shape_mask();
|
|
199
|
|
200 if (shaded) {
|
|
201 dock_shade(dock_window_list, GTK_WINDOW(equalizerwin), 14);
|
|
202 pbutton_set_button_data(equalizerwin_shade, -1, 3, -1, 47);
|
|
203 pbutton_set_skin_index1(equalizerwin_shade, SKIN_EQ_EX);
|
|
204 pbutton_set_button_data(equalizerwin_close, 11, 38, 11, 47);
|
|
205 pbutton_set_skin_index(equalizerwin_close, SKIN_EQ_EX);
|
|
206 widget_show(WIDGET(equalizerwin_volume));
|
|
207 widget_show(WIDGET(equalizerwin_balance));
|
|
208 }
|
|
209 else {
|
|
210 dock_shade(dock_window_list, GTK_WINDOW(equalizerwin), 116);
|
|
211 pbutton_set_button_data(equalizerwin_shade, -1, 137, -1, 38);
|
|
212 pbutton_set_skin_index1(equalizerwin_shade, SKIN_EQMAIN);
|
|
213 pbutton_set_button_data(equalizerwin_close, 0, 116, 0, 125);
|
|
214 pbutton_set_skin_index(equalizerwin_close, SKIN_EQMAIN);
|
|
215 widget_hide(WIDGET(equalizerwin_volume));
|
|
216 widget_hide(WIDGET(equalizerwin_balance));
|
|
217 }
|
|
218
|
|
219 draw_equalizer_window(TRUE);
|
|
220 }
|
|
221
|
|
222 static void
|
|
223 equalizerwin_set_shade(gboolean shaded)
|
|
224 {
|
|
225 GtkWidget *widget;
|
|
226 widget = gtk_item_factory_get_widget(mainwin_view_menu,
|
|
227 "/Roll up Equalizer");
|
|
228 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), shaded);
|
|
229 }
|
|
230
|
|
231 static void
|
|
232 equalizerwin_shade_toggle(void)
|
|
233 {
|
|
234 equalizerwin_set_shade(!cfg.equalizer_shaded);
|
|
235 }
|
|
236
|
|
237 static void
|
|
238 equalizerwin_raise(void)
|
|
239 {
|
|
240 if (cfg.equalizer_visible)
|
|
241 gtk_window_present(GTK_WINDOW(equalizerwin));
|
|
242 }
|
|
243
|
|
244 void
|
|
245 equalizerwin_eq_changed(void)
|
|
246 {
|
|
247 gint i;
|
|
248
|
|
249 cfg.equalizer_preamp = eqslider_get_position(equalizerwin_preamp);
|
|
250 for (i = 0; i < 10; i++)
|
|
251 cfg.equalizer_bands[i] = eqslider_get_position(equalizerwin_bands[i]);
|
|
252 /* um .. i think we need both of these for xmms compatibility ..
|
|
253 not sure. -larne */
|
|
254 input_set_eq(cfg.equalizer_active, cfg.equalizer_preamp,
|
|
255 cfg.equalizer_bands);
|
|
256 output_set_eq(cfg.equalizer_active, cfg.equalizer_preamp,
|
|
257 cfg.equalizer_bands);
|
|
258
|
|
259 widget_draw(WIDGET(equalizerwin_graph));
|
|
260 }
|
|
261
|
|
262 static void
|
|
263 equalizerwin_on_pushed(gboolean toggled)
|
|
264 {
|
|
265 cfg.equalizer_active = toggled;
|
|
266 equalizerwin_eq_changed();
|
|
267 }
|
|
268
|
|
269 static void
|
|
270 equalizerwin_presets_pushed(void)
|
|
271 {
|
|
272 GdkModifierType modmask;
|
|
273 gint x, y;
|
|
274
|
|
275 gdk_window_get_pointer(NULL, &x, &y, &modmask);
|
|
276 util_item_factory_popup(equalizerwin_presets_menu, x, y, 1,
|
|
277 GDK_CURRENT_TIME);
|
|
278 }
|
|
279
|
|
280 static void
|
|
281 equalizerwin_auto_pushed(gboolean toggled)
|
|
282 {
|
|
283 cfg.equalizer_autoload = toggled;
|
|
284 }
|
|
285
|
|
286 void
|
|
287 draw_equalizer_window(gboolean force)
|
|
288 {
|
|
289 gboolean redraw;
|
|
290
|
|
291 widget_list_lock(equalizerwin_wlist);
|
|
292
|
|
293 if (force) {
|
|
294 skin_draw_pixmap(bmp_active_skin, equalizerwin_bg, equalizerwin_gc,
|
|
295 SKIN_EQMAIN, 0, 0, 0, 0, 275, 116);
|
|
296 if (gtk_window_has_toplevel_focus(GTK_WINDOW(equalizerwin)) ||
|
|
297 !cfg.dim_titlebar) {
|
|
298 if (!cfg.equalizer_shaded)
|
|
299 skin_draw_pixmap(bmp_active_skin, equalizerwin_bg,
|
|
300 equalizerwin_gc, SKIN_EQMAIN, 0, 134, 0,
|
|
301 0, 275, 14);
|
|
302 else
|
|
303 skin_draw_pixmap(bmp_active_skin, equalizerwin_bg,
|
|
304 equalizerwin_gc, SKIN_EQ_EX, 0, 0, 0, 0,
|
|
305 275, 14);
|
|
306 }
|
|
307 else {
|
|
308 if (!cfg.equalizer_shaded)
|
|
309 skin_draw_pixmap(bmp_active_skin, equalizerwin_bg,
|
|
310 equalizerwin_gc, SKIN_EQMAIN, 0, 149, 0,
|
|
311 0, 275, 14);
|
|
312 else
|
|
313 skin_draw_pixmap(bmp_active_skin, equalizerwin_bg,
|
|
314 equalizerwin_gc, SKIN_EQ_EX, 0, 15, 0, 0,
|
|
315 275, 14);
|
|
316
|
|
317 }
|
|
318 }
|
|
319
|
|
320 widget_list_draw(equalizerwin_wlist, &redraw, force);
|
|
321
|
|
322 if (force || redraw) {
|
|
323 widget_list_clear_redraw(equalizerwin_wlist);
|
|
324 gdk_window_clear(equalizerwin->window);
|
|
325 gdk_flush();
|
|
326 }
|
|
327
|
|
328 widget_list_unlock(equalizerwin_wlist);
|
|
329 }
|
|
330
|
|
331 static gboolean
|
|
332 inside_sensitive_widgets(gint x, gint y)
|
|
333 {
|
|
334 return (widget_contains(WIDGET(equalizerwin_on), x, y) ||
|
|
335 widget_contains(WIDGET(equalizerwin_auto), x, y) ||
|
|
336 widget_contains(WIDGET(equalizerwin_presets), x, y) ||
|
|
337 widget_contains(WIDGET(equalizerwin_close), x, y) ||
|
|
338 widget_contains(WIDGET(equalizerwin_shade), x, y) ||
|
|
339 widget_contains(WIDGET(equalizerwin_preamp), x, y) ||
|
|
340 widget_contains(WIDGET(equalizerwin_bands[0]), x, y) ||
|
|
341 widget_contains(WIDGET(equalizerwin_bands[1]), x, y) ||
|
|
342 widget_contains(WIDGET(equalizerwin_bands[2]), x, y) ||
|
|
343 widget_contains(WIDGET(equalizerwin_bands[3]), x, y) ||
|
|
344 widget_contains(WIDGET(equalizerwin_bands[4]), x, y) ||
|
|
345 widget_contains(WIDGET(equalizerwin_bands[5]), x, y) ||
|
|
346 widget_contains(WIDGET(equalizerwin_bands[6]), x, y) ||
|
|
347 widget_contains(WIDGET(equalizerwin_bands[7]), x, y) ||
|
|
348 widget_contains(WIDGET(equalizerwin_bands[8]), x, y) ||
|
|
349 widget_contains(WIDGET(equalizerwin_bands[9]), x, y) ||
|
|
350 widget_contains(WIDGET(equalizerwin_volume), x, y) ||
|
|
351 widget_contains(WIDGET(equalizerwin_balance), x, y));
|
|
352 }
|
|
353
|
|
354 gboolean
|
|
355 equalizerwin_press(GtkWidget * widget, GdkEventButton * event,
|
|
356 gpointer callback_data)
|
|
357 {
|
|
358 gint mx, my;
|
|
359 gboolean grab = TRUE;
|
|
360
|
|
361 mx = event->x;
|
|
362 my = event->y;
|
|
363
|
|
364 if (event->button == 1 && event->type == GDK_BUTTON_PRESS &&
|
|
365 ((cfg.equalizer_shaded || event->y < 14) &&
|
|
366 !inside_sensitive_widgets(event->x, event->y))) {
|
|
367 if (0 && hint_move_resize_available()) {
|
|
368 hint_move_resize(equalizerwin, event->x_root,
|
|
369 event->y_root, TRUE);
|
|
370 grab = FALSE;
|
|
371 }
|
|
372 else {
|
|
373 equalizerwin_raise();
|
|
374 dock_move_press(dock_window_list, GTK_WINDOW(equalizerwin), event,
|
|
375 FALSE);
|
|
376 }
|
|
377 }
|
|
378 else if (event->button == 1 && event->type == GDK_2BUTTON_PRESS
|
|
379 && event->y < 14) {
|
|
380 equalizerwin_set_shade(!cfg.equalizer_shaded);
|
|
381 if (dock_is_moving(GTK_WINDOW(equalizerwin)))
|
|
382 dock_move_release(GTK_WINDOW(equalizerwin));
|
|
383 }
|
|
384 else if (event->button == 3 &&
|
|
385 !(widget_contains(WIDGET(equalizerwin_on), event->x, event->y) ||
|
|
386 widget_contains(WIDGET(equalizerwin_auto), event->x, event->y))) {
|
|
387 /*
|
|
388 * Pop up the main menu a few pixels down to avoid
|
|
389 * anything to be selected initially.
|
|
390 */
|
|
391 util_item_factory_popup(mainwin_general_menu, event->x_root,
|
|
392 event->y_root + 2, 3, event->time);
|
|
393 grab = FALSE;
|
|
394 }
|
|
395 else {
|
|
396 handle_press_cb(equalizerwin_wlist, widget, event);
|
|
397 draw_equalizer_window(FALSE);
|
|
398 }
|
|
399 if (grab)
|
|
400 gdk_pointer_grab(GDK_WINDOW(equalizerwin->window), FALSE,
|
|
401 GDK_BUTTON_MOTION_MASK | GDK_BUTTON_RELEASE_MASK,
|
|
402 NULL, NULL, GDK_CURRENT_TIME);
|
|
403
|
|
404 return FALSE;
|
|
405 }
|
|
406
|
|
407 static void
|
|
408 equalizerwin_scroll(GtkWidget * widget, GdkEventScroll * event, gpointer data)
|
|
409 {
|
|
410 handle_scroll_cb(equalizerwin_wlist, widget, event);
|
|
411 draw_equalizer_window(FALSE);
|
|
412 }
|
|
413
|
|
414 static gboolean
|
|
415 equalizerwin_motion(GtkWidget * widget,
|
|
416 GdkEventMotion * event, gpointer callback_data)
|
|
417 {
|
|
418 GdkEvent *gevent;
|
|
419
|
|
420 if (dock_is_moving(GTK_WINDOW(equalizerwin)))
|
|
421 {
|
|
422 dock_move_motion(GTK_WINDOW(equalizerwin), event);
|
|
423 }
|
|
424 else
|
|
425 {
|
|
426 handle_motion_cb(equalizerwin_wlist, widget, event);
|
|
427 draw_equalizer_window(FALSE);
|
|
428 }
|
|
429
|
|
430 gdk_flush();
|
|
431
|
|
432 while ((gevent = gdk_event_get()) != NULL) gdk_event_free(gevent);
|
|
433
|
|
434 return FALSE;
|
|
435 }
|
|
436
|
|
437 static gboolean
|
|
438 equalizerwin_release(GtkWidget * widget,
|
|
439 GdkEventButton * event, gpointer callback_data)
|
|
440 {
|
|
441 gdk_pointer_ungrab(GDK_CURRENT_TIME);
|
|
442 gdk_flush();
|
|
443
|
|
444 if (dock_is_moving(GTK_WINDOW(equalizerwin))) {
|
|
445 dock_move_release(GTK_WINDOW(equalizerwin));
|
|
446 }
|
|
447 else {
|
|
448 handle_release_cb(equalizerwin_wlist, widget, event);
|
|
449 draw_equalizer_window(FALSE);
|
|
450 }
|
|
451
|
|
452 return FALSE;
|
|
453 }
|
|
454
|
|
455 static gboolean
|
|
456 equalizerwin_focus_in(GtkWidget * widget,
|
|
457 GdkEvent * event,
|
|
458 gpointer data)
|
|
459 {
|
|
460 equalizerwin_close->pb_allow_draw = TRUE;
|
|
461 equalizerwin_shade->pb_allow_draw = TRUE;
|
|
462 draw_equalizer_window(TRUE);
|
|
463 return TRUE;
|
|
464 }
|
|
465
|
|
466 static gboolean
|
|
467 equalizerwin_focus_out(GtkWidget * widget,
|
|
468 GdkEventButton * event,
|
|
469 gpointer data)
|
|
470 {
|
|
471 equalizerwin_close->pb_allow_draw = FALSE;
|
|
472 equalizerwin_shade->pb_allow_draw = FALSE;
|
|
473 draw_equalizer_window(TRUE);
|
|
474 return TRUE;
|
|
475 }
|
|
476
|
|
477 static gboolean
|
|
478 equalizerwin_keypress(GtkWidget * widget,
|
|
479 GdkEventKey * event,
|
|
480 gpointer data)
|
|
481 {
|
|
482 if (!cfg.equalizer_shaded) {
|
|
483 gtk_widget_event(mainwin, (GdkEvent *) event);
|
|
484 return TRUE;
|
|
485 }
|
|
486
|
|
487 switch (event->keyval) {
|
|
488 case GDK_Left:
|
|
489 case GDK_KP_Left:
|
|
490 mainwin_set_balance_diff(-4);
|
|
491 break;
|
|
492 case GDK_Right:
|
|
493 case GDK_KP_Right:
|
|
494 mainwin_set_balance_diff(4);
|
|
495 break;
|
|
496 default:
|
|
497 gtk_widget_event(mainwin, (GdkEvent *) event);
|
|
498 break;
|
|
499 }
|
|
500
|
|
501 return FALSE;
|
|
502 }
|
|
503
|
|
504 static gboolean
|
|
505 equalizerwin_configure(GtkWidget * window,
|
|
506 GdkEventConfigure * event,
|
|
507 gpointer data)
|
|
508 {
|
|
509 if (!GTK_WIDGET_VISIBLE(window))
|
|
510 return FALSE;
|
|
511
|
|
512 cfg.equalizer_x = event->x;
|
|
513 cfg.equalizer_y = event->y;
|
|
514 return FALSE;
|
|
515 }
|
|
516
|
|
517 static void
|
|
518 equalizerwin_set_back_pixmap(void)
|
|
519 {
|
|
520 gdk_window_set_back_pixmap(equalizerwin->window, equalizerwin_bg, 0);
|
|
521 gdk_window_clear(equalizerwin->window);
|
|
522 }
|
|
523
|
|
524 static void
|
|
525 equalizerwin_close_cb(void)
|
|
526 {
|
|
527 equalizerwin_show(FALSE);
|
|
528 }
|
|
529
|
|
530 static gboolean
|
|
531 equalizerwin_delete(GtkWidget * widget,
|
|
532 gpointer data)
|
|
533 {
|
|
534 equalizerwin_show(FALSE);
|
|
535 return TRUE;
|
|
536 }
|
|
537
|
|
538 static GList *
|
|
539 equalizerwin_read_presets(const gchar * basename)
|
|
540 {
|
|
541 gchar *filename, *name;
|
|
542 RcFile *rcfile;
|
|
543 GList *list = NULL;
|
|
544 gint i, p = 0;
|
|
545 EqualizerPreset *preset;
|
|
546
|
|
547 filename = g_build_filename(bmp_paths[BMP_PATH_USER_DIR], basename, NULL);
|
|
548
|
|
549 if ((rcfile = bmp_rcfile_open(filename)) == NULL) {
|
|
550 g_free(filename);
|
|
551 return NULL;
|
|
552 }
|
|
553
|
|
554 g_free(filename);
|
|
555
|
|
556 for (;;) {
|
|
557 gchar section[21];
|
|
558
|
|
559 g_snprintf(section, sizeof(section), "Preset%d", p++);
|
|
560 if (bmp_rcfile_read_string(rcfile, "Presets", section, &name)) {
|
|
561 preset = g_new0(EqualizerPreset, 1);
|
|
562 preset->name = name;
|
|
563 bmp_rcfile_read_float(rcfile, name, "Preamp", &preset->preamp);
|
|
564 for (i = 0; i < 10; i++) {
|
|
565 gchar band[7];
|
|
566 g_snprintf(band, sizeof(band), "Band%d", i);
|
|
567 bmp_rcfile_read_float(rcfile, name, band, &preset->bands[i]);
|
|
568 }
|
|
569 list = g_list_prepend(list, preset);
|
|
570 }
|
|
571 else
|
|
572 break;
|
|
573 }
|
|
574 list = g_list_reverse(list);
|
|
575 bmp_rcfile_free(rcfile);
|
|
576 return list;
|
|
577 }
|
|
578
|
|
579 gint
|
|
580 equalizerwin_volume_frame_cb(gint pos)
|
|
581 {
|
|
582 if (equalizerwin_volume) {
|
|
583 if (pos < 32)
|
|
584 equalizerwin_volume->hs_knob_nx =
|
|
585 equalizerwin_volume->hs_knob_px = 1;
|
|
586 else if (pos < 63)
|
|
587 equalizerwin_volume->hs_knob_nx =
|
|
588 equalizerwin_volume->hs_knob_px = 4;
|
|
589 else
|
|
590 equalizerwin_volume->hs_knob_nx =
|
|
591 equalizerwin_volume->hs_knob_px = 7;
|
|
592 }
|
|
593 return 1;
|
|
594 }
|
|
595
|
|
596 static void
|
|
597 equalizerwin_volume_motion_cb(gint pos)
|
|
598 {
|
|
599 gint v = (gint) rint(pos * 100 / 94.0);
|
|
600 mainwin_adjust_volume_motion(v);
|
|
601 mainwin_set_volume_slider(v);
|
|
602 }
|
|
603
|
|
604 static void
|
|
605 equalizerwin_volume_release_cb(gint pos)
|
|
606 {
|
|
607 mainwin_adjust_volume_release();
|
|
608 }
|
|
609
|
|
610 static gint
|
|
611 equalizerwin_balance_frame_cb(gint pos)
|
|
612 {
|
|
613 if (equalizerwin_balance) {
|
|
614 if (pos < 13)
|
|
615 equalizerwin_balance->hs_knob_nx =
|
|
616 equalizerwin_balance->hs_knob_px = 11;
|
|
617 else if (pos < 26)
|
|
618 equalizerwin_balance->hs_knob_nx =
|
|
619 equalizerwin_balance->hs_knob_px = 14;
|
|
620 else
|
|
621 equalizerwin_balance->hs_knob_nx =
|
|
622 equalizerwin_balance->hs_knob_px = 17;
|
|
623 }
|
|
624
|
|
625 return 1;
|
|
626 }
|
|
627
|
|
628 static void
|
|
629 equalizerwin_balance_motion_cb(gint pos)
|
|
630 {
|
|
631 gint b;
|
|
632 pos = MIN(pos, 38); /* The skin uses a even number of pixels
|
|
633 for the balance-slider *sigh* */
|
|
634 b = (gint) rint((pos - 19) * 100 / 19.0);
|
|
635 mainwin_adjust_balance_motion(b);
|
|
636 mainwin_set_balance_slider(b);
|
|
637 }
|
|
638
|
|
639 static void
|
|
640 equalizerwin_balance_release_cb(gint pos)
|
|
641 {
|
|
642 mainwin_adjust_balance_release();
|
|
643 }
|
|
644
|
|
645 void
|
|
646 equalizerwin_set_balance_slider(gint percent)
|
|
647 {
|
|
648 hslider_set_position(equalizerwin_balance,
|
|
649 (gint) rint((percent * 19 / 100.0) + 19));
|
|
650 }
|
|
651
|
|
652 void
|
|
653 equalizerwin_set_volume_slider(gint percent)
|
|
654 {
|
|
655 hslider_set_position(equalizerwin_volume,
|
|
656 (gint) rint(percent * 94 / 100.0));
|
|
657 }
|
|
658
|
|
659 static void
|
|
660 equalizerwin_create_widgets(void)
|
|
661 {
|
|
662 gint i;
|
|
663
|
|
664 equalizerwin_on =
|
|
665 create_tbutton(&equalizerwin_wlist, equalizerwin_bg,
|
|
666 equalizerwin_gc, 14, 18, 25, 12, 10, 119, 128, 119,
|
|
667 69, 119, 187, 119, equalizerwin_on_pushed,
|
|
668 SKIN_EQMAIN);
|
|
669 tbutton_set_toggled(equalizerwin_on, cfg.equalizer_active);
|
|
670 equalizerwin_auto =
|
|
671 create_tbutton(&equalizerwin_wlist, equalizerwin_bg,
|
|
672 equalizerwin_gc, 39, 18, 33, 12, 35, 119, 153, 119,
|
|
673 94, 119, 212, 119, equalizerwin_auto_pushed,
|
|
674 SKIN_EQMAIN);
|
|
675 tbutton_set_toggled(equalizerwin_auto, cfg.equalizer_autoload);
|
|
676 equalizerwin_presets =
|
|
677 create_pbutton(&equalizerwin_wlist, equalizerwin_bg,
|
|
678 equalizerwin_gc, 217, 18, 44, 12, 224, 164, 224,
|
|
679 176, equalizerwin_presets_pushed, SKIN_EQMAIN);
|
|
680 equalizerwin_close =
|
|
681 create_pbutton(&equalizerwin_wlist, equalizerwin_bg,
|
|
682 equalizerwin_gc, 264, 3, 9, 9, 0, 116, 0, 125,
|
|
683 equalizerwin_close_cb, SKIN_EQMAIN);
|
|
684 equalizerwin_close->pb_allow_draw = FALSE;
|
|
685
|
|
686 equalizerwin_shade =
|
|
687 create_pbutton_ex(&equalizerwin_wlist, equalizerwin_bg,
|
|
688 equalizerwin_gc, 254, 3, 9, 9, 254, 137, 1, 38,
|
|
689 equalizerwin_shade_toggle, NULL, SKIN_EQMAIN, SKIN_EQ_EX);
|
|
690 equalizerwin_shade->pb_allow_draw = FALSE;
|
|
691
|
|
692 equalizerwin_graph =
|
|
693 create_eqgraph(&equalizerwin_wlist, equalizerwin_bg,
|
|
694 equalizerwin_gc, 86, 17);
|
|
695 equalizerwin_preamp =
|
|
696 create_eqslider(&equalizerwin_wlist, equalizerwin_bg,
|
|
697 equalizerwin_gc, 21, 38);
|
|
698 eqslider_set_position(equalizerwin_preamp, cfg.equalizer_preamp);
|
|
699 for (i = 0; i < 10; i++) {
|
|
700 equalizerwin_bands[i] =
|
|
701 create_eqslider(&equalizerwin_wlist, equalizerwin_bg,
|
|
702 equalizerwin_gc, 78 + (i * 18), 38);
|
|
703 eqslider_set_position(equalizerwin_bands[i], cfg.equalizer_bands[i]);
|
|
704 }
|
|
705
|
|
706 equalizerwin_volume =
|
|
707 create_hslider(&equalizerwin_wlist, equalizerwin_bg,
|
|
708 equalizerwin_gc, 61, 4, 97, 8, 1, 30, 1, 30, 3, 7,
|
|
709 4, 61, 0, 94, equalizerwin_volume_frame_cb,
|
|
710 equalizerwin_volume_motion_cb,
|
|
711 equalizerwin_volume_release_cb, SKIN_EQ_EX);
|
|
712 equalizerwin_balance =
|
|
713 create_hslider(&equalizerwin_wlist, equalizerwin_bg,
|
|
714 equalizerwin_gc, 164, 4, 42, 8, 11, 30, 11, 30, 3,
|
|
715 7, 4, 164, 0, 39, equalizerwin_balance_frame_cb,
|
|
716 equalizerwin_balance_motion_cb,
|
|
717 equalizerwin_balance_release_cb, SKIN_EQ_EX);
|
|
718
|
|
719 if (!cfg.equalizer_shaded) {
|
|
720 widget_hide(WIDGET(equalizerwin_volume));
|
|
721 widget_hide(WIDGET(equalizerwin_balance));
|
|
722 }
|
|
723 else {
|
|
724 pbutton_set_button_data(equalizerwin_shade, -1, 3, -1, 47);
|
|
725 pbutton_set_skin_index1(equalizerwin_shade, SKIN_EQ_EX);
|
|
726 pbutton_set_button_data(equalizerwin_close, 11, 38, 11, 47);
|
|
727 pbutton_set_skin_index(equalizerwin_close, SKIN_EQ_EX);
|
|
728 }
|
|
729 }
|
|
730
|
|
731
|
|
732 static void
|
|
733 equalizerwin_create_window(void)
|
|
734 {
|
|
735 GdkPixbuf *icon;
|
|
736 gint width, height;
|
|
737
|
|
738 equalizerwin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
|
739 gtk_window_set_title(GTK_WINDOW(equalizerwin), _("Audacious Equalizer"));
|
|
740 gtk_window_set_wmclass(GTK_WINDOW(equalizerwin), "equalizer", "Audacious");
|
|
741 gtk_window_set_role(GTK_WINDOW(equalizerwin), "equalizer");
|
|
742
|
|
743 width = 275;
|
|
744 height = cfg.equalizer_shaded ? 14 : 116;
|
|
745
|
|
746 gtk_window_set_default_size(GTK_WINDOW(equalizerwin), width, height);
|
|
747 gtk_window_set_resizable(GTK_WINDOW(equalizerwin), FALSE);
|
|
748
|
|
749 dock_window_list = dock_window_set_decorated(dock_window_list,
|
|
750 GTK_WINDOW(equalizerwin),
|
|
751 cfg.show_wm_decorations);
|
|
752
|
|
753 /* this will hide only mainwin. it's annoying! yaz */
|
|
754 gtk_window_set_transient_for(GTK_WINDOW(equalizerwin),
|
|
755 GTK_WINDOW(mainwin));
|
|
756 gtk_window_set_skip_taskbar_hint(GTK_WINDOW(equalizerwin), TRUE);
|
|
757
|
|
758 icon = gdk_pixbuf_new_from_xpm_data((const gchar **) bmp_eq_icon);
|
|
759 gtk_window_set_icon(GTK_WINDOW(equalizerwin), icon);
|
|
760 g_object_unref(icon);
|
|
761
|
|
762 gtk_widget_set_app_paintable(equalizerwin, TRUE);
|
|
763
|
|
764 if (cfg.equalizer_x != -1 && cfg.save_window_position)
|
|
765 gtk_window_move(GTK_WINDOW(equalizerwin),
|
|
766 cfg.equalizer_x, cfg.equalizer_y);
|
|
767
|
|
768 gtk_widget_set_events(equalizerwin,
|
|
769 GDK_FOCUS_CHANGE_MASK | GDK_BUTTON_MOTION_MASK |
|
|
770 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
|
|
771 GDK_VISIBILITY_NOTIFY_MASK);
|
|
772 gtk_widget_realize(equalizerwin);
|
|
773
|
|
774 util_set_cursor(equalizerwin);
|
|
775
|
|
776 g_signal_connect(equalizerwin, "delete_event",
|
|
777 G_CALLBACK(equalizerwin_delete), NULL);
|
|
778 g_signal_connect(equalizerwin, "button_press_event",
|
|
779 G_CALLBACK(equalizerwin_press), NULL);
|
|
780 g_signal_connect(equalizerwin, "button_release_event",
|
|
781 G_CALLBACK(equalizerwin_release), NULL);
|
|
782 g_signal_connect(equalizerwin, "motion_notify_event",
|
|
783 G_CALLBACK(equalizerwin_motion), NULL);
|
|
784 g_signal_connect_after(equalizerwin, "focus_in_event",
|
|
785 G_CALLBACK(equalizerwin_focus_in), NULL);
|
|
786 g_signal_connect_after(equalizerwin, "focus_out_event",
|
|
787 G_CALLBACK(equalizerwin_focus_out), NULL);
|
|
788 g_signal_connect(equalizerwin, "configure_event",
|
|
789 G_CALLBACK(equalizerwin_configure), NULL);
|
|
790 g_signal_connect(equalizerwin, "style_set",
|
|
791 G_CALLBACK(equalizerwin_set_back_pixmap), NULL);
|
|
792 g_signal_connect(equalizerwin, "key_press_event",
|
|
793 G_CALLBACK(equalizerwin_keypress), NULL);
|
|
794 g_signal_connect(equalizerwin, "scroll_event",
|
|
795 G_CALLBACK(equalizerwin_scroll), NULL);
|
|
796 }
|
|
797
|
|
798 void
|
|
799 equalizerwin_create_popup_menus(void)
|
|
800 {
|
|
801 equalizerwin_accel = gtk_accel_group_new();
|
|
802 gtk_window_add_accel_group(GTK_WINDOW(equalizerwin), equalizerwin_accel);
|
|
803
|
|
804 equalizerwin_presets_menu = create_menu(equalizerwin_presets_menu_entries,
|
|
805 equalizerwin_presets_menu_entries_num,
|
|
806 NULL);
|
|
807 }
|
|
808
|
|
809 void
|
|
810 equalizerwin_create(void)
|
|
811 {
|
|
812 equalizer_presets = equalizerwin_read_presets("eq.preset");
|
|
813 equalizer_auto_presets = equalizerwin_read_presets("eq.auto_preset");
|
|
814
|
|
815 equalizerwin_create_window();
|
|
816 equalizerwin_create_popup_menus();
|
|
817
|
|
818 equalizerwin_gc = gdk_gc_new(equalizerwin->window);
|
|
819 equalizerwin_bg = gdk_pixmap_new(equalizerwin->window, 275, 116, -1);
|
|
820
|
|
821 equalizerwin_create_widgets();
|
|
822
|
|
823 equalizerwin_set_back_pixmap();
|
|
824 gdk_window_set_back_pixmap(equalizerwin->window, equalizerwin_bg, 0);
|
|
825 }
|
|
826
|
|
827
|
|
828 void
|
|
829 equalizerwin_show(gboolean show)
|
|
830 {
|
|
831 GtkWidget *item = gtk_item_factory_get_widget(mainwin_view_menu,
|
|
832 "/Show Equalizer");
|
|
833 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), show);
|
|
834 }
|
|
835
|
|
836 void
|
|
837 equalizerwin_real_show(void)
|
|
838 {
|
|
839 /*
|
|
840 * This function should only be called from the
|
|
841 * main menu signal handler
|
|
842 */
|
|
843
|
|
844 gint x, y;
|
|
845
|
|
846 gtk_window_get_position(GTK_WINDOW(equalizerwin), &x, &y);
|
|
847 gtk_window_move(GTK_WINDOW(equalizerwin), x, y);
|
|
848 gtk_widget_set_size_request(equalizerwin, 275,
|
|
849 (cfg.equalizer_shaded ? 14 : 116));
|
|
850 gdk_flush();
|
|
851 draw_equalizer_window(TRUE);
|
|
852 cfg.equalizer_visible = TRUE;
|
|
853 tbutton_set_toggled(mainwin_eq, TRUE);
|
|
854
|
|
855 gtk_widget_show(equalizerwin);
|
|
856 }
|
|
857
|
|
858 void
|
|
859 equalizerwin_real_hide(void)
|
|
860 {
|
|
861 /*
|
|
862 * This function should only be called from the
|
|
863 * main menu signal handler
|
|
864 */
|
|
865 gtk_widget_hide(equalizerwin);
|
|
866 cfg.equalizer_visible = FALSE;
|
|
867 tbutton_set_toggled(mainwin_eq, FALSE);
|
|
868 }
|
|
869
|
|
870 static EqualizerPreset *
|
|
871 equalizerwin_find_preset(GList * list, const gchar * name)
|
|
872 {
|
|
873 GList *node = list;
|
|
874 EqualizerPreset *preset;
|
|
875
|
|
876 while (node) {
|
|
877 preset = node->data;
|
|
878 if (!strcasecmp(preset->name, name))
|
|
879 return preset;
|
|
880 node = g_list_next(node);
|
|
881 }
|
|
882 return NULL;
|
|
883 }
|
|
884
|
|
885 static void
|
|
886 equalizerwin_write_preset_file(GList * list, const gchar * basename)
|
|
887 {
|
|
888 gchar *filename, *tmp;
|
|
889 gint i, p;
|
|
890 EqualizerPreset *preset;
|
|
891 RcFile *rcfile;
|
|
892 GList *node;
|
|
893
|
|
894 rcfile = bmp_rcfile_new();
|
|
895 p = 0;
|
|
896 for (node = list; node; node = g_list_next(node)) {
|
|
897 preset = node->data;
|
|
898 tmp = g_strdup_printf("Preset%d", p++);
|
|
899 bmp_rcfile_write_string(rcfile, "Presets", tmp, preset->name);
|
|
900 g_free(tmp);
|
|
901 bmp_rcfile_write_float(rcfile, preset->name, "Preamp",
|
|
902 preset->preamp);
|
|
903 for (i = 0; i < 10; i++) {
|
|
904 tmp = g_strdup_printf("Band%d\n", i);
|
|
905 bmp_rcfile_write_float(rcfile, preset->name, tmp,
|
|
906 preset->bands[i]);
|
|
907 g_free(tmp);
|
|
908 }
|
|
909 }
|
|
910
|
|
911 filename = g_build_filename(bmp_paths[BMP_PATH_USER_DIR], basename, NULL);
|
|
912 bmp_rcfile_write(rcfile, filename);
|
|
913 bmp_rcfile_free(rcfile);
|
|
914 g_free(filename);
|
|
915 }
|
|
916
|
|
917 static gboolean
|
|
918 equalizerwin_load_preset(GList * list, const gchar * name)
|
|
919 {
|
|
920 EqualizerPreset *preset;
|
|
921 gint i;
|
|
922
|
|
923 if ((preset = equalizerwin_find_preset(list, name)) != NULL) {
|
|
924 eqslider_set_position(equalizerwin_preamp, preset->preamp);
|
|
925 for (i = 0; i < 10; i++)
|
|
926 eqslider_set_position(equalizerwin_bands[i], preset->bands[i]);
|
|
927 equalizerwin_eq_changed();
|
|
928 return TRUE;
|
|
929 }
|
|
930 return FALSE;
|
|
931 }
|
|
932
|
|
933 static GList *
|
|
934 equalizerwin_save_preset(GList * list, const gchar * name,
|
|
935 const gchar * filename)
|
|
936 {
|
|
937 gint i;
|
|
938 EqualizerPreset *preset;
|
|
939
|
|
940 if (!(preset = equalizerwin_find_preset(list, name))) {
|
|
941 preset = g_new0(EqualizerPreset, 1);
|
|
942 preset->name = g_strdup(name);
|
|
943 list = g_list_append(list, preset);
|
|
944 }
|
|
945
|
|
946 preset->preamp = eqslider_get_position(equalizerwin_preamp);
|
|
947 for (i = 0; i < 10; i++)
|
|
948 preset->bands[i] = eqslider_get_position(equalizerwin_bands[i]);
|
|
949
|
|
950 equalizerwin_write_preset_file(list, filename);
|
|
951
|
|
952 return list;
|
|
953 }
|
|
954
|
|
955 static GList *
|
|
956 equalizerwin_delete_preset(GList * list, gchar * name, gchar * filename)
|
|
957 {
|
|
958 EqualizerPreset *preset;
|
|
959 GList *node;
|
|
960
|
|
961 if (!(preset = equalizerwin_find_preset(list, name)))
|
|
962 return list;
|
|
963
|
|
964 if (!(node = g_list_find(list, preset)))
|
|
965 return list;
|
|
966
|
|
967 list = g_list_remove_link(list, node);
|
|
968 equalizer_preset_free(preset);
|
|
969 g_list_free_1(node);
|
|
970
|
|
971 equalizerwin_write_preset_file(list, filename);
|
|
972
|
|
973 return list;
|
|
974 }
|
|
975
|
|
976
|
|
977 static GList *
|
|
978 import_winamp_eqf(VFSFile * file)
|
|
979 {
|
|
980 gchar header[31];
|
|
981 gchar name[257];
|
|
982 gchar bands[11];
|
|
983 gint i = 0;
|
|
984 GList *list = NULL;
|
|
985 EqualizerPreset *preset;
|
|
986
|
|
987 vfs_fread(header, 1, 31, file);
|
|
988 if (!strncmp(header, "Winamp EQ library file v1.1", 27)) {
|
|
989 while (vfs_fread(name, 1, 257, file)) {
|
|
990 preset = equalizer_preset_new(name);
|
|
991 preset->preamp = 20.0 - ((bands[10] * 40.0) / 64);
|
|
992
|
|
993 vfs_fread(bands, 1, 11, file);
|
|
994
|
|
995 for (i = 0; i < 10; i++)
|
|
996 preset->bands[i] = 20.0 - ((bands[i] * 40.0) / 64);
|
|
997
|
|
998 list = g_list_prepend(list, preset);
|
|
999 }
|
|
1000 }
|
|
1001
|
|
1002 list = g_list_reverse(list);
|
|
1003 return list;
|
|
1004 }
|
|
1005
|
|
1006 static void
|
|
1007 equalizerwin_read_winamp_eqf(VFSFile * file)
|
|
1008 {
|
|
1009 gchar header[31];
|
|
1010 guchar bands[11];
|
|
1011 gint i;
|
|
1012
|
|
1013 vfs_fread(header, 1, 31, file);
|
|
1014
|
|
1015 if (!strncmp(header, "Winamp EQ library file v1.1", 27)) {
|
|
1016 /* Skip name */
|
|
1017 if (vfs_fseek(file, 257, SEEK_CUR) == -1)
|
|
1018 return;
|
|
1019
|
|
1020 if (vfs_fread(bands, 1, 11, file) != 11)
|
|
1021 return;
|
|
1022
|
|
1023 eqslider_set_position(equalizerwin_preamp,
|
|
1024 20.0 - ((bands[10] * 40.0) / 63.0));
|
|
1025
|
|
1026 for (i = 0; i < 10; i++)
|
|
1027 eqslider_set_position(equalizerwin_bands[i],
|
|
1028 20.0 - ((bands[i] * 40.0) / 64.0));
|
|
1029 }
|
|
1030
|
|
1031 equalizerwin_eq_changed();
|
|
1032 }
|
|
1033
|
|
1034 static void
|
|
1035 equalizerwin_read_bmp_preset(RcFile * rcfile)
|
|
1036 {
|
|
1037 gfloat val;
|
|
1038 gint i;
|
|
1039
|
|
1040 if (bmp_rcfile_read_float(rcfile, "Equalizer preset", "Preamp", &val))
|
|
1041 eqslider_set_position(equalizerwin_preamp, val);
|
|
1042 for (i = 0; i < 10; i++) {
|
|
1043 gchar tmp[7];
|
|
1044 g_snprintf(tmp, sizeof(tmp), "Band%d", i);
|
|
1045 if (bmp_rcfile_read_float(rcfile, "Equalizer preset", tmp, &val))
|
|
1046 eqslider_set_position(equalizerwin_bands[i], val);
|
|
1047 }
|
|
1048 equalizerwin_eq_changed();
|
|
1049 }
|
|
1050
|
|
1051 static void
|
|
1052 equalizerwin_save_ok(GtkWidget * widget, gpointer data)
|
|
1053 {
|
|
1054 const gchar *text;
|
|
1055
|
|
1056 text = gtk_entry_get_text(GTK_ENTRY(equalizerwin_save_entry));
|
|
1057 if (strlen(text) != 0)
|
|
1058 equalizer_presets =
|
|
1059 equalizerwin_save_preset(equalizer_presets, text, "eq.preset");
|
|
1060 gtk_widget_destroy(equalizerwin_save_window);
|
|
1061 }
|
|
1062
|
|
1063 static void
|
|
1064 equalizerwin_save_select(GtkCList * clist, gint row,
|
|
1065 gint column, GdkEventButton * event, gpointer data)
|
|
1066 {
|
|
1067 gchar *text;
|
|
1068
|
|
1069 gtk_clist_get_text(clist, row, 0, &text);
|
|
1070
|
|
1071 gtk_entry_set_text(GTK_ENTRY(equalizerwin_save_entry), text);
|
|
1072 if (event->type == GDK_2BUTTON_PRESS)
|
|
1073 equalizerwin_save_ok(NULL, NULL);
|
|
1074
|
|
1075 }
|
|
1076
|
|
1077 static void
|
|
1078 equalizerwin_load_ok(GtkWidget * widget, gpointer data)
|
|
1079 {
|
|
1080 gchar *text;
|
|
1081 GtkCList *clist = GTK_CLIST(data);
|
|
1082
|
|
1083 if (clist && clist->selection) {
|
|
1084 gtk_clist_get_text(clist, GPOINTER_TO_INT(clist->selection->data),
|
|
1085 0, &text);
|
|
1086 equalizerwin_load_preset(equalizer_presets, text);
|
|
1087 }
|
|
1088 gtk_widget_destroy(equalizerwin_load_window);
|
|
1089 }
|
|
1090
|
|
1091 static void
|
|
1092 equalizerwin_load_apply(GtkWidget * widget, gpointer data)
|
|
1093 {
|
|
1094 gchar *text;
|
|
1095 GtkCList *clist = GTK_CLIST(data);
|
|
1096
|
|
1097 if (clist && clist->selection) {
|
|
1098 gtk_clist_get_text(clist, GPOINTER_TO_INT(clist->selection->data),
|
|
1099 0, &text);
|
|
1100 equalizerwin_load_preset(equalizer_presets, text);
|
|
1101 }
|
|
1102 }
|
|
1103
|
|
1104
|
|
1105 static void
|
|
1106 equalizerwin_load_select(GtkCList * widget, gint row,
|
|
1107 gint column, GdkEventButton * event, gpointer data)
|
|
1108 {
|
|
1109 if (event->type == GDK_2BUTTON_PRESS)
|
|
1110 equalizerwin_load_ok(NULL, widget);
|
|
1111 }
|
|
1112
|
|
1113 static void
|
|
1114 equalizerwin_delete_delete(GtkWidget * widget, gpointer data)
|
|
1115 {
|
|
1116 gchar *text;
|
|
1117 GList *list, *next;
|
|
1118 GtkCList *clist = GTK_CLIST(data);
|
|
1119
|
|
1120 g_return_if_fail(clist != NULL);
|
|
1121
|
|
1122 list = clist->selection;
|
|
1123 gtk_clist_freeze(clist);
|
|
1124 while (list) {
|
|
1125 next = g_list_next(list);
|
|
1126 gtk_clist_get_text(clist, GPOINTER_TO_INT(list->data), 0, &text);
|
|
1127 equalizer_auto_presets =
|
|
1128 equalizerwin_delete_preset(equalizer_presets, text, "eq.preset");
|
|
1129 gtk_clist_remove(clist, GPOINTER_TO_INT(list->data));
|
|
1130 list = next;
|
|
1131 }
|
|
1132 gtk_clist_thaw(clist);
|
|
1133 }
|
|
1134
|
|
1135 static void
|
|
1136 equalizerwin_save_auto_ok(GtkWidget * widget, gpointer data)
|
|
1137 {
|
|
1138 const gchar *text;
|
|
1139
|
|
1140 text = gtk_entry_get_text(GTK_ENTRY(equalizerwin_save_auto_entry));
|
|
1141 if (strlen(text) != 0)
|
|
1142 equalizer_auto_presets =
|
|
1143 equalizerwin_save_preset(equalizer_auto_presets, text,
|
|
1144 "eq.auto_preset");
|
|
1145 gtk_widget_destroy(equalizerwin_save_auto_window);
|
|
1146 }
|
|
1147
|
|
1148 static void
|
|
1149 equalizerwin_save_auto_select(GtkCList * clist, gint row,
|
|
1150 gint column,
|
|
1151 GdkEventButton * event, gpointer data)
|
|
1152 {
|
|
1153 gchar *text;
|
|
1154
|
|
1155 gtk_clist_get_text(clist, row, 0, &text);
|
|
1156
|
|
1157 gtk_entry_set_text(GTK_ENTRY(equalizerwin_save_auto_entry), text);
|
|
1158 if (event->type == GDK_2BUTTON_PRESS)
|
|
1159 equalizerwin_save_auto_ok(NULL, NULL);
|
|
1160
|
|
1161 }
|
|
1162
|
|
1163 static void
|
|
1164 equalizerwin_load_auto_ok(GtkWidget * widget, gpointer data)
|
|
1165 {
|
|
1166 gchar *text;
|
|
1167 GtkCList *clist = GTK_CLIST(data);
|
|
1168
|
|
1169 if (clist && clist->selection) {
|
|
1170 gtk_clist_get_text(clist, GPOINTER_TO_INT(clist->selection->data),
|
|
1171 0, &text);
|
|
1172 equalizerwin_load_preset(equalizer_auto_presets, text);
|
|
1173 }
|
|
1174 gtk_widget_destroy(equalizerwin_load_auto_window);
|
|
1175 }
|
|
1176
|
|
1177 static void
|
|
1178 equalizerwin_load_auto_select(GtkWidget * widget, gint row,
|
|
1179 gint column,
|
|
1180 GdkEventButton * event, gpointer data)
|
|
1181 {
|
|
1182 if (event->type == GDK_2BUTTON_PRESS)
|
|
1183 equalizerwin_load_auto_ok(NULL, widget);
|
|
1184 }
|
|
1185
|
|
1186 static void
|
|
1187 equalizerwin_delete_auto_delete(GtkWidget * widget, gpointer data)
|
|
1188 {
|
|
1189 gchar *text;
|
|
1190 GList *list, *next;
|
|
1191 GtkCList *clist = GTK_CLIST(data);
|
|
1192
|
|
1193 g_return_if_fail(clist != NULL);
|
|
1194
|
|
1195 list = clist->selection;
|
|
1196 gtk_clist_freeze(clist);
|
|
1197 while (list) {
|
|
1198 next = g_list_next(list);
|
|
1199 gtk_clist_get_text(clist, GPOINTER_TO_INT(list->data), 0, &text);
|
|
1200 equalizer_auto_presets =
|
|
1201 equalizerwin_delete_preset(equalizer_auto_presets, text,
|
|
1202 "eq.auto_preset");
|
|
1203 gtk_clist_remove(clist, GPOINTER_TO_INT(list->data));
|
|
1204 list = next;
|
|
1205 }
|
|
1206 gtk_clist_thaw(clist);
|
|
1207 }
|
|
1208
|
|
1209
|
|
1210 typedef void (*ResponseHandler)(const gchar *filename);
|
|
1211
|
|
1212 static void
|
|
1213 equalizerwin_file_chooser_on_response(GtkWidget * dialog,
|
|
1214 gint response,
|
|
1215 gpointer data)
|
|
1216 {
|
|
1217 GtkFileChooser *file_chooser = GTK_FILE_CHOOSER(dialog);
|
|
1218 ResponseHandler handler = (ResponseHandler) data;
|
|
1219 gchar *filename;
|
|
1220
|
|
1221 gtk_widget_hide(dialog);
|
|
1222
|
|
1223 switch (response)
|
|
1224 {
|
|
1225 case GTK_RESPONSE_ACCEPT:
|
|
1226 filename = gtk_file_chooser_get_filename(file_chooser);
|
|
1227 handler(filename);
|
|
1228 g_free(filename);
|
|
1229 break;
|
|
1230
|
|
1231 case GTK_RESPONSE_REJECT:
|
|
1232 break;
|
|
1233 }
|
|
1234
|
|
1235 gtk_widget_destroy(dialog);
|
|
1236 }
|
|
1237
|
|
1238
|
|
1239
|
|
1240 static void
|
|
1241 load_preset_file(const gchar *filename)
|
|
1242 {
|
|
1243 RcFile *rcfile;
|
|
1244
|
|
1245 if ((rcfile = bmp_rcfile_open(filename)) != NULL) {
|
|
1246 equalizerwin_read_bmp_preset(rcfile);
|
|
1247 bmp_rcfile_free(rcfile);
|
|
1248 }
|
|
1249 }
|
|
1250
|
|
1251 static void
|
|
1252 load_winamp_file(const gchar * filename)
|
|
1253 {
|
|
1254 VFSFile *file;
|
|
1255 gchar *tmp;
|
|
1256
|
|
1257 if (!(file = vfs_fopen(filename, "rb"))) {
|
|
1258 tmp = g_strconcat("Failed to load WinAmp file: ",filename,"\n",NULL);
|
|
1259 report_error(tmp);
|
|
1260 g_free(tmp);
|
|
1261 return;
|
|
1262 }
|
|
1263
|
|
1264 equalizerwin_read_winamp_eqf(file);
|
|
1265 vfs_fclose(file);
|
|
1266 }
|
|
1267
|
|
1268 static void
|
|
1269 import_winamp_file(const gchar * filename)
|
|
1270 {
|
|
1271 VFSFile *file;
|
|
1272 gchar *tmp;
|
|
1273
|
|
1274 if (!(file = vfs_fopen(filename, "rb"))) {
|
|
1275 tmp = g_strconcat("Failed to import WinAmp file: ",filename,"\n",NULL);
|
|
1276 report_error(tmp);
|
|
1277 g_free(tmp);
|
|
1278 return;
|
|
1279 }
|
|
1280
|
|
1281 equalizer_presets = g_list_concat(equalizer_presets,
|
|
1282 import_winamp_eqf(file));
|
|
1283 equalizerwin_write_preset_file(equalizer_presets, "eq.preset");
|
|
1284
|
|
1285 vfs_fclose(file);
|
|
1286 }
|
|
1287
|
|
1288 static void
|
|
1289 save_preset_file(const gchar * filename)
|
|
1290 {
|
|
1291 RcFile *rcfile;
|
|
1292 gint i;
|
|
1293
|
|
1294 rcfile = bmp_rcfile_new();
|
|
1295 bmp_rcfile_write_float(rcfile, "Equalizer preset", "Preamp",
|
|
1296 eqslider_get_position(equalizerwin_preamp));
|
|
1297
|
|
1298 for (i = 0; i < 10; i++) {
|
|
1299 gchar tmp[7];
|
|
1300 g_snprintf(tmp, sizeof(tmp), "Band%d", i);
|
|
1301 bmp_rcfile_write_float(rcfile, "Equalizer preset", tmp,
|
|
1302 eqslider_get_position(equalizerwin_bands[i]));
|
|
1303 }
|
|
1304
|
|
1305 bmp_rcfile_write(rcfile, filename);
|
|
1306 bmp_rcfile_free(rcfile);
|
|
1307 }
|
|
1308
|
|
1309 static void
|
|
1310 save_winamp_file(const gchar * filename)
|
|
1311 {
|
|
1312 VFSFile *file;
|
|
1313
|
|
1314 gchar name[257];
|
|
1315 gint i;
|
|
1316 guchar bands[11];
|
|
1317 gchar *tmp;
|
|
1318
|
|
1319 if (!(file = vfs_fopen(filename, "wb"))) {
|
|
1320 tmp = g_strconcat("Failed to save WinAmp file: ",filename,"\n",NULL);
|
|
1321 report_error(tmp);
|
|
1322 g_free(tmp);
|
|
1323 return;
|
|
1324 }
|
|
1325
|
|
1326 vfs_fwrite("Winamp EQ library file v1.1\x1a!--", 1, 31, file);
|
|
1327
|
|
1328 memset(name, 0, 257);
|
|
1329 strcpy(name, "Entry1");
|
|
1330 vfs_fwrite(name, 1, 257, file);
|
|
1331
|
|
1332 for (i = 0; i < 10; i++)
|
|
1333 bands[i] = 63 - (((eqslider_get_position(equalizerwin_bands[i]) + 20) * 63) / 40);
|
|
1334 bands[10] = 63 - (((eqslider_get_position(equalizerwin_preamp) + 20) * 63) / 40);
|
|
1335 vfs_fwrite(bands, 1, 11, file);
|
|
1336
|
|
1337 vfs_fclose(file);
|
|
1338 }
|
|
1339
|
|
1340 static gint
|
|
1341 equalizerwin_list_sort_func(GtkCList * clist,
|
|
1342 gconstpointer ptr1, gconstpointer ptr2)
|
|
1343 {
|
|
1344 GtkCListRow *row1 = (GtkCListRow *) ptr1;
|
|
1345 GtkCListRow *row2 = (GtkCListRow *) ptr2;
|
|
1346
|
|
1347 return strcasecmp(GTK_CELL_TEXT(row1->cell[clist->sort_column])->text,
|
|
1348 GTK_CELL_TEXT(row2->cell[clist->sort_column])->text);
|
|
1349 }
|
|
1350
|
|
1351
|
|
1352 static GtkListStore *
|
|
1353 preset_list_store_new(GList * preset)
|
|
1354 {
|
|
1355 GtkListStore *store;
|
|
1356 GtkTreeIter iter;
|
|
1357 GList *node;
|
|
1358
|
|
1359 store = gtk_list_store_new(PRESET_VIEW_N_COLS, G_TYPE_STRING);
|
|
1360
|
|
1361 for (node = preset; node; node = g_list_next(node)) {
|
|
1362 gtk_list_store_append(store, &iter);
|
|
1363 gtk_list_store_set(store, &iter,
|
|
1364 PRESET_VIEW_COL_NAME,
|
|
1365 &((EqualizerPreset *) node->data)->name, -1);
|
|
1366 }
|
|
1367
|
|
1368 return store;
|
|
1369 }
|
|
1370
|
|
1371
|
|
1372 GtkWidget *
|
|
1373 preset_view_new(GList * preset)
|
|
1374 {
|
|
1375 GtkWidget *treeview;
|
|
1376 GtkTreeModel *model;
|
|
1377 GtkTreeViewColumn *column;
|
|
1378 GtkCellRenderer *renderer;
|
|
1379 GtkListStore *store;
|
|
1380
|
|
1381 store = preset_list_store_new(preset);
|
|
1382
|
|
1383 model = gtk_tree_model_sort_new_with_model(GTK_TREE_MODEL(store));
|
|
1384 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(model),
|
|
1385 PRESET_VIEW_COL_NAME,
|
|
1386 GTK_SORT_ASCENDING);
|
|
1387
|
|
1388 treeview = gtk_tree_view_new_with_model(model);
|
|
1389 gtk_tree_view_set_headers_clickable(GTK_TREE_VIEW(treeview), TRUE);
|
|
1390 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeview), TRUE);
|
|
1391
|
|
1392 renderer = gtk_cell_renderer_text_new();
|
|
1393 column = gtk_tree_view_column_new_with_attributes(_("Preset"), renderer,
|
|
1394 "text",
|
|
1395 PRESET_VIEW_COL_NAME,
|
|
1396 NULL);
|
|
1397 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
|
|
1398
|
|
1399 return treeview;
|
|
1400 }
|
|
1401
|
|
1402
|
|
1403 static GtkWidget *
|
|
1404 equalizerwin_create_list_window(GList * preset_list,
|
|
1405 const gchar * title,
|
|
1406 GtkWidget ** window,
|
|
1407 GtkSelectionMode sel_mode,
|
|
1408 GtkWidget ** entry,
|
|
1409 const gchar * btn2_stock_name,
|
|
1410 const gchar * btn3_stock_name,
|
|
1411 const gchar * btn1_stock_name,
|
|
1412 GCallback btn2_func,
|
|
1413 GCallback btn3_func,
|
|
1414 GCallback select_row_func)
|
|
1415 {
|
|
1416 GtkWidget *vbox, *scrolled_window, *bbox, *btn1, *btn2, *btn3, *clist;
|
|
1417 gchar *preset_text[1];
|
|
1418 GList *node;
|
|
1419
|
|
1420 *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
|
1421 gtk_window_set_title(GTK_WINDOW(*window), title);
|
|
1422 gtk_window_set_type_hint(GTK_WINDOW(*window), GDK_WINDOW_TYPE_HINT_DIALOG);
|
|
1423 gtk_window_set_default_size(GTK_WINDOW(*window), 350, 300);
|
|
1424 gtk_window_set_position(GTK_WINDOW(*window), GTK_WIN_POS_CENTER);
|
|
1425 gtk_container_set_border_width(GTK_CONTAINER(*window), 10);
|
|
1426 gtk_window_set_transient_for(GTK_WINDOW(*window),
|
|
1427 GTK_WINDOW(equalizerwin));
|
|
1428 g_signal_connect(*window, "destroy",
|
|
1429 G_CALLBACK(gtk_widget_destroyed), window);
|
|
1430
|
|
1431 vbox = gtk_vbox_new(FALSE, 10);
|
|
1432 gtk_container_add(GTK_CONTAINER(*window), vbox);
|
|
1433
|
|
1434 scrolled_window = gtk_scrolled_window_new(NULL, NULL);
|
|
1435 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),
|
|
1436 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
|
|
1437
|
|
1438 preset_text[0] = _("Presets");
|
|
1439 clist = gtk_clist_new_with_titles(1, preset_text);
|
|
1440 if (select_row_func)
|
|
1441 g_signal_connect(clist, "select_row",
|
|
1442 G_CALLBACK(select_row_func), NULL);
|
|
1443 gtk_clist_column_titles_passive(GTK_CLIST(clist));
|
|
1444 gtk_clist_set_selection_mode(GTK_CLIST(clist), sel_mode);
|
|
1445
|
|
1446 for (node = preset_list; node; node = g_list_next(node)) {
|
|
1447 gtk_clist_append(GTK_CLIST(clist),
|
|
1448 &((EqualizerPreset *) node->data)->name);
|
|
1449 }
|
|
1450 gtk_clist_set_compare_func(GTK_CLIST(clist), equalizerwin_list_sort_func);
|
|
1451 gtk_clist_sort(GTK_CLIST(clist));
|
|
1452
|
|
1453 gtk_container_add(GTK_CONTAINER(scrolled_window), clist);
|
|
1454 gtk_box_pack_start(GTK_BOX(vbox), scrolled_window, TRUE, TRUE, 0);
|
|
1455
|
|
1456 if (entry) {
|
|
1457 *entry = gtk_entry_new();
|
|
1458 g_signal_connect(*entry, "activate", btn2_func, NULL);
|
|
1459 gtk_box_pack_start(GTK_BOX(vbox), *entry, FALSE, FALSE, 0);
|
|
1460 }
|
|
1461
|
|
1462 bbox = gtk_hbutton_box_new();
|
|
1463 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END);
|
|
1464 gtk_button_box_set_spacing(GTK_BUTTON_BOX(bbox), 5);
|
|
1465 gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0);
|
|
1466
|
|
1467 btn1 = gtk_button_new_from_stock(btn1_stock_name);
|
|
1468 g_signal_connect_swapped(btn1, "clicked",
|
|
1469 G_CALLBACK(gtk_widget_destroy),
|
|
1470 GTK_OBJECT(*window));
|
|
1471 gtk_box_pack_start(GTK_BOX(bbox), btn1, TRUE, TRUE, 0);
|
|
1472
|
|
1473 if (btn3_stock_name) {
|
|
1474 btn3 = gtk_button_new_from_stock(btn3_stock_name);
|
|
1475 g_signal_connect(btn3, "clicked", G_CALLBACK(btn3_func), clist);
|
|
1476 gtk_box_pack_start(GTK_BOX(bbox), btn3, TRUE, TRUE, 0);
|
|
1477 }
|
|
1478
|
|
1479 btn2 = gtk_button_new_from_stock(btn2_stock_name);
|
|
1480 g_signal_connect(btn2, "clicked", G_CALLBACK(btn2_func), clist);
|
|
1481 GTK_WIDGET_SET_FLAGS(btn2, GTK_CAN_DEFAULT);
|
|
1482
|
|
1483 gtk_box_pack_start(GTK_BOX(bbox), btn2, TRUE, TRUE, 0);
|
|
1484
|
|
1485 gtk_widget_grab_default(btn2);
|
|
1486
|
|
1487
|
|
1488 gtk_widget_show_all(*window);
|
|
1489
|
|
1490 return *window;
|
|
1491 }
|
|
1492
|
|
1493 void
|
|
1494 equalizerwin_presets_menu_cb(gpointer cb_data, guint action, GtkWidget * w)
|
|
1495 {
|
|
1496 GtkWidget *dialog;
|
|
1497
|
|
1498 switch (action) {
|
|
1499 case EQUALIZER_PRESETS_LOAD_PRESET:
|
|
1500 if (!equalizerwin_load_window)
|
|
1501 equalizerwin_create_list_window(equalizer_presets,
|
|
1502 _("Load preset"),
|
|
1503 &equalizerwin_load_window,
|
|
1504 GTK_SELECTION_SINGLE, NULL,
|
|
1505 GTK_STOCK_OK, GTK_STOCK_APPLY, GTK_STOCK_CANCEL,
|
|
1506 G_CALLBACK
|
|
1507 (equalizerwin_load_ok),
|
|
1508 G_CALLBACK
|
|
1509 (equalizerwin_load_apply),
|
|
1510 G_CALLBACK
|
|
1511 (equalizerwin_load_select));
|
|
1512 else
|
|
1513 gtk_window_present(GTK_WINDOW(equalizerwin_load_window));
|
|
1514 break;
|
|
1515 case EQUALIZER_PRESETS_LOAD_AUTOPRESET:
|
|
1516 if (!equalizerwin_load_auto_window)
|
|
1517 equalizerwin_create_list_window(equalizer_auto_presets,
|
|
1518 _("Load auto-preset"),
|
|
1519 &equalizerwin_load_auto_window,
|
|
1520 GTK_SELECTION_SINGLE, NULL,
|
|
1521 GTK_STOCK_OK, NULL, GTK_STOCK_CANCEL,
|
|
1522 G_CALLBACK
|
|
1523 (equalizerwin_load_auto_ok),
|
|
1524 NULL,
|
|
1525 G_CALLBACK
|
|
1526 (equalizerwin_load_auto_select));
|
|
1527 else
|
|
1528 gtk_window_present(GTK_WINDOW(equalizerwin_load_auto_window));
|
|
1529 break;
|
|
1530 case EQUALIZER_PRESETS_LOAD_DEFAULT:
|
|
1531 equalizerwin_load_preset(equalizer_presets, "Default");
|
|
1532 break;
|
|
1533 case EQUALIZER_PRESETS_LOAD_ZERO:
|
|
1534 {
|
|
1535 gint i;
|
|
1536
|
|
1537 eqslider_set_position(equalizerwin_preamp, 0);
|
|
1538 for (i = 0; i < 10; i++)
|
|
1539 eqslider_set_position(equalizerwin_bands[i], 0);
|
|
1540 equalizerwin_eq_changed();
|
|
1541 break;
|
|
1542 }
|
|
1543 case EQUALIZER_PRESETS_LOAD_FROM_FILE:
|
|
1544 dialog = make_filebrowser(_("Load equalizer preset"), FALSE);
|
|
1545 g_signal_connect(dialog , "response",
|
|
1546 G_CALLBACK(equalizerwin_file_chooser_on_response),
|
|
1547 load_preset_file);
|
|
1548 break;
|
|
1549 case EQUALIZER_PRESETS_LOAD_FROM_WINAMPFILE:
|
|
1550 dialog = make_filebrowser(_("Load equalizer preset"), FALSE);
|
|
1551 g_signal_connect(dialog, "response",
|
|
1552 G_CALLBACK(equalizerwin_file_chooser_on_response),
|
|
1553 load_winamp_file);
|
|
1554 break;
|
|
1555
|
|
1556 case EQUALIZER_PRESETS_IMPORT_WINAMPFILE:
|
|
1557 dialog = make_filebrowser(_("Load equalizer preset"), FALSE);
|
|
1558 g_signal_connect(dialog, "response",
|
|
1559 G_CALLBACK(equalizerwin_file_chooser_on_response),
|
|
1560 import_winamp_file);
|
|
1561 break;
|
|
1562
|
|
1563 case EQUALIZER_PRESETS_SAVE_PRESET:
|
|
1564 if (!equalizerwin_save_window)
|
|
1565 equalizerwin_create_list_window(equalizer_presets,
|
|
1566 _("Save preset"),
|
|
1567 &equalizerwin_save_window,
|
|
1568 GTK_SELECTION_SINGLE,
|
|
1569 &equalizerwin_save_entry,
|
|
1570 GTK_STOCK_OK, NULL, GTK_STOCK_CANCEL,
|
|
1571 G_CALLBACK
|
|
1572 (equalizerwin_save_ok),
|
|
1573 NULL,
|
|
1574 G_CALLBACK
|
|
1575 (equalizerwin_save_select));
|
|
1576 else
|
|
1577 gtk_window_present(GTK_WINDOW(equalizerwin_save_window));
|
|
1578 break;
|
|
1579
|
|
1580 case EQUALIZER_PRESETS_SAVE_AUTOPRESET:
|
|
1581 {
|
|
1582 gchar *name;
|
|
1583
|
|
1584 if (!equalizerwin_save_auto_window)
|
|
1585 equalizerwin_create_list_window(equalizer_auto_presets,
|
|
1586 _("Save auto-preset"),
|
|
1587 &equalizerwin_save_auto_window,
|
|
1588 GTK_SELECTION_SINGLE,
|
|
1589 &equalizerwin_save_auto_entry,
|
|
1590 GTK_STOCK_OK,
|
|
1591 NULL,
|
|
1592 GTK_STOCK_CANCEL,
|
|
1593 G_CALLBACK
|
|
1594 (equalizerwin_save_auto_ok),
|
|
1595 NULL,
|
|
1596 G_CALLBACK
|
|
1597 (equalizerwin_save_auto_select));
|
|
1598 else
|
|
1599 gtk_window_present(GTK_WINDOW(equalizerwin_save_auto_window));
|
|
1600
|
|
1601 name = playlist_get_filename(playlist_get_position());
|
|
1602
|
|
1603 if (name) {
|
|
1604 gtk_entry_set_text(GTK_ENTRY(equalizerwin_save_auto_entry),
|
|
1605 g_basename(name));
|
|
1606 g_free(name);
|
|
1607 }
|
|
1608 break;
|
|
1609 }
|
|
1610
|
|
1611 case EQUALIZER_PRESETS_SAVE_DEFAULT:
|
|
1612 equalizer_presets =
|
|
1613 equalizerwin_save_preset(equalizer_presets, "Default",
|
|
1614 "eq.preset");
|
|
1615 break;
|
|
1616
|
|
1617 case EQUALIZER_PRESETS_SAVE_TO_FILE:
|
|
1618 {
|
|
1619 gchar *songname;
|
|
1620
|
|
1621 dialog = make_filebrowser(_("Save equalizer preset"), TRUE);
|
|
1622 g_signal_connect(dialog, "response",
|
|
1623 G_CALLBACK(equalizerwin_file_chooser_on_response),
|
|
1624 save_preset_file);
|
|
1625
|
|
1626 songname = playlist_get_filename(playlist_get_position());
|
|
1627 if (songname) {
|
|
1628 gchar *eqname = g_strdup_printf("%s.%s", songname,
|
|
1629 cfg.eqpreset_extension);
|
|
1630 g_free(songname);
|
|
1631 gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog),
|
|
1632 eqname);
|
|
1633 g_free(eqname);
|
|
1634 }
|
|
1635
|
|
1636 break;
|
|
1637 }
|
|
1638
|
|
1639 case EQUALIZER_PRESETS_SAVE_TO_WINAMPFILE:
|
|
1640 dialog = make_filebrowser(_("Save equalizer preset"), TRUE);
|
|
1641 g_signal_connect(dialog, "response",
|
|
1642 G_CALLBACK(equalizerwin_file_chooser_on_response),
|
|
1643 save_winamp_file);
|
|
1644 break;
|
|
1645
|
|
1646 case EQUALIZER_PRESETS_DELETE_PRESET:
|
|
1647 if (!equalizerwin_delete_window)
|
|
1648 equalizerwin_create_list_window(equalizer_presets,
|
|
1649 _("Delete preset"),
|
|
1650 &equalizerwin_delete_window,
|
|
1651 GTK_SELECTION_EXTENDED, NULL,
|
|
1652 GTK_STOCK_DELETE,
|
|
1653 NULL,
|
|
1654 GTK_STOCK_CLOSE,
|
|
1655 G_CALLBACK
|
|
1656 (equalizerwin_delete_delete),
|
|
1657 NULL,
|
|
1658 NULL);
|
|
1659 else
|
|
1660 gtk_window_present(GTK_WINDOW(equalizerwin_delete_window));
|
|
1661
|
|
1662 break;
|
|
1663
|
|
1664 case EQUALIZER_PRESETS_DELETE_AUTOPRESET:
|
|
1665 if (!equalizerwin_delete_auto_window)
|
|
1666 equalizerwin_create_list_window(equalizer_auto_presets,
|
|
1667 _("Delete auto-preset"),
|
|
1668 &equalizerwin_delete_auto_window,
|
|
1669 GTK_SELECTION_EXTENDED, NULL,
|
|
1670 GTK_STOCK_DELETE,
|
|
1671 NULL,
|
|
1672 GTK_STOCK_CLOSE,
|
|
1673 G_CALLBACK
|
|
1674 (equalizerwin_delete_auto_delete),
|
|
1675 NULL,
|
|
1676 NULL);
|
|
1677 else
|
|
1678 gtk_window_present(GTK_WINDOW(equalizerwin_delete_auto_window));
|
|
1679
|
|
1680 break;
|
|
1681 }
|
|
1682 }
|
|
1683
|
|
1684 void
|
|
1685 equalizerwin_load_auto_preset(const gchar * filename)
|
|
1686 {
|
|
1687 gchar *presetfilename, *directory;
|
|
1688 RcFile *rcfile;
|
|
1689
|
|
1690 g_return_if_fail(filename != NULL);
|
|
1691
|
|
1692 if (!cfg.equalizer_autoload)
|
|
1693 return;
|
|
1694
|
|
1695 presetfilename = g_strconcat(filename, ".", cfg.eqpreset_extension, NULL);
|
|
1696
|
|
1697 /* First try to find a per file preset file */
|
|
1698 if (strlen(cfg.eqpreset_extension) > 0 &&
|
|
1699 (rcfile = bmp_rcfile_open(presetfilename)) != NULL) {
|
|
1700 g_free(presetfilename);
|
|
1701 equalizerwin_read_bmp_preset(rcfile);
|
|
1702 bmp_rcfile_free(rcfile);
|
|
1703 return;
|
|
1704 }
|
|
1705
|
|
1706 g_free(presetfilename);
|
|
1707
|
|
1708 directory = g_path_get_dirname(filename);
|
|
1709 presetfilename = g_build_filename(directory, cfg.eqpreset_default_file,
|
|
1710 NULL);
|
|
1711 g_free(directory);
|
|
1712
|
|
1713 /* Try to find a per directory preset file */
|
|
1714 if (strlen(cfg.eqpreset_default_file) > 0 &&
|
|
1715 (rcfile = bmp_rcfile_open(presetfilename)) != NULL) {
|
|
1716 equalizerwin_read_bmp_preset(rcfile);
|
|
1717 bmp_rcfile_free(rcfile);
|
|
1718 }
|
|
1719 else if (!equalizerwin_load_preset
|
|
1720 (equalizer_auto_presets, g_basename(filename))) {
|
|
1721 /* Fall back to the oldstyle auto presets */
|
|
1722 equalizerwin_load_preset(equalizer_presets, "Default");
|
|
1723 }
|
|
1724
|
|
1725 g_free(presetfilename);
|
|
1726 }
|
|
1727
|
|
1728 void
|
|
1729 equalizerwin_set_preamp(gfloat preamp)
|
|
1730 {
|
|
1731 eqslider_set_position(equalizerwin_preamp, preamp);
|
|
1732 equalizerwin_eq_changed();
|
|
1733 }
|
|
1734
|
|
1735 void
|
|
1736 equalizerwin_set_band(gint band, gfloat value)
|
|
1737 {
|
|
1738 g_return_if_fail(band >= 0 && band < 10);
|
|
1739 eqslider_set_position(equalizerwin_bands[band], value);
|
|
1740 }
|
|
1741
|
|
1742 gfloat
|
|
1743 equalizerwin_get_preamp(void)
|
|
1744 {
|
|
1745 return eqslider_get_position(equalizerwin_preamp);
|
|
1746 }
|
|
1747
|
|
1748 gfloat
|
|
1749 equalizerwin_get_band(gint band)
|
|
1750 {
|
|
1751 g_return_val_if_fail(band >= 0 && band < 10, 0);
|
|
1752 return eqslider_get_position(equalizerwin_bands[band]);
|
|
1753 }
|