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