Mercurial > audlegacy
annotate src/audacious/input.c @ 2404:60f1bc20c19c trunk
[svn] - hooking implementation.
example: hook_register("playback begin"); hook_call("playback begin", <PlaylistEntry>);
| author | nenolod |
|---|---|
| date | Thu, 25 Jan 2007 20:23:16 -0800 |
| parents | 9b7b11176d4e |
| children | b23f52fe132f |
| 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 "ui_main.h" | |
| 37 #include "output.h" | |
|
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2347
diff
changeset
|
38 #include "strings.h" |
| 2313 | 39 #include "visualization.h" |
| 40 #include "playback.h" | |
| 41 #include "widgets/widgetcore.h" | |
| 42 #include "pluginenum.h" | |
| 43 #include "titlestring.h" | |
| 44 | |
| 45 #include "libaudacious/util.h" | |
| 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 | |
| 77 InputPlugin * | |
| 78 get_current_input_plugin(void) | |
| 79 { | |
| 80 return ip_data.current_input_plugin; | |
| 81 } | |
| 82 | |
| 83 void | |
| 84 set_current_input_plugin(InputPlugin * ip) | |
| 85 { | |
| 86 ip_data.current_input_plugin = ip; | |
| 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(gint time, guchar * s, InputVisType type) | |
| 264 { | |
| 265 g_warning("plugin uses obsoleted input_add_vis()"); | |
| 266 } | |
| 267 | |
| 268 void | |
| 269 input_add_vis_pcm(gint time, AFormat fmt, gint nch, gint length, gpointer ptr) | |
| 270 { | |
| 271 VisNode *vis_node; | |
| 272 gint max; | |
| 273 | |
| 274 max = length / nch; | |
| 275 if (fmt == FMT_U16_LE || fmt == FMT_U16_BE || fmt == FMT_U16_NE || | |
| 276 fmt == FMT_S16_LE || fmt == FMT_S16_BE || fmt == FMT_S16_NE) | |
| 277 max /= 2; | |
| 278 max = CLAMP(max, 0, 512); | |
| 279 | |
| 280 vis_node = g_new0(VisNode, 1); | |
| 281 vis_node->time = time; | |
| 282 vis_node->nch = nch; | |
| 283 vis_node->length = max; | |
| 284 convert_to_s16_ne(fmt, ptr, vis_node->data[0], vis_node->data[1], nch, | |
| 285 max); | |
| 286 | |
| 287 G_LOCK(vis_mutex); | |
| 288 vis_list = g_list_append(vis_list, vis_node); | |
| 289 G_UNLOCK(vis_mutex); | |
| 290 } | |
| 291 | |
| 292 void | |
| 293 input_dont_show_warning(GtkObject * object, gpointer user_data) | |
| 294 { | |
| 295 *((gboolean *) user_data) = | |
| 296 !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(object)); | |
| 297 } | |
| 298 | |
| 299 | |
| 300 void | |
| 301 input_show_unplayable_files(const gchar * filename) | |
| 302 { | |
| 303 static GtkWidget *dialog = NULL; | |
| 304 static GtkListStore *store = NULL; | |
| 305 | |
| 306 const gchar *markup = | |
| 307 N_("<b><big>Unable to play files.</big></b>\n\n" | |
| 308 "The following files could not be played. Please check that:\n" | |
| 309 "1. they are accessible.\n" | |
| 310 "2. you have enabled the media plugins required."); | |
| 311 | |
| 312 GtkTreeIter iter; | |
| 313 | |
| 314 gchar *filename_utf8; | |
| 315 | |
| 316 if (!dialog) { | |
| 317 GtkWidget *vbox, *check; | |
| 318 GtkWidget *expander; | |
| 319 GtkWidget *scrolled, *treeview; | |
| 320 GtkCellRenderer *renderer; | |
| 321 | |
| 322 dialog = | |
| 323 gtk_message_dialog_new_with_markup(GTK_WINDOW(mainwin), | |
| 324 GTK_DIALOG_DESTROY_WITH_PARENT, | |
| 325 GTK_MESSAGE_ERROR, | |
| 326 GTK_BUTTONS_OK, | |
| 327 _(markup)); | |
| 328 | |
| 329 vbox = gtk_vbox_new(FALSE, 6); | |
| 330 | |
| 331 check = gtk_check_button_new_with_label | |
| 332 (_("Don't show this warning anymore")); | |
| 333 | |
| 334 expander = gtk_expander_new_with_mnemonic(_("Show more _details")); | |
| 335 | |
| 336 scrolled = gtk_scrolled_window_new(NULL, NULL); | |
| 337 gtk_container_add(GTK_CONTAINER(expander), scrolled); | |
| 338 | |
| 339 store = gtk_list_store_new(1, G_TYPE_STRING); | |
| 340 | |
| 341 treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); | |
| 342 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeview), FALSE); | |
| 343 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled), | |
| 344 treeview); | |
| 345 | |
| 346 renderer = gtk_cell_renderer_text_new(); | |
| 347 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(treeview), | |
| 348 -1, _("Filename"), | |
| 349 renderer, | |
| 350 "text", 0, | |
| 351 NULL); | |
| 352 | |
| 353 vbox = GTK_DIALOG(dialog)->vbox; | |
| 354 gtk_box_pack_start(GTK_BOX(vbox), check, FALSE, FALSE, 0); | |
| 355 gtk_box_pack_start(GTK_BOX(vbox), expander, TRUE, TRUE, 0); | |
| 356 | |
| 357 g_signal_connect(dialog, "response", | |
| 358 G_CALLBACK(gtk_widget_destroy), | |
| 359 dialog); | |
| 360 g_signal_connect(dialog, "destroy", | |
| 361 G_CALLBACK(gtk_widget_destroyed), | |
| 362 &dialog); | |
| 363 g_signal_connect(check, "clicked", | |
| 364 G_CALLBACK(input_dont_show_warning), | |
| 365 &cfg.warn_about_unplayables); | |
| 366 | |
| 367 gtk_widget_show_all(dialog); | |
| 368 } | |
| 369 | |
| 370 gtk_window_present(GTK_WINDOW(dialog)); | |
| 371 | |
| 372 filename_utf8 = filename_to_utf8(filename); | |
| 373 gtk_list_store_append(store, &iter); | |
| 374 gtk_list_store_set(store, &iter, 0, filename_utf8, -1); | |
| 375 g_free(filename_utf8); | |
| 376 } | |
| 377 | |
| 378 | |
| 379 void | |
| 380 input_file_not_playable(const gchar * filename) | |
| 381 { | |
| 382 if (cfg.warn_about_unplayables) | |
| 383 input_show_unplayable_files(filename); | |
| 384 } | |
| 385 | |
| 386 /* | |
| 387 * input_check_file() | |
| 388 * | |
| 389 * Inputs: | |
| 390 * filename to check recursively against input plugins | |
| 391 * whether or not to show an error | |
| 392 * | |
| 393 * Outputs: | |
| 394 * pointer to input plugin which can handle this file | |
| 395 * otherwise, NULL | |
| 396 * | |
| 397 * (the previous code returned a boolean of whether or not we can | |
| 398 * play the file... even WORSE for performance) | |
| 399 * | |
| 400 * Side Effects: | |
| 401 * various input plugins open the file and probe it | |
| 402 * -- this can have very ugly effects performance wise on streams | |
| 403 * | |
| 404 * --nenolod, Dec 31 2005 | |
| 405 * | |
| 406 * Rewritten to use NewVFS probing, semantics are still basically the same. | |
| 407 * | |
| 408 * --nenolod, Dec 5 2006 | |
| 409 * | |
| 410 * Adapted to use the NewVFS extension probing system if enabled. | |
| 411 * | |
| 412 * --nenolod, Dec 12 2006 | |
| 413 */ | |
| 414 InputPlugin * | |
| 415 input_check_file(const gchar * filename, gboolean show_warning) | |
| 416 { | |
| 417 VFSFile *fd; | |
| 418 GList *node; | |
| 419 InputPlugin *ip; | |
| 420 gchar *filename_proxy; | |
| 421 gint ret = 1; | |
| 422 gchar *ext; | |
| 423 gboolean use_ext_filter; | |
| 424 | |
| 425 filename_proxy = g_strdup(filename); | |
|
2344
3196a09a03e5
[svn] - fix potential overflow on bigendian (<= is not proper for boundschecking -- duh)
nenolod
parents:
2343
diff
changeset
|
426 fd = vfs_buffered_file_new_from_uri(filename_proxy); |
| 2313 | 427 |
| 2399 | 428 if(!fd) |
| 429 return NULL; | |
| 430 | |
| 2313 | 431 ext = strrchr(filename_proxy, '.') + 1; |
| 432 | |
|
2343
0df1a48b8fc4
[svn] - compare against the uri, not the VFSConstructor class the fd comes from
nenolod
parents:
2342
diff
changeset
|
433 use_ext_filter = (fd != NULL && (!g_strncasecmp(filename, "/", 1) || !g_strncasecmp(filename, "file://", 7))) ? TRUE : FALSE; |
| 2313 | 434 |
| 435 for (node = get_input_list(); node != NULL; node = g_list_next(node)) | |
| 436 { | |
| 437 ip = INPUT_PLUGIN(node->data); | |
| 438 | |
| 439 if (!ip || !input_is_enabled(ip->filename)) | |
| 440 continue; | |
| 441 | |
|
2342
f140d0a27093
[svn] - use vfs_rewind() instead of vfs_fseek(fd, 0, seek_set) which was wrong
nenolod
parents:
2331
diff
changeset
|
442 vfs_rewind(fd); |
| 2313 | 443 |
| 444 if (cfg.use_extension_probing == TRUE && ip->vfs_extensions != NULL | |
| 2331 | 445 && ext != NULL && ext != (gpointer) 0x1 && use_ext_filter == TRUE) |
| 2313 | 446 { |
| 447 gint i; | |
| 448 gboolean is_our_ext = FALSE; | |
| 449 | |
| 450 for (i = 0; ip->vfs_extensions[i] != NULL; i++) | |
| 451 { | |
| 452 if (str_has_prefix_nocase(ext, ip->vfs_extensions[i])) | |
| 2331 | 453 { |
| 454 is_our_ext = TRUE; | |
| 455 break; | |
| 456 } | |
| 2313 | 457 } |
| 458 | |
| 459 /* not a plugin that supports this extension */ | |
| 460 if (is_our_ext == FALSE) | |
| 461 continue; | |
| 462 } | |
| 463 | |
| 464 if (ip->is_our_file_from_vfs != NULL) | |
| 465 { | |
| 466 ret = ip->is_our_file_from_vfs(filename_proxy, fd); | |
| 467 | |
| 468 if (ret > 0) | |
| 469 { | |
| 470 g_free(filename_proxy); | |
| 471 vfs_fclose(fd); | |
| 472 return ip; | |
| 473 } | |
| 474 } | |
| 475 else if (ip->is_our_file != NULL) | |
| 476 { | |
| 477 ret = ip->is_our_file(filename_proxy); | |
| 478 | |
| 479 if (ret > 0) | |
| 480 { | |
| 481 g_free(filename_proxy); | |
| 482 vfs_fclose(fd); | |
| 483 return ip; | |
| 484 } | |
| 485 } | |
| 486 | |
| 2331 | 487 if (ret <= -1) |
| 488 break; | |
| 2313 | 489 } |
| 490 | |
| 491 g_free(filename_proxy); | |
| 492 | |
| 493 if (show_warning && ret != -1) | |
| 494 input_file_not_playable(filename); | |
| 495 | |
| 496 vfs_fclose(fd); | |
| 497 | |
| 498 return NULL; | |
| 499 } | |
| 500 | |
| 501 | |
| 502 void | |
| 503 input_set_eq(gint on, gfloat preamp, gfloat * bands) | |
| 504 { | |
| 505 if (!ip_data.playing) | |
| 506 return; | |
| 507 | |
| 508 if (!get_current_input_plugin()) | |
| 509 return; | |
| 510 | |
| 511 if (get_current_input_plugin()->set_eq) | |
| 512 get_current_input_plugin()->set_eq(on, preamp, bands); | |
| 513 } | |
| 514 | |
| 515 void | |
| 516 input_get_song_info(const gchar * filename, gchar ** title, gint * length) | |
| 517 { | |
| 518 InputPlugin *ip = NULL; | |
| 519 BmpTitleInput *input; | |
| 520 gchar *tmp = NULL, *ext; | |
| 521 gchar *filename_proxy; | |
| 522 | |
| 523 g_return_if_fail(filename != NULL); | |
| 524 g_return_if_fail(title != NULL); | |
| 525 g_return_if_fail(length != NULL); | |
| 526 | |
| 527 filename_proxy = g_strdup(filename); | |
| 528 | |
| 529 ip = input_check_file(filename_proxy, FALSE); | |
| 530 | |
| 2331 | 531 if (ip && ip->get_song_info) { |
| 2313 | 532 ip->get_song_info(filename_proxy, &tmp, length); |
| 533 *title = str_to_utf8(tmp); | |
| 534 g_free(tmp); | |
| 535 } | |
| 536 else { | |
| 537 input = bmp_title_input_new(); | |
| 538 | |
| 539 tmp = g_strdup(filename); | |
| 540 if ((ext = strrchr(tmp, '.'))) | |
| 541 *ext = '\0'; | |
| 542 | |
| 543 input->file_name = g_path_get_basename(tmp); | |
| 544 input->file_ext = ext ? ext + 1 : NULL; | |
| 545 input->file_path = g_path_get_dirname(tmp); | |
| 546 | |
| 547 if ((tmp = xmms_get_titlestring(xmms_get_gentitle_format(), input))) { | |
| 548 (*title) = str_to_utf8(tmp); | |
| 549 g_free(tmp); | |
| 550 } | |
| 551 else { | |
| 552 (*title) = filename_to_utf8(input->file_name); | |
| 553 } | |
| 554 | |
| 555 (*length) = -1; | |
| 556 | |
| 557 bmp_title_input_free(input); | |
| 558 input = NULL; | |
| 559 } | |
| 560 | |
| 561 g_free(filename_proxy); | |
| 562 } | |
| 563 | |
| 564 TitleInput * | |
| 565 input_get_song_tuple(const gchar * filename) | |
| 566 { | |
| 567 InputPlugin *ip = NULL; | |
| 568 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
|
569 gchar *ext = NULL; |
| 2313 | 570 gchar *filename_proxy; |
| 571 | |
| 572 if (filename == NULL) | |
| 2331 | 573 return NULL; |
| 2313 | 574 |
| 575 filename_proxy = g_strdup(filename); | |
| 576 | |
| 577 ip = input_check_file(filename_proxy, FALSE); | |
| 578 | |
| 2331 | 579 if (ip && ip->get_song_tuple) |
| 2313 | 580 input = ip->get_song_tuple(filename_proxy); |
| 2331 | 581 else |
| 582 { | |
| 2313 | 583 input = bmp_title_input_new(); |
| 584 | |
|
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
|
585 ext = strrchr(filename, '.'); |
| 2313 | 586 |
| 2331 | 587 input->track_name = NULL; |
| 588 input->length = -1; | |
| 589 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
|
590 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
|
591 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
|
592 input->file_path = g_path_get_dirname(filename); |
| 2313 | 593 } |
| 594 | |
| 595 return input; | |
| 596 } | |
| 597 | |
| 598 static void | |
| 599 input_general_file_info_box(const gchar * filename, InputPlugin * ip) | |
| 600 { | |
| 601 GtkWidget *window, *vbox; | |
| 602 GtkWidget *label, *filename_hbox, *filename_entry; | |
| 603 GtkWidget *bbox, *cancel; | |
| 604 | |
| 605 gchar *title, *fileinfo, *basename, *iplugin; | |
| 606 gchar *filename_utf8; | |
| 607 | |
| 608 window = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
| 609 gtk_window_set_resizable(GTK_WINDOW(window), FALSE); | |
| 610 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER); | |
| 611 | |
| 612 basename = g_path_get_basename(filename); | |
| 613 fileinfo = filename_to_utf8(basename); | |
| 614 title = g_strdup_printf(_("audacious: %s"), fileinfo); | |
| 615 | |
| 616 gtk_window_set_title(GTK_WINDOW(window), title); | |
| 617 | |
| 618 g_free(title); | |
| 619 g_free(fileinfo); | |
| 620 g_free(basename); | |
| 621 | |
| 622 gtk_container_set_border_width(GTK_CONTAINER(window), 10); | |
| 623 | |
| 624 vbox = gtk_vbox_new(FALSE, 10); | |
| 625 gtk_container_add(GTK_CONTAINER(window), vbox); | |
| 626 | |
| 627 filename_hbox = gtk_hbox_new(FALSE, 5); | |
| 628 gtk_box_pack_start(GTK_BOX(vbox), filename_hbox, FALSE, TRUE, 0); | |
| 629 | |
| 630 label = gtk_label_new(_("Filename:")); | |
| 631 gtk_box_pack_start(GTK_BOX(filename_hbox), label, FALSE, TRUE, 0); | |
| 632 | |
| 633 filename_entry = gtk_entry_new(); | |
| 634 filename_utf8 = filename_to_utf8(filename); | |
| 635 | |
| 636 gtk_entry_set_text(GTK_ENTRY(filename_entry), filename_utf8); | |
| 637 gtk_editable_set_editable(GTK_EDITABLE(filename_entry), FALSE); | |
| 638 gtk_box_pack_start(GTK_BOX(filename_hbox), filename_entry, TRUE, TRUE, 0); | |
| 639 | |
| 640 g_free(filename_utf8); | |
| 641 | |
| 642 if (ip) | |
| 643 if (ip->description) | |
| 644 iplugin = ip->description; | |
| 645 else | |
| 646 iplugin = ip->filename; | |
| 647 else | |
| 648 iplugin = _("No input plugin recognized this file"); | |
| 649 | |
| 650 title = g_strdup_printf(_("Input plugin: %s"), iplugin); | |
| 651 | |
| 652 label = gtk_label_new(title); | |
| 653 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
| 654 gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT); | |
| 655 g_free(title); | |
| 656 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, TRUE, 0); | |
| 657 | |
| 658 bbox = gtk_hbutton_box_new(); | |
| 659 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); | |
| 660 gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0); | |
| 661 | |
| 662 cancel = gtk_button_new_from_stock(GTK_STOCK_CLOSE); | |
| 663 g_signal_connect_swapped(G_OBJECT(cancel), "clicked", | |
| 664 GTK_SIGNAL_FUNC(gtk_widget_destroy), | |
| 665 GTK_OBJECT(window)); | |
| 666 GTK_WIDGET_SET_FLAGS(cancel, GTK_CAN_DEFAULT); | |
| 667 gtk_box_pack_start(GTK_BOX(bbox), cancel, TRUE, TRUE, 0); | |
| 668 | |
| 669 gtk_widget_show_all(window); | |
| 670 } | |
| 671 | |
| 672 void | |
| 673 input_file_info_box(const gchar * filename) | |
| 674 { | |
| 675 InputPlugin *ip; | |
| 676 gchar *filename_proxy; | |
| 677 | |
| 678 filename_proxy = g_strdup(filename); | |
| 679 | |
| 680 ip = input_check_file(filename_proxy, FALSE); | |
| 681 | |
| 682 if (ip->file_info_box) | |
| 683 ip->file_info_box(filename_proxy); | |
| 684 else | |
| 685 input_general_file_info_box(filename, ip); | |
| 686 | |
| 687 input_general_file_info_box(filename, NULL); | |
| 688 g_free(filename_proxy); | |
| 689 } | |
| 690 | |
| 691 GList * | |
| 692 input_scan_dir(const gchar * path) | |
| 693 { | |
| 694 GList *node, *result = NULL; | |
| 695 InputPlugin *ip; | |
| 696 gchar *path_proxy; | |
| 697 | |
| 698 g_return_val_if_fail(path != NULL, NULL); | |
| 699 | |
| 700 if (*path == '/') | |
| 701 while (path[1] == '/') | |
| 702 path++; | |
| 703 | |
| 704 path_proxy = g_strdup(path); | |
| 705 | |
| 706 for (node = get_input_list(); node; node = g_list_next(node)) { | |
| 707 ip = INPUT_PLUGIN(node->data); | |
| 708 | |
| 709 if (!ip) | |
| 710 continue; | |
| 711 | |
| 712 if (!ip->scan_dir) | |
| 713 continue; | |
| 714 | |
| 715 if (!input_is_enabled(ip->filename)) | |
| 716 continue; | |
| 717 | |
| 718 if ((result = ip->scan_dir(path_proxy))) | |
| 719 break; | |
| 720 } | |
| 721 | |
| 722 g_free(path_proxy); | |
| 723 | |
| 724 return result; | |
| 725 } | |
| 726 | |
| 727 void | |
| 728 input_get_volume(gint * l, gint * r) | |
| 729 { | |
| 730 *l = -1; | |
| 731 *r = -1; | |
| 732 if (playback_get_playing()) { | |
| 733 if (get_current_input_plugin() && | |
| 734 get_current_input_plugin()->get_volume) { | |
| 735 get_current_input_plugin()->get_volume(l, r); | |
| 736 return; | |
| 737 } | |
| 738 } | |
| 739 output_get_volume(l, r); | |
| 740 } | |
| 741 | |
| 742 void | |
| 743 input_set_volume(gint l, gint r) | |
| 744 { | |
| 745 if (playback_get_playing()) { | |
| 746 if (get_current_input_plugin() && | |
| 747 get_current_input_plugin()->set_volume) { | |
| 748 get_current_input_plugin()->set_volume(l, r); | |
| 749 return; | |
| 750 } | |
| 751 } | |
| 752 output_set_volume(l, r); | |
| 753 } | |
| 754 | |
| 755 void | |
| 756 input_update_vis(gint time) | |
| 757 { | |
| 758 GList *node; | |
| 759 VisNode *vis = NULL, *visnext = NULL; | |
| 760 gboolean found = FALSE; | |
| 761 | |
| 762 G_LOCK(vis_mutex); | |
| 763 node = vis_list; | |
| 764 while (g_list_next(node) && !found) { | |
| 765 visnext = g_list_next(node)->data; | |
| 766 vis = node->data; | |
| 767 | |
| 768 if (vis->time >= time) | |
| 769 break; | |
| 770 | |
| 771 vis_list = g_list_delete_link(vis_list, node); | |
| 772 | |
| 773 if (visnext->time >= time) { | |
| 774 found = TRUE; | |
| 775 break; | |
| 776 } | |
| 777 g_free(vis); | |
| 778 node = vis_list; | |
| 779 } | |
| 780 G_UNLOCK(vis_mutex); | |
| 781 | |
| 782 if (found) { | |
| 783 vis_send_data(vis->data, vis->nch, vis->length); | |
| 784 g_free(vis); | |
| 785 } | |
| 786 else | |
| 787 vis_send_data(NULL, 0, 0); | |
| 788 } | |
| 789 | |
| 790 | |
| 791 gchar * | |
| 792 input_get_info_text(void) | |
| 793 { | |
| 794 return g_strdup(input_info_text); | |
| 795 } | |
| 796 | |
| 797 void | |
| 798 input_set_info_text(const gchar * text) | |
| 799 { | |
| 800 g_free(input_info_text); | |
| 801 input_info_text = g_strdup(text); | |
| 802 mainwin_set_info_text(); | |
| 803 } | |
| 804 | |
| 805 void | |
| 806 input_set_status_buffering(gboolean status) | |
| 807 { | |
| 808 if (!playback_get_playing()) | |
| 809 return; | |
| 810 | |
| 811 if (!get_current_input_plugin()) | |
| 812 return; | |
| 813 | |
| 814 ip_data.buffering = status; | |
| 815 | |
| 816 g_return_if_fail(mainwin_playstatus != NULL); | |
| 817 | |
| 818 if (ip_data.buffering == TRUE && mainwin_playstatus != NULL && mainwin_playstatus->ps_status == STATUS_STOP) | |
| 819 mainwin_playstatus->ps_status = STATUS_PLAY; | |
| 820 | |
| 821 playstatus_set_status_buffering(mainwin_playstatus, ip_data.buffering); | |
| 822 } | |
| 823 | |
| 824 void | |
| 825 input_about(gint index) | |
| 826 { | |
| 827 InputPlugin *ip; | |
| 828 | |
| 829 ip = g_list_nth(ip_data.input_list, index)->data; | |
| 830 if (ip && ip->about) | |
| 831 ip->about(); | |
| 832 } | |
| 833 | |
| 834 void | |
| 835 input_configure(gint index) | |
| 836 { | |
| 837 InputPlugin *ip; | |
| 838 | |
| 839 ip = g_list_nth(ip_data.input_list, index)->data; | |
| 840 if (ip && ip->configure) | |
| 841 ip->configure(); | |
| 842 } |
