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