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