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