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