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