Mercurial > audlegacy-plugins
annotate src/wavpack/ui.cxx @ 294:60b7388105ba trunk
[svn] - i hate the world.
author | nenolod |
---|---|
date | Wed, 22 Nov 2006 15:29:31 -0800 |
parents | 72f0de06bb56 |
children | 7385182ae4b8 |
rev | line source |
---|---|
109 | 1 #include <assert.h> |
2 #include <string.h> | |
3 #include <stdio.h> | |
4 #include <stdlib.h> | |
5 #include <pthread.h> | |
6 #include <unistd.h> | |
294 | 7 extern "C" { |
284
72f0de06bb56
[svn] - wavpack/wputils.h is deprecated, wavpack/wavpack.h should be used instead.
nenolod
parents:
246
diff
changeset
|
8 #include <wavpack/wavpack.h> |
109 | 9 #include <audacious/plugin.h> |
10 #include <audacious/configdb.h> | |
11 #include <audacious/titlestring.h> | |
12 #include <audacious/util.h> | |
13 } | |
14 #include <glib.h> | |
15 #include <gtk/gtk.h> | |
16 #include <iconv.h> | |
17 #include <math.h> | |
18 #include "tags.h" | |
19 #ifndef M_LN10 | |
20 #define M_LN10 2.3025850929940456840179914546843642 | |
21 #endif | |
22 | |
23 #define DBG(format, args...) fprintf(stderr, format, ## args) | |
24 | |
25 void load_tag(ape_tag *tag, WavpackContext *ctx); | |
26 gboolean clipPreventionEnabled; | |
27 gboolean dynBitrateEnabled; | |
28 gboolean replaygainEnabled; | |
29 gboolean albumReplaygainEnabled; | |
30 gboolean openedAudio; | |
31 static GtkWidget *window = NULL; | |
32 static GtkWidget *title_entry; | |
33 static GtkWidget *album_entry; | |
34 static GtkWidget *performer_entry; | |
35 static GtkWidget *tracknumber_entry; | |
36 static GtkWidget *date_entry; | |
37 static GtkWidget *genre_entry; | |
38 static GtkWidget *user_comment_entry; | |
39 static char *filename; | |
40 | |
41 void | |
42 wv_about_box() | |
43 { | |
44 static GtkWidget *about_window; | |
45 | |
46 if (about_window) | |
47 gdk_window_raise(about_window->window); | |
48 | |
49 about_window = | |
50 xmms_show_message(g_strdup_printf | |
51 ("Wavpack Decoder Plugin %s", VERSION), | |
246 | 52 ("Copyright (c) 2006 William Pitcock <nenolod -at- nenolod.net>\n\n" |
53 "Some of the plugin code was by Miles Egan\n" | |
109 | 54 "Visit the Wavpack site at http://www.wavpack.com/\n"), |
55 ("Ok"), FALSE, NULL, NULL); | |
56 gtk_signal_connect(GTK_OBJECT(about_window), "destroy", | |
57 GTK_SIGNAL_FUNC(gtk_widget_destroyed), &about_window); | |
58 } | |
59 | |
60 static void | |
61 label_set_text(GtkWidget * label, char *str, ...) | |
62 { | |
63 va_list args; | |
64 gchar *tempstr; | |
65 | |
66 va_start(args, str); | |
67 tempstr = g_strdup_vprintf(str, args); | |
68 va_end(args); | |
69 | |
70 gtk_label_set_text(GTK_LABEL(label), tempstr); | |
71 g_free(tempstr); | |
72 } | |
73 | |
74 static void | |
75 remove_cb(GtkWidget * w, gpointer data) | |
76 { | |
77 DeleteTag(filename); | |
78 g_free(filename); | |
79 gtk_widget_destroy(window); | |
80 } | |
81 | |
82 static void | |
83 save_cb(GtkWidget * w, gpointer data) | |
84 { | |
85 ape_tag Tag; | |
86 | |
87 strcpy(Tag.title, gtk_entry_get_text(GTK_ENTRY(title_entry))); | |
88 strcpy(Tag.artist, gtk_entry_get_text(GTK_ENTRY(performer_entry))); | |
89 strcpy(Tag.album, gtk_entry_get_text(GTK_ENTRY(album_entry))); | |
90 strcpy(Tag.comment, gtk_entry_get_text(GTK_ENTRY(user_comment_entry))); | |
91 strcpy(Tag.track, gtk_entry_get_text(GTK_ENTRY(tracknumber_entry))); | |
92 strcpy(Tag.year, gtk_entry_get_text(GTK_ENTRY(date_entry))); | |
93 strcpy(Tag.genre, gtk_entry_get_text(GTK_ENTRY(genre_entry))); | |
94 WriteAPE2Tag(filename, &Tag); | |
95 g_free(filename); | |
96 gtk_widget_destroy(window); | |
97 } | |
98 | |
99 static void | |
100 close_window(GtkWidget * w, gpointer data) | |
101 { | |
102 g_free(filename); | |
103 gtk_widget_destroy(window); | |
104 } | |
105 | |
106 void | |
107 wv_file_info_box(char *fn) | |
108 { | |
109 gchar *tmp; | |
110 gint time, minutes, seconds; | |
111 ape_tag tag; | |
112 | |
113 assert(fn != NULL); | |
114 char error_buff[4096]; // TODO: fixme! | |
115 WavpackContext *ctx = WavpackOpenFileInput(fn, error_buff, OPEN_TAGS | OPEN_WVC, 0); | |
116 if (ctx == NULL) { | |
117 printf("wavpack: Error opening file: \"%s: %s\"\n", fn, error_buff); | |
118 return; | |
119 } | |
120 int sample_rate = WavpackGetSampleRate(ctx); | |
121 int num_channels = WavpackGetNumChannels(ctx); | |
122 load_tag(&tag, ctx); | |
123 DBG("opened %s at %d rate with %d channels\n", fn, sample_rate, num_channels); | |
124 | |
125 filename = g_strdup(fn); | |
126 static GtkWidget *info_frame, *info_box, *bitrate_label, *rate_label; | |
127 static GtkWidget *version_label, *bits_per_sample_label; | |
128 static GtkWidget *channel_label, *length_label, *filesize_label; | |
129 static GtkWidget *peakTitle_label, *peakAlbum_label, *gainTitle_label; | |
130 static GtkWidget *gainAlbum_label, *filename_entry, *tag_frame; | |
131 | |
132 if (!window) { | |
133 GtkWidget *hbox, *label, *filename_hbox, *vbox, *left_vbox; | |
134 GtkWidget *table, *bbox, *cancel_button; | |
135 GtkWidget *save_button, *remove_button; | |
136 | |
111 | 137 window = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
109 | 138 gtk_window_set_policy(GTK_WINDOW(window), FALSE, FALSE, FALSE); |
139 gtk_signal_connect(GTK_OBJECT(window), "destroy", | |
140 GTK_SIGNAL_FUNC(gtk_widget_destroyed), &window); | |
141 gtk_container_set_border_width(GTK_CONTAINER(window), 10); | |
142 | |
143 vbox = gtk_vbox_new(FALSE, 10); | |
144 gtk_container_add(GTK_CONTAINER(window), vbox); | |
145 | |
146 filename_hbox = gtk_hbox_new(FALSE, 5); | |
147 gtk_box_pack_start(GTK_BOX(vbox), filename_hbox, FALSE, TRUE, 0); | |
148 | |
149 label = gtk_label_new("Filename:"); | |
150 gtk_box_pack_start(GTK_BOX(filename_hbox), label, FALSE, TRUE, 0); | |
151 filename_entry = gtk_entry_new(); | |
152 gtk_editable_set_editable(GTK_EDITABLE(filename_entry), FALSE); | |
153 gtk_box_pack_start(GTK_BOX(filename_hbox), filename_entry, | |
154 TRUE, TRUE, 0); | |
155 | |
156 hbox = gtk_hbox_new(FALSE, 10); | |
157 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0); | |
158 | |
159 left_vbox = gtk_vbox_new(FALSE, 10); | |
160 gtk_box_pack_start(GTK_BOX(hbox), left_vbox, FALSE, FALSE, 0); | |
161 | |
162 tag_frame = gtk_frame_new("Ape2 Tag"); | |
163 gtk_box_pack_start(GTK_BOX(left_vbox), tag_frame, FALSE, FALSE, 0); | |
164 | |
165 table = gtk_table_new(5, 5, FALSE); | |
166 gtk_container_set_border_width(GTK_CONTAINER(table), 5); | |
167 gtk_container_add(GTK_CONTAINER(tag_frame), table); | |
168 | |
169 label = gtk_label_new("Title:"); | |
170 gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5); | |
171 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1, | |
172 GTK_FILL, GTK_FILL, 5, 5); | |
173 | |
174 title_entry = gtk_entry_new(); | |
175 gtk_table_attach(GTK_TABLE(table), title_entry, 1, 4, 0, 1, | |
176 (GtkAttachOptions) (GTK_FILL | GTK_EXPAND | | |
177 GTK_SHRINK), | |
178 (GtkAttachOptions) (GTK_FILL | GTK_EXPAND | | |
179 GTK_SHRINK), 0, 5); | |
180 | |
181 label = gtk_label_new("Artist:"); | |
182 gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5); | |
183 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2, | |
184 GTK_FILL, GTK_FILL, 5, 5); | |
185 | |
186 performer_entry = gtk_entry_new(); | |
187 gtk_table_attach(GTK_TABLE(table), performer_entry, 1, 4, 1, 2, | |
188 (GtkAttachOptions) (GTK_FILL | GTK_EXPAND | | |
189 GTK_SHRINK), | |
190 (GtkAttachOptions) (GTK_FILL | GTK_EXPAND | | |
191 GTK_SHRINK), 0, 5); | |
192 | |
193 label = gtk_label_new("Album:"); | |
194 gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5); | |
195 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 2, 3, | |
196 GTK_FILL, GTK_FILL, 5, 5); | |
197 | |
198 album_entry = gtk_entry_new(); | |
199 gtk_table_attach(GTK_TABLE(table), album_entry, 1, 4, 2, 3, | |
200 (GtkAttachOptions) (GTK_FILL | GTK_EXPAND | | |
201 GTK_SHRINK), | |
202 (GtkAttachOptions) (GTK_FILL | GTK_EXPAND | | |
203 GTK_SHRINK), 0, 5); | |
204 | |
205 label = gtk_label_new("Comment:"); | |
206 gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5); | |
207 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 3, 4, | |
208 GTK_FILL, GTK_FILL, 5, 5); | |
209 | |
210 user_comment_entry = gtk_entry_new(); | |
211 gtk_table_attach(GTK_TABLE(table), user_comment_entry, 1, 4, 3, | |
212 4, | |
213 (GtkAttachOptions) (GTK_FILL | GTK_EXPAND | | |
214 GTK_SHRINK), | |
215 (GtkAttachOptions) (GTK_FILL | GTK_EXPAND | | |
216 GTK_SHRINK), 0, 5); | |
217 | |
218 label = gtk_label_new("Year:"); | |
219 gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5); | |
220 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 4, 5, | |
221 GTK_FILL, GTK_FILL, 5, 5); | |
222 | |
223 date_entry = gtk_entry_new(); | |
224 gtk_widget_set_usize(date_entry, 60, -1); | |
225 gtk_table_attach(GTK_TABLE(table), date_entry, 1, 2, 4, 5, | |
226 (GtkAttachOptions) (GTK_FILL | GTK_EXPAND | | |
227 GTK_SHRINK), | |
228 (GtkAttachOptions) (GTK_FILL | GTK_EXPAND | | |
229 GTK_SHRINK), 0, 5); | |
230 | |
113 | 231 label = gtk_label_new("Track number:"); |
109 | 232 gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5); |
233 gtk_table_attach(GTK_TABLE(table), label, 2, 3, 4, 5, | |
234 GTK_FILL, GTK_FILL, 5, 5); | |
235 | |
236 tracknumber_entry = gtk_entry_new_with_max_length(4); | |
237 gtk_widget_set_usize(tracknumber_entry, 20, -1); | |
238 gtk_table_attach(GTK_TABLE(table), tracknumber_entry, 3, 4, 4, | |
239 5, | |
240 (GtkAttachOptions) (GTK_FILL | GTK_EXPAND | | |
241 GTK_SHRINK), | |
242 (GtkAttachOptions) (GTK_FILL | GTK_EXPAND | | |
243 GTK_SHRINK), 0, 5); | |
244 | |
245 label = gtk_label_new("Genre:"); | |
246 gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5); | |
247 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 5, 6, | |
248 GTK_FILL, GTK_FILL, 5, 5); | |
249 | |
250 genre_entry = gtk_entry_new(); | |
251 gtk_widget_set_usize(genre_entry, 20, -1); | |
252 gtk_table_attach(GTK_TABLE(table), genre_entry, 1, 4, 5, | |
253 6, | |
254 (GtkAttachOptions) (GTK_FILL | GTK_EXPAND | | |
255 GTK_SHRINK), | |
256 (GtkAttachOptions) (GTK_FILL | GTK_EXPAND | | |
257 GTK_SHRINK), 0, 5); | |
258 | |
259 bbox = gtk_hbutton_box_new(); | |
260 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); | |
261 gtk_button_box_set_spacing(GTK_BUTTON_BOX(bbox), 5); | |
262 gtk_box_pack_start(GTK_BOX(left_vbox), bbox, FALSE, FALSE, 0); | |
263 | |
264 save_button = gtk_button_new_with_label("Save"); | |
265 gtk_signal_connect(GTK_OBJECT(save_button), "clicked", | |
266 GTK_SIGNAL_FUNC(save_cb), NULL); | |
267 GTK_WIDGET_SET_FLAGS(save_button, GTK_CAN_DEFAULT); | |
268 gtk_box_pack_start(GTK_BOX(bbox), save_button, TRUE, TRUE, 0); | |
269 | |
270 remove_button = gtk_button_new_with_label("Remove Tag"); | |
271 gtk_signal_connect_object(GTK_OBJECT(remove_button), | |
272 "clicked", | |
273 GTK_SIGNAL_FUNC(remove_cb), NULL); | |
274 GTK_WIDGET_SET_FLAGS(remove_button, GTK_CAN_DEFAULT); | |
275 gtk_box_pack_start(GTK_BOX(bbox), remove_button, TRUE, TRUE, 0); | |
276 | |
277 cancel_button = gtk_button_new_with_label("Cancel"); | |
278 gtk_signal_connect_object(GTK_OBJECT(cancel_button), | |
279 "clicked", | |
280 GTK_SIGNAL_FUNC(close_window), NULL); | |
281 GTK_WIDGET_SET_FLAGS(cancel_button, GTK_CAN_DEFAULT); | |
282 gtk_box_pack_start(GTK_BOX(bbox), cancel_button, TRUE, TRUE, 0); | |
283 gtk_widget_grab_default(cancel_button); | |
284 | |
285 info_frame = gtk_frame_new("Wavpack Info:"); | |
286 gtk_box_pack_start(GTK_BOX(hbox), info_frame, FALSE, FALSE, 0); | |
287 | |
288 info_box = gtk_vbox_new(FALSE, 5); | |
289 gtk_container_add(GTK_CONTAINER(info_frame), info_box); | |
290 gtk_container_set_border_width(GTK_CONTAINER(info_box), 10); | |
291 gtk_box_set_spacing(GTK_BOX(info_box), 0); | |
292 | |
293 version_label = gtk_label_new(""); | |
294 gtk_misc_set_alignment(GTK_MISC(version_label), 0, 0); | |
295 gtk_label_set_justify(GTK_LABEL(version_label), | |
296 GTK_JUSTIFY_LEFT); | |
297 gtk_box_pack_start(GTK_BOX(info_box), version_label, FALSE, | |
298 FALSE, 0); | |
299 | |
300 bits_per_sample_label = gtk_label_new(""); | |
301 gtk_misc_set_alignment(GTK_MISC(bits_per_sample_label), 0, 0); | |
302 gtk_label_set_justify(GTK_LABEL(bits_per_sample_label), GTK_JUSTIFY_LEFT); | |
303 gtk_box_pack_start(GTK_BOX(info_box), bits_per_sample_label, FALSE, FALSE, 0); | |
304 | |
305 bitrate_label = gtk_label_new(""); | |
306 gtk_misc_set_alignment(GTK_MISC(bitrate_label), 0, 0); | |
307 gtk_label_set_justify(GTK_LABEL(bitrate_label), GTK_JUSTIFY_LEFT); | |
308 gtk_box_pack_start(GTK_BOX(info_box), bitrate_label, FALSE, FALSE, 0); | |
309 | |
310 rate_label = gtk_label_new(""); | |
311 gtk_misc_set_alignment(GTK_MISC(rate_label), 0, 0); | |
312 gtk_label_set_justify(GTK_LABEL(rate_label), GTK_JUSTIFY_LEFT); | |
313 gtk_box_pack_start(GTK_BOX(info_box), rate_label, FALSE, FALSE, 0); | |
314 | |
315 channel_label = gtk_label_new(""); | |
316 gtk_misc_set_alignment(GTK_MISC(channel_label), 0, 0); | |
317 gtk_label_set_justify(GTK_LABEL(channel_label), GTK_JUSTIFY_LEFT); | |
318 gtk_box_pack_start(GTK_BOX(info_box), channel_label, FALSE, FALSE, 0); | |
319 | |
320 length_label = gtk_label_new(""); | |
321 gtk_misc_set_alignment(GTK_MISC(length_label), 0, 0); | |
322 gtk_label_set_justify(GTK_LABEL(length_label), GTK_JUSTIFY_LEFT); | |
323 gtk_box_pack_start(GTK_BOX(info_box), length_label, FALSE, FALSE, 0); | |
324 | |
325 filesize_label = gtk_label_new(""); | |
326 gtk_misc_set_alignment(GTK_MISC(filesize_label), 0, 0); | |
327 gtk_label_set_justify(GTK_LABEL(filesize_label), GTK_JUSTIFY_LEFT); | |
328 gtk_box_pack_start(GTK_BOX(info_box), filesize_label, FALSE, | |
329 FALSE, 0); | |
330 | |
331 peakTitle_label = gtk_label_new(""); | |
332 gtk_misc_set_alignment(GTK_MISC(peakTitle_label), 0, 0); | |
333 gtk_label_set_justify(GTK_LABEL(peakTitle_label), GTK_JUSTIFY_LEFT); | |
334 gtk_box_pack_start(GTK_BOX(info_box), peakTitle_label, FALSE, | |
335 FALSE, 0); | |
336 | |
337 peakAlbum_label = gtk_label_new(""); | |
338 gtk_misc_set_alignment(GTK_MISC(peakAlbum_label), 0, 0); | |
339 gtk_label_set_justify(GTK_LABEL(peakAlbum_label), GTK_JUSTIFY_LEFT); | |
340 gtk_box_pack_start(GTK_BOX(info_box), peakAlbum_label, FALSE, | |
341 FALSE, 0); | |
342 | |
343 gainTitle_label = gtk_label_new(""); | |
344 gtk_misc_set_alignment(GTK_MISC(gainTitle_label), 0, 0); | |
345 gtk_label_set_justify(GTK_LABEL(gainTitle_label), GTK_JUSTIFY_LEFT); | |
346 gtk_box_pack_start(GTK_BOX(info_box), gainTitle_label, FALSE, | |
347 FALSE, 0); | |
348 | |
349 gainAlbum_label = gtk_label_new(""); | |
350 gtk_misc_set_alignment(GTK_MISC(gainAlbum_label), 0, 0); | |
351 gtk_label_set_justify(GTK_LABEL(gainAlbum_label), GTK_JUSTIFY_LEFT); | |
352 gtk_box_pack_start(GTK_BOX(info_box), gainAlbum_label, FALSE, | |
353 FALSE, 0); | |
354 | |
355 gtk_widget_show_all(window); | |
356 } | |
357 else | |
358 gdk_window_raise(window->window); | |
359 | |
360 gtk_widget_set_sensitive(tag_frame, TRUE); | |
361 | |
362 gtk_label_set_text(GTK_LABEL(version_label), ""); | |
363 gtk_label_set_text(GTK_LABEL(bits_per_sample_label), ""); | |
364 gtk_label_set_text(GTK_LABEL(bitrate_label), ""); | |
365 gtk_label_set_text(GTK_LABEL(rate_label), ""); | |
366 gtk_label_set_text(GTK_LABEL(channel_label), ""); | |
367 gtk_label_set_text(GTK_LABEL(length_label), ""); | |
368 gtk_label_set_text(GTK_LABEL(filesize_label), ""); | |
369 gtk_label_set_text(GTK_LABEL(peakTitle_label), ""); | |
370 gtk_label_set_text(GTK_LABEL(peakAlbum_label), ""); | |
371 gtk_label_set_text(GTK_LABEL(gainTitle_label), ""); | |
372 gtk_label_set_text(GTK_LABEL(gainAlbum_label), ""); | |
373 | |
374 time = WavpackGetNumSamples(ctx) / WavpackGetSampleRate(ctx); | |
375 minutes = time / 60; | |
376 seconds = time % 60; | |
377 | |
378 label_set_text(version_label, "version %d", WavpackGetVersion(ctx)); | |
379 label_set_text(bitrate_label, "average bitrate: %6.1f kbps", WavpackGetAverageBitrate(ctx, 0) / 1000); | |
380 label_set_text(rate_label, "samplerate: %d Hz", WavpackGetSampleRate(ctx)); | |
381 label_set_text(bits_per_sample_label, "bits per sample: %d", WavpackGetBitsPerSample(ctx)); | |
382 label_set_text(channel_label, "channels: %d", WavpackGetNumChannels(ctx)); | |
383 label_set_text(length_label, "length: %d:%.2d", minutes, seconds); | |
384 label_set_text(filesize_label, "file size: %d Bytes", WavpackGetFileSize(ctx)); | |
385 /* | |
386 label_set_text(peakTitle_label, "Title Peak: %5u", 100); | |
387 label_set_text(peakAlbum_label, "Album Peak: %5u", 100); | |
388 label_set_text(gainTitle_label, "Title Gain: %-+5.2f dB", 100.0); | |
389 label_set_text(gainAlbum_label, "Album Gain: %-+5.2f dB", 100.0); | |
390 */ | |
391 label_set_text(peakTitle_label, "Title Peak: ?"); | |
392 label_set_text(peakAlbum_label, "Album Peak: ?"); | |
393 label_set_text(gainTitle_label, "Title Gain: ?"); | |
394 label_set_text(gainAlbum_label, "Album Gain: ?"); | |
395 | |
396 gtk_entry_set_text(GTK_ENTRY(title_entry), tag.title); | |
397 gtk_entry_set_text(GTK_ENTRY(performer_entry), tag.artist); | |
398 gtk_entry_set_text(GTK_ENTRY(album_entry), tag.album); | |
399 gtk_entry_set_text(GTK_ENTRY(user_comment_entry), tag.comment); | |
400 gtk_entry_set_text(GTK_ENTRY(genre_entry), tag.genre); | |
401 gtk_entry_set_text(GTK_ENTRY(tracknumber_entry), tag.track); | |
402 gtk_entry_set_text(GTK_ENTRY(date_entry), tag.year); | |
403 gtk_entry_set_text(GTK_ENTRY(filename_entry), fn); | |
404 gtk_editable_set_position(GTK_EDITABLE(filename_entry), -1); | |
405 | |
406 tmp = g_strdup_printf("File Info - %s", g_basename(fn)); | |
407 gtk_window_set_title(GTK_WINDOW(window), tmp); | |
408 g_free(tmp); | |
409 } | |
410 | |
411 static GtkWidget *wv_configurewin = NULL; | |
412 static GtkWidget *vbox, *notebook; | |
413 static GtkWidget *rg_switch, *rg_clip_switch, *rg_track_gain, *rg_dyn_bitrate; | |
414 | |
415 static void | |
416 wv_configurewin_ok(GtkWidget * widget, gpointer data) | |
417 { | |
418 ConfigDb *cfg; | |
419 GtkToggleButton *tb; | |
420 | |
421 tb = GTK_TOGGLE_BUTTON(rg_switch); | |
422 replaygainEnabled = gtk_toggle_button_get_active(tb); | |
423 tb = GTK_TOGGLE_BUTTON(rg_clip_switch); | |
424 clipPreventionEnabled = gtk_toggle_button_get_active(tb); | |
425 tb = GTK_TOGGLE_BUTTON(rg_dyn_bitrate); | |
426 dynBitrateEnabled = gtk_toggle_button_get_active(tb); | |
427 tb = GTK_TOGGLE_BUTTON(rg_track_gain); | |
428 albumReplaygainEnabled = !gtk_toggle_button_get_active(tb); | |
429 | |
430 cfg = bmp_cfg_db_open(); | |
431 | |
432 bmp_cfg_db_set_bool(cfg, "wavpack", "clip_prevention", | |
433 clipPreventionEnabled); | |
434 bmp_cfg_db_set_bool(cfg, "wavpack", "album_replaygain", | |
435 albumReplaygainEnabled); | |
436 bmp_cfg_db_set_bool(cfg, "wavpack", "dyn_bitrate", dynBitrateEnabled); | |
437 bmp_cfg_db_set_bool(cfg, "wavpack", "replaygain", replaygainEnabled); | |
438 bmp_cfg_db_close(cfg); | |
439 gtk_widget_destroy(wv_configurewin); | |
440 } | |
441 | |
442 static void | |
443 rg_switch_cb(GtkWidget * w, gpointer data) | |
444 { | |
445 gtk_widget_set_sensitive(GTK_WIDGET(data), | |
446 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON | |
447 (w))); | |
448 } | |
449 | |
450 void | |
451 wv_configure(void) | |
452 { | |
453 | |
454 GtkWidget *rg_frame, *rg_vbox; | |
455 GtkWidget *bbox, *ok, *cancel; | |
456 GtkWidget *rg_type_frame, *rg_type_vbox, *rg_album_gain; | |
457 | |
458 if (wv_configurewin != NULL) { | |
459 gdk_window_raise(wv_configurewin->window); | |
460 return; | |
461 } | |
462 | |
111 | 463 wv_configurewin = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
109 | 464 gtk_signal_connect(GTK_OBJECT(wv_configurewin), "destroy", |
465 GTK_SIGNAL_FUNC(gtk_widget_destroyed), | |
466 &wv_configurewin); | |
467 gtk_window_set_title(GTK_WINDOW(wv_configurewin), | |
468 "Musepack Configuration"); | |
469 gtk_window_set_policy(GTK_WINDOW(wv_configurewin), FALSE, FALSE, FALSE); | |
470 gtk_container_border_width(GTK_CONTAINER(wv_configurewin), 10); | |
471 | |
472 vbox = gtk_vbox_new(FALSE, 10); | |
473 gtk_container_add(GTK_CONTAINER(wv_configurewin), vbox); | |
474 | |
475 notebook = gtk_notebook_new(); | |
476 gtk_box_pack_start(GTK_BOX(vbox), notebook, TRUE, TRUE, 0); | |
477 | |
478 | |
479 /* Plugin Settings */ | |
480 | |
481 rg_frame = gtk_frame_new("General Plugin Settings:"); | |
482 gtk_container_border_width(GTK_CONTAINER(rg_frame), 5); | |
483 | |
484 rg_vbox = gtk_vbox_new(FALSE, 10); | |
485 gtk_container_border_width(GTK_CONTAINER(rg_vbox), 5); | |
486 gtk_container_add(GTK_CONTAINER(rg_frame), rg_vbox); | |
487 | |
488 rg_dyn_bitrate = | |
489 gtk_check_button_new_with_label("Enable Dynamic Bitrate Display"); | |
490 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(rg_dyn_bitrate), | |
491 dynBitrateEnabled); | |
492 gtk_box_pack_start(GTK_BOX(rg_vbox), rg_dyn_bitrate, FALSE, FALSE, 0); | |
493 | |
494 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), rg_frame, | |
495 gtk_label_new("Plugin")); | |
496 | |
497 /* Replay Gain.. */ | |
498 | |
499 rg_frame = gtk_frame_new("ReplayGain Settings:"); | |
500 gtk_container_border_width(GTK_CONTAINER(rg_frame), 5); | |
501 | |
502 rg_vbox = gtk_vbox_new(FALSE, 10); | |
503 gtk_container_border_width(GTK_CONTAINER(rg_vbox), 5); | |
504 gtk_container_add(GTK_CONTAINER(rg_frame), rg_vbox); | |
505 | |
506 rg_clip_switch = | |
507 gtk_check_button_new_with_label("Enable Clipping Prevention"); | |
508 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(rg_clip_switch), | |
509 clipPreventionEnabled); | |
510 gtk_box_pack_start(GTK_BOX(rg_vbox), rg_clip_switch, FALSE, FALSE, 0); | |
511 | |
512 rg_switch = gtk_check_button_new_with_label("Enable ReplayGain"); | |
513 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(rg_switch), | |
514 replaygainEnabled); | |
515 gtk_box_pack_start(GTK_BOX(rg_vbox), rg_switch, FALSE, FALSE, 0); | |
516 | |
517 rg_type_frame = gtk_frame_new("ReplayGain Type:"); | |
518 gtk_box_pack_start(GTK_BOX(rg_vbox), rg_type_frame, FALSE, FALSE, 0); | |
519 | |
520 gtk_signal_connect(GTK_OBJECT(rg_switch), "toggled", | |
521 GTK_SIGNAL_FUNC(rg_switch_cb), rg_type_frame); | |
522 | |
523 rg_type_vbox = gtk_vbox_new(FALSE, 5); | |
524 gtk_container_set_border_width(GTK_CONTAINER(rg_type_vbox), 5); | |
525 gtk_container_add(GTK_CONTAINER(rg_type_frame), rg_type_vbox); | |
526 | |
527 rg_track_gain = | |
528 gtk_radio_button_new_with_label(NULL, "use Track Gain/Peak"); | |
529 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(rg_track_gain), | |
530 !albumReplaygainEnabled); | |
531 gtk_box_pack_start(GTK_BOX(rg_type_vbox), rg_track_gain, FALSE, FALSE, 0); | |
532 | |
533 rg_album_gain = | |
534 gtk_radio_button_new_with_label(gtk_radio_button_group | |
535 (GTK_RADIO_BUTTON(rg_track_gain)), | |
536 "use Album Gain/Peak"); | |
537 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(rg_album_gain), | |
538 albumReplaygainEnabled); | |
539 gtk_box_pack_start(GTK_BOX(rg_type_vbox), rg_album_gain, FALSE, FALSE, 0); | |
540 | |
541 gtk_widget_set_sensitive(rg_type_frame, replaygainEnabled); | |
542 | |
543 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), rg_frame, | |
544 gtk_label_new("ReplayGain")); | |
545 | |
546 /* Buttons */ | |
547 | |
548 bbox = gtk_hbutton_box_new(); | |
549 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); | |
550 gtk_button_box_set_spacing(GTK_BUTTON_BOX(bbox), 5); | |
551 gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0); | |
552 | |
553 ok = gtk_button_new_with_label("Ok"); | |
554 gtk_signal_connect(GTK_OBJECT(ok), "clicked", | |
555 GTK_SIGNAL_FUNC(wv_configurewin_ok), NULL); | |
556 GTK_WIDGET_SET_FLAGS(ok, GTK_CAN_DEFAULT); | |
557 gtk_box_pack_start(GTK_BOX(bbox), ok, TRUE, TRUE, 0); | |
558 gtk_widget_grab_default(ok); | |
559 | |
560 cancel = gtk_button_new_with_label("Cancel"); | |
561 gtk_signal_connect_object(GTK_OBJECT(cancel), "clicked", | |
562 GTK_SIGNAL_FUNC(gtk_widget_destroy), | |
563 GTK_OBJECT(wv_configurewin)); | |
564 GTK_WIDGET_SET_FLAGS(cancel, GTK_CAN_DEFAULT); | |
565 gtk_box_pack_start(GTK_BOX(bbox), cancel, TRUE, TRUE, 0); | |
566 | |
567 gtk_widget_show_all(wv_configurewin); | |
568 } |