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