Mercurial > audlegacy
annotate src/audacious/input.c @ 3097:bb1fa0aed8f4
add url unescape code to playlist_get_info_text().
author | Yoshiki Yazawa <yaz@cc.rim.or.jp> |
---|---|
date | Thu, 19 Jul 2007 12:49:50 +0900 |
parents | ba2143c1c6f5 |
children | 35e560fa183f |
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" | |
3072
84de3244aeaa
replace Playstatus with UiSkinnedPlaystatus
Tomasz Mon <desowin@gmail.com>
parents:
3013
diff
changeset
|
45 #include "ui_skinned_playstatus.h" |
2505 | 46 #include "hook.h" |
2313 | 47 |
2347
74bbc3e18cba
[svn] - fix W:input.c(422) [input_check_file]:Implicit declaration
nenolod
parents:
2344
diff
changeset
|
48 #include "vfs.h" |
74bbc3e18cba
[svn] - fix W:input.c(422) [input_check_file]:Implicit declaration
nenolod
parents:
2344
diff
changeset
|
49 #include "vfs_buffer.h" |
74bbc3e18cba
[svn] - fix W:input.c(422) [input_check_file]:Implicit declaration
nenolod
parents:
2344
diff
changeset
|
50 #include "vfs_buffered_file.h" |
74bbc3e18cba
[svn] - fix W:input.c(422) [input_check_file]:Implicit declaration
nenolod
parents:
2344
diff
changeset
|
51 |
2313 | 52 G_LOCK_DEFINE_STATIC(vis_mutex); |
53 | |
54 struct _VisNode { | |
55 gint time; | |
56 gint nch; | |
57 gint length; /* number of samples per channel */ | |
58 gint16 data[2][512]; | |
59 }; | |
60 | |
61 typedef struct _VisNode VisNode; | |
62 | |
63 | |
64 InputPluginData ip_data = { | |
65 NULL, | |
66 NULL, | |
67 FALSE, | |
68 FALSE, | |
69 FALSE, | |
70 FALSE, | |
71 NULL | |
72 }; | |
73 | |
74 static GList *vis_list = NULL; | |
75 | |
76 gchar *input_info_text = NULL; | |
77 | |
2436
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2430
diff
changeset
|
78 InputPlayback * |
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2430
diff
changeset
|
79 get_current_input_playback(void) |
2313 | 80 { |
2436
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2430
diff
changeset
|
81 return ip_data.current_input_playback; |
2313 | 82 } |
83 | |
84 void | |
2436
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2430
diff
changeset
|
85 set_current_input_playback(InputPlayback * ip) |
2313 | 86 { |
2436
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2430
diff
changeset
|
87 ip_data.current_input_playback = ip; |
2313 | 88 } |
89 | |
90 GList * | |
91 get_input_list(void) | |
92 { | |
93 return ip_data.input_list; | |
94 } | |
95 | |
96 | |
97 gboolean | |
98 input_is_enabled(const gchar * filename) | |
99 { | |
100 gchar *basename = g_path_get_basename(filename); | |
101 gint enabled; | |
102 | |
103 enabled = GPOINTER_TO_INT(g_hash_table_lookup(plugin_matrix, basename)); | |
104 g_free(basename); | |
105 | |
106 return enabled; | |
107 } | |
108 | |
109 static void | |
110 disabled_iplugins_foreach_func(const gchar * name, | |
111 gboolean enabled, | |
112 GString * list) | |
113 { | |
114 g_return_if_fail(list != NULL); | |
115 | |
116 if (enabled) | |
117 return; | |
118 | |
119 if (list->len > 0) | |
120 g_string_append(list, ":"); | |
121 | |
122 g_string_append(list, name); | |
123 } | |
124 | |
125 gchar * | |
126 input_stringify_disabled_list(void) | |
127 { | |
128 GString *disabled_list; | |
129 | |
130 disabled_list = g_string_new(""); | |
131 g_hash_table_foreach(plugin_matrix, | |
132 (GHFunc) disabled_iplugins_foreach_func, | |
133 disabled_list); | |
134 | |
135 return g_string_free(disabled_list, FALSE); | |
136 } | |
137 | |
138 void | |
139 free_vis_data(void) | |
140 { | |
141 G_LOCK(vis_mutex); | |
142 g_list_foreach(vis_list, (GFunc) g_free, NULL); | |
143 g_list_free(vis_list); | |
144 vis_list = NULL; | |
145 G_UNLOCK(vis_mutex); | |
146 } | |
147 | |
148 static void | |
149 convert_to_s16_ne(AFormat fmt, gpointer ptr, gint16 * left, | |
150 gint16 * right, gint nch, gint max) | |
151 { | |
152 gint16 *ptr16; | |
153 guint16 *ptru16; | |
154 guint8 *ptru8; | |
155 gint i; | |
156 | |
157 switch (fmt) { | |
158 case FMT_U8: | |
159 ptru8 = ptr; | |
160 if (nch == 1) | |
161 for (i = 0; i < max; i++) | |
162 left[i] = ((*ptru8++) ^ 128) << 8; | |
163 else | |
164 for (i = 0; i < max; i++) { | |
165 left[i] = ((*ptru8++) ^ 128) << 8; | |
166 right[i] = ((*ptru8++) ^ 128) << 8; | |
167 } | |
168 break; | |
169 case FMT_S8: | |
170 ptru8 = ptr; | |
171 if (nch == 1) | |
172 for (i = 0; i < max; i++) | |
173 left[i] = (*ptru8++) << 8; | |
174 else | |
175 for (i = 0; i < max; i++) { | |
176 left[i] = (*ptru8++) << 8; | |
177 right[i] = (*ptru8++) << 8; | |
178 } | |
179 break; | |
180 case FMT_U16_LE: | |
181 ptru16 = ptr; | |
182 if (nch == 1) | |
183 for (i = 0; i < max; i++, ptru16++) | |
184 left[i] = GUINT16_FROM_LE(*ptru16) ^ 32768; | |
185 else | |
186 for (i = 0; i < max; i++) { | |
187 left[i] = GUINT16_FROM_LE(*ptru16) ^ 32768; | |
188 ptru16++; | |
189 right[i] = GUINT16_FROM_LE(*ptru16) ^ 32768; | |
190 ptru16++; | |
191 } | |
192 break; | |
193 case FMT_U16_BE: | |
194 ptru16 = ptr; | |
195 if (nch == 1) | |
196 for (i = 0; i < max; i++, ptru16++) | |
197 left[i] = GUINT16_FROM_BE(*ptru16) ^ 32768; | |
198 else | |
199 for (i = 0; i < max; i++) { | |
200 left[i] = GUINT16_FROM_BE(*ptru16) ^ 32768; | |
201 ptru16++; | |
202 right[i] = GUINT16_FROM_BE(*ptru16) ^ 32768; | |
203 ptru16++; | |
204 } | |
205 break; | |
206 case FMT_U16_NE: | |
207 ptru16 = ptr; | |
208 if (nch == 1) | |
209 for (i = 0; i < max; i++) | |
210 left[i] = (*ptru16++) ^ 32768; | |
211 else | |
212 for (i = 0; i < max; i++) { | |
213 left[i] = (*ptru16++) ^ 32768; | |
214 right[i] = (*ptru16++) ^ 32768; | |
215 } | |
216 break; | |
217 case FMT_S16_LE: | |
218 ptr16 = ptr; | |
219 if (nch == 1) | |
220 for (i = 0; i < max; i++, ptr16++) | |
221 left[i] = GINT16_FROM_LE(*ptr16); | |
222 else | |
223 for (i = 0; i < max; i++) { | |
224 left[i] = GINT16_FROM_LE(*ptr16); | |
225 ptr16++; | |
226 right[i] = GINT16_FROM_LE(*ptr16); | |
227 ptr16++; | |
228 } | |
229 break; | |
230 case FMT_S16_BE: | |
231 ptr16 = ptr; | |
232 if (nch == 1) | |
233 for (i = 0; i < max; i++, ptr16++) | |
234 left[i] = GINT16_FROM_BE(*ptr16); | |
235 else | |
236 for (i = 0; i < max; i++) { | |
237 left[i] = GINT16_FROM_BE(*ptr16); | |
238 ptr16++; | |
239 right[i] = GINT16_FROM_BE(*ptr16); | |
240 ptr16++; | |
241 } | |
242 break; | |
243 case FMT_S16_NE: | |
244 ptr16 = ptr; | |
245 if (nch == 1) | |
246 for (i = 0; i < max; i++) | |
247 left[i] = (*ptr16++); | |
248 else | |
249 for (i = 0; i < max; i++) { | |
250 left[i] = (*ptr16++); | |
251 right[i] = (*ptr16++); | |
252 } | |
253 break; | |
254 } | |
255 } | |
256 | |
257 InputVisType | |
258 input_get_vis_type() | |
259 { | |
260 return INPUT_VIS_OFF; | |
261 } | |
262 | |
263 void | |
264 input_add_vis_pcm(gint time, AFormat fmt, gint nch, gint length, gpointer ptr) | |
265 { | |
266 VisNode *vis_node; | |
267 gint max; | |
268 | |
269 max = length / nch; | |
270 if (fmt == FMT_U16_LE || fmt == FMT_U16_BE || fmt == FMT_U16_NE || | |
271 fmt == FMT_S16_LE || fmt == FMT_S16_BE || fmt == FMT_S16_NE) | |
272 max /= 2; | |
273 max = CLAMP(max, 0, 512); | |
274 | |
275 vis_node = g_new0(VisNode, 1); | |
276 vis_node->time = time; | |
277 vis_node->nch = nch; | |
278 vis_node->length = max; | |
279 convert_to_s16_ne(fmt, ptr, vis_node->data[0], vis_node->data[1], nch, | |
280 max); | |
281 | |
282 G_LOCK(vis_mutex); | |
283 vis_list = g_list_append(vis_list, vis_node); | |
284 G_UNLOCK(vis_mutex); | |
285 } | |
286 | |
287 void | |
288 input_dont_show_warning(GtkObject * object, gpointer user_data) | |
289 { | |
290 *((gboolean *) user_data) = | |
291 !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(object)); | |
292 } | |
293 | |
294 /* | |
295 * input_check_file() | |
296 * | |
297 * Inputs: | |
298 * filename to check recursively against input plugins | |
299 * whether or not to show an error | |
300 * | |
301 * Outputs: | |
302 * pointer to input plugin which can handle this file | |
303 * otherwise, NULL | |
304 * | |
305 * (the previous code returned a boolean of whether or not we can | |
306 * play the file... even WORSE for performance) | |
307 * | |
308 * Side Effects: | |
309 * various input plugins open the file and probe it | |
310 * -- this can have very ugly effects performance wise on streams | |
311 * | |
312 * --nenolod, Dec 31 2005 | |
313 * | |
314 * Rewritten to use NewVFS probing, semantics are still basically the same. | |
315 * | |
316 * --nenolod, Dec 5 2006 | |
317 * | |
318 * Adapted to use the NewVFS extension probing system if enabled. | |
319 * | |
320 * --nenolod, Dec 12 2006 | |
3013
a5f606b01038
Use mimetype system to accelerate detection of network streams.
William Pitcock <nenolod@atheme-project.org>
parents:
2707
diff
changeset
|
321 * |
a5f606b01038
Use mimetype system to accelerate detection of network streams.
William Pitcock <nenolod@atheme-project.org>
parents:
2707
diff
changeset
|
322 * Adapted to use the mimetype system. |
a5f606b01038
Use mimetype system to accelerate detection of network streams.
William Pitcock <nenolod@atheme-project.org>
parents:
2707
diff
changeset
|
323 * |
a5f606b01038
Use mimetype system to accelerate detection of network streams.
William Pitcock <nenolod@atheme-project.org>
parents:
2707
diff
changeset
|
324 * --nenolod, Jul 9 2007 |
2313 | 325 */ |
326 InputPlugin * | |
327 input_check_file(const gchar * filename, gboolean show_warning) | |
328 { | |
329 VFSFile *fd; | |
330 GList *node; | |
331 InputPlugin *ip; | |
332 gchar *filename_proxy; | |
333 gint ret = 1; | |
2430
4e2fc64d95ef
[svn] - make vfs_buffered_file_new_from_uri declaration const
nenolod
parents:
2427
diff
changeset
|
334 gchar *ext, *tmp, *tmp_uri; |
2313 | 335 gboolean use_ext_filter; |
3013
a5f606b01038
Use mimetype system to accelerate detection of network streams.
William Pitcock <nenolod@atheme-project.org>
parents:
2707
diff
changeset
|
336 gchar *mimetype; |
2313 | 337 |
338 filename_proxy = g_strdup(filename); | |
2430
4e2fc64d95ef
[svn] - make vfs_buffered_file_new_from_uri declaration const
nenolod
parents:
2427
diff
changeset
|
339 |
4e2fc64d95ef
[svn] - make vfs_buffered_file_new_from_uri declaration const
nenolod
parents:
2427
diff
changeset
|
340 /* 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
|
341 tmp_uri = g_strdup(filename); |
4e2fc64d95ef
[svn] - make vfs_buffered_file_new_from_uri declaration const
nenolod
parents:
2427
diff
changeset
|
342 |
4e2fc64d95ef
[svn] - make vfs_buffered_file_new_from_uri declaration const
nenolod
parents:
2427
diff
changeset
|
343 tmp = strrchr(tmp_uri, '?'); |
4e2fc64d95ef
[svn] - make vfs_buffered_file_new_from_uri declaration const
nenolod
parents:
2427
diff
changeset
|
344 |
2510
c8d6564f9c82
[svn] - only strip the subsong identifier if it is really a valid subsong identifier. closes #792.
nenolod
parents:
2505
diff
changeset
|
345 if (tmp != NULL && g_ascii_isdigit(*(tmp + 1))) |
2430
4e2fc64d95ef
[svn] - make vfs_buffered_file_new_from_uri declaration const
nenolod
parents:
2427
diff
changeset
|
346 *tmp = '\0'; |
4e2fc64d95ef
[svn] - make vfs_buffered_file_new_from_uri declaration const
nenolod
parents:
2427
diff
changeset
|
347 |
4e2fc64d95ef
[svn] - make vfs_buffered_file_new_from_uri declaration const
nenolod
parents:
2427
diff
changeset
|
348 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
|
349 g_free(tmp_uri); |
2313 | 350 |
351 ext = strrchr(filename_proxy, '.') + 1; | |
352 | |
2569 | 353 use_ext_filter = |
354 (fd != NULL && (!g_strncasecmp(filename, "/", 1) || | |
355 !g_strncasecmp(filename, "file://", 7))) ? TRUE : FALSE; | |
2313 | 356 |
3013
a5f606b01038
Use mimetype system to accelerate detection of network streams.
William Pitcock <nenolod@atheme-project.org>
parents:
2707
diff
changeset
|
357 mimetype = vfs_get_metadata(fd, "content-type"); |
a5f606b01038
Use mimetype system to accelerate detection of network streams.
William Pitcock <nenolod@atheme-project.org>
parents:
2707
diff
changeset
|
358 if ((ip = mime_get_plugin(mimetype)) != NULL) |
a5f606b01038
Use mimetype system to accelerate detection of network streams.
William Pitcock <nenolod@atheme-project.org>
parents:
2707
diff
changeset
|
359 { |
a5f606b01038
Use mimetype system to accelerate detection of network streams.
William Pitcock <nenolod@atheme-project.org>
parents:
2707
diff
changeset
|
360 g_free(filename_proxy); |
a5f606b01038
Use mimetype system to accelerate detection of network streams.
William Pitcock <nenolod@atheme-project.org>
parents:
2707
diff
changeset
|
361 vfs_fclose(fd); |
a5f606b01038
Use mimetype system to accelerate detection of network streams.
William Pitcock <nenolod@atheme-project.org>
parents:
2707
diff
changeset
|
362 return ip; |
a5f606b01038
Use mimetype system to accelerate detection of network streams.
William Pitcock <nenolod@atheme-project.org>
parents:
2707
diff
changeset
|
363 } |
a5f606b01038
Use mimetype system to accelerate detection of network streams.
William Pitcock <nenolod@atheme-project.org>
parents:
2707
diff
changeset
|
364 |
2313 | 365 for (node = get_input_list(); node != NULL; node = g_list_next(node)) |
366 { | |
367 ip = INPUT_PLUGIN(node->data); | |
368 | |
369 if (!ip || !input_is_enabled(ip->filename)) | |
370 continue; | |
371 | |
2342
f140d0a27093
[svn] - use vfs_rewind() instead of vfs_fseek(fd, 0, seek_set) which was wrong
nenolod
parents:
2331
diff
changeset
|
372 vfs_rewind(fd); |
2313 | 373 |
2569 | 374 if (cfg.use_extension_probing == TRUE && ip->vfs_extensions != NULL && |
375 ext != NULL && ext != (gpointer) 0x1 && use_ext_filter == TRUE) | |
2313 | 376 { |
377 gint i; | |
378 gboolean is_our_ext = FALSE; | |
379 | |
380 for (i = 0; ip->vfs_extensions[i] != NULL; i++) | |
381 { | |
382 if (str_has_prefix_nocase(ext, ip->vfs_extensions[i])) | |
2331 | 383 { |
384 is_our_ext = TRUE; | |
385 break; | |
386 } | |
2313 | 387 } |
388 | |
389 /* not a plugin that supports this extension */ | |
390 if (is_our_ext == FALSE) | |
391 continue; | |
392 } | |
393 | |
2427
64948ea58c53
[svn] - revise logic of r3808 so that cdaudio works again.
yaz
parents:
2420
diff
changeset
|
394 if (fd && ip->is_our_file_from_vfs != NULL) |
2313 | 395 { |
396 ret = ip->is_our_file_from_vfs(filename_proxy, fd); | |
397 | |
398 if (ret > 0) | |
399 { | |
400 g_free(filename_proxy); | |
401 vfs_fclose(fd); | |
402 return ip; | |
403 } | |
404 } | |
405 else if (ip->is_our_file != NULL) | |
406 { | |
407 ret = ip->is_our_file(filename_proxy); | |
408 | |
409 if (ret > 0) | |
410 { | |
411 g_free(filename_proxy); | |
412 vfs_fclose(fd); | |
413 return ip; | |
414 } | |
415 } | |
416 | |
2331 | 417 if (ret <= -1) |
418 break; | |
2313 | 419 } |
420 | |
421 g_free(filename_proxy); | |
422 | |
423 vfs_fclose(fd); | |
424 | |
425 return NULL; | |
426 } | |
427 | |
428 | |
429 void | |
430 input_set_eq(gint on, gfloat preamp, gfloat * bands) | |
431 { | |
432 if (!ip_data.playing) | |
433 return; | |
434 | |
2436
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2430
diff
changeset
|
435 if (!get_current_input_playback()) |
2313 | 436 return; |
437 | |
2436
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2430
diff
changeset
|
438 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
|
439 get_current_input_playback()->plugin->set_eq(on, preamp, bands); |
2313 | 440 } |
441 | |
442 void | |
443 input_get_song_info(const gchar * filename, gchar ** title, gint * length) | |
444 { | |
445 InputPlugin *ip = NULL; | |
446 BmpTitleInput *input; | |
447 gchar *tmp = NULL, *ext; | |
448 gchar *filename_proxy; | |
449 | |
450 g_return_if_fail(filename != NULL); | |
451 g_return_if_fail(title != NULL); | |
452 g_return_if_fail(length != NULL); | |
453 | |
454 filename_proxy = g_strdup(filename); | |
455 | |
456 ip = input_check_file(filename_proxy, FALSE); | |
457 | |
2331 | 458 if (ip && ip->get_song_info) { |
2313 | 459 ip->get_song_info(filename_proxy, &tmp, length); |
460 *title = str_to_utf8(tmp); | |
461 g_free(tmp); | |
462 } | |
463 else { | |
464 input = bmp_title_input_new(); | |
465 | |
466 tmp = g_strdup(filename); | |
467 if ((ext = strrchr(tmp, '.'))) | |
468 *ext = '\0'; | |
469 | |
470 input->file_name = g_path_get_basename(tmp); | |
471 input->file_ext = ext ? ext + 1 : NULL; | |
472 input->file_path = g_path_get_dirname(tmp); | |
473 | |
474 if ((tmp = xmms_get_titlestring(xmms_get_gentitle_format(), input))) { | |
475 (*title) = str_to_utf8(tmp); | |
476 g_free(tmp); | |
477 } | |
478 else { | |
479 (*title) = filename_to_utf8(input->file_name); | |
480 } | |
481 | |
482 (*length) = -1; | |
483 | |
484 bmp_title_input_free(input); | |
485 input = NULL; | |
486 } | |
487 | |
488 g_free(filename_proxy); | |
489 } | |
490 | |
491 TitleInput * | |
492 input_get_song_tuple(const gchar * filename) | |
493 { | |
494 InputPlugin *ip = NULL; | |
495 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
|
496 gchar *ext = NULL; |
2313 | 497 gchar *filename_proxy; |
498 | |
499 if (filename == NULL) | |
2331 | 500 return NULL; |
2313 | 501 |
502 filename_proxy = g_strdup(filename); | |
503 | |
504 ip = input_check_file(filename_proxy, FALSE); | |
505 | |
2331 | 506 if (ip && ip->get_song_tuple) |
2313 | 507 input = ip->get_song_tuple(filename_proxy); |
2331 | 508 else |
509 { | |
2313 | 510 input = bmp_title_input_new(); |
511 | |
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
|
512 ext = strrchr(filename, '.'); |
2313 | 513 |
2331 | 514 input->track_name = NULL; |
515 input->length = -1; | |
516 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
|
517 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
|
518 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
|
519 input->file_path = g_path_get_dirname(filename); |
2313 | 520 } |
521 | |
2569 | 522 g_free(filename_proxy); |
2313 | 523 return input; |
524 } | |
525 | |
526 static void | |
527 input_general_file_info_box(const gchar * filename, InputPlugin * ip) | |
528 { | |
529 GtkWidget *window, *vbox; | |
530 GtkWidget *label, *filename_hbox, *filename_entry; | |
531 GtkWidget *bbox, *cancel; | |
532 | |
533 gchar *title, *fileinfo, *basename, *iplugin; | |
534 gchar *filename_utf8; | |
3081
ba2143c1c6f5
unescape url encoded filename where real filename is needed.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3072
diff
changeset
|
535 gchar *realfn = NULL; |
2313 | 536 |
537 window = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
538 gtk_window_set_resizable(GTK_WINDOW(window), FALSE); | |
539 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER); | |
540 | |
3081
ba2143c1c6f5
unescape url encoded filename where real filename is needed.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3072
diff
changeset
|
541 realfn = g_filename_from_uri(filename, NULL, NULL); |
ba2143c1c6f5
unescape url encoded filename where real filename is needed.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3072
diff
changeset
|
542 basename = g_path_get_basename(realfn ? realfn : filename); |
2313 | 543 fileinfo = filename_to_utf8(basename); |
544 title = g_strdup_printf(_("audacious: %s"), fileinfo); | |
545 | |
546 gtk_window_set_title(GTK_WINDOW(window), title); | |
547 | |
548 g_free(title); | |
549 g_free(fileinfo); | |
550 g_free(basename); | |
551 | |
552 gtk_container_set_border_width(GTK_CONTAINER(window), 10); | |
553 | |
554 vbox = gtk_vbox_new(FALSE, 10); | |
555 gtk_container_add(GTK_CONTAINER(window), vbox); | |
556 | |
557 filename_hbox = gtk_hbox_new(FALSE, 5); | |
558 gtk_box_pack_start(GTK_BOX(vbox), filename_hbox, FALSE, TRUE, 0); | |
559 | |
560 label = gtk_label_new(_("Filename:")); | |
561 gtk_box_pack_start(GTK_BOX(filename_hbox), label, FALSE, TRUE, 0); | |
562 | |
563 filename_entry = gtk_entry_new(); | |
3081
ba2143c1c6f5
unescape url encoded filename where real filename is needed.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3072
diff
changeset
|
564 filename_utf8 = filename_to_utf8(realfn ? realfn : filename); |
ba2143c1c6f5
unescape url encoded filename where real filename is needed.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3072
diff
changeset
|
565 g_free(realfn); realfn = NULL; |
2313 | 566 |
567 gtk_entry_set_text(GTK_ENTRY(filename_entry), filename_utf8); | |
568 gtk_editable_set_editable(GTK_EDITABLE(filename_entry), FALSE); | |
569 gtk_box_pack_start(GTK_BOX(filename_hbox), filename_entry, TRUE, TRUE, 0); | |
570 | |
571 g_free(filename_utf8); | |
572 | |
573 if (ip) | |
574 if (ip->description) | |
575 iplugin = ip->description; | |
576 else | |
577 iplugin = ip->filename; | |
578 else | |
579 iplugin = _("No input plugin recognized this file"); | |
580 | |
581 title = g_strdup_printf(_("Input plugin: %s"), iplugin); | |
582 | |
583 label = gtk_label_new(title); | |
584 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
585 gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT); | |
586 g_free(title); | |
587 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, TRUE, 0); | |
588 | |
589 bbox = gtk_hbutton_box_new(); | |
590 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); | |
591 gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0); | |
592 | |
593 cancel = gtk_button_new_from_stock(GTK_STOCK_CLOSE); | |
594 g_signal_connect_swapped(G_OBJECT(cancel), "clicked", | |
595 GTK_SIGNAL_FUNC(gtk_widget_destroy), | |
596 GTK_OBJECT(window)); | |
597 GTK_WIDGET_SET_FLAGS(cancel, GTK_CAN_DEFAULT); | |
598 gtk_box_pack_start(GTK_BOX(bbox), cancel, TRUE, TRUE, 0); | |
599 | |
600 gtk_widget_show_all(window); | |
601 } | |
602 | |
603 void | |
604 input_file_info_box(const gchar * filename) | |
605 { | |
606 InputPlugin *ip; | |
607 gchar *filename_proxy; | |
608 | |
609 filename_proxy = g_strdup(filename); | |
610 | |
611 ip = input_check_file(filename_proxy, FALSE); | |
612 | |
613 if (ip->file_info_box) | |
614 ip->file_info_box(filename_proxy); | |
615 else | |
616 input_general_file_info_box(filename, ip); | |
617 | |
618 input_general_file_info_box(filename, NULL); | |
619 g_free(filename_proxy); | |
620 } | |
621 | |
622 GList * | |
623 input_scan_dir(const gchar * path) | |
624 { | |
625 GList *node, *result = NULL; | |
626 InputPlugin *ip; | |
627 gchar *path_proxy; | |
628 | |
629 g_return_val_if_fail(path != NULL, NULL); | |
630 | |
631 if (*path == '/') | |
632 while (path[1] == '/') | |
633 path++; | |
634 | |
635 path_proxy = g_strdup(path); | |
636 | |
637 for (node = get_input_list(); node; node = g_list_next(node)) { | |
638 ip = INPUT_PLUGIN(node->data); | |
639 | |
640 if (!ip) | |
641 continue; | |
642 | |
643 if (!ip->scan_dir) | |
644 continue; | |
645 | |
646 if (!input_is_enabled(ip->filename)) | |
647 continue; | |
648 | |
649 if ((result = ip->scan_dir(path_proxy))) | |
650 break; | |
651 } | |
652 | |
653 g_free(path_proxy); | |
654 | |
655 return result; | |
656 } | |
657 | |
658 void | |
659 input_get_volume(gint * l, gint * r) | |
660 { | |
661 *l = -1; | |
662 *r = -1; | |
663 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
|
664 if (get_current_input_playback() && |
2439
f2b3d6428b67
[svn] Allow input plugin that implements get_volume to punt to the output plugin.
iabervon
parents:
2437
diff
changeset
|
665 get_current_input_playback()->plugin->get_volume && |
f2b3d6428b67
[svn] Allow input plugin that implements get_volume to punt to the output plugin.
iabervon
parents:
2437
diff
changeset
|
666 get_current_input_playback()->plugin->get_volume(l, r)) { |
2313 | 667 return; |
668 } | |
669 } | |
670 output_get_volume(l, r); | |
671 } | |
672 | |
673 void | |
674 input_set_volume(gint l, gint r) | |
675 { | |
2505 | 676 gint h_vol[2]; |
677 | |
2569 | 678 if (playback_get_playing() && |
679 get_current_input_playback() && | |
680 get_current_input_playback()->plugin->set_volume && | |
681 get_current_input_playback()->plugin->set_volume(l, r)) | |
682 return; | |
683 | |
2313 | 684 output_set_volume(l, r); |
2505 | 685 |
686 h_vol[0] = l; | |
687 h_vol[1] = r; | |
688 hook_call("volume set", h_vol); | |
2313 | 689 } |
690 | |
691 void | |
692 input_update_vis(gint time) | |
693 { | |
694 GList *node; | |
695 VisNode *vis = NULL, *visnext = NULL; | |
696 gboolean found = FALSE; | |
697 | |
698 G_LOCK(vis_mutex); | |
699 node = vis_list; | |
700 while (g_list_next(node) && !found) { | |
701 visnext = g_list_next(node)->data; | |
702 vis = node->data; | |
703 | |
704 if (vis->time >= time) | |
705 break; | |
706 | |
707 vis_list = g_list_delete_link(vis_list, node); | |
708 | |
709 if (visnext->time >= time) { | |
710 found = TRUE; | |
711 break; | |
712 } | |
713 g_free(vis); | |
714 node = vis_list; | |
715 } | |
716 G_UNLOCK(vis_mutex); | |
717 | |
718 if (found) { | |
719 vis_send_data(vis->data, vis->nch, vis->length); | |
720 g_free(vis); | |
721 } | |
722 else | |
723 vis_send_data(NULL, 0, 0); | |
724 } | |
725 | |
726 | |
727 gchar * | |
728 input_get_info_text(void) | |
729 { | |
730 return g_strdup(input_info_text); | |
731 } | |
732 | |
733 void | |
734 input_set_info_text(const gchar * text) | |
735 { | |
736 g_free(input_info_text); | |
737 input_info_text = g_strdup(text); | |
738 mainwin_set_info_text(); | |
739 } | |
740 | |
741 void | |
742 input_set_status_buffering(gboolean status) | |
743 { | |
744 if (!playback_get_playing()) | |
745 return; | |
746 | |
2436
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2430
diff
changeset
|
747 if (!get_current_input_playback()) |
2313 | 748 return; |
749 | |
750 ip_data.buffering = status; | |
751 | |
752 g_return_if_fail(mainwin_playstatus != NULL); | |
753 | |
3072
84de3244aeaa
replace Playstatus with UiSkinnedPlaystatus
Tomasz Mon <desowin@gmail.com>
parents:
3013
diff
changeset
|
754 if (ip_data.buffering == TRUE && mainwin_playstatus != NULL && UI_SKINNED_PLAYSTATUS(mainwin_playstatus)->status == STATUS_STOP) |
84de3244aeaa
replace Playstatus with UiSkinnedPlaystatus
Tomasz Mon <desowin@gmail.com>
parents:
3013
diff
changeset
|
755 UI_SKINNED_PLAYSTATUS(mainwin_playstatus)->status = STATUS_PLAY; |
2313 | 756 |
3072
84de3244aeaa
replace Playstatus with UiSkinnedPlaystatus
Tomasz Mon <desowin@gmail.com>
parents:
3013
diff
changeset
|
757 ui_skinned_playstatus_set_buffering(mainwin_playstatus, ip_data.buffering); |
2313 | 758 } |
759 | |
760 void | |
761 input_about(gint index) | |
762 { | |
763 InputPlugin *ip; | |
764 | |
765 ip = g_list_nth(ip_data.input_list, index)->data; | |
766 if (ip && ip->about) | |
767 ip->about(); | |
768 } | |
769 | |
770 void | |
771 input_configure(gint index) | |
772 { | |
773 InputPlugin *ip; | |
774 | |
775 ip = g_list_nth(ip_data.input_list, index)->data; | |
776 if (ip && ip->configure) | |
777 ip->configure(); | |
778 } |