Mercurial > audlegacy
annotate audacious/input.c @ 1982:cf33371e7ac3 trunk
[svn] - enhancements to the NewVFS probing layer.
author | nenolod |
---|---|
date | Sat, 18 Nov 2006 19:44:58 -0800 |
parents | b067ca382dd0 |
children | 041d40c0f640 |
rev | line source |
---|---|
1951
c2a63f41d8c6
[svn] - NewVFS input probing layer. VFS-Aware plugins can automatically take
nenolod
parents:
1765
diff
changeset
|
1 /* Audacious |
c2a63f41d8c6
[svn] - NewVFS input probing layer. VFS-Aware plugins can automatically take
nenolod
parents:
1765
diff
changeset
|
2 * Copyright (C) 2005-2006 Audacious development team. |
c2a63f41d8c6
[svn] - NewVFS input probing layer. VFS-Aware plugins can automatically take
nenolod
parents:
1765
diff
changeset
|
3 * |
c2a63f41d8c6
[svn] - NewVFS input probing layer. VFS-Aware plugins can automatically take
nenolod
parents:
1765
diff
changeset
|
4 * BMP - Cross-platform multimedia player |
0 | 5 * Copyright (C) 2003-2004 BMP development team. |
6 * | |
7 * Based on XMMS: | |
8 * Copyright (C) 1998-2003 XMMS development team. | |
9 * | |
10 * This program is free software; you can redistribute it and/or modify | |
11 * it under the terms of the GNU General Public License as published by | |
12 * the Free Software Foundation; either version 2 of the License, or | |
13 * (at your option) any later version. | |
14 * | |
15 * This program is distributed in the hope that it will be useful, | |
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 * GNU General Public License for more details. | |
19 * | |
20 * You should have received a copy of the GNU General Public License | |
21 * along with this program; if not, write to the Free Software | |
1459 | 22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
0 | 23 */ |
24 | |
25 #ifdef HAVE_CONFIG_H | |
26 # include "config.h" | |
27 #endif | |
28 | |
29 #include <glib.h> | |
30 #include <glib/gi18n.h> | |
31 #include <gtk/gtk.h> | |
32 #include <string.h> | |
33 | |
34 #include "fft.h" | |
35 #include "input.h" | |
36 #include "main.h" | |
1653 | 37 #include "mainwin.h" |
0 | 38 #include "output.h" |
39 #include "util.h" | |
40 #include "visualization.h" | |
538
e4e897d20791
[svn] remove libaudcore, we never did anything with it
nenolod
parents:
355
diff
changeset
|
41 #include "playback.h" |
1653 | 42 #include "widgets/widgetcore.h" |
0 | 43 #include "pluginenum.h" |
1755 | 44 #include "titlestring.h" |
0 | 45 |
46 #include "libaudacious/util.h" | |
47 #include "libaudacious/xentry.h" | |
48 | |
49 G_LOCK_DEFINE_STATIC(vis_mutex); | |
50 | |
51 struct _VisNode { | |
52 gint time; | |
53 gint nch; | |
54 gint length; /* number of samples per channel */ | |
55 gint16 data[2][512]; | |
56 }; | |
57 | |
58 typedef struct _VisNode VisNode; | |
59 | |
60 | |
61 InputPluginData ip_data = { | |
62 NULL, | |
63 NULL, | |
64 FALSE, | |
625
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
538
diff
changeset
|
65 FALSE, |
890
ed26947bbf57
[svn] Gapless support. This comes with a few caveats, that I will mention here:
nenolod
parents:
625
diff
changeset
|
66 FALSE, |
1273
3b990c26fc46
[svn] - Support for the buffer indicator in playpaus.png that was apparently
nhjm449
parents:
1235
diff
changeset
|
67 FALSE, |
625
0a73d1faeb4e
[svn] GCC 4.1 warning fixes by Diego 'Flameeyes' Petteno from Gentoo.
chainsaw
parents:
538
diff
changeset
|
68 NULL |
0 | 69 }; |
70 | |
71 static GList *vis_list = NULL; | |
72 | |
73 gchar *input_info_text = NULL; | |
74 | |
75 InputPlugin * | |
76 get_current_input_plugin(void) | |
77 { | |
78 return ip_data.current_input_plugin; | |
79 } | |
80 | |
81 void | |
82 set_current_input_plugin(InputPlugin * ip) | |
83 { | |
84 ip_data.current_input_plugin = ip; | |
85 } | |
86 | |
87 GList * | |
88 get_input_list(void) | |
89 { | |
90 return ip_data.input_list; | |
91 } | |
92 | |
93 | |
94 gboolean | |
95 input_is_enabled(const gchar * filename) | |
96 { | |
97 gchar *basename = g_path_get_basename(filename); | |
98 gint enabled; | |
99 | |
100 enabled = GPOINTER_TO_INT(g_hash_table_lookup(plugin_matrix, basename)); | |
101 g_free(basename); | |
102 | |
103 return enabled; | |
104 } | |
105 | |
106 static void | |
107 disabled_iplugins_foreach_func(const gchar * name, | |
108 gboolean enabled, | |
109 GString * list) | |
110 { | |
111 g_return_if_fail(list != NULL); | |
112 | |
113 if (enabled) | |
114 return; | |
115 | |
116 if (list->len > 0) | |
117 g_string_append(list, ":"); | |
118 | |
119 g_string_append(list, name); | |
120 } | |
121 | |
122 gchar * | |
123 input_stringify_disabled_list(void) | |
124 { | |
125 GString *disabled_list; | |
126 | |
127 disabled_list = g_string_new(""); | |
128 g_hash_table_foreach(plugin_matrix, | |
129 (GHFunc) disabled_iplugins_foreach_func, | |
130 disabled_list); | |
131 | |
132 return g_string_free(disabled_list, FALSE); | |
133 } | |
134 | |
135 void | |
136 free_vis_data(void) | |
137 { | |
138 G_LOCK(vis_mutex); | |
139 g_list_foreach(vis_list, (GFunc) g_free, NULL); | |
140 g_list_free(vis_list); | |
141 vis_list = NULL; | |
142 G_UNLOCK(vis_mutex); | |
143 } | |
144 | |
145 static void | |
146 convert_to_s16_ne(AFormat fmt, gpointer ptr, gint16 * left, | |
147 gint16 * right, gint nch, gint max) | |
148 { | |
149 gint16 *ptr16; | |
150 guint16 *ptru16; | |
151 guint8 *ptru8; | |
152 gint i; | |
153 | |
154 switch (fmt) { | |
155 case FMT_U8: | |
156 ptru8 = ptr; | |
157 if (nch == 1) | |
158 for (i = 0; i < max; i++) | |
159 left[i] = ((*ptru8++) ^ 128) << 8; | |
160 else | |
161 for (i = 0; i < max; i++) { | |
162 left[i] = ((*ptru8++) ^ 128) << 8; | |
163 right[i] = ((*ptru8++) ^ 128) << 8; | |
164 } | |
165 break; | |
166 case FMT_S8: | |
167 ptru8 = ptr; | |
168 if (nch == 1) | |
169 for (i = 0; i < max; i++) | |
170 left[i] = (*ptru8++) << 8; | |
171 else | |
172 for (i = 0; i < max; i++) { | |
173 left[i] = (*ptru8++) << 8; | |
174 right[i] = (*ptru8++) << 8; | |
175 } | |
176 break; | |
177 case FMT_U16_LE: | |
178 ptru16 = ptr; | |
179 if (nch == 1) | |
180 for (i = 0; i < max; i++, ptru16++) | |
181 left[i] = GUINT16_FROM_LE(*ptru16) ^ 32768; | |
182 else | |
183 for (i = 0; i < max; i++) { | |
184 left[i] = GUINT16_FROM_LE(*ptru16) ^ 32768; | |
185 ptru16++; | |
186 right[i] = GUINT16_FROM_LE(*ptru16) ^ 32768; | |
187 ptru16++; | |
188 } | |
189 break; | |
190 case FMT_U16_BE: | |
191 ptru16 = ptr; | |
192 if (nch == 1) | |
193 for (i = 0; i < max; i++, ptru16++) | |
194 left[i] = GUINT16_FROM_BE(*ptru16) ^ 32768; | |
195 else | |
196 for (i = 0; i < max; i++) { | |
197 left[i] = GUINT16_FROM_BE(*ptru16) ^ 32768; | |
198 ptru16++; | |
199 right[i] = GUINT16_FROM_BE(*ptru16) ^ 32768; | |
200 ptru16++; | |
201 } | |
202 break; | |
203 case FMT_U16_NE: | |
204 ptru16 = ptr; | |
205 if (nch == 1) | |
206 for (i = 0; i < max; i++) | |
207 left[i] = (*ptru16++) ^ 32768; | |
208 else | |
209 for (i = 0; i < max; i++) { | |
210 left[i] = (*ptru16++) ^ 32768; | |
211 right[i] = (*ptru16++) ^ 32768; | |
212 } | |
213 break; | |
214 case FMT_S16_LE: | |
215 ptr16 = ptr; | |
216 if (nch == 1) | |
217 for (i = 0; i < max; i++, ptr16++) | |
218 left[i] = GINT16_FROM_LE(*ptr16); | |
219 else | |
220 for (i = 0; i < max; i++) { | |
221 left[i] = GINT16_FROM_LE(*ptr16); | |
222 ptr16++; | |
223 right[i] = GINT16_FROM_LE(*ptr16); | |
224 ptr16++; | |
225 } | |
226 break; | |
227 case FMT_S16_BE: | |
228 ptr16 = ptr; | |
229 if (nch == 1) | |
230 for (i = 0; i < max; i++, ptr16++) | |
231 left[i] = GINT16_FROM_BE(*ptr16); | |
232 else | |
233 for (i = 0; i < max; i++) { | |
234 left[i] = GINT16_FROM_BE(*ptr16); | |
235 ptr16++; | |
236 right[i] = GINT16_FROM_BE(*ptr16); | |
237 ptr16++; | |
238 } | |
239 break; | |
240 case FMT_S16_NE: | |
241 ptr16 = ptr; | |
242 if (nch == 1) | |
243 for (i = 0; i < max; i++) | |
244 left[i] = (*ptr16++); | |
245 else | |
246 for (i = 0; i < max; i++) { | |
247 left[i] = (*ptr16++); | |
248 right[i] = (*ptr16++); | |
249 } | |
250 break; | |
251 } | |
252 } | |
253 | |
254 InputVisType | |
255 input_get_vis_type() | |
256 { | |
257 return INPUT_VIS_OFF; | |
258 } | |
259 | |
260 void | |
261 input_add_vis(gint time, guchar * s, InputVisType type) | |
262 { | |
263 g_warning("plugin uses obsoleted input_add_vis()"); | |
264 } | |
265 | |
266 void | |
267 input_add_vis_pcm(gint time, AFormat fmt, gint nch, gint length, gpointer ptr) | |
268 { | |
269 VisNode *vis_node; | |
270 gint max; | |
271 | |
272 max = length / nch; | |
273 if (fmt == FMT_U16_LE || fmt == FMT_U16_BE || fmt == FMT_U16_NE || | |
274 fmt == FMT_S16_LE || fmt == FMT_S16_BE || fmt == FMT_S16_NE) | |
275 max /= 2; | |
276 max = CLAMP(max, 0, 512); | |
277 | |
278 vis_node = g_new0(VisNode, 1); | |
279 vis_node->time = time; | |
280 vis_node->nch = nch; | |
281 vis_node->length = max; | |
282 convert_to_s16_ne(fmt, ptr, vis_node->data[0], vis_node->data[1], nch, | |
283 max); | |
284 | |
285 G_LOCK(vis_mutex); | |
286 vis_list = g_list_append(vis_list, vis_node); | |
287 G_UNLOCK(vis_mutex); | |
288 } | |
289 | |
290 void | |
291 input_dont_show_warning(GtkObject * object, gpointer user_data) | |
292 { | |
293 *((gboolean *) user_data) = | |
294 !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(object)); | |
295 } | |
296 | |
297 | |
298 void | |
299 input_show_unplayable_files(const gchar * filename) | |
300 { | |
301 static GtkWidget *dialog = NULL; | |
302 static GtkListStore *store = NULL; | |
303 | |
304 const gchar *markup = | |
305 N_("<b><big>Unable to play files.</big></b>\n\n" | |
306 "The following files could not be played. Please check that:\n" | |
307 "1. they are accessible.\n" | |
308 "2. you have enabled the media plugins required."); | |
309 | |
310 GtkTreeIter iter; | |
311 | |
312 gchar *filename_utf8; | |
313 | |
314 if (!dialog) { | |
315 GtkWidget *vbox, *check; | |
316 GtkWidget *expander; | |
317 GtkWidget *scrolled, *treeview; | |
318 GtkCellRenderer *renderer; | |
319 | |
320 dialog = | |
1653 | 321 gtk_message_dialog_new_with_markup(GTK_WINDOW(mainwin), |
0 | 322 GTK_DIALOG_DESTROY_WITH_PARENT, |
323 GTK_MESSAGE_ERROR, | |
324 GTK_BUTTONS_OK, | |
325 _(markup)); | |
326 | |
327 vbox = gtk_vbox_new(FALSE, 6); | |
328 | |
329 check = gtk_check_button_new_with_label | |
330 (_("Don't show this warning anymore")); | |
331 | |
332 expander = gtk_expander_new_with_mnemonic(_("Show more _details")); | |
333 | |
334 scrolled = gtk_scrolled_window_new(NULL, NULL); | |
335 gtk_container_add(GTK_CONTAINER(expander), scrolled); | |
336 | |
337 store = gtk_list_store_new(1, G_TYPE_STRING); | |
338 | |
339 treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); | |
340 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeview), FALSE); | |
341 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled), | |
342 treeview); | |
343 | |
344 renderer = gtk_cell_renderer_text_new(); | |
345 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(treeview), | |
346 -1, _("Filename"), | |
347 renderer, | |
348 "text", 0, | |
349 NULL); | |
350 | |
351 vbox = GTK_DIALOG(dialog)->vbox; | |
352 gtk_box_pack_start(GTK_BOX(vbox), check, FALSE, FALSE, 0); | |
353 gtk_box_pack_start(GTK_BOX(vbox), expander, TRUE, TRUE, 0); | |
354 | |
355 g_signal_connect(dialog, "response", | |
356 G_CALLBACK(gtk_widget_destroy), | |
357 dialog); | |
358 g_signal_connect(dialog, "destroy", | |
359 G_CALLBACK(gtk_widget_destroyed), | |
360 &dialog); | |
361 g_signal_connect(check, "clicked", | |
362 G_CALLBACK(input_dont_show_warning), | |
363 &cfg.warn_about_unplayables); | |
364 | |
365 gtk_widget_show_all(dialog); | |
366 } | |
367 | |
368 gtk_window_present(GTK_WINDOW(dialog)); | |
369 | |
370 filename_utf8 = filename_to_utf8(filename); | |
371 gtk_list_store_append(store, &iter); | |
372 gtk_list_store_set(store, &iter, 0, filename_utf8, -1); | |
373 g_free(filename_utf8); | |
374 } | |
375 | |
376 | |
377 void | |
378 input_file_not_playable(const gchar * filename) | |
379 { | |
380 if (cfg.warn_about_unplayables) | |
381 input_show_unplayable_files(filename); | |
382 } | |
383 | |
355
1c701dfe5098
[svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents:
284
diff
changeset
|
384 /* |
1c701dfe5098
[svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents:
284
diff
changeset
|
385 * input_check_file() |
1c701dfe5098
[svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents:
284
diff
changeset
|
386 * |
1c701dfe5098
[svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents:
284
diff
changeset
|
387 * Inputs: |
1c701dfe5098
[svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents:
284
diff
changeset
|
388 * filename to check recursively against input plugins |
1c701dfe5098
[svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents:
284
diff
changeset
|
389 * whether or not to show an error |
1c701dfe5098
[svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents:
284
diff
changeset
|
390 * |
1c701dfe5098
[svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents:
284
diff
changeset
|
391 * Outputs: |
1c701dfe5098
[svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents:
284
diff
changeset
|
392 * pointer to input plugin which can handle this file |
1c701dfe5098
[svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents:
284
diff
changeset
|
393 * otherwise, NULL |
1c701dfe5098
[svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents:
284
diff
changeset
|
394 * |
1c701dfe5098
[svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents:
284
diff
changeset
|
395 * (the previous code returned a boolean of whether or not we can |
1c701dfe5098
[svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents:
284
diff
changeset
|
396 * play the file... even WORSE for performance) |
1c701dfe5098
[svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents:
284
diff
changeset
|
397 * |
1c701dfe5098
[svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents:
284
diff
changeset
|
398 * Side Effects: |
1c701dfe5098
[svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents:
284
diff
changeset
|
399 * various input plugins open the file and probe it |
1c701dfe5098
[svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents:
284
diff
changeset
|
400 * -- this can have very ugly effects performance wise on streams |
1c701dfe5098
[svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents:
284
diff
changeset
|
401 * |
1c701dfe5098
[svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents:
284
diff
changeset
|
402 * --nenolod, Dec 31 2005 |
1c701dfe5098
[svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents:
284
diff
changeset
|
403 */ |
1c701dfe5098
[svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents:
284
diff
changeset
|
404 InputPlugin * |
0 | 405 input_check_file(const gchar * filename, gboolean show_warning) |
406 { | |
1951
c2a63f41d8c6
[svn] - NewVFS input probing layer. VFS-Aware plugins can automatically take
nenolod
parents:
1765
diff
changeset
|
407 VFSFile *fd; |
0 | 408 GList *node; |
409 InputPlugin *ip; | |
410 gchar *filename_proxy; | |
1486 | 411 gint ret = 1; |
0 | 412 |
413 filename_proxy = g_strdup(filename); | |
1951
c2a63f41d8c6
[svn] - NewVFS input probing layer. VFS-Aware plugins can automatically take
nenolod
parents:
1765
diff
changeset
|
414 fd = vfs_fopen(filename, "rb"); |
0 | 415 |
416 for (node = get_input_list(); node != NULL; node = g_list_next(node)) { | |
417 ip = INPUT_PLUGIN(node->data); | |
418 if (ip && input_is_enabled(ip->filename) && | |
1951
c2a63f41d8c6
[svn] - NewVFS input probing layer. VFS-Aware plugins can automatically take
nenolod
parents:
1765
diff
changeset
|
419 (ip->is_our_file_from_vfs != NULL && |
c2a63f41d8c6
[svn] - NewVFS input probing layer. VFS-Aware plugins can automatically take
nenolod
parents:
1765
diff
changeset
|
420 (ret = ip->is_our_file_from_vfs(filename_proxy, fd) > 0) || |
c2a63f41d8c6
[svn] - NewVFS input probing layer. VFS-Aware plugins can automatically take
nenolod
parents:
1765
diff
changeset
|
421 (ip->is_our_file != NULL && |
c2a63f41d8c6
[svn] - NewVFS input probing layer. VFS-Aware plugins can automatically take
nenolod
parents:
1765
diff
changeset
|
422 (ret = ip->is_our_file(filename_proxy)) > 0))) { |
0 | 423 g_free(filename_proxy); |
1951
c2a63f41d8c6
[svn] - NewVFS input probing layer. VFS-Aware plugins can automatically take
nenolod
parents:
1765
diff
changeset
|
424 vfs_fclose(fd); |
355
1c701dfe5098
[svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents:
284
diff
changeset
|
425 return ip; |
0 | 426 } |
1973
b067ca382dd0
[svn] - reseek to 0 on a newvfs FD for each probe pass
nenolod
parents:
1951
diff
changeset
|
427 else if (ret == 0) |
b067ca382dd0
[svn] - reseek to 0 on a newvfs FD for each probe pass
nenolod
parents:
1951
diff
changeset
|
428 vfs_fseek(fd, 0, SEEK_SET); |
1765
c186ee9524ed
[svn] - enforce the ret = -1 == silent failure rule
nenolod
parents:
1755
diff
changeset
|
429 else if (ret <= -1) |
c186ee9524ed
[svn] - enforce the ret = -1 == silent failure rule
nenolod
parents:
1755
diff
changeset
|
430 break; |
0 | 431 } |
432 | |
433 g_free(filename_proxy); | |
434 | |
1486 | 435 if (show_warning && !(ret <= -1)) { |
0 | 436 input_file_not_playable(filename); |
437 } | |
438 | |
1951
c2a63f41d8c6
[svn] - NewVFS input probing layer. VFS-Aware plugins can automatically take
nenolod
parents:
1765
diff
changeset
|
439 vfs_fclose(fd); |
c2a63f41d8c6
[svn] - NewVFS input probing layer. VFS-Aware plugins can automatically take
nenolod
parents:
1765
diff
changeset
|
440 |
355
1c701dfe5098
[svn] Cache the decoder used for each PlaylistEntry. This reduces the amount
nenolod
parents:
284
diff
changeset
|
441 return NULL; |
0 | 442 } |
443 | |
444 | |
445 void | |
446 input_set_eq(gint on, gfloat preamp, gfloat * bands) | |
447 { | |
448 if (!ip_data.playing) | |
449 return; | |
450 | |
451 if (!get_current_input_plugin()) | |
452 return; | |
453 | |
454 if (get_current_input_plugin()->set_eq) | |
455 get_current_input_plugin()->set_eq(on, preamp, bands); | |
456 } | |
457 | |
458 void | |
459 input_get_song_info(const gchar * filename, gchar ** title, gint * length) | |
460 { | |
461 InputPlugin *ip = NULL; | |
462 BmpTitleInput *input; | |
463 GList *node; | |
464 gchar *tmp = NULL, *ext; | |
465 gchar *filename_proxy; | |
1982 | 466 VFSFile *fd; |
0 | 467 |
468 g_return_if_fail(filename != NULL); | |
469 g_return_if_fail(title != NULL); | |
470 g_return_if_fail(length != NULL); | |
471 | |
472 filename_proxy = g_strdup(filename); | |
1982 | 473 fd = vfs_fopen(filename, "rb"); |
0 | 474 |
475 for (node = get_input_list(); node != NULL; node = g_list_next(node)) { | |
476 ip = INPUT_PLUGIN(node->data); | |
1982 | 477 if (ip && input_is_enabled(ip->filename) && |
478 (ip->is_our_file_from_vfs != NULL && | |
479 (ret = ip->is_our_file_from_vfs(filename_proxy, fd) > 0) || | |
480 (ip->is_our_file != NULL && | |
481 (ret = ip->is_our_file(filename_proxy)) > 0))) { | |
482 g_free(filename_proxy); | |
0 | 483 break; |
1982 | 484 } |
0 | 485 } |
486 | |
1982 | 487 vfs_fclose(fd); |
488 | |
0 | 489 if (ip && node && ip->get_song_info) { |
490 ip->get_song_info(filename_proxy, &tmp, length); | |
491 *title = str_to_utf8(tmp); | |
492 g_free(tmp); | |
493 } | |
494 else { | |
495 input = bmp_title_input_new(); | |
496 | |
497 tmp = g_strdup(filename); | |
498 if ((ext = strrchr(tmp, '.'))) | |
499 *ext = '\0'; | |
500 | |
501 input->file_name = g_path_get_basename(tmp); | |
502 input->file_ext = ext ? ext + 1 : NULL; | |
503 input->file_path = tmp; | |
504 | |
505 if ((tmp = xmms_get_titlestring(xmms_get_gentitle_format(), input))) { | |
506 (*title) = str_to_utf8(tmp); | |
507 g_free(tmp); | |
508 } | |
509 else { | |
510 (*title) = filename_to_utf8(input->file_name); | |
511 } | |
512 | |
513 (*length) = -1; | |
514 | |
515 bmp_title_input_free(input); | |
1588
15d92c51bde6
[svn] - modified time (mtime) has been introduced into tuple
yaz
parents:
1547
diff
changeset
|
516 input = NULL; |
0 | 517 } |
518 | |
519 g_free(filename_proxy); | |
520 } | |
521 | |
1231 | 522 TitleInput * |
523 input_get_song_tuple(const gchar * filename) | |
524 { | |
525 InputPlugin *ip = NULL; | |
526 TitleInput *input; | |
527 GList *node; | |
528 gchar *tmp = NULL, *ext; | |
529 gchar *filename_proxy; | |
1982 | 530 VFSFile *fd; |
1231 | 531 |
532 if (filename == NULL) | |
533 return NULL; | |
534 | |
535 filename_proxy = g_strdup(filename); | |
1982 | 536 fd = vfs_fopen(filename, "rb"); |
1231 | 537 |
538 for (node = get_input_list(); node != NULL; node = g_list_next(node)) { | |
539 ip = INPUT_PLUGIN(node->data); | |
1982 | 540 if (ip && input_is_enabled(ip->filename) && |
541 (ip->is_our_file_from_vfs != NULL && | |
542 (ret = ip->is_our_file_from_vfs(filename_proxy, fd) > 0) || | |
543 (ip->is_our_file != NULL && | |
544 (ret = ip->is_our_file(filename_proxy)) > 0))) { | |
545 g_free(filename_proxy); | |
1231 | 546 break; |
1982 | 547 } |
1231 | 548 } |
549 | |
1982 | 550 vfs_fclose(fd); |
551 | |
1231 | 552 if (ip && node && ip->get_song_tuple) |
553 input = ip->get_song_tuple(filename_proxy); | |
554 else { | |
555 input = bmp_title_input_new(); | |
556 | |
557 tmp = g_strdup(filename); | |
558 if ((ext = strrchr(tmp, '.'))) | |
559 *ext = '\0'; | |
560 | |
1235 | 561 input->track_name = NULL; |
562 input->length = -1; | |
563 input_get_song_info(filename, &input->track_name, &input->length); | |
1231 | 564 input->file_name = g_path_get_basename(tmp); |
565 input->file_ext = ext ? ext + 1 : NULL; | |
566 input->file_path = tmp; | |
567 } | |
568 | |
569 return input; | |
570 } | |
571 | |
0 | 572 static void |
573 input_general_file_info_box(const gchar * filename, InputPlugin * ip) | |
574 { | |
575 GtkWidget *window, *vbox; | |
576 GtkWidget *label, *filename_hbox, *filename_entry; | |
577 GtkWidget *bbox, *cancel; | |
578 | |
579 gchar *title, *fileinfo, *basename, *iplugin; | |
580 gchar *filename_utf8; | |
581 | |
582 window = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
583 gtk_window_set_resizable(GTK_WINDOW(window), FALSE); | |
584 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER); | |
585 | |
586 basename = g_path_get_basename(filename); | |
587 fileinfo = filename_to_utf8(basename); | |
257
256b3acc87d4
[svn] Properly report Audacious instead of XMMS or BMP in all places. Patch by laci; closes bug #379.
chainsaw
parents:
0
diff
changeset
|
588 title = g_strdup_printf(_("audacious: %s"), fileinfo); |
0 | 589 |
590 gtk_window_set_title(GTK_WINDOW(window), title); | |
591 | |
592 g_free(title); | |
593 g_free(fileinfo); | |
594 g_free(basename); | |
595 | |
596 gtk_container_set_border_width(GTK_CONTAINER(window), 10); | |
597 | |
598 vbox = gtk_vbox_new(FALSE, 10); | |
599 gtk_container_add(GTK_CONTAINER(window), vbox); | |
600 | |
601 filename_hbox = gtk_hbox_new(FALSE, 5); | |
602 gtk_box_pack_start(GTK_BOX(vbox), filename_hbox, FALSE, TRUE, 0); | |
603 | |
604 label = gtk_label_new(_("Filename:")); | |
605 gtk_box_pack_start(GTK_BOX(filename_hbox), label, FALSE, TRUE, 0); | |
606 | |
607 filename_entry = xmms_entry_new(); | |
608 filename_utf8 = filename_to_utf8(filename); | |
609 | |
610 gtk_entry_set_text(GTK_ENTRY(filename_entry), filename_utf8); | |
611 gtk_editable_set_editable(GTK_EDITABLE(filename_entry), FALSE); | |
612 gtk_box_pack_start(GTK_BOX(filename_hbox), filename_entry, TRUE, TRUE, 0); | |
613 | |
614 g_free(filename_utf8); | |
615 | |
616 if (ip) | |
617 if (ip->description) | |
618 iplugin = ip->description; | |
619 else | |
620 iplugin = ip->filename; | |
621 else | |
622 iplugin = _("No input plugin recognized this file"); | |
623 | |
624 title = g_strdup_printf(_("Input plugin: %s"), iplugin); | |
625 | |
626 label = gtk_label_new(title); | |
627 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
628 gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT); | |
629 g_free(title); | |
630 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, TRUE, 0); | |
631 | |
632 bbox = gtk_hbutton_box_new(); | |
633 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); | |
634 gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0); | |
635 | |
636 cancel = gtk_button_new_from_stock(GTK_STOCK_CLOSE); | |
637 g_signal_connect_swapped(G_OBJECT(cancel), "clicked", | |
638 GTK_SIGNAL_FUNC(gtk_widget_destroy), | |
639 GTK_OBJECT(window)); | |
640 GTK_WIDGET_SET_FLAGS(cancel, GTK_CAN_DEFAULT); | |
641 gtk_box_pack_start(GTK_BOX(bbox), cancel, TRUE, TRUE, 0); | |
642 | |
643 gtk_widget_show_all(window); | |
644 } | |
645 | |
646 void | |
647 input_file_info_box(const gchar * filename) | |
648 { | |
649 GList *node; | |
650 InputPlugin *ip; | |
651 gchar *filename_proxy; | |
1982 | 652 VFSFile *fd; |
0 | 653 |
654 filename_proxy = g_strdup(filename); | |
655 | |
1982 | 656 fd = vfs_fopen(filename, "rb"); |
657 | |
0 | 658 for (node = get_input_list(); node != NULL; node = g_list_next(node)) { |
659 ip = INPUT_PLUGIN(node->data); | |
1982 | 660 if (ip && input_is_enabled(ip->filename) && |
661 (ip->is_our_file_from_vfs != NULL && | |
662 (ret = ip->is_our_file_from_vfs(filename_proxy, fd) > 0) || | |
663 (ip->is_our_file != NULL && | |
664 (ret = ip->is_our_file(filename_proxy)) > 0))) { | |
0 | 665 if (ip->file_info_box) |
666 ip->file_info_box(filename_proxy); | |
667 else | |
668 input_general_file_info_box(filename, ip); | |
669 | |
1982 | 670 vfs_fclose(fd); |
0 | 671 g_free(filename_proxy); |
672 return; | |
673 } | |
674 } | |
675 | |
1982 | 676 vfs_close(fd); |
0 | 677 input_general_file_info_box(filename, NULL); |
678 g_free(filename_proxy); | |
679 } | |
680 | |
681 GList * | |
682 input_scan_dir(const gchar * path) | |
683 { | |
684 GList *node, *result = NULL; | |
685 InputPlugin *ip; | |
686 gchar *path_proxy; | |
687 | |
688 g_return_val_if_fail(path != NULL, NULL); | |
689 | |
690 if (*path == '/') | |
691 while (path[1] == '/') | |
692 path++; | |
693 | |
694 path_proxy = g_strdup(path); | |
695 | |
696 for (node = get_input_list(); node; node = g_list_next(node)) { | |
697 ip = INPUT_PLUGIN(node->data); | |
698 | |
699 if (!ip) | |
700 continue; | |
701 | |
702 if (!ip->scan_dir) | |
703 continue; | |
704 | |
705 if (!input_is_enabled(ip->filename)) | |
706 continue; | |
707 | |
708 if ((result = ip->scan_dir(path_proxy))) | |
709 break; | |
710 } | |
711 | |
712 g_free(path_proxy); | |
713 | |
714 return result; | |
715 } | |
716 | |
717 void | |
718 input_get_volume(gint * l, gint * r) | |
719 { | |
720 *l = -1; | |
721 *r = -1; | |
722 if (bmp_playback_get_playing()) { | |
723 if (get_current_input_plugin() && | |
724 get_current_input_plugin()->get_volume) { | |
725 get_current_input_plugin()->get_volume(l, r); | |
726 return; | |
727 } | |
728 } | |
729 output_get_volume(l, r); | |
730 } | |
731 | |
732 void | |
733 input_set_volume(gint l, gint r) | |
734 { | |
735 if (bmp_playback_get_playing()) { | |
736 if (get_current_input_plugin() && | |
737 get_current_input_plugin()->set_volume) { | |
738 get_current_input_plugin()->set_volume(l, r); | |
739 return; | |
740 } | |
741 } | |
742 output_set_volume(l, r); | |
743 } | |
744 | |
745 void | |
746 input_update_vis(gint time) | |
747 { | |
748 GList *node; | |
749 VisNode *vis = NULL, *visnext = NULL; | |
750 gboolean found = FALSE; | |
751 | |
752 G_LOCK(vis_mutex); | |
753 node = vis_list; | |
754 while (g_list_next(node) && !found) { | |
755 visnext = g_list_next(node)->data; | |
756 vis = node->data; | |
757 | |
758 if (vis->time >= time) | |
759 break; | |
760 | |
761 vis_list = g_list_delete_link(vis_list, node); | |
762 | |
763 if (visnext->time >= time) { | |
764 found = TRUE; | |
765 break; | |
766 } | |
767 g_free(vis); | |
768 node = vis_list; | |
769 } | |
770 G_UNLOCK(vis_mutex); | |
771 | |
772 if (found) { | |
773 vis_send_data(vis->data, vis->nch, vis->length); | |
774 g_free(vis); | |
775 } | |
776 else | |
777 vis_send_data(NULL, 0, 0); | |
778 } | |
779 | |
780 | |
781 gchar * | |
782 input_get_info_text(void) | |
783 { | |
1653 | 784 return g_strdup(input_info_text); |
0 | 785 } |
786 | |
787 void | |
788 input_set_info_text(const gchar * text) | |
789 { | |
1653 | 790 g_free(input_info_text); |
791 input_info_text = g_strdup(text); | |
792 mainwin_set_info_text(); | |
0 | 793 } |
794 | |
795 void | |
1273
3b990c26fc46
[svn] - Support for the buffer indicator in playpaus.png that was apparently
nhjm449
parents:
1235
diff
changeset
|
796 input_set_status_buffering(gboolean status) |
3b990c26fc46
[svn] - Support for the buffer indicator in playpaus.png that was apparently
nhjm449
parents:
1235
diff
changeset
|
797 { |
3b990c26fc46
[svn] - Support for the buffer indicator in playpaus.png that was apparently
nhjm449
parents:
1235
diff
changeset
|
798 if (!bmp_playback_get_playing()) |
3b990c26fc46
[svn] - Support for the buffer indicator in playpaus.png that was apparently
nhjm449
parents:
1235
diff
changeset
|
799 return; |
3b990c26fc46
[svn] - Support for the buffer indicator in playpaus.png that was apparently
nhjm449
parents:
1235
diff
changeset
|
800 |
3b990c26fc46
[svn] - Support for the buffer indicator in playpaus.png that was apparently
nhjm449
parents:
1235
diff
changeset
|
801 if (!get_current_input_plugin()) |
3b990c26fc46
[svn] - Support for the buffer indicator in playpaus.png that was apparently
nhjm449
parents:
1235
diff
changeset
|
802 return; |
3b990c26fc46
[svn] - Support for the buffer indicator in playpaus.png that was apparently
nhjm449
parents:
1235
diff
changeset
|
803 |
3b990c26fc46
[svn] - Support for the buffer indicator in playpaus.png that was apparently
nhjm449
parents:
1235
diff
changeset
|
804 ip_data.buffering = status; |
3b990c26fc46
[svn] - Support for the buffer indicator in playpaus.png that was apparently
nhjm449
parents:
1235
diff
changeset
|
805 |
1672
600efc52c645
[svn] - be careful about referencing a NULL widget (e.g. headless/serveronly mode crashes on streams, bug #562)
nenolod
parents:
1653
diff
changeset
|
806 g_return_if_fail(mainwin_playstatus != NULL); |
600efc52c645
[svn] - be careful about referencing a NULL widget (e.g. headless/serveronly mode crashes on streams, bug #562)
nenolod
parents:
1653
diff
changeset
|
807 |
600efc52c645
[svn] - be careful about referencing a NULL widget (e.g. headless/serveronly mode crashes on streams, bug #562)
nenolod
parents:
1653
diff
changeset
|
808 if (ip_data.buffering == TRUE && mainwin_playstatus != NULL && mainwin_playstatus->ps_status == STATUS_STOP) |
1273
3b990c26fc46
[svn] - Support for the buffer indicator in playpaus.png that was apparently
nhjm449
parents:
1235
diff
changeset
|
809 mainwin_playstatus->ps_status = STATUS_PLAY; |
1672
600efc52c645
[svn] - be careful about referencing a NULL widget (e.g. headless/serveronly mode crashes on streams, bug #562)
nenolod
parents:
1653
diff
changeset
|
810 |
1273
3b990c26fc46
[svn] - Support for the buffer indicator in playpaus.png that was apparently
nhjm449
parents:
1235
diff
changeset
|
811 playstatus_set_status_buffering(mainwin_playstatus, ip_data.buffering); |
3b990c26fc46
[svn] - Support for the buffer indicator in playpaus.png that was apparently
nhjm449
parents:
1235
diff
changeset
|
812 } |
3b990c26fc46
[svn] - Support for the buffer indicator in playpaus.png that was apparently
nhjm449
parents:
1235
diff
changeset
|
813 |
3b990c26fc46
[svn] - Support for the buffer indicator in playpaus.png that was apparently
nhjm449
parents:
1235
diff
changeset
|
814 void |
0 | 815 input_about(gint index) |
816 { | |
817 InputPlugin *ip; | |
818 | |
819 ip = g_list_nth(ip_data.input_list, index)->data; | |
820 if (ip && ip->about) | |
821 ip->about(); | |
822 } | |
823 | |
824 void | |
825 input_configure(gint index) | |
826 { | |
827 InputPlugin *ip; | |
828 | |
829 ip = g_list_nth(ip_data.input_list, index)->data; | |
830 if (ip && ip->configure) | |
831 ip->configure(); | |
832 } |