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