Mercurial > audlegacy
annotate src/audacious/playlist.c @ 2518:4c9910af4cc5 trunk
[svn] - fix signed vs unsigned comparisons and missing initializer warnings
author | nenolod |
---|---|
date | Wed, 14 Feb 2007 11:05:36 -0800 |
parents | fcf730269639 |
children | 610d85b8a22b |
rev | line source |
---|---|
2313 | 1 /* Audacious |
2 * Copyright (C) 2005-2007 Audacious team. | |
3 * | |
4 * BMP (C) GPL 2003 $top_src_dir/AUTHORS | |
5 * | |
6 * based on: | |
7 * | |
8 * XMMS - Cross-platform multimedia player | |
9 * Copyright (C) 1998-2003 Peter Alm, Mikael Alm, Olle Hallnas, | |
10 * Thomas Nilsson and 4Front Technologies | |
11 * Copyright (C) 1999-2003 Haavard Kvaalen | |
12 * | |
13 * This program is free software; you can redistribute it and/or modify | |
14 * it under the terms of the GNU General Public License as published by | |
15 * the Free Software Foundation; under version 2 of the License. | |
16 * | |
17 * This program is distributed in the hope that it will be useful, | |
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 * GNU General Public License for more details. | |
21 * | |
22 * You should have received a copy of the GNU General Public License | |
23 * along with this program; if not, write to the Free Software | |
24 * Foundation, Inc., 59 Tmple Place - Suite 330, Boston, MA 02110-1301, USA. | |
25 */ | |
26 | |
27 #ifdef HAVE_CONFIG_H | |
28 # include "config.h" | |
29 #endif | |
30 | |
31 #include "playlist.h" | |
32 | |
33 #include <glib.h> | |
34 #include <glib/gprintf.h> | |
35 #include <stdlib.h> | |
36 #include <string.h> | |
37 #include <time.h> | |
38 | |
39 #include <unistd.h> | |
40 #include <sys/types.h> | |
41 #include <sys/stat.h> | |
42 #include <sys/errno.h> | |
43 | |
44 #if defined(USE_REGEX_ONIGURUMA) | |
45 #include <onigposix.h> | |
46 #elif defined(USE_REGEX_PCRE) | |
47 #include <pcreposix.h> | |
48 #else | |
49 #include <regex.h> | |
50 #endif | |
51 | |
52 #include "input.h" | |
53 #include "main.h" | |
54 #include "ui_main.h" | |
2416
0fd7f4f969ad
[svn] integrated urldecode.* from libaudacious into audacious directory, made separate ui_fileopener.*
mf0102
parents:
2408
diff
changeset
|
55 #include "util.h" |
2313 | 56 #include "libaudacious/configdb.h" |
57 #include "vfs.h" | |
2416
0fd7f4f969ad
[svn] integrated urldecode.* from libaudacious into audacious directory, made separate ui_fileopener.*
mf0102
parents:
2408
diff
changeset
|
58 #include "urldecode.h" |
2313 | 59 #include "ui_equalizer.h" |
60 #include "playback.h" | |
61 #include "playlist.h" | |
62 #include "playlist_container.h" | |
2499
15a1f5ee4d1c
[svn] - playlist_manager -> ui_playlist_manager, since it's a UI component.
nenolod
parents:
2493
diff
changeset
|
63 #include "ui_playlist_manager.h" |
2313 | 64 #include "ui_playlist.h" |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2328
diff
changeset
|
65 #include "strings.h" |
2313 | 66 #include "ui_fileinfo.h" |
67 | |
68 #include "debug.h" | |
69 | |
2407
1dc1d36d0347
[svn] - add hooks: playback begin, playback end, playlist reached end
nenolod
parents:
2380
diff
changeset
|
70 #include "hook.h" |
1dc1d36d0347
[svn] - add hooks: playback begin, playback end, playlist reached end
nenolod
parents:
2380
diff
changeset
|
71 |
2313 | 72 typedef gint (*PlaylistCompareFunc) (PlaylistEntry * a, PlaylistEntry * b); |
73 typedef void (*PlaylistSaveFunc) (FILE * file); | |
74 | |
75 /* If we manually change the song, p_p_b_j will show us where to go back to */ | |
76 PlaylistEntry *playlist_position_before_jump = NULL; | |
77 | |
78 static GList *playlists = NULL; | |
79 static GList *playlists_iter; | |
80 | |
81 /* If this is set to TRUE, we do not probe upon playlist add. | |
82 * | |
83 * Under Audacious 0.1.x, this was not a big deal because we used | |
84 * file extension introspection instead of looking for file format magic | |
85 * strings. | |
86 * | |
87 * Because we use file magic strings, we have to fstat a file being added | |
88 * to a playlist up to 1 * <number of input plugins installed> times. | |
89 * | |
90 * This can get really slow now that we're looking for files to add to a | |
91 * playlist. (Up to 5 minutes for 5000 songs, etcetera.) | |
92 * | |
93 * So, we obviously don't want to probe while opening a large playlist | |
94 * up. Hince the boolean below. | |
95 * | |
96 * January 7, 2006, William Pitcock <nenolod@nenolod.net> | |
97 */ | |
98 | |
99 G_LOCK_DEFINE(playlist_get_info_going); | |
100 | |
2328 | 101 //static gchar *playlist_current_name = NULL; |
2313 | 102 |
103 static gboolean playlist_get_info_scan_active = FALSE; | |
104 static gboolean playlist_get_info_going = FALSE; | |
105 static GThread *playlist_get_info_thread; | |
106 | |
107 static gint path_compare(const gchar * a, const gchar * b); | |
108 static gint playlist_compare_path(PlaylistEntry * a, PlaylistEntry * b); | |
109 static gint playlist_compare_filename(PlaylistEntry * a, PlaylistEntry * b); | |
110 static gint playlist_compare_title(PlaylistEntry * a, PlaylistEntry * b); | |
111 static gint playlist_compare_artist(PlaylistEntry * a, PlaylistEntry * b); | |
112 static time_t playlist_get_mtime(const gchar *filename); | |
113 static gint playlist_compare_date(PlaylistEntry * a, PlaylistEntry * b); | |
114 static gint playlist_compare_track(PlaylistEntry * a, PlaylistEntry * b); | |
115 static gint playlist_compare_playlist(PlaylistEntry * a, PlaylistEntry * b); | |
116 | |
117 static gint playlist_dupscmp_path(PlaylistEntry * a, PlaylistEntry * b); | |
118 static gint playlist_dupscmp_filename(PlaylistEntry * a, PlaylistEntry * b); | |
119 static gint playlist_dupscmp_title(PlaylistEntry * a, PlaylistEntry * b); | |
120 | |
121 static PlaylistCompareFunc playlist_compare_func_table[] = { | |
122 playlist_compare_path, | |
123 playlist_compare_filename, | |
124 playlist_compare_title, | |
125 playlist_compare_artist, | |
126 playlist_compare_date, | |
127 playlist_compare_track, | |
128 playlist_compare_playlist | |
129 }; | |
130 | |
131 static guint playlist_load_ins(Playlist * playlist, const gchar * filename, gint pos); | |
132 | |
133 static void playlist_generate_shuffle_list(Playlist *); | |
134 static void playlist_generate_shuffle_list_nolock(Playlist *); | |
135 | |
136 static void playlist_recalc_total_time_nolock(Playlist *); | |
137 static void playlist_recalc_total_time(Playlist *); | |
138 static gboolean playlist_entry_get_info(PlaylistEntry * entry); | |
139 | |
140 /* *********************** playlist entry code ********************** */ | |
141 | |
142 PlaylistEntry * | |
143 playlist_entry_new(const gchar * filename, | |
144 const gchar * title, | |
145 const gint length, | |
146 InputPlugin * dec) | |
147 { | |
148 PlaylistEntry *entry; | |
149 | |
150 entry = g_new0(PlaylistEntry, 1); | |
151 entry->filename = g_strdup(filename); | |
152 entry->title = str_to_utf8(title); | |
153 entry->length = length; | |
154 entry->selected = FALSE; | |
155 entry->decoder = dec; | |
156 | |
157 /* only do this if we have a decoder, otherwise it just takes too long */ | |
158 if (entry->decoder) | |
159 playlist_entry_get_info(entry); | |
160 | |
161 return entry; | |
162 } | |
163 | |
164 void | |
165 playlist_entry_free(PlaylistEntry * entry) | |
166 { | |
167 if (!entry) | |
168 return; | |
169 | |
170 if (entry->tuple != NULL) { | |
171 bmp_title_input_free(entry->tuple); | |
172 entry->tuple = NULL; | |
173 } | |
174 | |
175 if (entry->filename != NULL) | |
176 g_free(entry->filename); | |
177 | |
178 if (entry->title != NULL) | |
179 g_free(entry->title); | |
180 | |
181 g_free(entry); | |
182 } | |
183 | |
184 static gboolean | |
185 playlist_entry_get_info(PlaylistEntry * entry) | |
186 { | |
187 TitleInput *tuple; | |
188 time_t modtime; | |
189 | |
190 g_return_val_if_fail(entry != NULL, FALSE); | |
191 | |
2433
6cdccf094e51
[svn] - Why are we probing streams so unnecessarily often?
nhjm449
parents:
2416
diff
changeset
|
192 // Let's not randomly probe streams, mmkay? |
6cdccf094e51
[svn] - Why are we probing streams so unnecessarily often?
nhjm449
parents:
2416
diff
changeset
|
193 if (entry->decoder == NULL && (str_has_prefix_nocase(entry->filename, "http://") || str_has_prefix_nocase(entry->filename, "https://"))) |
6cdccf094e51
[svn] - Why are we probing streams so unnecessarily often?
nhjm449
parents:
2416
diff
changeset
|
194 return TRUE; |
6cdccf094e51
[svn] - Why are we probing streams so unnecessarily often?
nhjm449
parents:
2416
diff
changeset
|
195 |
2313 | 196 if (entry->tuple == NULL || entry->tuple->mtime > 0 || entry->tuple->mtime == -1) |
197 modtime = playlist_get_mtime(entry->filename); | |
198 else | |
199 modtime = 0; /* URI -nenolod */ | |
200 | |
201 if (entry->decoder == NULL) | |
202 entry->decoder = input_check_file(entry->filename, FALSE); | |
203 | |
204 /* renew tuple if file mtime is newer than tuple mtime. */ | |
205 if(entry->tuple){ | |
206 if(entry->tuple->mtime == modtime) | |
207 return TRUE; | |
208 else { | |
209 bmp_title_input_free(entry->tuple); | |
210 entry->tuple = NULL; | |
211 } | |
212 } | |
213 | |
214 if (entry->decoder == NULL || entry->decoder->get_song_tuple == NULL) | |
215 tuple = input_get_song_tuple(entry->filename); | |
216 else | |
217 tuple = entry->decoder->get_song_tuple(entry->filename); | |
218 | |
219 if (tuple == NULL) | |
220 return FALSE; | |
221 | |
222 /* attach mtime */ | |
223 tuple->mtime = modtime; | |
224 | |
225 /* entry is still around */ | |
226 entry->title = xmms_get_titlestring(tuple->formatter != NULL ? tuple->formatter : xmms_get_gentitle_format(), tuple); | |
227 entry->length = tuple->length; | |
228 entry->tuple = tuple; | |
229 | |
230 return TRUE; | |
231 } | |
232 | |
233 /* *********************** playlist selector code ************************* */ | |
234 | |
235 void | |
236 playlist_init(void) | |
237 { | |
238 Playlist *initial_pl; | |
239 | |
240 /* FIXME: is this really necessary? REQUIRE_STATIC_LOCK(playlists); */ | |
241 | |
242 initial_pl = playlist_new(); | |
243 | |
244 playlist_add_playlist(initial_pl); | |
245 } | |
246 | |
247 void | |
248 playlist_add_playlist(Playlist *playlist) | |
249 { | |
250 playlists = g_list_append(playlists, playlist); | |
251 | |
252 if (playlists_iter == NULL) | |
253 playlists_iter = playlists; | |
254 | |
255 playlist_manager_update(); | |
256 } | |
257 | |
258 void | |
259 playlist_remove_playlist(Playlist *playlist) | |
260 { | |
261 /* trying to free the last playlist simply clears and resets it */ | |
262 if (g_list_length(playlists) < 2) { | |
263 playlist_clear(playlist); | |
264 playlist_set_current_name(playlist, NULL); | |
265 return; | |
266 } | |
267 | |
268 if (playlist == playlist_get_active()) | |
269 playlist_select_next(); | |
270 | |
271 /* upon removal, a playlist should be cleared and freed */ | |
272 playlists = g_list_remove(playlists, playlist); | |
273 playlist_clear(playlist); | |
274 playlist_free(playlist); | |
275 | |
276 if (playlists_iter == NULL) | |
277 playlists_iter = playlists; | |
278 | |
279 playlist_manager_update(); | |
280 } | |
281 | |
282 GList * | |
283 playlist_get_playlists(void) | |
284 { | |
285 return playlists; | |
286 } | |
287 | |
288 void | |
289 playlist_select_next(void) | |
290 { | |
291 if (playlists_iter == NULL) | |
292 playlists_iter = playlists; | |
293 | |
294 playlists_iter = g_list_next(playlists_iter); | |
295 | |
296 if (playlists_iter == NULL) | |
297 playlists_iter = playlists; | |
298 | |
299 playlistwin_update_list(playlist_get_active()); | |
300 } | |
301 | |
302 void | |
303 playlist_select_prev(void) | |
304 { | |
305 if (playlists_iter == NULL) | |
306 playlists_iter = playlists; | |
307 | |
308 playlists_iter = g_list_previous(playlists_iter); | |
309 | |
310 if (playlists_iter == NULL) | |
311 playlists_iter = playlists; | |
312 | |
313 playlistwin_update_list(playlist_get_active()); | |
314 } | |
315 | |
316 void | |
317 playlist_select_playlist(Playlist *playlist) | |
318 { | |
319 if (playlists_iter == NULL) | |
320 playlists_iter = playlists; | |
321 | |
322 playlists_iter = g_list_find(playlists, playlist); | |
323 | |
324 if (playlists_iter == NULL) | |
325 playlists_iter = playlists; | |
326 | |
327 playlistwin_update_list(playlist); | |
328 } | |
329 | |
330 /* *********************** playlist code ********************** */ | |
331 | |
332 const gchar * | |
333 playlist_get_current_name(Playlist *playlist) | |
334 { | |
335 return playlist->title; | |
336 } | |
337 | |
338 gboolean | |
339 playlist_set_current_name(Playlist *playlist, const gchar * filename) | |
340 { | |
341 if (playlist->title) | |
342 g_free(playlist->title); | |
343 | |
344 if (!filename) { | |
345 playlist->title = NULL; | |
346 return FALSE; | |
347 } | |
348 | |
2504
fcf730269639
[svn] - convert filename string to utf8 for playlist->title (closes bug #789)
giacomo
parents:
2499
diff
changeset
|
349 playlist->title = filename_to_utf8(filename); |
2313 | 350 return TRUE; |
351 } | |
352 | |
353 static GList * | |
354 find_playlist_position_list(Playlist *playlist) | |
355 { | |
356 REQUIRE_LOCK(playlist->mutex); | |
357 | |
358 if (!playlist->position) { | |
359 if (cfg.shuffle) | |
360 return playlist->shuffle; | |
361 else | |
362 return playlist->entries; | |
363 } | |
364 | |
365 if (cfg.shuffle) | |
366 return g_list_find(playlist->shuffle, playlist->position); | |
367 else | |
368 return g_list_find(playlist->entries, playlist->position); | |
369 } | |
370 | |
371 static void | |
372 play_queued(Playlist *playlist) | |
373 { | |
374 GList *tmp = playlist->queue; | |
375 | |
376 REQUIRE_LOCK( playlist->mutex ); | |
377 | |
378 playlist->position = playlist->queue->data; | |
379 playlist->queue = g_list_remove_link(playlist->queue, playlist->queue); | |
380 g_list_free_1(tmp); | |
381 } | |
382 | |
383 void | |
384 playlist_clear(Playlist *playlist) | |
385 { | |
386 if (!playlist) | |
387 return; | |
388 | |
389 PLAYLIST_LOCK( playlist->mutex ); | |
390 | |
391 g_list_foreach(playlist->entries, (GFunc) playlist_entry_free, NULL); | |
392 g_list_free(playlist->entries); | |
393 playlist->position = NULL; | |
394 playlist->entries = NULL; | |
395 | |
396 PLAYLIST_UNLOCK( playlist->mutex ); | |
397 | |
398 playlist_generate_shuffle_list(playlist); | |
399 playlistwin_update_list(playlist); | |
400 playlist_recalc_total_time(playlist); | |
401 playlist_manager_update(); | |
402 } | |
403 | |
404 static void | |
405 playlist_delete_node(Playlist * playlist, GList * node, gboolean * set_info_text, | |
406 gboolean * restart_playing) | |
407 { | |
408 PlaylistEntry *entry; | |
409 GList *playing_song = NULL; | |
410 | |
411 REQUIRE_LOCK(playlist->mutex); | |
412 | |
413 /* We call g_list_find manually here because we don't want an item | |
414 * in the shuffle_list */ | |
415 | |
416 if (playlist->position) | |
417 playing_song = g_list_find(playlist->entries, playlist->position); | |
418 | |
419 entry = PLAYLIST_ENTRY(node->data); | |
420 | |
421 if (playing_song == node) { | |
422 *set_info_text = TRUE; | |
423 | |
424 if (playback_get_playing()) { | |
425 PLAYLIST_UNLOCK(playlist->mutex); | |
426 ip_data.stop = TRUE; | |
427 playback_stop(); | |
428 ip_data.stop = FALSE; | |
429 PLAYLIST_LOCK(playlist->mutex); | |
430 *restart_playing = TRUE; | |
431 } | |
432 | |
433 playing_song = find_playlist_position_list(playlist); | |
434 | |
435 if (g_list_next(playing_song)) | |
436 playlist->position = g_list_next(playing_song)->data; | |
437 else if (g_list_previous(playing_song)) | |
438 playlist->position = g_list_previous(playing_song)->data; | |
439 else | |
440 playlist->position = NULL; | |
441 | |
442 /* Make sure the entry did not disappear under us */ | |
443 if (g_list_index(playlist->entries, entry) == -1) | |
444 return; | |
445 | |
446 } | |
447 else if (g_list_position(playlist->entries, playing_song) > | |
448 g_list_position(playlist->entries, node)) { | |
449 *set_info_text = TRUE; | |
450 } | |
451 | |
452 playlist->shuffle = g_list_remove(playlist->shuffle, entry); | |
453 playlist->queue = g_list_remove(playlist->queue, entry); | |
454 playlist->entries = g_list_remove_link(playlist->entries, node); | |
455 playlist_entry_free(entry); | |
456 g_list_free_1(node); | |
457 | |
458 playlist_recalc_total_time_nolock(playlist); | |
459 } | |
460 | |
461 void | |
462 playlist_delete_index(Playlist *playlist, guint pos) | |
463 { | |
464 gboolean restart_playing = FALSE, set_info_text = FALSE; | |
465 GList *node; | |
466 | |
467 if (!playlist) | |
468 return; | |
469 | |
470 PLAYLIST_LOCK(playlist->mutex); | |
471 | |
472 node = g_list_nth(playlist->entries, pos); | |
473 | |
474 if (!node) { | |
475 PLAYLIST_UNLOCK(playlist->mutex); | |
476 return; | |
477 } | |
478 | |
479 playlist_delete_node(playlist, node, &set_info_text, &restart_playing); | |
480 | |
481 PLAYLIST_UNLOCK(playlist->mutex); | |
482 | |
483 playlist_recalc_total_time(playlist); | |
484 | |
485 playlistwin_update_list(playlist); | |
486 if (restart_playing) { | |
487 if (playlist->position) { | |
488 playback_initiate(); | |
489 } | |
490 else { | |
491 mainwin_clear_song_info(); | |
492 } | |
493 } | |
494 else if (set_info_text) { | |
495 mainwin_set_info_text(); | |
496 } | |
497 | |
498 playlist_manager_update(); | |
499 } | |
500 | |
501 void | |
502 playlist_delete_filenames(Playlist * playlist, GList * filenames) | |
503 { | |
504 GList *node, *fnode; | |
505 gboolean set_info_text = FALSE, restart_playing = FALSE; | |
506 | |
507 PLAYLIST_LOCK(playlist->mutex); | |
508 | |
509 for (fnode = filenames; fnode; fnode = g_list_next(fnode)) { | |
510 node = playlist->entries; | |
511 | |
512 while (node) { | |
513 GList *next = g_list_next(node); | |
514 PlaylistEntry *entry = node->data; | |
515 | |
516 if (!strcmp(entry->filename, fnode->data)) | |
517 playlist_delete_node(playlist, node, &set_info_text, &restart_playing); | |
518 | |
519 node = next; | |
520 } | |
521 } | |
522 | |
523 playlist_recalc_total_time(playlist); | |
524 PLAYLIST_UNLOCK(playlist->mutex); | |
525 | |
526 playlistwin_update_list(playlist); | |
527 | |
528 if (restart_playing) { | |
529 if (playlist->position) { | |
530 playback_initiate(); | |
531 } | |
532 else { | |
533 mainwin_clear_song_info(); | |
534 } | |
535 } | |
536 else if (set_info_text) { | |
537 mainwin_set_info_text(); | |
538 } | |
539 | |
540 playlist_manager_update(); | |
541 } | |
542 | |
543 void | |
544 playlist_delete(Playlist * playlist, gboolean crop) | |
545 { | |
546 gboolean restart_playing = FALSE, set_info_text = FALSE; | |
547 GList *node, *next_node; | |
548 PlaylistEntry *entry; | |
549 | |
550 g_return_if_fail(playlist != NULL); | |
551 | |
552 PLAYLIST_LOCK(playlist->mutex); | |
553 | |
554 node = playlist->entries; | |
555 | |
556 while (node) { | |
557 entry = PLAYLIST_ENTRY(node->data); | |
558 | |
559 next_node = g_list_next(node); | |
560 | |
561 if ((entry->selected && !crop) || (!entry->selected && crop)) { | |
562 playlist_delete_node(playlist, node, &set_info_text, &restart_playing); | |
563 } | |
564 | |
565 node = next_node; | |
566 } | |
567 | |
568 PLAYLIST_UNLOCK(playlist->mutex); | |
569 | |
570 playlist_recalc_total_time(playlist); | |
571 | |
572 if (set_info_text) { | |
573 mainwin_set_info_text(); | |
574 } | |
575 | |
576 if (restart_playing) { | |
577 if (playlist->position) { | |
578 playback_initiate(); | |
579 } | |
580 else { | |
581 mainwin_clear_song_info(); | |
582 } | |
583 } | |
584 | |
585 playlistwin_update_list(playlist); | |
586 playlist_manager_update(); | |
587 } | |
588 | |
589 static void | |
590 __playlist_ins_with_info(Playlist * playlist, | |
591 const gchar * filename, | |
592 gint pos, | |
593 const gchar * title, | |
594 gint len, | |
595 InputPlugin * dec) | |
596 { | |
597 g_return_if_fail(filename != NULL); | |
598 | |
599 PLAYLIST_LOCK(playlist->mutex); | |
600 playlist->entries = g_list_insert(playlist->entries, | |
601 playlist_entry_new(filename, title, len, dec), | |
602 pos); | |
603 PLAYLIST_UNLOCK(playlist->mutex); | |
604 | |
605 g_mutex_lock(mutex_scan); | |
606 playlist_get_info_scan_active = TRUE; | |
607 g_mutex_unlock(mutex_scan); | |
608 g_cond_signal(cond_scan); | |
609 } | |
610 | |
611 static void | |
612 __playlist_ins_with_info_tuple(Playlist * playlist, | |
613 const gchar * filename, | |
614 gint pos, | |
615 TitleInput *tuple, | |
616 InputPlugin * dec) | |
617 { | |
618 GList *node; | |
619 PlaylistEntry *entry; | |
620 | |
621 g_return_if_fail(playlist != NULL); | |
622 g_return_if_fail(filename != NULL); | |
623 | |
624 PLAYLIST_LOCK(playlist->mutex); | |
625 playlist->entries = g_list_insert(playlist->entries, | |
626 playlist_entry_new(filename, tuple->track_name, tuple->length, dec), | |
627 pos); | |
628 | |
629 if (pos < 0) | |
630 pos = g_list_length(playlist->entries) - 1; /* last element. */ | |
631 | |
632 node = g_list_nth(playlist->entries, pos); | |
633 entry = PLAYLIST_ENTRY(node->data); | |
634 | |
635 if (tuple != NULL) { | |
636 entry->title = xmms_get_titlestring(tuple->formatter != NULL ? tuple->formatter : xmms_get_gentitle_format(), tuple); | |
637 entry->length = tuple->length; | |
638 entry->tuple = tuple; | |
639 } | |
640 | |
641 PLAYLIST_UNLOCK(playlist->mutex); | |
642 | |
643 g_mutex_lock(mutex_scan); | |
644 playlist_get_info_scan_active = TRUE; | |
645 g_mutex_unlock(mutex_scan); | |
646 g_cond_signal(cond_scan); | |
647 } | |
648 | |
649 static void | |
650 __playlist_ins(Playlist * playlist, const gchar * filename, gint pos, InputPlugin *dec) | |
651 { | |
652 __playlist_ins_with_info(playlist, filename, pos, NULL, -1, dec); | |
653 playlist_recalc_total_time(playlist); | |
654 playlist_manager_update(); | |
655 } | |
656 | |
657 gboolean | |
658 playlist_ins(Playlist * playlist, const gchar * filename, gint pos) | |
659 { | |
660 gchar buf[64], *p; | |
661 gint r; | |
662 VFSFile *file; | |
663 InputPlugin *dec; | |
664 | |
665 g_return_val_if_fail(playlist != NULL, FALSE); | |
666 g_return_val_if_fail(filename != NULL, FALSE); | |
667 | |
668 if (is_playlist_name(filename)) { | |
669 playlist->loading_playlist = TRUE; | |
670 playlist_load_ins(playlist, filename, pos); | |
671 playlist->loading_playlist = FALSE; | |
672 return TRUE; | |
673 } | |
674 | |
675 if (playlist->loading_playlist == TRUE || cfg.playlist_detect == TRUE) | |
676 dec = NULL; | |
677 else | |
678 dec = input_check_file(filename, TRUE); | |
679 | |
680 if (cfg.playlist_detect == TRUE || playlist->loading_playlist == TRUE || (playlist->loading_playlist == FALSE && dec != NULL)) | |
681 { | |
682 __playlist_ins(playlist, filename, pos, dec); | |
683 playlist_generate_shuffle_list(playlist); | |
684 playlistwin_update_list(playlist); | |
685 return TRUE; | |
686 } | |
687 | |
688 /* Some files (typically produced by some cgi-scripts) don't have | |
689 * the correct extension. Try to recognize these files by looking | |
690 * at their content. We only check for http entries since it does | |
691 * not make sense to have file entries in a playlist fetched from | |
692 * the net. */ | |
693 | |
694 /* Some strange people put fifo's with the .mp3 extension, so we | |
695 * need to make sure it's a real file (otherwise fread() may block | |
696 * and stall the entire program) */ | |
697 | |
698 /* FIXME: bah, FIFOs actually pass this regular file test */ | |
699 if (!vfs_file_test(filename, G_FILE_TEST_IS_REGULAR)) | |
700 return FALSE; | |
701 | |
702 if (!(file = vfs_fopen(filename, "rb"))) | |
703 return FALSE; | |
704 | |
705 r = vfs_fread(buf, 1, sizeof(buf), file); | |
706 vfs_fclose(file); | |
707 | |
708 for (p = buf; r-- > 0 && (*p == '\r' || *p == '\n'); p++); | |
709 | |
710 if (r > 5 && str_has_prefix_nocase(p, "http:")) { | |
711 playlist_load_ins(playlist, filename, pos); | |
712 return TRUE; | |
713 } | |
714 | |
2493
b7f48f00a342
[svn] - patch from Mark Glines to ad https:// URI support to playlists.
nenolod
parents:
2489
diff
changeset
|
715 if (r > 6 && str_has_prefix_nocase(p, "https:")) { |
b7f48f00a342
[svn] - patch from Mark Glines to ad https:// URI support to playlists.
nenolod
parents:
2489
diff
changeset
|
716 playlist_load_ins(playlist, filename, pos); |
b7f48f00a342
[svn] - patch from Mark Glines to ad https:// URI support to playlists.
nenolod
parents:
2489
diff
changeset
|
717 return TRUE; |
b7f48f00a342
[svn] - patch from Mark Glines to ad https:// URI support to playlists.
nenolod
parents:
2489
diff
changeset
|
718 } |
b7f48f00a342
[svn] - patch from Mark Glines to ad https:// URI support to playlists.
nenolod
parents:
2489
diff
changeset
|
719 |
2313 | 720 return FALSE; |
721 } | |
722 | |
723 /* FIXME: The next few functions are specific to Unix | |
724 * filesystems. Either abstract it away, or don't even bother checking | |
725 * at such low level */ | |
726 | |
727 typedef struct { | |
728 dev_t dev; | |
729 ino_t ino; | |
730 } DeviceInode; | |
731 | |
732 static DeviceInode * | |
733 devino_new(dev_t device, | |
734 ino_t inode) | |
735 { | |
736 DeviceInode *devino = g_new0(DeviceInode, 1); | |
737 | |
738 if (devino) | |
739 { | |
740 devino->dev = device; | |
741 devino->ino = inode; | |
742 } | |
743 | |
744 return devino; | |
745 } | |
746 | |
747 static guint | |
748 devino_hash(gconstpointer key) | |
749 { | |
750 const DeviceInode *d = key; | |
751 return d->ino; | |
752 } | |
753 | |
754 static gint | |
755 devino_compare(gconstpointer a, | |
756 gconstpointer b) | |
757 { | |
758 const DeviceInode *da = a, *db = b; | |
759 return (da->dev == db->dev && da->ino == db->ino); | |
760 } | |
761 | |
762 static gboolean | |
763 devino_destroy(gpointer key, | |
764 gpointer value, | |
765 gpointer data) | |
766 { | |
767 g_free(key); | |
768 return TRUE; | |
769 } | |
770 | |
771 static gboolean | |
772 file_is_hidden(const gchar * filename) | |
773 { | |
774 // FIXME: remove the const cast | |
775 g_return_val_if_fail(filename != NULL, FALSE); | |
776 return (g_basename((gchar *) filename)[0] == '.'); | |
777 } | |
778 | |
779 static GList * | |
780 playlist_dir_find_files(const gchar * path, | |
781 gboolean background, | |
782 GHashTable * htab) | |
783 { | |
784 GDir *dir; | |
785 GList *list = NULL, *ilist; | |
786 const gchar *dir_entry; | |
787 | |
788 struct stat statbuf; | |
789 DeviceInode *devino; | |
790 | |
791 if (!g_file_test(path, G_FILE_TEST_IS_DIR)) | |
792 return NULL; | |
793 | |
794 stat(path, &statbuf); | |
795 devino = devino_new(statbuf.st_dev, statbuf.st_ino); | |
796 | |
797 if (g_hash_table_lookup(htab, devino)) { | |
798 g_free(devino); | |
799 return NULL; | |
800 } | |
801 | |
802 g_hash_table_insert(htab, devino, GINT_TO_POINTER(1)); | |
803 | |
804 if ((ilist = input_scan_dir(path))) { | |
805 GList *node; | |
806 for (node = ilist; node; node = g_list_next(node)) { | |
807 gchar *name = g_build_filename(path, node->data, NULL); | |
808 list = g_list_prepend(list, name); | |
809 g_free(node->data); | |
810 } | |
811 g_list_free(ilist); | |
812 return list; | |
813 } | |
814 | |
815 if (!(dir = g_dir_open(path, 0, NULL))) | |
816 return NULL; | |
817 | |
818 while ((dir_entry = g_dir_read_name(dir))) { | |
819 gchar *filename; | |
820 | |
821 if (file_is_hidden(dir_entry)) | |
822 continue; | |
823 | |
824 filename = g_build_filename(path, dir_entry, NULL); | |
825 | |
826 if (g_file_test(filename, G_FILE_TEST_IS_DIR)) { | |
827 GList *sub; | |
828 sub = playlist_dir_find_files(filename, background, htab); | |
829 g_free(filename); | |
830 list = g_list_concat(list, sub); | |
831 } | |
832 else if (cfg.playlist_detect == TRUE) | |
833 list = g_list_prepend(list, filename); | |
834 else if (input_check_file(filename, TRUE)) | |
835 list = g_list_prepend(list, filename); | |
836 else | |
837 g_free(filename); | |
838 | |
839 while (background && gtk_events_pending()) | |
840 gtk_main_iteration(); | |
841 } | |
842 g_dir_close(dir); | |
843 | |
844 return list; | |
845 } | |
846 | |
847 gboolean | |
848 playlist_add(Playlist * playlist, const gchar * filename) | |
849 { | |
850 return playlist_ins(playlist, filename, -1); | |
851 } | |
852 | |
853 guint | |
854 playlist_add_dir(Playlist * playlist, const gchar * directory) | |
855 { | |
856 return playlist_ins_dir(playlist, directory, -1, TRUE); | |
857 } | |
858 | |
859 guint | |
860 playlist_add_url(Playlist * playlist, const gchar * url) | |
861 { | |
862 return playlist_ins_url(playlist, url, -1); | |
863 } | |
864 | |
865 guint | |
866 playlist_ins_dir(Playlist * playlist, const gchar * path, | |
867 gint pos, | |
868 gboolean background) | |
869 { | |
870 guint entries = 0; | |
871 GList *list, *node; | |
872 GHashTable *htab; | |
873 | |
874 htab = g_hash_table_new(devino_hash, devino_compare); | |
875 | |
876 list = playlist_dir_find_files(path, background, htab); | |
877 list = g_list_sort(list, (GCompareFunc) path_compare); | |
878 | |
879 g_hash_table_foreach_remove(htab, devino_destroy, NULL); | |
880 | |
881 for (node = list; node; node = g_list_next(node)) { | |
882 __playlist_ins(playlist, node->data, pos, NULL); | |
883 g_free(node->data); | |
884 entries++; | |
885 if (pos >= 0) | |
886 pos++; | |
887 } | |
888 | |
889 g_list_free(list); | |
890 | |
891 playlist_recalc_total_time(playlist); | |
892 playlist_generate_shuffle_list(playlist); | |
893 playlistwin_update_list(playlist); | |
894 playlist_manager_update(); | |
895 return entries; | |
896 } | |
897 | |
898 guint | |
899 playlist_ins_url(Playlist * playlist, const gchar * string, | |
900 gint pos) | |
901 { | |
902 gchar *tmp; | |
903 gint i = 1, entries = 0; | |
904 gboolean first = TRUE; | |
905 guint firstpos = 0; | |
906 gboolean success = FALSE; | |
907 gchar *decoded = NULL; | |
908 | |
909 g_return_val_if_fail(playlist != NULL, 0); | |
910 g_return_val_if_fail(string != NULL, 0); | |
911 | |
912 playlistwin_update_list(playlist); | |
913 | |
914 while (*string) { | |
915 GList *node; | |
916 tmp = strchr(string, '\n'); | |
917 if (tmp) { | |
918 if (*(tmp - 1) == '\r') | |
919 *(tmp - 1) = '\0'; | |
920 *tmp = '\0'; | |
921 } | |
922 | |
923 decoded = g_strdup(string); | |
924 | |
925 if (g_file_test(decoded, G_FILE_TEST_IS_DIR)) { | |
926 i = playlist_ins_dir(playlist, decoded, pos, FALSE); | |
927 } | |
928 else { | |
929 if (is_playlist_name(decoded)) { | |
930 i = playlist_load_ins(playlist, decoded, pos); | |
931 } | |
932 else { | |
933 success = playlist_ins(playlist, decoded, pos); | |
934 i = 1; | |
935 } | |
936 } | |
937 | |
938 g_free(decoded); | |
939 | |
940 PLAYLIST_LOCK(playlist->mutex); | |
941 node = g_list_nth(playlist->entries, pos); | |
942 PLAYLIST_UNLOCK(playlist->mutex); | |
943 | |
944 entries += i; | |
945 | |
946 if (first) { | |
947 first = FALSE; | |
948 firstpos = pos; | |
949 } | |
950 | |
951 if (pos >= 0) | |
952 pos += i; | |
953 if (!tmp) | |
954 break; | |
955 | |
956 string = tmp + 1; | |
957 } | |
958 | |
959 playlist_recalc_total_time(playlist); | |
960 playlist_generate_shuffle_list(playlist); | |
961 playlistwin_update_list(playlist); | |
962 | |
963 playlist_manager_update(); | |
964 | |
965 return entries; | |
966 } | |
967 | |
968 void | |
969 playlist_set_info_old_abi(const gchar * title, gint length, gint rate, | |
970 gint freq, gint nch) | |
971 { | |
972 Playlist *playlist = playlist_get_active(); | |
973 | |
974 PLAYLIST_LOCK(playlist->mutex); | |
975 | |
976 g_return_if_fail(playlist != NULL); | |
977 | |
978 if (playlist->position) { | |
979 g_free(playlist->position->title); | |
980 playlist->position->title = g_strdup(title); | |
981 playlist->position->length = length; | |
2488
c5075a79f1aa
[svn] make input->set_info overwrite tuple->track_name. it allows input
yaz
parents:
2480
diff
changeset
|
982 |
c5075a79f1aa
[svn] make input->set_info overwrite tuple->track_name. it allows input
yaz
parents:
2480
diff
changeset
|
983 // overwrite tuple->track_name, mainly for streaming. it may incur side effects. --yaz |
2489
e56a55d07935
[svn] - revise r3986 to only override tuple->track_name on lengthless streams
nenolod
parents:
2488
diff
changeset
|
984 if(playlist->position->tuple && length == -1){ |
2488
c5075a79f1aa
[svn] make input->set_info overwrite tuple->track_name. it allows input
yaz
parents:
2480
diff
changeset
|
985 if(playlist->position->tuple->track_name){ |
c5075a79f1aa
[svn] make input->set_info overwrite tuple->track_name. it allows input
yaz
parents:
2480
diff
changeset
|
986 g_free(playlist->position->tuple->track_name); |
c5075a79f1aa
[svn] make input->set_info overwrite tuple->track_name. it allows input
yaz
parents:
2480
diff
changeset
|
987 } |
c5075a79f1aa
[svn] make input->set_info overwrite tuple->track_name. it allows input
yaz
parents:
2480
diff
changeset
|
988 playlist->position->tuple->track_name = g_strdup(title); |
c5075a79f1aa
[svn] make input->set_info overwrite tuple->track_name. it allows input
yaz
parents:
2480
diff
changeset
|
989 } |
2313 | 990 } |
991 | |
992 PLAYLIST_UNLOCK(playlist->mutex); | |
993 | |
994 playlist_recalc_total_time(playlist); | |
995 | |
996 mainwin_set_song_info(rate, freq, nch); | |
2460 | 997 |
998 if ( playlist->position ) | |
999 hook_call( "playlist set info" , playlist->position ); | |
2313 | 1000 } |
1001 | |
1002 void | |
1003 playlist_set_info(Playlist * playlist, const gchar * title, gint length, gint rate, | |
1004 gint freq, gint nch) | |
1005 { | |
1006 PLAYLIST_LOCK(playlist->mutex); | |
1007 | |
1008 g_return_if_fail(playlist != NULL); | |
1009 | |
1010 if (playlist->position) { | |
1011 g_free(playlist->position->title); | |
1012 playlist->position->title = g_strdup(title); | |
1013 playlist->position->length = length; | |
1014 } | |
1015 | |
1016 PLAYLIST_UNLOCK(playlist->mutex); | |
1017 | |
1018 playlist_recalc_total_time(playlist); | |
1019 | |
1020 mainwin_set_song_info(rate, freq, nch); | |
2460 | 1021 |
1022 if ( playlist->position ) | |
1023 hook_call( "playlist set info" , playlist->position ); | |
2313 | 1024 } |
1025 | |
1026 void | |
1027 playlist_check_pos_current(Playlist *playlist) | |
1028 { | |
1029 gint pos, row, bottom; | |
1030 | |
1031 if (!playlist) | |
1032 return; | |
1033 | |
1034 PLAYLIST_LOCK(playlist->mutex); | |
1035 if (!playlist->position || !playlistwin_list) { | |
1036 PLAYLIST_UNLOCK(playlist->mutex); | |
1037 return; | |
1038 } | |
1039 | |
1040 pos = g_list_index(playlist->entries, playlist->position); | |
1041 | |
1042 if (playlistwin_item_visible(pos)) { | |
1043 PLAYLIST_UNLOCK(playlist->mutex); | |
1044 return; | |
1045 } | |
1046 | |
1047 bottom = MAX(0, playlist_get_length_nolock(playlist) - | |
1048 playlistwin_list->pl_num_visible); | |
1049 row = CLAMP(pos - playlistwin_list->pl_num_visible / 2, 0, bottom); | |
1050 PLAYLIST_UNLOCK(playlist->mutex); | |
1051 playlistwin_set_toprow(row); | |
1052 g_cond_signal(cond_scan); | |
1053 } | |
1054 | |
1055 void | |
1056 playlist_next(Playlist *playlist) | |
1057 { | |
1058 GList *plist_pos_list; | |
1059 gboolean restart_playing = FALSE; | |
2480
bb2f191895ce
[svn] - fixed crash when skipping to next song with an empty playlist
marvin
parents:
2460
diff
changeset
|
1060 if (!playlist_get_length(playlist)) |
2313 | 1061 return; |
1062 | |
1063 PLAYLIST_LOCK(playlist->mutex); | |
1064 | |
1065 if ((playlist_position_before_jump != NULL) && playlist->queue == NULL) | |
1066 { | |
1067 playlist->position = playlist_position_before_jump; | |
1068 playlist_position_before_jump = NULL; | |
1069 } | |
1070 | |
1071 plist_pos_list = find_playlist_position_list(playlist); | |
1072 | |
1073 if (!cfg.repeat && !g_list_next(plist_pos_list) && playlist->queue == NULL) { | |
1074 PLAYLIST_UNLOCK(playlist->mutex); | |
1075 return; | |
1076 } | |
1077 | |
1078 if (playback_get_playing()) { | |
1079 /* We need to stop before changing playlist_position */ | |
1080 PLAYLIST_UNLOCK(playlist->mutex); | |
1081 ip_data.stop = TRUE; | |
1082 playback_stop(); | |
1083 ip_data.stop = FALSE; | |
1084 PLAYLIST_LOCK(playlist->mutex); | |
1085 restart_playing = TRUE; | |
1086 } | |
1087 | |
1088 plist_pos_list = find_playlist_position_list(playlist); | |
1089 if (playlist->queue != NULL) | |
1090 play_queued(playlist); | |
1091 else if (g_list_next(plist_pos_list)) | |
1092 playlist->position = g_list_next(plist_pos_list)->data; | |
1093 else if (cfg.repeat) { | |
1094 playlist->position = NULL; | |
1095 playlist_generate_shuffle_list_nolock(playlist); | |
1096 if (cfg.shuffle) | |
1097 playlist->position = playlist->shuffle->data; | |
1098 else | |
1099 playlist->position = playlist->entries->data; | |
1100 } | |
1101 PLAYLIST_UNLOCK(playlist->mutex); | |
1102 playlist_check_pos_current(playlist); | |
1103 | |
1104 if (restart_playing) | |
1105 playback_initiate(); | |
1106 else { | |
1107 mainwin_set_info_text(); | |
1108 playlistwin_update_list(playlist); | |
1109 } | |
1110 } | |
1111 | |
1112 void | |
1113 playlist_prev(Playlist *playlist) | |
1114 { | |
1115 GList *plist_pos_list; | |
1116 gboolean restart_playing = FALSE; | |
1117 | |
2480
bb2f191895ce
[svn] - fixed crash when skipping to next song with an empty playlist
marvin
parents:
2460
diff
changeset
|
1118 if (!playlist_get_length(playlist)) |
2313 | 1119 return; |
1120 | |
1121 PLAYLIST_LOCK(playlist->mutex); | |
1122 | |
1123 if ((playlist_position_before_jump != NULL) && playlist->queue == NULL) | |
1124 { | |
1125 playlist->position = playlist_position_before_jump; | |
1126 playlist_position_before_jump = NULL; | |
1127 } | |
1128 | |
1129 plist_pos_list = find_playlist_position_list(playlist); | |
1130 | |
1131 if (!cfg.repeat && !g_list_previous(plist_pos_list)) { | |
1132 PLAYLIST_UNLOCK(playlist->mutex); | |
1133 return; | |
1134 } | |
1135 | |
1136 if (playback_get_playing()) { | |
1137 /* We need to stop before changing playlist_position */ | |
1138 PLAYLIST_UNLOCK(playlist->mutex); | |
1139 ip_data.stop = TRUE; | |
1140 playback_stop(); | |
1141 ip_data.stop = FALSE; | |
1142 PLAYLIST_LOCK(playlist->mutex); | |
1143 restart_playing = TRUE; | |
1144 } | |
1145 | |
1146 plist_pos_list = find_playlist_position_list(playlist); | |
1147 if (g_list_previous(plist_pos_list)) { | |
1148 playlist->position = g_list_previous(plist_pos_list)->data; | |
1149 } | |
1150 else if (cfg.repeat) { | |
1151 GList *node; | |
1152 playlist->position = NULL; | |
1153 playlist_generate_shuffle_list_nolock(playlist); | |
1154 if (cfg.shuffle) | |
1155 node = g_list_last(playlist->shuffle); | |
1156 else | |
1157 node = g_list_last(playlist->entries); | |
1158 if (node) | |
1159 playlist->position = node->data; | |
1160 } | |
1161 | |
1162 PLAYLIST_UNLOCK(playlist->mutex); | |
1163 | |
1164 playlist_check_pos_current(playlist); | |
1165 | |
1166 if (restart_playing) | |
1167 playback_initiate(); | |
1168 else { | |
1169 mainwin_set_info_text(); | |
1170 playlistwin_update_list(playlist); | |
1171 } | |
1172 } | |
1173 | |
1174 void | |
1175 playlist_queue(Playlist *playlist) | |
1176 { | |
1177 GList *list = playlist_get_selected(playlist); | |
1178 GList *it = list; | |
1179 | |
1180 PLAYLIST_LOCK(playlist->mutex); | |
1181 | |
1182 if ((cfg.shuffle) && (playlist_position_before_jump == NULL)) | |
1183 { | |
1184 /* Shuffling and this is our first manual jump. */ | |
1185 playlist_position_before_jump = playlist->position; | |
1186 } | |
1187 | |
1188 while (it) { | |
1189 GList *next = g_list_next(it); | |
1190 GList *tmp; | |
1191 | |
1192 /* XXX: WTF? --nenolod */ | |
1193 it->data = g_list_nth_data(playlist->entries, GPOINTER_TO_INT(it->data)); | |
1194 if ((tmp = g_list_find(playlist->queue, it->data))) { | |
1195 playlist->queue = g_list_remove_link(playlist->queue, tmp); | |
1196 g_list_free_1(tmp); | |
1197 list = g_list_remove_link(list, it); | |
1198 g_list_free_1(it); | |
1199 } | |
1200 | |
1201 it = next; | |
1202 } | |
1203 | |
1204 playlist->queue = g_list_concat(playlist->queue, list); | |
1205 | |
1206 PLAYLIST_UNLOCK(playlist->mutex); | |
1207 | |
1208 playlist_recalc_total_time(playlist); | |
1209 playlistwin_update_list(playlist); | |
1210 } | |
1211 | |
1212 void | |
1213 playlist_queue_position(Playlist *playlist, guint pos) | |
1214 { | |
1215 GList *tmp; | |
1216 PlaylistEntry *entry; | |
1217 | |
1218 PLAYLIST_LOCK(playlist->mutex); | |
1219 | |
1220 if ((cfg.shuffle) && (playlist_position_before_jump == NULL)) | |
1221 { | |
1222 /* Shuffling and this is our first manual jump. */ | |
1223 playlist_position_before_jump = playlist->position; | |
1224 } | |
1225 | |
1226 entry = g_list_nth_data(playlist->entries, pos); | |
1227 if ((tmp = g_list_find(playlist->queue, entry))) { | |
1228 playlist->queue = g_list_remove_link(playlist->queue, tmp); | |
1229 g_list_free_1(tmp); | |
1230 } | |
1231 else | |
1232 playlist->queue = g_list_append(playlist->queue, entry); | |
1233 PLAYLIST_UNLOCK(playlist->mutex); | |
1234 | |
1235 playlist_recalc_total_time(playlist); | |
1236 playlistwin_update_list(playlist); | |
1237 } | |
1238 | |
1239 gboolean | |
1240 playlist_is_position_queued(Playlist *playlist, guint pos) | |
1241 { | |
1242 PlaylistEntry *entry; | |
1243 GList *tmp; | |
1244 | |
1245 PLAYLIST_LOCK(playlist->mutex); | |
1246 entry = g_list_nth_data(playlist->entries, pos); | |
1247 tmp = g_list_find(playlist->queue, entry); | |
1248 PLAYLIST_UNLOCK(playlist->mutex); | |
1249 | |
1250 return tmp != NULL; | |
1251 } | |
1252 | |
1253 gint | |
1254 playlist_get_queue_position_number(Playlist *playlist, guint pos) | |
1255 { | |
1256 PlaylistEntry *entry; | |
1257 gint tmp; | |
1258 | |
1259 PLAYLIST_LOCK(playlist->mutex); | |
1260 entry = g_list_nth_data(playlist->entries, pos); | |
1261 tmp = g_list_index(playlist->queue, entry); | |
1262 PLAYLIST_UNLOCK(playlist->mutex); | |
1263 | |
1264 return tmp; | |
1265 } | |
1266 | |
1267 gint | |
1268 playlist_get_queue_qposition_number(Playlist *playlist, guint pos) | |
1269 { | |
1270 PlaylistEntry *entry; | |
1271 gint tmp; | |
1272 | |
1273 PLAYLIST_LOCK(playlist->mutex); | |
1274 entry = g_list_nth_data(playlist->queue, pos); | |
1275 tmp = g_list_index(playlist->entries, entry); | |
1276 PLAYLIST_UNLOCK(playlist->mutex); | |
1277 | |
1278 return tmp; | |
1279 } | |
1280 | |
1281 void | |
1282 playlist_clear_queue(Playlist *playlist) | |
1283 { | |
1284 PLAYLIST_LOCK(playlist->mutex); | |
1285 g_list_free(playlist->queue); | |
1286 playlist->queue = NULL; | |
1287 PLAYLIST_UNLOCK(playlist->mutex); | |
1288 | |
1289 playlist_recalc_total_time(playlist); | |
1290 playlistwin_update_list(playlist); | |
1291 } | |
1292 | |
1293 void | |
1294 playlist_queue_remove(Playlist *playlist, guint pos) | |
1295 { | |
1296 void *entry; | |
1297 | |
1298 PLAYLIST_LOCK(playlist->mutex); | |
1299 entry = g_list_nth_data(playlist->entries, pos); | |
1300 playlist->queue = g_list_remove(playlist->queue, entry); | |
1301 PLAYLIST_UNLOCK(playlist->mutex); | |
1302 | |
1303 playlistwin_update_list(playlist); | |
1304 } | |
1305 | |
1306 gint | |
1307 playlist_get_queue_position(Playlist *playlist, PlaylistEntry * entry) | |
1308 { | |
1309 return g_list_index(playlist->queue, entry); | |
1310 } | |
1311 | |
1312 void | |
1313 playlist_set_position(Playlist *playlist, guint pos) | |
1314 { | |
1315 GList *node; | |
1316 gboolean restart_playing = FALSE; | |
1317 | |
1318 if (!playlist) | |
1319 return; | |
1320 | |
1321 PLAYLIST_LOCK(playlist->mutex); | |
1322 | |
1323 node = g_list_nth(playlist->entries, pos); | |
1324 if (!node) { | |
1325 PLAYLIST_UNLOCK(playlist->mutex); | |
1326 return; | |
1327 } | |
1328 | |
1329 if (playback_get_playing()) { | |
1330 /* We need to stop before changing playlist_position */ | |
1331 PLAYLIST_UNLOCK(playlist->mutex); | |
1332 ip_data.stop = TRUE; | |
1333 playback_stop(); | |
1334 ip_data.stop = FALSE; | |
1335 PLAYLIST_LOCK(playlist->mutex); | |
1336 restart_playing = TRUE; | |
1337 } | |
1338 | |
1339 if ((cfg.shuffle) && (playlist_position_before_jump == NULL)) | |
1340 { | |
1341 /* Shuffling and this is our first manual jump. */ | |
1342 playlist_position_before_jump = playlist->position; | |
1343 } | |
1344 | |
1345 playlist->position = node->data; | |
1346 PLAYLIST_UNLOCK(playlist->mutex); | |
1347 playlist_check_pos_current(playlist); | |
1348 | |
1349 if (restart_playing) | |
1350 playback_initiate(); | |
1351 else { | |
1352 mainwin_set_info_text(); | |
1353 playlistwin_update_list(playlist); | |
1354 } | |
1355 } | |
1356 | |
1357 void | |
1358 playlist_eof_reached(Playlist *playlist) | |
1359 { | |
1360 GList *plist_pos_list; | |
1361 | |
1362 if ((cfg.no_playlist_advance && !cfg.repeat) || cfg.stopaftersong) | |
1363 ip_data.stop = TRUE; | |
1364 playback_stop(); | |
1365 if ((cfg.no_playlist_advance && !cfg.repeat) || cfg.stopaftersong) | |
1366 ip_data.stop = FALSE; | |
1367 | |
2408
b380e84148bb
[svn] - rename some hooks so that they are more logical
nenolod
parents:
2407
diff
changeset
|
1368 hook_call("playback end", playlist->position); |
2407
1dc1d36d0347
[svn] - add hooks: playback begin, playback end, playlist reached end
nenolod
parents:
2380
diff
changeset
|
1369 |
2313 | 1370 PLAYLIST_LOCK(playlist->mutex); |
1371 | |
1372 if ((playlist_position_before_jump != NULL) && playlist->queue == NULL) | |
1373 { | |
1374 playlist->position = playlist_position_before_jump; | |
1375 playlist_position_before_jump = NULL; | |
1376 } | |
1377 | |
1378 plist_pos_list = find_playlist_position_list(playlist); | |
1379 | |
1380 if (cfg.no_playlist_advance) { | |
1381 PLAYLIST_UNLOCK(playlist->mutex); | |
1382 mainwin_clear_song_info(); | |
1383 if (cfg.repeat) | |
1384 playback_initiate(); | |
1385 return; | |
1386 } | |
1387 | |
1388 if (cfg.stopaftersong) { | |
1389 PLAYLIST_UNLOCK(playlist->mutex); | |
1390 mainwin_clear_song_info(); | |
1391 mainwin_set_stopaftersong(FALSE); | |
1392 return; | |
1393 } | |
1394 | |
1395 if (playlist->queue != NULL) { | |
1396 play_queued(playlist); | |
1397 } | |
1398 else if (!g_list_next(plist_pos_list)) { | |
1399 if (cfg.shuffle) { | |
1400 playlist->position = NULL; | |
1401 playlist_generate_shuffle_list_nolock(playlist); | |
1402 } | |
2380 | 1403 else if (playlist->entries != NULL) |
2313 | 1404 playlist->position = playlist->entries->data; |
1405 | |
1406 if (!cfg.repeat) { | |
1407 PLAYLIST_UNLOCK(playlist->mutex); | |
2408
b380e84148bb
[svn] - rename some hooks so that they are more logical
nenolod
parents:
2407
diff
changeset
|
1408 hook_call("playlist end reached", playlist->position); |
2313 | 1409 mainwin_clear_song_info(); |
1410 mainwin_set_info_text(); | |
1411 return; | |
1412 } | |
1413 } | |
1414 else | |
1415 playlist->position = g_list_next(plist_pos_list)->data; | |
1416 | |
1417 PLAYLIST_UNLOCK(playlist->mutex); | |
1418 | |
1419 playlist_check_pos_current(playlist); | |
1420 playback_initiate(); | |
1421 mainwin_set_info_text(); | |
1422 playlistwin_update_list(playlist); | |
1423 } | |
1424 | |
1425 gint | |
1426 playlist_get_length(Playlist *playlist) | |
1427 { | |
1428 gint retval; | |
1429 | |
1430 PLAYLIST_LOCK(playlist->mutex); | |
1431 retval = playlist_get_length_nolock(playlist); | |
1432 PLAYLIST_UNLOCK(playlist->mutex); | |
1433 | |
1434 return retval; | |
1435 } | |
1436 | |
1437 gint | |
1438 playlist_queue_get_length(Playlist *playlist) | |
1439 { | |
1440 gint length; | |
1441 | |
1442 PLAYLIST_LOCK(playlist->mutex); | |
1443 length = g_list_length(playlist->queue); | |
1444 PLAYLIST_UNLOCK(playlist->mutex); | |
1445 | |
1446 return length; | |
1447 } | |
1448 | |
1449 gint | |
1450 playlist_get_length_nolock(Playlist *playlist) | |
1451 { | |
1452 return g_list_length(playlist->entries); | |
1453 } | |
1454 | |
1455 gchar * | |
1456 playlist_get_info_text(Playlist *playlist) | |
1457 { | |
1458 gchar *text, *title, *numbers, *length; | |
1459 | |
1460 g_return_val_if_fail(playlist != NULL, NULL); | |
1461 | |
1462 PLAYLIST_LOCK(playlist->mutex); | |
1463 if (!playlist->position) { | |
1464 PLAYLIST_UNLOCK(playlist->mutex); | |
1465 return NULL; | |
1466 } | |
1467 | |
1468 /* FIXME: there should not be a need to do additional conversion, | |
1469 * if playlist is properly maintained */ | |
1470 if (playlist->position->title) { | |
1471 title = str_to_utf8(playlist->position->title); | |
1472 } | |
1473 else { | |
1474 gchar *basename = g_path_get_basename(playlist->position->filename); | |
1475 title = filename_to_utf8(basename); | |
1476 g_free(basename); | |
1477 } | |
1478 | |
1479 /* | |
1480 * If the user don't want numbers in the playlist, don't | |
1481 * display them in other parts of XMMS | |
1482 */ | |
1483 | |
1484 if (cfg.show_numbers_in_pl) | |
1485 numbers = g_strdup_printf("%d. ", playlist_get_position_nolock(playlist) + 1); | |
1486 else | |
1487 numbers = g_strdup(""); | |
1488 | |
1489 if (playlist->position->length != -1) | |
1490 length = g_strdup_printf(" (%d:%-2.2d)", | |
1491 playlist->position->length / 60000, | |
1492 (playlist->position->length / 1000) % 60); | |
1493 else | |
1494 length = g_strdup(""); | |
1495 | |
1496 PLAYLIST_UNLOCK(playlist->mutex); | |
1497 | |
1498 text = convert_title_text(g_strconcat(numbers, title, length, NULL)); | |
1499 | |
1500 g_free(numbers); | |
1501 g_free(title); | |
1502 g_free(length); | |
1503 | |
1504 return text; | |
1505 } | |
1506 | |
1507 gint | |
1508 playlist_get_current_length(Playlist * playlist) | |
1509 { | |
1510 gint len = 0; | |
1511 | |
1512 if (!playlist) | |
1513 return 0; | |
1514 | |
1515 PLAYLIST_LOCK(playlist->mutex); | |
1516 if (playlist->position) | |
1517 len = playlist->position->length; | |
1518 PLAYLIST_UNLOCK(playlist->mutex); | |
1519 | |
1520 return len; | |
1521 } | |
1522 | |
1523 gboolean | |
1524 playlist_save(Playlist * playlist, const gchar * filename) | |
1525 { | |
1526 PlaylistContainer *plc = NULL; | |
1527 gchar *ext; | |
1528 | |
1529 g_return_val_if_fail(playlist != NULL, FALSE); | |
1530 g_return_val_if_fail(filename != NULL, FALSE); | |
1531 | |
1532 ext = strrchr(filename, '.') + 1; | |
1533 | |
1534 playlist_set_current_name(playlist, filename); | |
1535 | |
1536 if ((plc = playlist_container_find(ext)) == NULL) | |
1537 return FALSE; | |
1538 | |
1539 if (plc->plc_write == NULL) | |
1540 return FALSE; | |
1541 | |
1542 plc->plc_write(filename, 0); | |
1543 | |
1544 return TRUE; | |
1545 } | |
1546 | |
1547 gboolean | |
1548 playlist_load(Playlist * playlist, const gchar * filename) | |
1549 { | |
1550 gboolean ret = FALSE; | |
1551 g_return_val_if_fail(playlist != NULL, FALSE); | |
1552 | |
1553 playlist->loading_playlist = TRUE; | |
1554 ret = playlist_load_ins(playlist, filename, -1); | |
1555 playlist->loading_playlist = FALSE; | |
1556 | |
1557 return ret; | |
1558 } | |
1559 | |
1560 void | |
1561 playlist_load_ins_file(Playlist *playlist, | |
1562 const gchar * filename_p, | |
1563 const gchar * playlist_name, gint pos, | |
1564 const gchar * title, gint len) | |
1565 { | |
1566 gchar *filename; | |
1567 gchar *tmp, *path; | |
1568 InputPlugin *dec; /* for decoder cache */ | |
1569 | |
1570 g_return_if_fail(filename_p != NULL); | |
1571 g_return_if_fail(playlist != NULL); | |
1572 g_return_if_fail(playlist_name != NULL); | |
1573 | |
1574 filename = g_strchug(g_strdup(filename_p)); | |
1575 | |
1576 if(cfg.convert_slash) | |
1577 while ((tmp = strchr(filename, '\\')) != NULL) | |
1578 *tmp = '/'; | |
1579 | |
1580 if (filename[0] != '/' && !strstr(filename, "://")) { | |
1581 path = g_strdup(playlist_name); | |
1582 if ((tmp = strrchr(path, '/'))) | |
1583 *tmp = '\0'; | |
1584 else { | |
1585 if (playlist->loading_playlist != TRUE || cfg.playlist_detect == FALSE) | |
1586 dec = input_check_file(filename, FALSE); | |
1587 else | |
1588 dec = NULL; | |
1589 | |
1590 __playlist_ins_with_info(playlist, filename, pos, title, len, dec); | |
1591 return; | |
1592 } | |
1593 tmp = g_build_filename(path, filename, NULL); | |
1594 | |
1595 if (playlist->loading_playlist != TRUE && cfg.playlist_detect != TRUE) | |
1596 dec = input_check_file(tmp, FALSE); | |
1597 else | |
1598 dec = NULL; | |
1599 | |
1600 __playlist_ins_with_info(playlist, tmp, pos, title, len, dec); | |
1601 g_free(tmp); | |
1602 g_free(path); | |
1603 } | |
1604 else | |
1605 { | |
1606 if (playlist->loading_playlist != TRUE && cfg.playlist_detect != TRUE) | |
1607 dec = input_check_file(filename, FALSE); | |
1608 else | |
1609 dec = NULL; | |
1610 | |
1611 __playlist_ins_with_info(playlist, filename, pos, title, len, dec); | |
1612 } | |
1613 | |
1614 g_free(filename); | |
1615 } | |
1616 | |
1617 void | |
1618 playlist_load_ins_file_tuple(Playlist * playlist, | |
1619 const gchar * filename_p, | |
1620 const gchar * playlist_name, | |
1621 gint pos, | |
1622 TitleInput *tuple) | |
1623 { | |
1624 gchar *filename; | |
1625 gchar *tmp, *path; | |
1626 InputPlugin *dec; /* for decoder cache */ | |
1627 | |
1628 g_return_if_fail(filename_p != NULL); | |
1629 g_return_if_fail(playlist_name != NULL); | |
1630 g_return_if_fail(playlist != NULL); | |
1631 | |
1632 filename = g_strchug(g_strdup(filename_p)); | |
1633 | |
1634 while ((tmp = strchr(filename, '\\')) != NULL) | |
1635 *tmp = '/'; | |
1636 | |
1637 if (filename[0] != '/' && !strstr(filename, "://")) { | |
1638 path = g_strdup(playlist_name); | |
1639 if ((tmp = strrchr(path, '/'))) | |
1640 *tmp = '\0'; | |
1641 else { | |
1642 if (playlist->loading_playlist != TRUE || cfg.playlist_detect == FALSE) | |
1643 dec = input_check_file(filename, FALSE); | |
1644 else | |
1645 dec = NULL; | |
1646 | |
1647 __playlist_ins_with_info_tuple(playlist, filename, pos, tuple, dec); | |
1648 return; | |
1649 } | |
1650 tmp = g_build_filename(path, filename, NULL); | |
1651 | |
1652 if (playlist->loading_playlist != TRUE && cfg.playlist_detect != TRUE) | |
1653 dec = input_check_file(tmp, FALSE); | |
1654 else | |
1655 dec = NULL; | |
1656 | |
1657 __playlist_ins_with_info_tuple(playlist, tmp, pos, tuple, dec); | |
1658 g_free(tmp); | |
1659 g_free(path); | |
1660 } | |
1661 else | |
1662 { | |
1663 if (playlist->loading_playlist != TRUE && cfg.playlist_detect != TRUE) | |
1664 dec = input_check_file(filename, FALSE); | |
1665 else | |
1666 dec = NULL; | |
1667 | |
1668 __playlist_ins_with_info_tuple(playlist, filename, pos, tuple, dec); | |
1669 } | |
1670 | |
1671 g_free(filename); | |
1672 } | |
1673 | |
1674 static guint | |
1675 playlist_load_ins(Playlist * playlist, const gchar * filename, gint pos) | |
1676 { | |
1677 PlaylistContainer *plc; | |
1678 gchar *ext; | |
1679 | |
1680 g_return_val_if_fail(playlist != NULL, 0); | |
1681 g_return_val_if_fail(filename != NULL, 0); | |
1682 | |
1683 ext = strrchr(filename, '.') + 1; | |
1684 plc = playlist_container_find(ext); | |
1685 | |
1686 g_return_val_if_fail(plc != NULL, 0); | |
1687 g_return_val_if_fail(plc->plc_read != NULL, 0); | |
1688 | |
1689 plc->plc_read(filename, pos); | |
1690 | |
1691 playlist_generate_shuffle_list(playlist); | |
1692 playlistwin_update_list(playlist); | |
1693 | |
1694 return 1; | |
1695 } | |
1696 | |
1697 GList * | |
1698 get_playlist_nth(Playlist *playlist, guint nth) | |
1699 { | |
1700 g_warning("deprecated function get_playlist_nth() was called"); | |
1701 REQUIRE_LOCK(playlist->mutex); | |
1702 return g_list_nth(playlist->entries, nth); | |
1703 } | |
1704 | |
1705 gint | |
1706 playlist_get_position_nolock(Playlist *playlist) | |
1707 { | |
1708 if (playlist && playlist->position) | |
1709 return g_list_index(playlist->entries, playlist->position); | |
1710 return 0; | |
1711 } | |
1712 | |
1713 gint | |
1714 playlist_get_position(Playlist *playlist) | |
1715 { | |
1716 gint pos; | |
1717 | |
1718 PLAYLIST_LOCK(playlist->mutex); | |
1719 pos = playlist_get_position_nolock(playlist); | |
1720 PLAYLIST_UNLOCK(playlist->mutex); | |
1721 | |
1722 return pos; | |
1723 } | |
1724 | |
1725 gchar * | |
1726 playlist_get_filename(Playlist *playlist, guint pos) | |
1727 { | |
1728 gchar *filename; | |
1729 PlaylistEntry *entry; | |
1730 GList *node; | |
1731 | |
1732 if (!playlist) | |
1733 return NULL; | |
1734 | |
1735 PLAYLIST_LOCK(playlist->mutex); | |
1736 node = g_list_nth(playlist->entries, pos); | |
1737 if (!node) { | |
1738 PLAYLIST_UNLOCK(playlist->mutex); | |
1739 return NULL; | |
1740 } | |
1741 entry = node->data; | |
1742 | |
1743 filename = g_strdup(entry->filename); | |
1744 PLAYLIST_UNLOCK(playlist->mutex); | |
1745 | |
1746 return filename; | |
1747 } | |
1748 | |
1749 gchar * | |
1750 playlist_get_songtitle(Playlist *playlist, guint pos) | |
1751 { | |
1752 gchar *title = NULL; | |
1753 PlaylistEntry *entry; | |
1754 GList *node; | |
1755 | |
1756 if (!playlist) | |
1757 return NULL; | |
1758 | |
1759 PLAYLIST_LOCK(playlist->mutex); | |
1760 | |
1761 if (!(node = g_list_nth(playlist->entries, pos))) { | |
1762 PLAYLIST_UNLOCK(playlist->mutex); | |
1763 return NULL; | |
1764 } | |
1765 | |
1766 entry = node->data; | |
1767 | |
1768 /* FIXME: simplify this logic */ | |
1769 if ((entry->title == NULL && entry->length == -1) || | |
1770 (entry->tuple && entry->tuple->mtime != 0 && (entry->tuple->mtime == -1 || entry->tuple->mtime != playlist_get_mtime(entry->filename)))) | |
1771 { | |
1772 if (playlist_entry_get_info(entry)) | |
1773 title = entry->title; | |
1774 } | |
1775 else { | |
1776 title = entry->title; | |
1777 } | |
1778 | |
1779 PLAYLIST_UNLOCK(playlist->mutex); | |
1780 | |
1781 if (!title) { | |
1782 title = g_path_get_basename(entry->filename); | |
1783 return str_replace(title, filename_to_utf8(title)); | |
1784 } | |
1785 | |
1786 return str_to_utf8(title); | |
1787 } | |
1788 | |
1789 TitleInput * | |
1790 playlist_get_tuple(Playlist *playlist, guint pos) | |
1791 { | |
1792 PlaylistEntry *entry; | |
1793 TitleInput *tuple = NULL; | |
1794 GList *node; | |
1795 | |
1796 if (!playlist) | |
1797 return NULL; | |
1798 | |
1799 PLAYLIST_LOCK(playlist->mutex); | |
1800 | |
1801 if (!(node = g_list_nth(playlist->entries, pos))) { | |
1802 PLAYLIST_UNLOCK(playlist->mutex); | |
1803 return NULL; | |
1804 } | |
1805 | |
1806 entry = (PlaylistEntry *) node->data; | |
1807 | |
1808 tuple = entry->tuple; | |
1809 | |
1810 // if no tuple or tuple with old mtime, get new one. | |
1811 if (tuple == NULL || | |
1812 (entry->tuple && entry->tuple->mtime != 0 && (entry->tuple->mtime == -1 || entry->tuple->mtime != playlist_get_mtime(entry->filename)))) | |
1813 { | |
1814 playlist_entry_get_info(entry); | |
1815 tuple = entry->tuple; | |
1816 } | |
1817 | |
1818 PLAYLIST_UNLOCK(playlist->mutex); | |
1819 | |
1820 return tuple; | |
1821 } | |
1822 | |
1823 gint | |
1824 playlist_get_songtime(Playlist *playlist, guint pos) | |
1825 { | |
1826 gint song_time = -1; | |
1827 PlaylistEntry *entry; | |
1828 GList *node; | |
1829 | |
1830 if (!playlist) | |
1831 return -1; | |
1832 | |
1833 PLAYLIST_LOCK(playlist->mutex); | |
1834 | |
1835 if (!(node = g_list_nth(playlist->entries, pos))) { | |
1836 PLAYLIST_UNLOCK(playlist->mutex); | |
1837 return -1; | |
1838 } | |
1839 | |
1840 entry = node->data; | |
1841 if (entry->tuple == NULL || | |
1842 (entry->tuple->mtime != 0 && (entry->tuple->mtime == -1 || entry->tuple->mtime != playlist_get_mtime(entry->filename)))) { | |
1843 | |
1844 if (playlist_entry_get_info(entry)) | |
1845 song_time = entry->length; | |
1846 | |
1847 PLAYLIST_UNLOCK(playlist->mutex); | |
1848 } | |
1849 else { | |
1850 song_time = entry->length; | |
1851 PLAYLIST_UNLOCK(playlist->mutex); | |
1852 } | |
1853 | |
1854 return song_time; | |
1855 } | |
1856 | |
1857 static gint | |
1858 playlist_compare_track(PlaylistEntry * a, | |
1859 PlaylistEntry * b) | |
1860 { | |
1861 g_return_val_if_fail(a != NULL, 0); | |
1862 g_return_val_if_fail(b != NULL, 0); | |
1863 | |
1864 g_return_val_if_fail(a->tuple != NULL, 0); | |
1865 g_return_val_if_fail(b->tuple != NULL, 0); | |
1866 | |
1867 return (a->tuple->track_number - b->tuple->track_number); | |
1868 } | |
1869 | |
1870 static gint | |
1871 playlist_compare_playlist(PlaylistEntry * a, | |
1872 PlaylistEntry * b) | |
1873 { | |
1874 const gchar *a_title = NULL, *b_title = NULL; | |
1875 | |
1876 g_return_val_if_fail(a != NULL, 0); | |
1877 g_return_val_if_fail(b != NULL, 0); | |
1878 | |
1879 if (a->title != NULL) | |
1880 a_title = a->title; | |
1881 else { | |
1882 if (strrchr(a->filename, '/')) | |
1883 a_title = strrchr(a->filename, '/') + 1; | |
1884 else | |
1885 a_title = a->filename; | |
1886 } | |
1887 | |
1888 if (b->title != NULL) | |
1889 b_title = b->title; | |
1890 else { | |
1891 if (strrchr(a->filename, '/')) | |
1892 b_title = strrchr(b->filename, '/') + 1; | |
1893 else | |
1894 b_title = b->filename; | |
1895 } | |
1896 | |
1897 return strcasecmp(a_title, b_title); | |
1898 } | |
1899 | |
1900 static gint | |
1901 playlist_compare_title(PlaylistEntry * a, | |
1902 PlaylistEntry * b) | |
1903 { | |
1904 const gchar *a_title = NULL, *b_title = NULL; | |
1905 | |
1906 g_return_val_if_fail(a != NULL, 0); | |
1907 g_return_val_if_fail(b != NULL, 0); | |
1908 | |
1909 if (a->tuple != NULL && a->tuple->track_name != NULL) | |
1910 a_title = a->tuple->track_name; | |
1911 if (b->tuple != NULL && b->tuple->track_name != NULL) | |
1912 b_title = b->tuple->track_name; | |
1913 | |
1914 if (a_title != NULL && b_title != NULL) | |
1915 return strcasecmp(a_title, b_title); | |
1916 | |
1917 if (a->title != NULL) | |
1918 a_title = a->title; | |
1919 else { | |
1920 if (strrchr(a->filename, '/')) | |
1921 a_title = strrchr(a->filename, '/') + 1; | |
1922 else | |
1923 a_title = a->filename; | |
1924 } | |
1925 | |
1926 if (b->title != NULL) | |
1927 b_title = b->title; | |
1928 else { | |
1929 if (strrchr(a->filename, '/')) | |
1930 b_title = strrchr(b->filename, '/') + 1; | |
1931 else | |
1932 b_title = b->filename; | |
1933 } | |
1934 | |
1935 return strcasecmp(a_title, b_title); | |
1936 } | |
1937 | |
1938 static gint | |
1939 playlist_compare_artist(PlaylistEntry * a, | |
1940 PlaylistEntry * b) | |
1941 { | |
1942 const gchar *a_artist = NULL, *b_artist = NULL; | |
1943 | |
1944 g_return_val_if_fail(a != NULL, 0); | |
1945 g_return_val_if_fail(b != NULL, 0); | |
1946 | |
1947 if (a->tuple != NULL) | |
1948 playlist_entry_get_info(a); | |
1949 | |
1950 if (b->tuple != NULL) | |
1951 playlist_entry_get_info(b); | |
1952 | |
1953 if (a->tuple != NULL && a->tuple->performer != NULL) | |
1954 a_artist = a->tuple->performer; | |
1955 if (b->tuple != NULL && b->tuple->performer != NULL) | |
1956 b_artist = b->tuple->performer; | |
1957 | |
1958 if (a_artist != NULL && b_artist != NULL) | |
1959 return strcasecmp(a_artist, b_artist); | |
1960 | |
1961 return 0; | |
1962 } | |
1963 | |
1964 static gint | |
1965 playlist_compare_filename(PlaylistEntry * a, | |
1966 PlaylistEntry * b) | |
1967 { | |
1968 gchar *a_filename, *b_filename; | |
1969 | |
1970 g_return_val_if_fail(a != NULL, 0); | |
1971 g_return_val_if_fail(b != NULL, 0); | |
1972 | |
1973 if (strrchr(a->filename, '/')) | |
1974 a_filename = strrchr(a->filename, '/') + 1; | |
1975 else | |
1976 a_filename = a->filename; | |
1977 | |
1978 if (strrchr(b->filename, '/')) | |
1979 b_filename = strrchr(b->filename, '/') + 1; | |
1980 else | |
1981 b_filename = b->filename; | |
1982 | |
1983 | |
1984 return strcasecmp(a_filename, b_filename); | |
1985 } | |
1986 | |
1987 static gint | |
1988 path_compare(const gchar * a, const gchar * b) | |
1989 { | |
1990 gchar *posa, *posb; | |
1991 gint len, ret; | |
1992 | |
1993 posa = strrchr(a, '/'); | |
1994 posb = strrchr(b, '/'); | |
1995 | |
1996 /* | |
1997 * Sort directories before files | |
1998 */ | |
1999 if (posa && posb && (posa - a != posb - b)) { | |
2000 if (posa - a > posb - b) { | |
2001 len = posb - b; | |
2002 ret = -1; | |
2003 } | |
2004 else { | |
2005 len = posa - a; | |
2006 ret = 1; | |
2007 } | |
2008 if (!strncasecmp(a, b, len)) | |
2009 return ret; | |
2010 } | |
2011 return strcasecmp(a, b); | |
2012 } | |
2013 | |
2014 static gint | |
2015 playlist_compare_path(PlaylistEntry * a, | |
2016 PlaylistEntry * b) | |
2017 { | |
2018 return path_compare(a->filename, b->filename); | |
2019 } | |
2020 | |
2021 | |
2022 static time_t | |
2023 playlist_get_mtime(const gchar *filename) | |
2024 { | |
2025 struct stat buf; | |
2026 gint rv; | |
2027 | |
2028 rv = stat(filename, &buf); | |
2029 | |
2030 if (rv == 0) { | |
2031 return buf.st_mtime; | |
2032 } else { | |
2033 return 0; //error | |
2034 } | |
2035 } | |
2036 | |
2037 | |
2038 static gint | |
2039 playlist_compare_date(PlaylistEntry * a, | |
2040 PlaylistEntry * b) | |
2041 { | |
2042 struct stat buf; | |
2043 time_t modtime; | |
2044 | |
2045 gint rv; | |
2046 | |
2047 | |
2048 rv = stat(a->filename, &buf); | |
2049 | |
2050 if (rv == 0) { | |
2051 modtime = buf.st_mtime; | |
2052 rv = stat(b->filename, &buf); | |
2053 | |
2054 if (stat(b->filename, &buf) == 0) { | |
2055 if (buf.st_mtime == modtime) | |
2056 return 0; | |
2057 else | |
2058 return (buf.st_mtime - modtime) > 0 ? -1 : 1; | |
2059 } | |
2060 else | |
2061 return -1; | |
2062 } | |
2063 else if (!lstat(b->filename, &buf)) | |
2064 return 1; | |
2065 else | |
2066 return playlist_compare_filename(a, b); | |
2067 } | |
2068 | |
2069 | |
2070 void | |
2071 playlist_sort(Playlist *playlist, PlaylistSortType type) | |
2072 { | |
2073 playlist_remove_dead_files(playlist); | |
2074 PLAYLIST_LOCK(playlist->mutex); | |
2075 playlist->entries = | |
2076 g_list_sort(playlist->entries, | |
2077 (GCompareFunc) playlist_compare_func_table[type]); | |
2078 PLAYLIST_UNLOCK(playlist->mutex); | |
2079 } | |
2080 | |
2081 static GList * | |
2082 playlist_sort_selected_generic(GList * list, GCompareFunc cmpfunc) | |
2083 { | |
2084 GList *list1, *list2; | |
2085 GList *tmp_list = NULL; | |
2086 GList *index_list = NULL; | |
2087 | |
2088 /* | |
2089 * We take all the selected entries out of the playlist, | |
2090 * sorts them, and then put them back in again. | |
2091 */ | |
2092 | |
2093 list1 = g_list_last(list); | |
2094 | |
2095 while (list1) { | |
2096 list2 = g_list_previous(list1); | |
2097 if (PLAYLIST_ENTRY(list1->data)->selected) { | |
2098 gpointer idx; | |
2099 idx = GINT_TO_POINTER(g_list_position(list, list1)); | |
2100 index_list = g_list_prepend(index_list, idx); | |
2101 list = g_list_remove_link(list, list1); | |
2102 tmp_list = g_list_concat(list1, tmp_list); | |
2103 } | |
2104 list1 = list2; | |
2105 } | |
2106 | |
2107 tmp_list = g_list_sort(tmp_list, cmpfunc); | |
2108 list1 = tmp_list; | |
2109 list2 = index_list; | |
2110 | |
2111 while (list2) { | |
2112 if (!list1) { | |
2113 g_critical(G_STRLOC ": Error during list sorting. " | |
2114 "Possibly dropped some playlist-entries."); | |
2115 break; | |
2116 } | |
2117 | |
2118 list = g_list_insert(list, list1->data, GPOINTER_TO_INT(list2->data)); | |
2119 | |
2120 list2 = g_list_next(list2); | |
2121 list1 = g_list_next(list1); | |
2122 } | |
2123 | |
2124 g_list_free(index_list); | |
2125 g_list_free(tmp_list); | |
2126 | |
2127 return list; | |
2128 } | |
2129 | |
2130 void | |
2131 playlist_sort_selected(Playlist *playlist, PlaylistSortType type) | |
2132 { | |
2133 PLAYLIST_LOCK(playlist->mutex); | |
2134 playlist->entries = playlist_sort_selected_generic(playlist->entries, (GCompareFunc) | |
2135 playlist_compare_func_table | |
2136 [type]); | |
2137 PLAYLIST_UNLOCK(playlist->mutex); | |
2138 } | |
2139 | |
2140 void | |
2141 playlist_reverse(Playlist *playlist) | |
2142 { | |
2143 PLAYLIST_LOCK(playlist->mutex); | |
2144 playlist->entries = g_list_reverse(playlist->entries); | |
2145 PLAYLIST_UNLOCK(playlist->mutex); | |
2146 } | |
2147 | |
2148 static GList * | |
2149 playlist_shuffle_list(Playlist *playlist, GList * list) | |
2150 { | |
2151 /* | |
2152 * Note that this doesn't make a copy of the original list. | |
2153 * The pointer to the original list is not valid after this | |
2154 * fuction is run. | |
2155 */ | |
2156 gint len = g_list_length(list); | |
2157 gint i, j; | |
2158 GList *node, **ptrs; | |
2159 | |
2160 if (!playlist) | |
2161 return NULL; | |
2162 | |
2163 REQUIRE_LOCK(playlist->mutex); | |
2164 | |
2165 if (!len) | |
2166 return NULL; | |
2167 | |
2168 ptrs = g_new(GList *, len); | |
2169 | |
2170 for (node = list, i = 0; i < len; node = g_list_next(node), i++) | |
2171 ptrs[i] = node; | |
2172 | |
2173 j = g_random_int_range(0, len); | |
2174 list = ptrs[j]; | |
2175 ptrs[j]->next = NULL; | |
2176 ptrs[j] = ptrs[0]; | |
2177 | |
2178 for (i = 1; i < len; i++) { | |
2179 j = g_random_int_range(0, len - i); | |
2180 list->prev = ptrs[i + j]; | |
2181 ptrs[i + j]->next = list; | |
2182 list = ptrs[i + j]; | |
2183 ptrs[i + j] = ptrs[i]; | |
2184 } | |
2185 list->prev = NULL; | |
2186 | |
2187 g_free(ptrs); | |
2188 | |
2189 return list; | |
2190 } | |
2191 | |
2192 void | |
2193 playlist_random(Playlist *playlist) | |
2194 { | |
2195 PLAYLIST_LOCK(playlist->mutex); | |
2196 playlist->entries = playlist_shuffle_list(playlist, playlist->entries); | |
2197 PLAYLIST_UNLOCK(playlist->mutex); | |
2198 } | |
2199 | |
2200 GList * | |
2201 playlist_get_selected(Playlist *playlist) | |
2202 { | |
2203 GList *node, *list = NULL; | |
2204 gint i = 0; | |
2205 | |
2206 PLAYLIST_LOCK(playlist->mutex); | |
2207 for (node = playlist->entries; node; node = g_list_next(node), i++) { | |
2208 PlaylistEntry *entry = node->data; | |
2209 if (entry->selected) | |
2210 list = g_list_prepend(list, GINT_TO_POINTER(i)); | |
2211 } | |
2212 PLAYLIST_UNLOCK(playlist->mutex); | |
2213 return g_list_reverse(list); | |
2214 } | |
2215 | |
2216 void | |
2217 playlist_clear_selected(Playlist *playlist) | |
2218 { | |
2219 GList *node = NULL; | |
2220 gint i = 0; | |
2221 | |
2222 PLAYLIST_LOCK(playlist->mutex); | |
2223 for (node = playlist->entries; node; node = g_list_next(node), i++) { | |
2224 PLAYLIST_ENTRY(node->data)->selected = FALSE; | |
2225 } | |
2226 PLAYLIST_UNLOCK(playlist->mutex); | |
2227 playlist_recalc_total_time(playlist); | |
2228 playlist_manager_update(); | |
2229 } | |
2230 | |
2231 gint | |
2232 playlist_get_num_selected(Playlist *playlist) | |
2233 { | |
2234 GList *node; | |
2235 gint num = 0; | |
2236 | |
2237 PLAYLIST_LOCK(playlist->mutex); | |
2238 for (node = playlist->entries; node; node = g_list_next(node)) { | |
2239 PlaylistEntry *entry = node->data; | |
2240 if (entry->selected) | |
2241 num++; | |
2242 } | |
2243 PLAYLIST_UNLOCK(playlist->mutex); | |
2244 return num; | |
2245 } | |
2246 | |
2247 | |
2248 static void | |
2249 playlist_generate_shuffle_list(Playlist *playlist) | |
2250 { | |
2251 PLAYLIST_LOCK(playlist->mutex); | |
2252 playlist_generate_shuffle_list_nolock(playlist); | |
2253 PLAYLIST_UNLOCK(playlist->mutex); | |
2254 } | |
2255 | |
2256 static void | |
2257 playlist_generate_shuffle_list_nolock(Playlist *playlist) | |
2258 { | |
2259 GList *node; | |
2260 gint numsongs; | |
2261 | |
2262 if (!cfg.shuffle || !playlist) | |
2263 return; | |
2264 | |
2265 REQUIRE_LOCK(playlist->mutex); | |
2266 | |
2267 if (playlist->shuffle) { | |
2268 g_list_free(playlist->shuffle); | |
2269 playlist->shuffle = NULL; | |
2270 } | |
2271 | |
2272 playlist->shuffle = playlist_shuffle_list(playlist, g_list_copy(playlist->entries)); | |
2273 numsongs = g_list_length(playlist->shuffle); | |
2274 | |
2275 if (playlist->position) { | |
2276 gint i = g_list_index(playlist->shuffle, playlist->position); | |
2277 node = g_list_nth(playlist->shuffle, i); | |
2278 playlist->shuffle = g_list_remove_link(playlist->shuffle, node); | |
2279 playlist->shuffle = g_list_prepend(playlist->shuffle, node->data); | |
2280 } | |
2281 } | |
2282 | |
2283 void | |
2284 playlist_fileinfo(Playlist *playlist, guint pos) | |
2285 { | |
2286 gchar *path = NULL; | |
2287 GList *node; | |
2288 PlaylistEntry *entry = NULL; | |
2289 TitleInput *tuple = NULL; | |
2290 | |
2291 PLAYLIST_LOCK(playlist->mutex); | |
2292 | |
2293 if ((node = g_list_nth(playlist->entries, pos))) | |
2294 { | |
2295 entry = node->data; | |
2296 tuple = entry->tuple; | |
2297 path = g_strdup(entry->filename); | |
2298 } | |
2299 | |
2300 PLAYLIST_UNLOCK(playlist->mutex); | |
2301 | |
2302 /* No tuple? Try to set this entry up properly. --nenolod */ | |
2303 if (entry->tuple == NULL || entry->tuple->mtime == -1 || | |
2304 entry->tuple->mtime == 0 || entry->tuple->mtime != playlist_get_mtime(entry->filename)) | |
2305 { | |
2306 playlist_entry_get_info(entry); | |
2307 tuple = entry->tuple; | |
2308 } | |
2309 | |
2310 if (tuple != NULL) | |
2311 { | |
2312 if (entry->decoder == NULL) | |
2313 entry->decoder = input_check_file(entry->filename, FALSE); /* try to find a decoder */ | |
2314 | |
2315 if (entry->decoder != NULL && entry->decoder->file_info_box == NULL) | |
2316 fileinfo_show_for_tuple(tuple); | |
2317 else if (entry->decoder != NULL && entry->decoder->file_info_box != NULL) | |
2318 entry->decoder->file_info_box(path); | |
2319 else | |
2320 fileinfo_show_for_path(path); | |
2321 g_free(path); | |
2322 } | |
2323 else if (path != NULL) | |
2324 { | |
2325 if (entry != NULL && entry->decoder != NULL && entry->decoder->file_info_box != NULL) | |
2326 entry->decoder->file_info_box(path); | |
2327 else | |
2328 fileinfo_show_for_path(path); | |
2329 g_free(path); | |
2330 } | |
2331 } | |
2332 | |
2333 void | |
2334 playlist_fileinfo_current(Playlist *playlist) | |
2335 { | |
2336 gchar *path = NULL; | |
2337 TitleInput *tuple = NULL; | |
2338 | |
2339 PLAYLIST_LOCK(playlist->mutex); | |
2340 | |
2341 if (playlist->entries && playlist->position) | |
2342 { | |
2343 path = g_strdup(playlist->position->filename); | |
2344 if (( playlist->position->tuple == NULL ) || ( playlist->position->decoder == NULL )) | |
2345 playlist_entry_get_info(playlist->position); | |
2346 tuple = playlist->position->tuple; | |
2347 } | |
2348 | |
2349 PLAYLIST_UNLOCK(playlist->mutex); | |
2350 | |
2351 if (tuple != NULL) | |
2352 { | |
2353 if (playlist->position->decoder != NULL && playlist->position->decoder->file_info_box == NULL) | |
2354 fileinfo_show_for_tuple(tuple); | |
2355 else if (playlist->position->decoder != NULL && playlist->position->decoder->file_info_box != NULL) | |
2356 playlist->position->decoder->file_info_box(path); | |
2357 else | |
2358 fileinfo_show_for_path(path); | |
2359 g_free(path); | |
2360 } | |
2361 else if (path != NULL) | |
2362 { | |
2363 if (playlist->position != NULL && playlist->position->decoder != NULL && playlist->position->decoder->file_info_box != NULL) | |
2364 playlist->position->decoder->file_info_box(path); | |
2365 else | |
2366 fileinfo_show_for_path(path); | |
2367 g_free(path); | |
2368 } | |
2369 } | |
2370 | |
2371 | |
2372 static gboolean | |
2373 playlist_get_info_is_going(void) | |
2374 { | |
2375 gboolean result; | |
2376 | |
2377 G_LOCK(playlist_get_info_going); | |
2378 result = playlist_get_info_going; | |
2379 G_UNLOCK(playlist_get_info_going); | |
2380 | |
2381 return result; | |
2382 } | |
2383 | |
2384 static gpointer | |
2385 playlist_get_info_func(gpointer arg) | |
2386 { | |
2387 GList *node; | |
2388 gboolean update_playlistwin = FALSE; | |
2389 gboolean update_mainwin = FALSE; | |
2390 | |
2391 while (playlist_get_info_is_going()) { | |
2392 PlaylistEntry *entry; | |
2393 Playlist *playlist = playlist_get_active(); | |
2394 | |
2395 // on_load | |
2396 if (cfg.use_pl_metadata && | |
2397 cfg.get_info_on_load && | |
2398 playlist_get_info_scan_active) { | |
2399 | |
2400 PLAYLIST_LOCK(playlist->mutex); | |
2401 for (node = playlist->entries; node; node = g_list_next(node)) { | |
2402 entry = node->data; | |
2403 | |
2404 if(entry->tuple && (entry->tuple->length > -1)) { | |
2405 update_playlistwin = TRUE; | |
2406 continue; | |
2407 } | |
2408 | |
2409 if (!playlist_entry_get_info(entry)) { | |
2410 if (g_list_index(playlist->entries, entry) == -1) | |
2411 /* Entry disappeared while we looked it up. | |
2412 Restart. */ | |
2413 node = playlist->entries; | |
2414 } | |
2415 else if ((entry->tuple != NULL || entry->title != NULL) && entry->length != -1) { | |
2416 update_playlistwin = TRUE; | |
2417 if (entry == playlist->position) | |
2418 update_mainwin = TRUE; | |
2419 break; | |
2420 } | |
2421 } | |
2422 PLAYLIST_UNLOCK(playlist->mutex); | |
2423 | |
2424 if (!node) { | |
2425 g_mutex_lock(mutex_scan); | |
2426 playlist_get_info_scan_active = FALSE; | |
2427 g_mutex_unlock(mutex_scan); | |
2428 } | |
2429 } // on_load | |
2430 | |
2431 // on_demand | |
2432 else if (!cfg.get_info_on_load && | |
2433 cfg.get_info_on_demand && | |
2434 cfg.playlist_visible && | |
2435 !cfg.playlist_shaded && | |
2436 cfg.use_pl_metadata) { | |
2437 | |
2438 g_mutex_lock(mutex_scan); | |
2439 playlist_get_info_scan_active = FALSE; | |
2440 g_mutex_unlock(mutex_scan); | |
2441 | |
2442 PLAYLIST_LOCK(playlist->mutex); | |
2443 | |
2444 if (!playlist->entries) { | |
2445 PLAYLIST_UNLOCK(playlist->mutex); | |
2446 } | |
2447 else { | |
2448 for (node = g_list_nth(playlist->entries, playlistwin_get_toprow()); | |
2449 node && playlistwin_item_visible(g_list_position(playlist->entries, node)); | |
2450 node = g_list_next(node)) { | |
2451 | |
2452 entry = node->data; | |
2453 | |
2454 if(entry->tuple && (entry->tuple->length > -1)) { | |
2455 update_playlistwin = TRUE; | |
2456 continue; | |
2457 } | |
2458 | |
2459 if (!playlist_entry_get_info(entry)) { | |
2460 if (g_list_index(playlist->entries, entry) == -1) | |
2461 /* Entry disapeared while we | |
2462 looked it up. Restart. */ | |
2463 node = | |
2464 g_list_nth(playlist->entries, | |
2465 playlistwin_get_toprow()); | |
2466 } | |
2467 else if ((entry->tuple != NULL || entry->title != NULL) && entry->length != -1) { | |
2468 update_playlistwin = TRUE; | |
2469 if (entry == playlist->position) | |
2470 update_mainwin = TRUE; | |
2471 // no need for break here since this iteration is very short. | |
2472 } | |
2473 } | |
2474 PLAYLIST_UNLOCK(playlist->mutex); | |
2475 } | |
2476 } // on_demand | |
2477 else if (cfg.get_info_on_demand && | |
2478 (!cfg.playlist_visible || cfg.playlist_shaded | |
2479 || !cfg.use_pl_metadata)) | |
2480 { | |
2481 g_mutex_lock(mutex_scan); | |
2482 playlist_get_info_scan_active = FALSE; | |
2483 g_mutex_unlock(mutex_scan); | |
2484 } | |
2485 else /* not on_demand and not on_load... | |
2486 NOTE: this shouldn't happen anymore, sanity check in bmp_config_load now */ | |
2487 { | |
2488 g_mutex_lock(mutex_scan); | |
2489 playlist_get_info_scan_active = FALSE; | |
2490 g_mutex_unlock(mutex_scan); | |
2491 } | |
2492 | |
2493 if (update_playlistwin) { | |
2494 playlistwin_update_list(playlist); | |
2495 update_playlistwin = FALSE; | |
2496 } | |
2497 | |
2498 if (update_mainwin) { | |
2499 mainwin_set_info_text(); | |
2500 update_mainwin = FALSE; | |
2501 } | |
2502 | |
2503 if (playlist_get_info_scan_active) { | |
2504 continue; | |
2505 } | |
2506 | |
2507 g_mutex_lock(mutex_scan); | |
2508 g_cond_wait(cond_scan, mutex_scan); | |
2509 g_mutex_unlock(mutex_scan); | |
2510 | |
2511 } // while | |
2512 | |
2513 g_thread_exit(NULL); | |
2514 return NULL; | |
2515 } | |
2516 | |
2517 void | |
2518 playlist_start_get_info_thread(void) | |
2519 { | |
2520 G_LOCK(playlist_get_info_going); | |
2521 playlist_get_info_going = TRUE; | |
2522 G_UNLOCK(playlist_get_info_going); | |
2523 | |
2524 playlist_get_info_thread = g_thread_create(playlist_get_info_func, | |
2525 NULL, TRUE, NULL); | |
2526 } | |
2527 | |
2528 void | |
2529 playlist_stop_get_info_thread(void) | |
2530 { | |
2531 G_LOCK(playlist_get_info_going); | |
2532 playlist_get_info_going = FALSE; | |
2533 G_UNLOCK(playlist_get_info_going); | |
2534 | |
2535 g_cond_broadcast(cond_scan); | |
2536 g_thread_join(playlist_get_info_thread); | |
2537 } | |
2538 | |
2539 void | |
2540 playlist_start_get_info_scan(void) | |
2541 { | |
2542 g_mutex_lock(mutex_scan); | |
2543 playlist_get_info_scan_active = TRUE; | |
2544 g_mutex_unlock(mutex_scan); | |
2545 g_cond_signal(cond_scan); | |
2546 } | |
2547 | |
2548 void | |
2549 playlist_remove_dead_files(Playlist *playlist) | |
2550 { | |
2551 GList *node, *next_node; | |
2552 | |
2553 PLAYLIST_LOCK(playlist->mutex); | |
2554 | |
2555 for (node = playlist->entries; node; node = next_node) { | |
2556 PlaylistEntry *entry = PLAYLIST_ENTRY(node->data); | |
2557 next_node = g_list_next(node); | |
2558 | |
2559 if (!entry || !entry->filename) { | |
2560 g_message(G_STRLOC ": Playlist entry is invalid!"); | |
2561 continue; | |
2562 } | |
2563 | |
2564 /* FIXME: What about 'file:///'? */ | |
2565 /* Don't kill URLs */ | |
2566 if (strstr(entry->filename, "://")) | |
2567 continue; | |
2568 | |
2569 /* FIXME: Should test for readability */ | |
2570 if (vfs_file_test(entry->filename, G_FILE_TEST_EXISTS)) | |
2571 continue; | |
2572 | |
2573 if (entry == playlist->position) { | |
2574 /* Don't remove the currently playing song */ | |
2575 if (playback_get_playing()) | |
2576 continue; | |
2577 | |
2578 if (next_node) | |
2579 playlist->position = PLAYLIST_ENTRY(next_node->data); | |
2580 else | |
2581 playlist->position = NULL; | |
2582 } | |
2583 | |
2584 playlist_entry_free(entry); | |
2585 playlist->entries = g_list_delete_link(playlist->entries, node); | |
2586 } | |
2587 | |
2588 PLAYLIST_UNLOCK(playlist->mutex); | |
2589 | |
2590 playlist_generate_shuffle_list(playlist); | |
2591 playlistwin_update_list(playlist); | |
2592 playlist_recalc_total_time(playlist); | |
2593 playlist_manager_update(); | |
2594 } | |
2595 | |
2596 | |
2597 static gint | |
2598 playlist_dupscmp_title(PlaylistEntry * a, | |
2599 PlaylistEntry * b) | |
2600 { | |
2601 const gchar *a_title, *b_title; | |
2602 | |
2603 g_return_val_if_fail(a != NULL, 0); | |
2604 g_return_val_if_fail(b != NULL, 0); | |
2605 | |
2606 if (a->title) | |
2607 a_title = a->title; | |
2608 else { | |
2609 if (strrchr(a->filename, '/')) | |
2610 a_title = strrchr(a->filename, '/') + 1; | |
2611 else | |
2612 a_title = a->filename; | |
2613 } | |
2614 | |
2615 if (b->title) | |
2616 b_title = b->title; | |
2617 else { | |
2618 if (strrchr(a->filename, '/')) | |
2619 b_title = strrchr(b->filename, '/') + 1; | |
2620 else | |
2621 b_title = b->filename; | |
2622 } | |
2623 | |
2624 return strcmp(a_title, b_title); | |
2625 } | |
2626 | |
2627 static gint | |
2628 playlist_dupscmp_filename(PlaylistEntry * a, | |
2629 PlaylistEntry * b ) | |
2630 { | |
2631 gchar *a_filename, *b_filename; | |
2632 | |
2633 g_return_val_if_fail(a != NULL, 0); | |
2634 g_return_val_if_fail(b != NULL, 0); | |
2635 | |
2636 if (strrchr(a->filename, '/')) | |
2637 a_filename = strrchr(a->filename, '/') + 1; | |
2638 else | |
2639 a_filename = a->filename; | |
2640 | |
2641 if (strrchr(b->filename, '/')) | |
2642 b_filename = strrchr(b->filename, '/') + 1; | |
2643 else | |
2644 b_filename = b->filename; | |
2645 | |
2646 return strcmp(a_filename, b_filename); | |
2647 } | |
2648 | |
2649 static gint | |
2650 playlist_dupscmp_path(PlaylistEntry * a, | |
2651 PlaylistEntry * b) | |
2652 { | |
2653 /* simply compare the entire filename string */ | |
2654 return strcmp(a->filename, b->filename); | |
2655 } | |
2656 | |
2657 void | |
2658 playlist_remove_duplicates(Playlist *playlist, PlaylistDupsType type) | |
2659 { | |
2660 GList *node, *next_node; | |
2661 GList *node_cmp, *next_node_cmp; | |
2662 gint (*dups_compare_func)(PlaylistEntry * , PlaylistEntry *); | |
2663 | |
2664 switch ( type ) | |
2665 { | |
2666 case PLAYLIST_DUPS_TITLE: | |
2667 dups_compare_func = playlist_dupscmp_title; | |
2668 break; | |
2669 case PLAYLIST_DUPS_PATH: | |
2670 dups_compare_func = playlist_dupscmp_path; | |
2671 break; | |
2672 case PLAYLIST_DUPS_FILENAME: | |
2673 default: | |
2674 dups_compare_func = playlist_dupscmp_filename; | |
2675 break; | |
2676 } | |
2677 | |
2678 PLAYLIST_LOCK(playlist->mutex); | |
2679 | |
2680 for (node = playlist->entries; node; node = next_node) { | |
2681 PlaylistEntry *entry = PLAYLIST_ENTRY(node->data); | |
2682 next_node = g_list_next(node); | |
2683 | |
2684 if (!entry || !entry->filename) { | |
2685 g_message(G_STRLOC ": Playlist entry is invalid!"); | |
2686 continue; | |
2687 } | |
2688 | |
2689 for (node_cmp = next_node; node_cmp; node_cmp = next_node_cmp) { | |
2690 PlaylistEntry *entry_cmp = PLAYLIST_ENTRY(node_cmp->data); | |
2691 next_node_cmp = g_list_next(node_cmp); | |
2692 | |
2693 if (!entry_cmp || !entry_cmp->filename) { | |
2694 g_message(G_STRLOC ": Playlist entry is invalid!"); | |
2695 continue; | |
2696 } | |
2697 | |
2698 /* compare using the chosen dups_compare_func */ | |
2699 if ( !dups_compare_func( entry , entry_cmp ) ) { | |
2700 | |
2701 if (entry_cmp == playlist->position) { | |
2702 /* Don't remove the currently playing song */ | |
2703 if (playback_get_playing()) | |
2704 continue; | |
2705 | |
2706 if (next_node_cmp) | |
2707 playlist->position = PLAYLIST_ENTRY(next_node_cmp->data); | |
2708 else | |
2709 playlist->position = NULL; | |
2710 } | |
2711 | |
2712 /* check if this was the next item of the external | |
2713 loop; if true, replace it with the next of the next*/ | |
2714 if ( node_cmp == next_node ) | |
2715 next_node = g_list_next(next_node); | |
2716 | |
2717 playlist_entry_free(entry_cmp); | |
2718 playlist->entries = g_list_delete_link(playlist->entries, node_cmp); | |
2719 } | |
2720 } | |
2721 } | |
2722 | |
2723 PLAYLIST_UNLOCK(playlist->mutex); | |
2724 | |
2725 playlistwin_update_list(playlist); | |
2726 playlist_recalc_total_time(playlist); | |
2727 | |
2728 playlist_manager_update(); | |
2729 } | |
2730 | |
2731 void | |
2732 playlist_get_total_time(Playlist * playlist, | |
2733 gulong * total_time, | |
2734 gulong * selection_time, | |
2735 gboolean * total_more, | |
2736 gboolean * selection_more) | |
2737 { | |
2738 PLAYLIST_LOCK(playlist->mutex); | |
2739 *total_time = playlist->pl_total_time; | |
2740 *selection_time = playlist->pl_selection_time; | |
2741 *total_more = playlist->pl_total_more; | |
2742 *selection_more = playlist->pl_selection_more; | |
2743 PLAYLIST_UNLOCK(playlist->mutex); | |
2744 } | |
2745 | |
2746 | |
2747 static void | |
2748 playlist_recalc_total_time_nolock(Playlist *playlist) | |
2749 { | |
2750 GList *list; | |
2751 PlaylistEntry *entry; | |
2752 | |
2753 REQUIRE_LOCK(playlist->mutex); | |
2754 | |
2755 playlist->pl_total_time = 0; | |
2756 playlist->pl_selection_time = 0; | |
2757 playlist->pl_total_more = FALSE; | |
2758 playlist->pl_selection_more = FALSE; | |
2759 | |
2760 for (list = playlist->entries; list; list = g_list_next(list)) { | |
2761 entry = list->data; | |
2762 | |
2763 if (entry->length != -1) | |
2764 playlist->pl_total_time += entry->length / 1000; | |
2765 else | |
2766 playlist->pl_total_more = TRUE; | |
2767 | |
2768 if (entry->selected) { | |
2769 if (entry->length != -1) | |
2770 playlist->pl_selection_time += entry->length / 1000; | |
2771 else | |
2772 playlist->pl_selection_more = TRUE; | |
2773 } | |
2774 } | |
2775 } | |
2776 | |
2777 static void | |
2778 playlist_recalc_total_time(Playlist *playlist) | |
2779 { | |
2780 PLAYLIST_LOCK(playlist->mutex); | |
2781 playlist_recalc_total_time_nolock(playlist); | |
2782 PLAYLIST_UNLOCK(playlist->mutex); | |
2783 } | |
2784 | |
2785 gint | |
2786 playlist_select_search( Playlist *playlist , TitleInput *tuple , gint action ) | |
2787 { | |
2788 GList *entry_list = NULL, *found_list = NULL, *sel_list = NULL; | |
2789 gboolean is_first_search = TRUE; | |
2790 gint num_of_entries_found = 0; | |
2791 | |
2792 #if defined(USE_REGEX_ONIGURUMA) | |
2793 /* set encoding for Oniguruma regex to UTF-8 */ | |
2794 reg_set_encoding( REG_POSIX_ENCODING_UTF8 ); | |
2795 onig_set_default_syntax( ONIG_SYNTAX_POSIX_BASIC ); | |
2796 #endif | |
2797 | |
2798 PLAYLIST_LOCK(playlist->mutex); | |
2799 | |
2800 if ( tuple->track_name != NULL ) | |
2801 { | |
2802 /* match by track_name */ | |
2803 const gchar *regex_pattern = tuple->track_name; | |
2804 regex_t regex; | |
2805 #if defined(USE_REGEX_PCRE) | |
2806 if ( regcomp( ®ex , regex_pattern , REG_NOSUB | REG_ICASE | REG_UTF8 ) == 0 ) | |
2807 #else | |
2808 if ( regcomp( ®ex , regex_pattern , REG_NOSUB | REG_ICASE ) == 0 ) | |
2809 #endif | |
2810 { | |
2811 GList *tfound_list = NULL; | |
2812 if ( is_first_search == TRUE ) entry_list = playlist->entries; | |
2813 else entry_list = found_list; /* use found_list */ | |
2814 for ( ; entry_list ; entry_list = g_list_next(entry_list) ) | |
2815 { | |
2816 PlaylistEntry *entry = entry_list->data; | |
2817 if ( ( entry->tuple != NULL ) && ( entry->tuple->track_name != NULL ) && | |
2818 ( regexec( ®ex , entry->tuple->track_name , 0 , NULL , 0 ) == 0 ) ) | |
2819 { | |
2820 tfound_list = g_list_append( tfound_list , entry ); | |
2821 } | |
2822 } | |
2823 g_list_free( found_list ); /* wipe old found_list */ | |
2824 found_list = tfound_list; /* move tfound_list in found_list */ | |
2825 regfree( ®ex ); | |
2826 } | |
2827 is_first_search = FALSE; | |
2828 } | |
2829 | |
2830 if ( tuple->album_name != NULL ) | |
2831 { | |
2832 /* match by album_name */ | |
2833 const gchar *regex_pattern = tuple->album_name; | |
2834 regex_t regex; | |
2835 #if defined(USE_REGEX_PCRE) | |
2836 if ( regcomp( ®ex , regex_pattern , REG_NOSUB | REG_ICASE | REG_UTF8 ) == 0 ) | |
2837 #else | |
2838 if ( regcomp( ®ex , regex_pattern , REG_NOSUB | REG_ICASE ) == 0 ) | |
2839 #endif | |
2840 { | |
2841 GList *tfound_list = NULL; | |
2842 if ( is_first_search == TRUE ) entry_list = playlist->entries; | |
2843 else entry_list = found_list; /* use found_list */ | |
2844 for ( ; entry_list ; entry_list = g_list_next(entry_list) ) | |
2845 { | |
2846 PlaylistEntry *entry = entry_list->data; | |
2847 if ( ( entry->tuple != NULL ) && ( entry->tuple->album_name != NULL ) && | |
2848 ( regexec( ®ex , entry->tuple->album_name , 0 , NULL , 0 ) == 0 ) ) | |
2849 { | |
2850 tfound_list = g_list_append( tfound_list , entry ); | |
2851 } | |
2852 } | |
2853 g_list_free( found_list ); /* wipe old found_list */ | |
2854 found_list = tfound_list; /* move tfound_list in found_list */ | |
2855 regfree( ®ex ); | |
2856 } | |
2857 is_first_search = FALSE; | |
2858 } | |
2859 | |
2860 if ( tuple->performer != NULL ) | |
2861 { | |
2862 /* match by performer */ | |
2863 const gchar *regex_pattern = tuple->performer; | |
2864 regex_t regex; | |
2865 #if defined(USE_REGEX_PCRE) | |
2866 if ( regcomp( ®ex , regex_pattern , REG_NOSUB | REG_ICASE | REG_UTF8 ) == 0 ) | |
2867 #else | |
2868 if ( regcomp( ®ex , regex_pattern , REG_NOSUB | REG_ICASE ) == 0 ) | |
2869 #endif | |
2870 { | |
2871 GList *tfound_list = NULL; | |
2872 if ( is_first_search == TRUE ) entry_list = playlist->entries; | |
2873 else entry_list = found_list; /* use found_list */ | |
2874 for ( ; entry_list ; entry_list = g_list_next(entry_list) ) | |
2875 { | |
2876 PlaylistEntry *entry = entry_list->data; | |
2877 if ( ( entry->tuple != NULL ) && ( entry->tuple->performer != NULL ) && | |
2878 ( regexec( ®ex , entry->tuple->performer , 0 , NULL , 0 ) == 0 ) ) | |
2879 { | |
2880 tfound_list = g_list_append( tfound_list , entry ); | |
2881 } | |
2882 } | |
2883 g_list_free( found_list ); /* wipe old found_list */ | |
2884 found_list = tfound_list; /* move tfound_list in found_list */ | |
2885 regfree( ®ex ); | |
2886 } | |
2887 is_first_search = FALSE; | |
2888 } | |
2889 | |
2890 if ( tuple->file_name != NULL ) | |
2891 { | |
2892 /* match by file_name */ | |
2893 const gchar *regex_pattern = tuple->file_name; | |
2894 regex_t regex; | |
2895 #if defined(USE_REGEX_PCRE) | |
2896 if ( regcomp( ®ex , regex_pattern , REG_NOSUB | REG_ICASE | REG_UTF8 ) == 0 ) | |
2897 #else | |
2898 if ( regcomp( ®ex , regex_pattern , REG_NOSUB | REG_ICASE ) == 0 ) | |
2899 #endif | |
2900 { | |
2901 GList *tfound_list = NULL; | |
2902 if ( is_first_search == TRUE ) entry_list = playlist->entries; | |
2903 else entry_list = found_list; /* use found_list */ | |
2904 for ( ; entry_list ; entry_list = g_list_next(entry_list) ) | |
2905 { | |
2906 PlaylistEntry *entry = entry_list->data; | |
2907 if ( ( entry->tuple != NULL ) && ( entry->tuple->file_name != NULL ) && | |
2908 ( regexec( ®ex , entry->tuple->file_name , 0 , NULL , 0 ) == 0 ) ) | |
2909 { | |
2910 tfound_list = g_list_append( tfound_list , entry ); | |
2911 } | |
2912 } | |
2913 g_list_free( found_list ); /* wipe old found_list */ | |
2914 found_list = tfound_list; /* move tfound_list in found_list */ | |
2915 regfree( ®ex ); | |
2916 } | |
2917 is_first_search = FALSE; | |
2918 } | |
2919 | |
2920 /* NOTE: action = 0 -> default behaviour, select all matching entries */ | |
2921 /* if some entries are still in found_list, those | |
2922 are what the user is searching for; select them */ | |
2923 for ( sel_list = found_list ; sel_list ; sel_list = g_list_next(sel_list) ) | |
2924 { | |
2925 PlaylistEntry *entry = sel_list->data; | |
2926 entry->selected = TRUE; | |
2927 num_of_entries_found++; | |
2928 } | |
2929 | |
2930 g_list_free( found_list ); | |
2931 | |
2932 PLAYLIST_UNLOCK(playlist->mutex); | |
2933 playlist_recalc_total_time(playlist); | |
2934 | |
2935 return num_of_entries_found; | |
2936 } | |
2937 | |
2938 void | |
2939 playlist_select_all(Playlist *playlist, gboolean set) | |
2940 { | |
2941 GList *list; | |
2942 | |
2943 PLAYLIST_LOCK(playlist->mutex); | |
2944 | |
2945 for (list = playlist->entries; list; list = g_list_next(list)) { | |
2946 PlaylistEntry *entry = list->data; | |
2947 entry->selected = set; | |
2948 } | |
2949 | |
2950 PLAYLIST_UNLOCK(playlist->mutex); | |
2951 playlist_recalc_total_time(playlist); | |
2952 } | |
2953 | |
2954 void | |
2955 playlist_select_invert_all(Playlist *playlist) | |
2956 { | |
2957 GList *list; | |
2958 | |
2959 PLAYLIST_LOCK(playlist->mutex); | |
2960 | |
2961 for (list = playlist->entries; list; list = g_list_next(list)) { | |
2962 PlaylistEntry *entry = list->data; | |
2963 entry->selected = !entry->selected; | |
2964 } | |
2965 | |
2966 PLAYLIST_UNLOCK(playlist->mutex); | |
2967 playlist_recalc_total_time(playlist); | |
2968 } | |
2969 | |
2970 gboolean | |
2971 playlist_select_invert(Playlist *playlist, guint pos) | |
2972 { | |
2973 GList *list; | |
2974 gboolean invert_ok = FALSE; | |
2975 | |
2976 PLAYLIST_LOCK(playlist->mutex); | |
2977 | |
2978 if ((list = g_list_nth(playlist->entries, pos))) { | |
2979 PlaylistEntry *entry = list->data; | |
2980 entry->selected = !entry->selected; | |
2981 invert_ok = TRUE; | |
2982 } | |
2983 | |
2984 PLAYLIST_UNLOCK(playlist->mutex); | |
2985 playlist_recalc_total_time(playlist); | |
2986 | |
2987 return invert_ok; | |
2988 } | |
2989 | |
2990 | |
2991 void | |
2992 playlist_select_range(Playlist *playlist, gint min_pos, gint max_pos, gboolean select) | |
2993 { | |
2994 GList *list; | |
2995 gint i; | |
2996 | |
2997 if (min_pos > max_pos) | |
2998 SWAP(min_pos, max_pos); | |
2999 | |
3000 PLAYLIST_LOCK(playlist->mutex); | |
3001 | |
3002 list = g_list_nth(playlist->entries, min_pos); | |
3003 for (i = min_pos; i <= max_pos && list; i++) { | |
3004 PlaylistEntry *entry = list->data; | |
3005 entry->selected = select; | |
3006 list = g_list_next(list); | |
3007 } | |
3008 | |
3009 PLAYLIST_UNLOCK(playlist->mutex); | |
3010 | |
3011 playlist_recalc_total_time(playlist); | |
3012 } | |
3013 | |
3014 gboolean | |
3015 playlist_read_info_selection(Playlist *playlist) | |
3016 { | |
3017 GList *node; | |
3018 gboolean retval = FALSE; | |
3019 | |
3020 PLAYLIST_LOCK(playlist->mutex); | |
3021 | |
3022 for (node = playlist->entries; node; node = g_list_next(node)) { | |
3023 PlaylistEntry *entry = node->data; | |
3024 if (!entry->selected) | |
3025 continue; | |
3026 | |
3027 retval = TRUE; | |
3028 | |
3029 str_replace_in(&entry->title, NULL); | |
3030 entry->length = -1; | |
3031 | |
3032 /* invalidate mtime to reread */ | |
3033 if (entry->tuple != NULL) | |
3034 entry->tuple->mtime = -1; /* -1 denotes "non-initialized". now 0 is for stream etc. yaz */ | |
3035 | |
3036 if (!playlist_entry_get_info(entry)) { | |
3037 if (g_list_index(playlist->entries, entry) == -1) | |
3038 /* Entry disappeared while we looked it up. Restart. */ | |
3039 node = playlist->entries; | |
3040 } | |
3041 } | |
3042 | |
3043 PLAYLIST_UNLOCK(playlist->mutex); | |
3044 | |
3045 playlistwin_update_list(playlist); | |
3046 playlist_recalc_total_time(playlist); | |
3047 | |
3048 return retval; | |
3049 } | |
3050 | |
3051 void | |
3052 playlist_read_info(Playlist *playlist, guint pos) | |
3053 { | |
3054 GList *node; | |
3055 | |
3056 PLAYLIST_LOCK(playlist->mutex); | |
3057 | |
3058 if ((node = g_list_nth(playlist->entries, pos))) { | |
3059 PlaylistEntry *entry = node->data; | |
3060 str_replace_in(&entry->title, NULL); | |
3061 entry->length = -1; | |
3062 playlist_entry_get_info(entry); | |
3063 } | |
3064 | |
3065 PLAYLIST_UNLOCK(playlist->mutex); | |
3066 | |
3067 playlistwin_update_list(playlist); | |
3068 playlist_recalc_total_time(playlist); | |
3069 } | |
3070 | |
3071 Playlist * | |
3072 playlist_get_active(void) | |
3073 { | |
3074 if (playlists_iter != NULL) | |
3075 return (Playlist *) playlists_iter->data; | |
3076 | |
3077 return (Playlist *) playlists->data; | |
3078 } | |
3079 | |
3080 void | |
3081 playlist_set_shuffle(gboolean shuffle) | |
3082 { | |
3083 Playlist *playlist = playlist_get_active(); | |
3084 if (!playlist) | |
3085 return; | |
3086 | |
3087 PLAYLIST_LOCK(playlist->mutex); | |
3088 | |
3089 playlist_position_before_jump = NULL; | |
3090 | |
3091 cfg.shuffle = shuffle; | |
3092 playlist_generate_shuffle_list_nolock(playlist); | |
3093 | |
3094 PLAYLIST_UNLOCK(playlist->mutex); | |
3095 } | |
3096 | |
3097 Playlist * | |
3098 playlist_new(void) | |
3099 { | |
3100 Playlist *playlist = g_new0(Playlist, 1); | |
3101 playlist->mutex = g_mutex_new(); | |
3102 playlist->loading_playlist = FALSE; | |
3103 | |
3104 playlist_set_current_name(playlist, NULL); | |
3105 playlist_clear(playlist); | |
3106 | |
3107 return playlist; | |
3108 } | |
3109 | |
3110 void | |
3111 playlist_free(Playlist *playlist) | |
3112 { | |
3113 g_mutex_free( playlist->mutex ); | |
3114 g_free( playlist ); | |
3115 return; | |
3116 } | |
3117 | |
3118 Playlist * | |
3119 playlist_new_from_selected(void) | |
3120 { | |
3121 Playlist *newpl = playlist_new(); | |
3122 Playlist *playlist = playlist_get_active(); | |
3123 GList *list = playlist_get_selected(playlist); | |
3124 | |
3125 playlist_add_playlist( newpl ); | |
3126 | |
3127 PLAYLIST_LOCK(playlist->mutex); | |
3128 | |
3129 while ( list != NULL ) | |
3130 { | |
3131 PlaylistEntry *entry = g_list_nth_data(playlist->entries, GPOINTER_TO_INT(list->data)); | |
3132 if ( entry->filename != NULL ) /* paranoid? oh well... */ | |
3133 playlist_add( newpl , entry->filename ); | |
3134 list = g_list_next(list); | |
3135 } | |
3136 | |
3137 PLAYLIST_UNLOCK(playlist->mutex); | |
3138 | |
3139 playlist_recalc_total_time(newpl); | |
3140 playlistwin_update_list(playlist); | |
3141 | |
3142 return newpl; | |
3143 } | |
3144 | |
3145 const gchar * | |
3146 playlist_get_filename_to_play(Playlist *playlist) | |
3147 { | |
3148 const gchar *filename = NULL; | |
3149 | |
3150 if (!playlist) | |
3151 return NULL; | |
3152 | |
3153 PLAYLIST_LOCK(playlist->mutex); | |
3154 | |
3155 if (!playlist->position) { | |
3156 if (cfg.shuffle) | |
3157 playlist->position = playlist->shuffle->data; | |
3158 else | |
3159 playlist->position = playlist->entries->data; | |
3160 } | |
3161 | |
3162 filename = playlist->position->filename; | |
3163 | |
3164 PLAYLIST_UNLOCK(playlist->mutex); | |
3165 | |
3166 return filename; | |
3167 } | |
3168 | |
3169 PlaylistEntry * | |
3170 playlist_get_entry_to_play(Playlist *playlist) | |
3171 { | |
3172 if (!playlist) | |
3173 return NULL; | |
3174 | |
3175 PLAYLIST_LOCK(playlist->mutex); | |
3176 | |
3177 if (!playlist->position) { | |
3178 if (cfg.shuffle) | |
3179 playlist->position = playlist->shuffle->data; | |
3180 else | |
3181 playlist->position = playlist->entries->data; | |
3182 } | |
3183 | |
3184 PLAYLIST_UNLOCK(playlist->mutex); | |
3185 | |
3186 return playlist->position; | |
3187 } |