Mercurial > audlegacy
annotate audacious/equalizer.c @ 1546:693531793a75 trunk
[svn] - dependency cleanup (pass 1 of many probably)
author | nenolod |
---|---|
date | Thu, 10 Aug 2006 13:47:58 -0700 |
parents | 06329cbf186a |
children | fb2ac7c9e096 |
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 |
1085 | 757 gtk_window_set_transient_for(GTK_WINDOW(equalizerwin), |
758 GTK_WINDOW(mainwin)); | |
759 gtk_window_set_skip_taskbar_hint(GTK_WINDOW(equalizerwin), TRUE); | |
760 | |
0 | 761 icon = gdk_pixbuf_new_from_xpm_data((const gchar **) bmp_eq_icon); |
762 gtk_window_set_icon(GTK_WINDOW(equalizerwin), icon); | |
763 g_object_unref(icon); | |
764 | |
765 gtk_widget_set_app_paintable(equalizerwin, TRUE); | |
766 | |
767 if (cfg.equalizer_x != -1 && cfg.save_window_position) | |
768 gtk_window_move(GTK_WINDOW(equalizerwin), | |
769 cfg.equalizer_x, cfg.equalizer_y); | |
770 | |
771 gtk_widget_set_events(equalizerwin, | |
772 GDK_FOCUS_CHANGE_MASK | GDK_BUTTON_MOTION_MASK | | |
773 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | | |
774 GDK_VISIBILITY_NOTIFY_MASK); | |
775 gtk_widget_realize(equalizerwin); | |
776 | |
777 util_set_cursor(equalizerwin); | |
778 | |
779 g_signal_connect(equalizerwin, "delete_event", | |
780 G_CALLBACK(equalizerwin_delete), NULL); | |
781 g_signal_connect(equalizerwin, "button_press_event", | |
782 G_CALLBACK(equalizerwin_press), NULL); | |
783 g_signal_connect(equalizerwin, "button_release_event", | |
784 G_CALLBACK(equalizerwin_release), NULL); | |
785 g_signal_connect(equalizerwin, "motion_notify_event", | |
786 G_CALLBACK(equalizerwin_motion), NULL); | |
787 g_signal_connect_after(equalizerwin, "focus_in_event", | |
788 G_CALLBACK(equalizerwin_focus_in), NULL); | |
789 g_signal_connect_after(equalizerwin, "focus_out_event", | |
790 G_CALLBACK(equalizerwin_focus_out), NULL); | |
791 g_signal_connect(equalizerwin, "configure_event", | |
792 G_CALLBACK(equalizerwin_configure), NULL); | |
793 g_signal_connect(equalizerwin, "style_set", | |
794 G_CALLBACK(equalizerwin_set_back_pixmap), NULL); | |
795 g_signal_connect(equalizerwin, "key_press_event", | |
796 G_CALLBACK(equalizerwin_keypress), NULL); | |
797 g_signal_connect(equalizerwin, "scroll_event", | |
798 G_CALLBACK(equalizerwin_scroll), NULL); | |
799 } | |
800 | |
801 void | |
802 equalizerwin_create_popup_menus(void) | |
803 { | |
804 equalizerwin_accel = gtk_accel_group_new(); | |
805 gtk_window_add_accel_group(GTK_WINDOW(equalizerwin), equalizerwin_accel); | |
806 | |
807 equalizerwin_presets_menu = create_menu(equalizerwin_presets_menu_entries, | |
808 equalizerwin_presets_menu_entries_num, | |
809 NULL); | |
810 } | |
811 | |
812 void | |
813 equalizerwin_create(void) | |
814 { | |
815 equalizer_presets = equalizerwin_read_presets("eq.preset"); | |
816 equalizer_auto_presets = equalizerwin_read_presets("eq.auto_preset"); | |
817 | |
818 equalizerwin_create_window(); | |
819 equalizerwin_create_popup_menus(); | |
820 | |
821 equalizerwin_gc = gdk_gc_new(equalizerwin->window); | |
822 equalizerwin_bg = gdk_pixmap_new(equalizerwin->window, 275, 116, -1); | |
823 | |
824 equalizerwin_create_widgets(); | |
825 | |
826 equalizerwin_set_back_pixmap(); | |
827 gdk_window_set_back_pixmap(equalizerwin->window, equalizerwin_bg, 0); | |
828 } | |
829 | |
830 | |
831 void | |
832 equalizerwin_show(gboolean show) | |
833 { | |
834 GtkWidget *item = gtk_item_factory_get_widget(mainwin_view_menu, | |
835 "/Show Equalizer"); | |
836 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), show); | |
837 } | |
838 | |
839 void | |
840 equalizerwin_real_show(void) | |
841 { | |
842 /* | |
843 * This function should only be called from the | |
844 * main menu signal handler | |
845 */ | |
846 | |
847 gint x, y; | |
848 | |
849 gtk_window_get_position(GTK_WINDOW(equalizerwin), &x, &y); | |
850 gtk_window_move(GTK_WINDOW(equalizerwin), x, y); | |
851 gtk_widget_set_size_request(equalizerwin, 275, | |
852 (cfg.equalizer_shaded ? 14 : 116)); | |
853 gdk_flush(); | |
854 draw_equalizer_window(TRUE); | |
855 cfg.equalizer_visible = TRUE; | |
856 tbutton_set_toggled(mainwin_eq, TRUE); | |
857 | |
858 gtk_widget_show(equalizerwin); | |
859 } | |
860 | |
861 void | |
862 equalizerwin_real_hide(void) | |
863 { | |
864 /* | |
865 * This function should only be called from the | |
866 * main menu signal handler | |
867 */ | |
868 gtk_widget_hide(equalizerwin); | |
869 cfg.equalizer_visible = FALSE; | |
870 tbutton_set_toggled(mainwin_eq, FALSE); | |
871 } | |
872 | |
873 static EqualizerPreset * | |
874 equalizerwin_find_preset(GList * list, const gchar * name) | |
875 { | |
876 GList *node = list; | |
877 EqualizerPreset *preset; | |
878 | |
879 while (node) { | |
880 preset = node->data; | |
881 if (!strcasecmp(preset->name, name)) | |
882 return preset; | |
883 node = g_list_next(node); | |
884 } | |
885 return NULL; | |
886 } | |
887 | |
888 static void | |
889 equalizerwin_write_preset_file(GList * list, const gchar * basename) | |
890 { | |
891 gchar *filename, *tmp; | |
892 gint i, p; | |
893 EqualizerPreset *preset; | |
894 RcFile *rcfile; | |
895 GList *node; | |
896 | |
897 rcfile = bmp_rcfile_new(); | |
898 p = 0; | |
899 for (node = list; node; node = g_list_next(node)) { | |
900 preset = node->data; | |
901 tmp = g_strdup_printf("Preset%d", p++); | |
902 bmp_rcfile_write_string(rcfile, "Presets", tmp, preset->name); | |
903 g_free(tmp); | |
904 bmp_rcfile_write_float(rcfile, preset->name, "Preamp", | |
905 preset->preamp); | |
906 for (i = 0; i < 10; i++) { | |
907 tmp = g_strdup_printf("Band%d\n", i); | |
908 bmp_rcfile_write_float(rcfile, preset->name, tmp, | |
909 preset->bands[i]); | |
910 g_free(tmp); | |
911 } | |
912 } | |
913 | |
914 filename = g_build_filename(bmp_paths[BMP_PATH_USER_DIR], basename, NULL); | |
915 bmp_rcfile_write(rcfile, filename); | |
916 bmp_rcfile_free(rcfile); | |
917 g_free(filename); | |
918 } | |
919 | |
920 static gboolean | |
921 equalizerwin_load_preset(GList * list, const gchar * name) | |
922 { | |
923 EqualizerPreset *preset; | |
924 gint i; | |
925 | |
926 if ((preset = equalizerwin_find_preset(list, name)) != NULL) { | |
927 eqslider_set_position(equalizerwin_preamp, preset->preamp); | |
928 for (i = 0; i < 10; i++) | |
929 eqslider_set_position(equalizerwin_bands[i], preset->bands[i]); | |
930 equalizerwin_eq_changed(); | |
931 return TRUE; | |
932 } | |
933 return FALSE; | |
934 } | |
935 | |
936 static GList * | |
937 equalizerwin_save_preset(GList * list, const gchar * name, | |
938 const gchar * filename) | |
939 { | |
940 gint i; | |
941 EqualizerPreset *preset; | |
942 | |
943 if (!(preset = equalizerwin_find_preset(list, name))) { | |
944 preset = g_new0(EqualizerPreset, 1); | |
945 preset->name = g_strdup(name); | |
946 list = g_list_append(list, preset); | |
947 } | |
948 | |
949 preset->preamp = eqslider_get_position(equalizerwin_preamp); | |
950 for (i = 0; i < 10; i++) | |
951 preset->bands[i] = eqslider_get_position(equalizerwin_bands[i]); | |
952 | |
953 equalizerwin_write_preset_file(list, filename); | |
954 | |
955 return list; | |
956 } | |
957 | |
958 static GList * | |
959 equalizerwin_delete_preset(GList * list, gchar * name, gchar * filename) | |
960 { | |
961 EqualizerPreset *preset; | |
962 GList *node; | |
963 | |
964 if (!(preset = equalizerwin_find_preset(list, name))) | |
965 return list; | |
966 | |
967 if (!(node = g_list_find(list, preset))) | |
968 return list; | |
969 | |
970 list = g_list_remove_link(list, node); | |
971 equalizer_preset_free(preset); | |
972 g_list_free_1(node); | |
973 | |
974 equalizerwin_write_preset_file(list, filename); | |
975 | |
976 return list; | |
977 } | |
978 | |
979 | |
980 static GList * | |
981 import_winamp_eqf(VFSFile * file) | |
982 { | |
983 gchar header[31]; | |
984 gchar name[257]; | |
985 gchar bands[11]; | |
986 gint i = 0; | |
987 GList *list = NULL; | |
988 EqualizerPreset *preset; | |
989 | |
990 vfs_fread(header, 1, 31, file); | |
991 if (!strncmp(header, "Winamp EQ library file v1.1", 27)) { | |
992 while (vfs_fread(name, 1, 257, file)) { | |
993 preset = equalizer_preset_new(name); | |
994 preset->preamp = 20.0 - ((bands[10] * 40.0) / 64); | |
995 | |
996 vfs_fread(bands, 1, 11, file); | |
997 | |
998 for (i = 0; i < 10; i++) | |
999 preset->bands[i] = 20.0 - ((bands[i] * 40.0) / 64); | |
1000 | |
1001 list = g_list_prepend(list, preset); | |
1002 } | |
1003 } | |
1004 | |
1005 list = g_list_reverse(list); | |
1006 return list; | |
1007 } | |
1008 | |
1009 static void | |
1010 equalizerwin_read_winamp_eqf(VFSFile * file) | |
1011 { | |
1012 gchar header[31]; | |
1013 guchar bands[11]; | |
1014 gint i; | |
1015 | |
1016 vfs_fread(header, 1, 31, file); | |
1017 | |
1018 if (!strncmp(header, "Winamp EQ library file v1.1", 27)) { | |
1019 /* Skip name */ | |
1020 if (vfs_fseek(file, 257, SEEK_CUR) == -1) | |
1021 return; | |
1022 | |
1023 if (vfs_fread(bands, 1, 11, file) != 11) | |
1024 return; | |
1025 | |
1026 eqslider_set_position(equalizerwin_preamp, | |
1027 20.0 - ((bands[10] * 40.0) / 63.0)); | |
1028 | |
1029 for (i = 0; i < 10; i++) | |
1030 eqslider_set_position(equalizerwin_bands[i], | |
1031 20.0 - ((bands[i] * 40.0) / 64.0)); | |
1032 } | |
1033 | |
1034 equalizerwin_eq_changed(); | |
1035 } | |
1036 | |
1037 static void | |
1038 equalizerwin_read_bmp_preset(RcFile * rcfile) | |
1039 { | |
1040 gfloat val; | |
1041 gint i; | |
1042 | |
1043 if (bmp_rcfile_read_float(rcfile, "Equalizer preset", "Preamp", &val)) | |
1044 eqslider_set_position(equalizerwin_preamp, val); | |
1045 for (i = 0; i < 10; i++) { | |
1046 gchar tmp[7]; | |
1047 g_snprintf(tmp, sizeof(tmp), "Band%d", i); | |
1048 if (bmp_rcfile_read_float(rcfile, "Equalizer preset", tmp, &val)) | |
1049 eqslider_set_position(equalizerwin_bands[i], val); | |
1050 } | |
1051 equalizerwin_eq_changed(); | |
1052 } | |
1053 | |
1054 static void | |
1055 equalizerwin_save_ok(GtkWidget * widget, gpointer data) | |
1056 { | |
1057 const gchar *text; | |
1058 | |
1059 text = gtk_entry_get_text(GTK_ENTRY(equalizerwin_save_entry)); | |
1060 if (strlen(text) != 0) | |
1061 equalizer_presets = | |
1062 equalizerwin_save_preset(equalizer_presets, text, "eq.preset"); | |
1063 gtk_widget_destroy(equalizerwin_save_window); | |
1064 } | |
1065 | |
1066 static void | |
1067 equalizerwin_save_select(GtkCList * clist, gint row, | |
1068 gint column, GdkEventButton * event, gpointer data) | |
1069 { | |
1070 gchar *text; | |
1071 | |
1072 gtk_clist_get_text(clist, row, 0, &text); | |
1073 | |
1074 gtk_entry_set_text(GTK_ENTRY(equalizerwin_save_entry), text); | |
1075 if (event->type == GDK_2BUTTON_PRESS) | |
1076 equalizerwin_save_ok(NULL, NULL); | |
1077 | |
1078 } | |
1079 | |
1080 static void | |
1081 equalizerwin_load_ok(GtkWidget * widget, gpointer data) | |
1082 { | |
1083 gchar *text; | |
1084 GtkCList *clist = GTK_CLIST(data); | |
1085 | |
1086 if (clist && clist->selection) { | |
1087 gtk_clist_get_text(clist, GPOINTER_TO_INT(clist->selection->data), | |
1088 0, &text); | |
1089 equalizerwin_load_preset(equalizer_presets, text); | |
1090 } | |
1091 gtk_widget_destroy(equalizerwin_load_window); | |
1092 } | |
1093 | |
1094 static void | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1095 equalizerwin_load_apply(GtkWidget * widget, gpointer data) |
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1096 { |
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1097 gchar *text; |
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1098 GtkCList *clist = GTK_CLIST(data); |
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1099 |
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1100 if (clist && clist->selection) { |
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1101 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
|
1102 0, &text); |
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1103 equalizerwin_load_preset(equalizer_presets, text); |
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1104 } |
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 static void |
0 | 1109 equalizerwin_load_select(GtkCList * widget, gint row, |
1110 gint column, GdkEventButton * event, gpointer data) | |
1111 { | |
1112 if (event->type == GDK_2BUTTON_PRESS) | |
1113 equalizerwin_load_ok(NULL, widget); | |
1114 } | |
1115 | |
1116 static void | |
1117 equalizerwin_delete_delete(GtkWidget * widget, gpointer data) | |
1118 { | |
1119 gchar *text; | |
1120 GList *list, *next; | |
1121 GtkCList *clist = GTK_CLIST(data); | |
1122 | |
1123 g_return_if_fail(clist != NULL); | |
1124 | |
1125 list = clist->selection; | |
1126 gtk_clist_freeze(clist); | |
1127 while (list) { | |
1128 next = g_list_next(list); | |
1129 gtk_clist_get_text(clist, GPOINTER_TO_INT(list->data), 0, &text); | |
1130 equalizer_auto_presets = | |
1131 equalizerwin_delete_preset(equalizer_presets, text, "eq.preset"); | |
1132 gtk_clist_remove(clist, GPOINTER_TO_INT(list->data)); | |
1133 list = next; | |
1134 } | |
1135 gtk_clist_thaw(clist); | |
1136 } | |
1137 | |
1138 static void | |
1139 equalizerwin_save_auto_ok(GtkWidget * widget, gpointer data) | |
1140 { | |
1141 const gchar *text; | |
1142 | |
1143 text = gtk_entry_get_text(GTK_ENTRY(equalizerwin_save_auto_entry)); | |
1144 if (strlen(text) != 0) | |
1145 equalizer_auto_presets = | |
1146 equalizerwin_save_preset(equalizer_auto_presets, text, | |
1147 "eq.auto_preset"); | |
1148 gtk_widget_destroy(equalizerwin_save_auto_window); | |
1149 } | |
1150 | |
1151 static void | |
1152 equalizerwin_save_auto_select(GtkCList * clist, gint row, | |
1153 gint column, | |
1154 GdkEventButton * event, gpointer data) | |
1155 { | |
1156 gchar *text; | |
1157 | |
1158 gtk_clist_get_text(clist, row, 0, &text); | |
1159 | |
1160 gtk_entry_set_text(GTK_ENTRY(equalizerwin_save_auto_entry), text); | |
1161 if (event->type == GDK_2BUTTON_PRESS) | |
1162 equalizerwin_save_auto_ok(NULL, NULL); | |
1163 | |
1164 } | |
1165 | |
1166 static void | |
1167 equalizerwin_load_auto_ok(GtkWidget * widget, gpointer data) | |
1168 { | |
1169 gchar *text; | |
1170 GtkCList *clist = GTK_CLIST(data); | |
1171 | |
1172 if (clist && clist->selection) { | |
1173 gtk_clist_get_text(clist, GPOINTER_TO_INT(clist->selection->data), | |
1174 0, &text); | |
1175 equalizerwin_load_preset(equalizer_auto_presets, text); | |
1176 } | |
1177 gtk_widget_destroy(equalizerwin_load_auto_window); | |
1178 } | |
1179 | |
1180 static void | |
1181 equalizerwin_load_auto_select(GtkWidget * widget, gint row, | |
1182 gint column, | |
1183 GdkEventButton * event, gpointer data) | |
1184 { | |
1185 if (event->type == GDK_2BUTTON_PRESS) | |
1186 equalizerwin_load_auto_ok(NULL, widget); | |
1187 } | |
1188 | |
1189 static void | |
1190 equalizerwin_delete_auto_delete(GtkWidget * widget, gpointer data) | |
1191 { | |
1192 gchar *text; | |
1193 GList *list, *next; | |
1194 GtkCList *clist = GTK_CLIST(data); | |
1195 | |
1196 g_return_if_fail(clist != NULL); | |
1197 | |
1198 list = clist->selection; | |
1199 gtk_clist_freeze(clist); | |
1200 while (list) { | |
1201 next = g_list_next(list); | |
1202 gtk_clist_get_text(clist, GPOINTER_TO_INT(list->data), 0, &text); | |
1203 equalizer_auto_presets = | |
1204 equalizerwin_delete_preset(equalizer_auto_presets, text, | |
1205 "eq.auto_preset"); | |
1206 gtk_clist_remove(clist, GPOINTER_TO_INT(list->data)); | |
1207 list = next; | |
1208 } | |
1209 gtk_clist_thaw(clist); | |
1210 } | |
1211 | |
1212 | |
1213 typedef void (*ResponseHandler)(const gchar *filename); | |
1214 | |
1215 static void | |
1216 equalizerwin_file_chooser_on_response(GtkWidget * dialog, | |
1217 gint response, | |
1218 gpointer data) | |
1219 { | |
1220 GtkFileChooser *file_chooser = GTK_FILE_CHOOSER(dialog); | |
1221 ResponseHandler handler = (ResponseHandler) data; | |
1222 gchar *filename; | |
1223 | |
1224 gtk_widget_hide(dialog); | |
1225 | |
1226 switch (response) | |
1227 { | |
1228 case GTK_RESPONSE_ACCEPT: | |
1229 filename = gtk_file_chooser_get_filename(file_chooser); | |
1230 handler(filename); | |
1231 g_free(filename); | |
1232 break; | |
1233 | |
1234 case GTK_RESPONSE_REJECT: | |
1235 break; | |
1236 } | |
1237 | |
1238 gtk_widget_destroy(dialog); | |
1239 } | |
1240 | |
1241 | |
1242 | |
1243 static void | |
1244 load_preset_file(const gchar *filename) | |
1245 { | |
1246 RcFile *rcfile; | |
1247 | |
1248 if ((rcfile = bmp_rcfile_open(filename)) != NULL) { | |
1249 equalizerwin_read_bmp_preset(rcfile); | |
1250 bmp_rcfile_free(rcfile); | |
1251 } | |
1252 } | |
1253 | |
1254 static void | |
1255 load_winamp_file(const gchar * filename) | |
1256 { | |
1257 VFSFile *file; | |
781
12c47704b4b5
[svn] Add error reporting for many places, patch by external contributor Derek
nenolod
parents:
625
diff
changeset
|
1258 gchar *tmp; |
0 | 1259 |
781
12c47704b4b5
[svn] Add error reporting for many places, patch by external contributor Derek
nenolod
parents:
625
diff
changeset
|
1260 if (!(file = vfs_fopen(filename, "rb"))) { |
12c47704b4b5
[svn] Add error reporting for many places, patch by external contributor Derek
nenolod
parents:
625
diff
changeset
|
1261 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
|
1262 report_error(tmp); |
12c47704b4b5
[svn] Add error reporting for many places, patch by external contributor Derek
nenolod
parents:
625
diff
changeset
|
1263 g_free(tmp); |
0 | 1264 return; |
781
12c47704b4b5
[svn] Add error reporting for many places, patch by external contributor Derek
nenolod
parents:
625
diff
changeset
|
1265 } |
0 | 1266 |
1267 equalizerwin_read_winamp_eqf(file); | |
1268 vfs_fclose(file); | |
1269 } | |
1270 | |
1271 static void | |
1272 import_winamp_file(const gchar * filename) | |
1273 { | |
1274 VFSFile *file; | |
781
12c47704b4b5
[svn] Add error reporting for many places, patch by external contributor Derek
nenolod
parents:
625
diff
changeset
|
1275 gchar *tmp; |
0 | 1276 |
781
12c47704b4b5
[svn] Add error reporting for many places, patch by external contributor Derek
nenolod
parents:
625
diff
changeset
|
1277 if (!(file = vfs_fopen(filename, "rb"))) { |
12c47704b4b5
[svn] Add error reporting for many places, patch by external contributor Derek
nenolod
parents:
625
diff
changeset
|
1278 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
|
1279 report_error(tmp); |
12c47704b4b5
[svn] Add error reporting for many places, patch by external contributor Derek
nenolod
parents:
625
diff
changeset
|
1280 g_free(tmp); |
0 | 1281 return; |
781
12c47704b4b5
[svn] Add error reporting for many places, patch by external contributor Derek
nenolod
parents:
625
diff
changeset
|
1282 } |
0 | 1283 |
1284 equalizer_presets = g_list_concat(equalizer_presets, | |
1285 import_winamp_eqf(file)); | |
1286 equalizerwin_write_preset_file(equalizer_presets, "eq.preset"); | |
1287 | |
1288 vfs_fclose(file); | |
1289 } | |
1290 | |
1291 static void | |
1292 save_preset_file(const gchar * filename) | |
1293 { | |
1294 RcFile *rcfile; | |
1295 gint i; | |
1296 | |
1297 rcfile = bmp_rcfile_new(); | |
1298 bmp_rcfile_write_float(rcfile, "Equalizer preset", "Preamp", | |
1299 eqslider_get_position(equalizerwin_preamp)); | |
1300 | |
1301 for (i = 0; i < 10; i++) { | |
1302 gchar tmp[7]; | |
1303 g_snprintf(tmp, sizeof(tmp), "Band%d", i); | |
1304 bmp_rcfile_write_float(rcfile, "Equalizer preset", tmp, | |
1305 eqslider_get_position(equalizerwin_bands[i])); | |
1306 } | |
1307 | |
1308 bmp_rcfile_write(rcfile, filename); | |
1309 bmp_rcfile_free(rcfile); | |
1310 } | |
1311 | |
1312 static void | |
1313 save_winamp_file(const gchar * filename) | |
1314 { | |
1315 VFSFile *file; | |
1316 | |
1317 gchar name[257]; | |
1318 gint i; | |
1319 guchar bands[11]; | |
781
12c47704b4b5
[svn] Add error reporting for many places, patch by external contributor Derek
nenolod
parents:
625
diff
changeset
|
1320 gchar *tmp; |
0 | 1321 |
781
12c47704b4b5
[svn] Add error reporting for many places, patch by external contributor Derek
nenolod
parents:
625
diff
changeset
|
1322 if (!(file = vfs_fopen(filename, "wb"))) { |
12c47704b4b5
[svn] Add error reporting for many places, patch by external contributor Derek
nenolod
parents:
625
diff
changeset
|
1323 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
|
1324 report_error(tmp); |
12c47704b4b5
[svn] Add error reporting for many places, patch by external contributor Derek
nenolod
parents:
625
diff
changeset
|
1325 g_free(tmp); |
0 | 1326 return; |
781
12c47704b4b5
[svn] Add error reporting for many places, patch by external contributor Derek
nenolod
parents:
625
diff
changeset
|
1327 } |
0 | 1328 |
1329 vfs_fwrite("Winamp EQ library file v1.1\x1a!--", 1, 31, file); | |
1330 | |
1331 memset(name, 0, 257); | |
1332 strcpy(name, "Entry1"); | |
1333 vfs_fwrite(name, 1, 257, file); | |
1334 | |
1335 for (i = 0; i < 10; i++) | |
1336 bands[i] = 63 - (((eqslider_get_position(equalizerwin_bands[i]) + 20) * 63) / 40); | |
1337 bands[10] = 63 - (((eqslider_get_position(equalizerwin_preamp) + 20) * 63) / 40); | |
1338 vfs_fwrite(bands, 1, 11, file); | |
1339 | |
1340 vfs_fclose(file); | |
1341 } | |
1342 | |
1343 static gint | |
1344 equalizerwin_list_sort_func(GtkCList * clist, | |
1345 gconstpointer ptr1, gconstpointer ptr2) | |
1346 { | |
1347 GtkCListRow *row1 = (GtkCListRow *) ptr1; | |
1348 GtkCListRow *row2 = (GtkCListRow *) ptr2; | |
1349 | |
1350 return strcasecmp(GTK_CELL_TEXT(row1->cell[clist->sort_column])->text, | |
1351 GTK_CELL_TEXT(row2->cell[clist->sort_column])->text); | |
1352 } | |
1353 | |
1354 | |
1355 static GtkListStore * | |
1356 preset_list_store_new(GList * preset) | |
1357 { | |
1358 GtkListStore *store; | |
1359 GtkTreeIter iter; | |
1360 GList *node; | |
1361 | |
1362 store = gtk_list_store_new(PRESET_VIEW_N_COLS, G_TYPE_STRING); | |
1363 | |
1364 for (node = preset; node; node = g_list_next(node)) { | |
1365 gtk_list_store_append(store, &iter); | |
1366 gtk_list_store_set(store, &iter, | |
1367 PRESET_VIEW_COL_NAME, | |
1368 &((EqualizerPreset *) node->data)->name, -1); | |
1369 } | |
1370 | |
1371 return store; | |
1372 } | |
1373 | |
1374 | |
1375 GtkWidget * | |
1376 preset_view_new(GList * preset) | |
1377 { | |
1378 GtkWidget *treeview; | |
1379 GtkTreeModel *model; | |
1380 GtkTreeViewColumn *column; | |
1381 GtkCellRenderer *renderer; | |
1382 GtkListStore *store; | |
1383 | |
1384 store = preset_list_store_new(preset); | |
1385 | |
1386 model = gtk_tree_model_sort_new_with_model(GTK_TREE_MODEL(store)); | |
1387 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(model), | |
1388 PRESET_VIEW_COL_NAME, | |
1389 GTK_SORT_ASCENDING); | |
1390 | |
1391 treeview = gtk_tree_view_new_with_model(model); | |
1392 gtk_tree_view_set_headers_clickable(GTK_TREE_VIEW(treeview), TRUE); | |
1393 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeview), TRUE); | |
1394 | |
1395 renderer = gtk_cell_renderer_text_new(); | |
1396 column = gtk_tree_view_column_new_with_attributes(_("Preset"), renderer, | |
1397 "text", | |
1398 PRESET_VIEW_COL_NAME, | |
1399 NULL); | |
1400 gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); | |
1401 | |
1402 return treeview; | |
1403 } | |
1404 | |
1405 | |
1406 static GtkWidget * | |
1407 equalizerwin_create_list_window(GList * preset_list, | |
1408 const gchar * title, | |
1409 GtkWidget ** window, | |
1410 GtkSelectionMode sel_mode, | |
1411 GtkWidget ** entry, | |
1412 const gchar * btn2_stock_name, | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1413 const gchar * btn3_stock_name, |
0 | 1414 const gchar * btn1_stock_name, |
1415 GCallback btn2_func, | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1416 GCallback btn3_func, |
0 | 1417 GCallback select_row_func) |
1418 { | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1419 GtkWidget *vbox, *scrolled_window, *bbox, *btn1, *btn2, *btn3, *clist; |
0 | 1420 gchar *preset_text[1]; |
1421 GList *node; | |
1422 | |
1423 *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
1424 gtk_window_set_title(GTK_WINDOW(*window), title); | |
1425 gtk_window_set_type_hint(GTK_WINDOW(*window), GDK_WINDOW_TYPE_HINT_DIALOG); | |
1426 gtk_window_set_default_size(GTK_WINDOW(*window), 350, 300); | |
1427 gtk_window_set_position(GTK_WINDOW(*window), GTK_WIN_POS_CENTER); | |
1428 gtk_container_set_border_width(GTK_CONTAINER(*window), 10); | |
1429 gtk_window_set_transient_for(GTK_WINDOW(*window), | |
1430 GTK_WINDOW(equalizerwin)); | |
1431 g_signal_connect(*window, "destroy", | |
1432 G_CALLBACK(gtk_widget_destroyed), window); | |
1433 | |
1434 vbox = gtk_vbox_new(FALSE, 10); | |
1435 gtk_container_add(GTK_CONTAINER(*window), vbox); | |
1436 | |
1437 scrolled_window = gtk_scrolled_window_new(NULL, NULL); | |
1438 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window), | |
1439 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); | |
1440 | |
1441 preset_text[0] = _("Presets"); | |
1442 clist = gtk_clist_new_with_titles(1, preset_text); | |
1443 if (select_row_func) | |
1444 g_signal_connect(clist, "select_row", | |
1445 G_CALLBACK(select_row_func), NULL); | |
1446 gtk_clist_column_titles_passive(GTK_CLIST(clist)); | |
1447 gtk_clist_set_selection_mode(GTK_CLIST(clist), sel_mode); | |
1448 | |
1449 for (node = preset_list; node; node = g_list_next(node)) { | |
1450 gtk_clist_append(GTK_CLIST(clist), | |
1451 &((EqualizerPreset *) node->data)->name); | |
1452 } | |
1453 gtk_clist_set_compare_func(GTK_CLIST(clist), equalizerwin_list_sort_func); | |
1454 gtk_clist_sort(GTK_CLIST(clist)); | |
1455 | |
1456 gtk_container_add(GTK_CONTAINER(scrolled_window), clist); | |
1457 gtk_box_pack_start(GTK_BOX(vbox), scrolled_window, TRUE, TRUE, 0); | |
1458 | |
1459 if (entry) { | |
1460 *entry = gtk_entry_new(); | |
1461 g_signal_connect(*entry, "activate", btn2_func, NULL); | |
1462 gtk_box_pack_start(GTK_BOX(vbox), *entry, FALSE, FALSE, 0); | |
1463 } | |
1464 | |
1465 bbox = gtk_hbutton_box_new(); | |
1466 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); | |
1467 gtk_button_box_set_spacing(GTK_BUTTON_BOX(bbox), 5); | |
1468 gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0); | |
1469 | |
1470 btn1 = gtk_button_new_from_stock(btn1_stock_name); | |
1471 g_signal_connect_swapped(btn1, "clicked", | |
1472 G_CALLBACK(gtk_widget_destroy), | |
1473 GTK_OBJECT(*window)); | |
1474 gtk_box_pack_start(GTK_BOX(bbox), btn1, TRUE, TRUE, 0); | |
1475 | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1476 if (btn3_stock_name) { |
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1477 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
|
1478 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
|
1479 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
|
1480 } |
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1481 |
0 | 1482 btn2 = gtk_button_new_from_stock(btn2_stock_name); |
1483 g_signal_connect(btn2, "clicked", G_CALLBACK(btn2_func), clist); | |
1484 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
|
1485 |
0 | 1486 gtk_box_pack_start(GTK_BOX(bbox), btn2, TRUE, TRUE, 0); |
1487 | |
1488 gtk_widget_grab_default(btn2); | |
1489 | |
1490 | |
1491 gtk_widget_show_all(*window); | |
1492 | |
1493 return *window; | |
1494 } | |
1495 | |
1496 void | |
1497 equalizerwin_presets_menu_cb(gpointer cb_data, guint action, GtkWidget * w) | |
1498 { | |
1499 GtkWidget *dialog; | |
1500 | |
1501 switch (action) { | |
1502 case EQUALIZER_PRESETS_LOAD_PRESET: | |
1503 if (!equalizerwin_load_window) | |
1504 equalizerwin_create_list_window(equalizer_presets, | |
1505 _("Load preset"), | |
1506 &equalizerwin_load_window, | |
1507 GTK_SELECTION_SINGLE, NULL, | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1508 GTK_STOCK_OK, GTK_STOCK_APPLY, GTK_STOCK_CANCEL, |
0 | 1509 G_CALLBACK |
1510 (equalizerwin_load_ok), | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1511 G_CALLBACK |
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1512 (equalizerwin_load_apply), |
0 | 1513 G_CALLBACK |
1514 (equalizerwin_load_select)); | |
1515 else | |
1516 gtk_window_present(GTK_WINDOW(equalizerwin_load_window)); | |
1517 break; | |
1518 case EQUALIZER_PRESETS_LOAD_AUTOPRESET: | |
1519 if (!equalizerwin_load_auto_window) | |
1520 equalizerwin_create_list_window(equalizer_auto_presets, | |
1521 _("Load auto-preset"), | |
1522 &equalizerwin_load_auto_window, | |
1523 GTK_SELECTION_SINGLE, NULL, | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1524 GTK_STOCK_OK, NULL, GTK_STOCK_CANCEL, |
0 | 1525 G_CALLBACK |
1526 (equalizerwin_load_auto_ok), | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1527 NULL, |
0 | 1528 G_CALLBACK |
1529 (equalizerwin_load_auto_select)); | |
1530 else | |
1531 gtk_window_present(GTK_WINDOW(equalizerwin_load_auto_window)); | |
1532 break; | |
1533 case EQUALIZER_PRESETS_LOAD_DEFAULT: | |
1534 equalizerwin_load_preset(equalizer_presets, "Default"); | |
1535 break; | |
1536 case EQUALIZER_PRESETS_LOAD_ZERO: | |
1537 { | |
1538 gint i; | |
1539 | |
1540 eqslider_set_position(equalizerwin_preamp, 0); | |
1541 for (i = 0; i < 10; i++) | |
1542 eqslider_set_position(equalizerwin_bands[i], 0); | |
1543 equalizerwin_eq_changed(); | |
1544 break; | |
1545 } | |
1546 case EQUALIZER_PRESETS_LOAD_FROM_FILE: | |
1547 dialog = make_filebrowser(_("Load equalizer preset"), FALSE); | |
1548 g_signal_connect(dialog , "response", | |
1549 G_CALLBACK(equalizerwin_file_chooser_on_response), | |
1550 load_preset_file); | |
1551 break; | |
1552 case EQUALIZER_PRESETS_LOAD_FROM_WINAMPFILE: | |
1553 dialog = make_filebrowser(_("Load equalizer preset"), FALSE); | |
1554 g_signal_connect(dialog, "response", | |
1555 G_CALLBACK(equalizerwin_file_chooser_on_response), | |
1556 load_winamp_file); | |
1557 break; | |
1558 | |
1559 case EQUALIZER_PRESETS_IMPORT_WINAMPFILE: | |
1560 dialog = make_filebrowser(_("Load equalizer preset"), FALSE); | |
1561 g_signal_connect(dialog, "response", | |
1562 G_CALLBACK(equalizerwin_file_chooser_on_response), | |
1563 import_winamp_file); | |
1564 break; | |
1565 | |
1566 case EQUALIZER_PRESETS_SAVE_PRESET: | |
1567 if (!equalizerwin_save_window) | |
1568 equalizerwin_create_list_window(equalizer_presets, | |
1569 _("Save preset"), | |
1570 &equalizerwin_save_window, | |
1571 GTK_SELECTION_SINGLE, | |
1572 &equalizerwin_save_entry, | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1573 GTK_STOCK_OK, NULL, GTK_STOCK_CANCEL, |
0 | 1574 G_CALLBACK |
1575 (equalizerwin_save_ok), | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1576 NULL, |
0 | 1577 G_CALLBACK |
1578 (equalizerwin_save_select)); | |
1579 else | |
1580 gtk_window_present(GTK_WINDOW(equalizerwin_save_window)); | |
1581 break; | |
1582 | |
1583 case EQUALIZER_PRESETS_SAVE_AUTOPRESET: | |
1584 { | |
1585 gchar *name; | |
1586 | |
1587 if (!equalizerwin_save_auto_window) | |
1588 equalizerwin_create_list_window(equalizer_auto_presets, | |
1589 _("Save auto-preset"), | |
1590 &equalizerwin_save_auto_window, | |
1591 GTK_SELECTION_SINGLE, | |
1592 &equalizerwin_save_auto_entry, | |
1593 GTK_STOCK_OK, | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1594 NULL, |
0 | 1595 GTK_STOCK_CANCEL, |
1596 G_CALLBACK | |
1597 (equalizerwin_save_auto_ok), | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1598 NULL, |
0 | 1599 G_CALLBACK |
1600 (equalizerwin_save_auto_select)); | |
1601 else | |
1602 gtk_window_present(GTK_WINDOW(equalizerwin_save_auto_window)); | |
1603 | |
1604 name = playlist_get_filename(playlist_get_position()); | |
1605 | |
1606 if (name) { | |
1607 gtk_entry_set_text(GTK_ENTRY(equalizerwin_save_auto_entry), | |
1608 g_basename(name)); | |
1609 g_free(name); | |
1610 } | |
1611 break; | |
1612 } | |
1613 | |
1614 case EQUALIZER_PRESETS_SAVE_DEFAULT: | |
1615 equalizer_presets = | |
1616 equalizerwin_save_preset(equalizer_presets, "Default", | |
1617 "eq.preset"); | |
1618 break; | |
1619 | |
1620 case EQUALIZER_PRESETS_SAVE_TO_FILE: | |
1621 { | |
1622 gchar *songname; | |
1623 | |
1624 dialog = make_filebrowser(_("Save equalizer preset"), TRUE); | |
1625 g_signal_connect(dialog, "response", | |
1626 G_CALLBACK(equalizerwin_file_chooser_on_response), | |
1627 save_preset_file); | |
1628 | |
1629 songname = playlist_get_filename(playlist_get_position()); | |
1630 if (songname) { | |
1631 gchar *eqname = g_strdup_printf("%s.%s", songname, | |
1632 cfg.eqpreset_extension); | |
1633 g_free(songname); | |
1634 gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), | |
1635 eqname); | |
1636 g_free(eqname); | |
1637 } | |
1638 | |
1639 break; | |
1640 } | |
1641 | |
1642 case EQUALIZER_PRESETS_SAVE_TO_WINAMPFILE: | |
1643 dialog = make_filebrowser(_("Save equalizer preset"), TRUE); | |
1644 g_signal_connect(dialog, "response", | |
1645 G_CALLBACK(equalizerwin_file_chooser_on_response), | |
1646 save_winamp_file); | |
1647 break; | |
1648 | |
1649 case EQUALIZER_PRESETS_DELETE_PRESET: | |
1650 if (!equalizerwin_delete_window) | |
1651 equalizerwin_create_list_window(equalizer_presets, | |
1652 _("Delete preset"), | |
1653 &equalizerwin_delete_window, | |
1654 GTK_SELECTION_EXTENDED, NULL, | |
1655 GTK_STOCK_DELETE, | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1656 NULL, |
0 | 1657 GTK_STOCK_CLOSE, |
1658 G_CALLBACK | |
1659 (equalizerwin_delete_delete), | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1660 NULL, |
0 | 1661 NULL); |
1662 else | |
1663 gtk_window_present(GTK_WINDOW(equalizerwin_delete_window)); | |
1664 | |
1665 break; | |
1666 | |
1667 case EQUALIZER_PRESETS_DELETE_AUTOPRESET: | |
1668 if (!equalizerwin_delete_auto_window) | |
1669 equalizerwin_create_list_window(equalizer_auto_presets, | |
1670 _("Delete auto-preset"), | |
1671 &equalizerwin_delete_auto_window, | |
1672 GTK_SELECTION_EXTENDED, NULL, | |
1673 GTK_STOCK_DELETE, | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1674 NULL, |
0 | 1675 GTK_STOCK_CLOSE, |
1676 G_CALLBACK | |
1677 (equalizerwin_delete_auto_delete), | |
439
3c43e25ddc7d
[svn] Add `Apply' button to the presets window. Patch via NhJm.
nenolod
parents:
424
diff
changeset
|
1678 NULL, |
0 | 1679 NULL); |
1680 else | |
1681 gtk_window_present(GTK_WINDOW(equalizerwin_delete_auto_window)); | |
1682 | |
1683 break; | |
1684 } | |
1685 } | |
1686 | |
1687 void | |
1688 equalizerwin_load_auto_preset(const gchar * filename) | |
1689 { | |
1690 gchar *presetfilename, *directory; | |
1691 RcFile *rcfile; | |
1692 | |
1693 g_return_if_fail(filename != NULL); | |
1694 | |
1695 if (!cfg.equalizer_autoload) | |
1696 return; | |
1697 | |
1698 presetfilename = g_strconcat(filename, ".", cfg.eqpreset_extension, NULL); | |
1699 | |
1700 /* First try to find a per file preset file */ | |
1701 if (strlen(cfg.eqpreset_extension) > 0 && | |
1702 (rcfile = bmp_rcfile_open(presetfilename)) != NULL) { | |
1703 g_free(presetfilename); | |
1704 equalizerwin_read_bmp_preset(rcfile); | |
1705 bmp_rcfile_free(rcfile); | |
1706 return; | |
1707 } | |
1708 | |
1709 g_free(presetfilename); | |
1710 | |
1711 directory = g_path_get_dirname(filename); | |
1712 presetfilename = g_build_filename(directory, cfg.eqpreset_default_file, | |
1713 NULL); | |
1714 g_free(directory); | |
1715 | |
1716 /* Try to find a per directory preset file */ | |
1717 if (strlen(cfg.eqpreset_default_file) > 0 && | |
1718 (rcfile = bmp_rcfile_open(presetfilename)) != NULL) { | |
1719 equalizerwin_read_bmp_preset(rcfile); | |
1720 bmp_rcfile_free(rcfile); | |
1721 } | |
1722 else if (!equalizerwin_load_preset | |
1723 (equalizer_auto_presets, g_basename(filename))) { | |
1724 /* Fall back to the oldstyle auto presets */ | |
1725 equalizerwin_load_preset(equalizer_presets, "Default"); | |
1726 } | |
1727 | |
1728 g_free(presetfilename); | |
1729 } | |
1730 | |
1731 void | |
1732 equalizerwin_set_preamp(gfloat preamp) | |
1733 { | |
1734 eqslider_set_position(equalizerwin_preamp, preamp); | |
1735 equalizerwin_eq_changed(); | |
1736 } | |
1737 | |
1738 void | |
1739 equalizerwin_set_band(gint band, gfloat value) | |
1740 { | |
1741 g_return_if_fail(band >= 0 && band < 10); | |
1742 eqslider_set_position(equalizerwin_bands[band], value); | |
1743 } | |
1744 | |
1745 gfloat | |
1746 equalizerwin_get_preamp(void) | |
1747 { | |
1748 return eqslider_get_position(equalizerwin_preamp); | |
1749 } | |
1750 | |
1751 gfloat | |
1752 equalizerwin_get_band(gint band) | |
1753 { | |
1754 g_return_val_if_fail(band >= 0 && band < 10, 0); | |
1755 return eqslider_get_position(equalizerwin_bands[band]); | |
1756 } |