Mercurial > audlegacy
annotate src/audacious/playlist.c @ 2545:610d85b8a22b trunk
[svn] - on loading a playlist with tuple, invoke the scanner thread only if mtime is -1.
author | yaz |
---|---|
date | Sat, 17 Feb 2007 19:59:01 -0800 |
parents | fcf730269639 |
children | 68d1e9761cc5 |
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, | |
2545
610d85b8a22b
[svn] - on loading a playlist with tuple, invoke the scanner thread only if mtime is -1.
yaz
parents:
2504
diff
changeset
|
591 const gchar * filename, |
2313 | 592 gint pos, |
593 const gchar * title, | |
594 gint len, | |
2545
610d85b8a22b
[svn] - on loading a playlist with tuple, invoke the scanner thread only if mtime is -1.
yaz
parents:
2504
diff
changeset
|
595 InputPlugin * dec) |
2313 | 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); | |
2545
610d85b8a22b
[svn] - on loading a playlist with tuple, invoke the scanner thread only if mtime is -1.
yaz
parents:
2504
diff
changeset
|
642 if(tuple->mtime == -1) { // kick the scanner thread only if mtime = -1 (uninitialized). |
610d85b8a22b
[svn] - on loading a playlist with tuple, invoke the scanner thread only if mtime is -1.
yaz
parents:
2504
diff
changeset
|
643 g_mutex_lock(mutex_scan); |
610d85b8a22b
[svn] - on loading a playlist with tuple, invoke the scanner thread only if mtime is -1.
yaz
parents:
2504
diff
changeset
|
644 playlist_get_info_scan_active = TRUE; |
610d85b8a22b
[svn] - on loading a playlist with tuple, invoke the scanner thread only if mtime is -1.
yaz
parents:
2504
diff
changeset
|
645 g_mutex_unlock(mutex_scan); |
610d85b8a22b
[svn] - on loading a playlist with tuple, invoke the scanner thread only if mtime is -1.
yaz
parents:
2504
diff
changeset
|
646 g_cond_signal(cond_scan); |
610d85b8a22b
[svn] - on loading a playlist with tuple, invoke the scanner thread only if mtime is -1.
yaz
parents:
2504
diff
changeset
|
647 } |
2313 | 648 } |
649 | |
650 static void | |
651 __playlist_ins(Playlist * playlist, const gchar * filename, gint pos, InputPlugin *dec) | |
652 { | |
653 __playlist_ins_with_info(playlist, filename, pos, NULL, -1, dec); | |
654 playlist_recalc_total_time(playlist); | |
655 playlist_manager_update(); | |
656 } | |
657 | |
658 gboolean | |
659 playlist_ins(Playlist * playlist, const gchar * filename, gint pos) | |
660 { | |
661 gchar buf[64], *p; | |
662 gint r; | |
663 VFSFile *file; | |
664 InputPlugin *dec; | |
665 | |
666 g_return_val_if_fail(playlist != NULL, FALSE); | |
667 g_return_val_if_fail(filename != NULL, FALSE); | |
668 | |
669 if (is_playlist_name(filename)) { | |
670 playlist->loading_playlist = TRUE; | |
671 playlist_load_ins(playlist, filename, pos); | |
672 playlist->loading_playlist = FALSE; | |
673 return TRUE; | |
674 } | |
675 | |
676 if (playlist->loading_playlist == TRUE || cfg.playlist_detect == TRUE) | |
677 dec = NULL; | |
678 else | |
679 dec = input_check_file(filename, TRUE); | |
680 | |
681 if (cfg.playlist_detect == TRUE || playlist->loading_playlist == TRUE || (playlist->loading_playlist == FALSE && dec != NULL)) | |
682 { | |
2545
610d85b8a22b
[svn] - on loading a playlist with tuple, invoke the scanner thread only if mtime is -1.
yaz
parents:
2504
diff
changeset
|
683 __playlist_ins(playlist, filename, pos, dec); |
610d85b8a22b
[svn] - on loading a playlist with tuple, invoke the scanner thread only if mtime is -1.
yaz
parents:
2504
diff
changeset
|
684 playlist_generate_shuffle_list(playlist); |
610d85b8a22b
[svn] - on loading a playlist with tuple, invoke the scanner thread only if mtime is -1.
yaz
parents:
2504
diff
changeset
|
685 playlistwin_update_list(playlist); |
2313 | 686 return TRUE; |
687 } | |
688 | |
689 /* Some files (typically produced by some cgi-scripts) don't have | |
690 * the correct extension. Try to recognize these files by looking | |
691 * at their content. We only check for http entries since it does | |
692 * not make sense to have file entries in a playlist fetched from | |
693 * the net. */ | |
694 | |
695 /* Some strange people put fifo's with the .mp3 extension, so we | |
696 * need to make sure it's a real file (otherwise fread() may block | |
697 * and stall the entire program) */ | |
698 | |
699 /* FIXME: bah, FIFOs actually pass this regular file test */ | |
700 if (!vfs_file_test(filename, G_FILE_TEST_IS_REGULAR)) | |
701 return FALSE; | |
702 | |
703 if (!(file = vfs_fopen(filename, "rb"))) | |
704 return FALSE; | |
705 | |
706 r = vfs_fread(buf, 1, sizeof(buf), file); | |
707 vfs_fclose(file); | |
708 | |
709 for (p = buf; r-- > 0 && (*p == '\r' || *p == '\n'); p++); | |
710 | |
711 if (r > 5 && str_has_prefix_nocase(p, "http:")) { | |
712 playlist_load_ins(playlist, filename, pos); | |
713 return TRUE; | |
714 } | |
715 | |
2493
b7f48f00a342
[svn] - patch from Mark Glines to ad https:// URI support to playlists.
nenolod
parents:
2489
diff
changeset
|
716 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
|
717 playlist_load_ins(playlist, filename, pos); |
b7f48f00a342
[svn] - patch from Mark Glines to ad https:// URI support to playlists.
nenolod
parents:
2489
diff
changeset
|
718 return TRUE; |
b7f48f00a342
[svn] - patch from Mark Glines to ad https:// URI support to playlists.
nenolod
parents:
2489
diff
changeset
|
719 } |
b7f48f00a342
[svn] - patch from Mark Glines to ad https:// URI support to playlists.
nenolod
parents:
2489
diff
changeset
|
720 |
2313 | 721 return FALSE; |
722 } | |
723 | |
724 /* FIXME: The next few functions are specific to Unix | |
725 * filesystems. Either abstract it away, or don't even bother checking | |
726 * at such low level */ | |
727 | |
728 typedef struct { | |
729 dev_t dev; | |
730 ino_t ino; | |
731 } DeviceInode; | |
732 | |
733 static DeviceInode * | |
734 devino_new(dev_t device, | |
735 ino_t inode) | |
736 { | |
737 DeviceInode *devino = g_new0(DeviceInode, 1); | |
738 | |
739 if (devino) | |
740 { | |
741 devino->dev = device; | |
742 devino->ino = inode; | |
743 } | |
744 | |
745 return devino; | |
746 } | |
747 | |
748 static guint | |
749 devino_hash(gconstpointer key) | |
750 { | |
751 const DeviceInode *d = key; | |
752 return d->ino; | |
753 } | |
754 | |
755 static gint | |
756 devino_compare(gconstpointer a, | |
757 gconstpointer b) | |
758 { | |
759 const DeviceInode *da = a, *db = b; | |
760 return (da->dev == db->dev && da->ino == db->ino); | |
761 } | |
762 | |
763 static gboolean | |
764 devino_destroy(gpointer key, | |
765 gpointer value, | |
766 gpointer data) | |
767 { | |
768 g_free(key); | |
769 return TRUE; | |
770 } | |
771 | |
772 static gboolean | |
773 file_is_hidden(const gchar * filename) | |
774 { | |
775 // FIXME: remove the const cast | |
776 g_return_val_if_fail(filename != NULL, FALSE); | |
777 return (g_basename((gchar *) filename)[0] == '.'); | |
778 } | |
779 | |
780 static GList * | |
781 playlist_dir_find_files(const gchar * path, | |
782 gboolean background, | |
783 GHashTable * htab) | |
784 { | |
785 GDir *dir; | |
786 GList *list = NULL, *ilist; | |
787 const gchar *dir_entry; | |
788 | |
789 struct stat statbuf; | |
790 DeviceInode *devino; | |
791 | |
792 if (!g_file_test(path, G_FILE_TEST_IS_DIR)) | |
793 return NULL; | |
794 | |
795 stat(path, &statbuf); | |
796 devino = devino_new(statbuf.st_dev, statbuf.st_ino); | |
797 | |
798 if (g_hash_table_lookup(htab, devino)) { | |
799 g_free(devino); | |
800 return NULL; | |
801 } | |
802 | |
803 g_hash_table_insert(htab, devino, GINT_TO_POINTER(1)); | |
804 | |
805 if ((ilist = input_scan_dir(path))) { | |
806 GList *node; | |
807 for (node = ilist; node; node = g_list_next(node)) { | |
808 gchar *name = g_build_filename(path, node->data, NULL); | |
809 list = g_list_prepend(list, name); | |
810 g_free(node->data); | |
811 } | |
812 g_list_free(ilist); | |
813 return list; | |
814 } | |
815 | |
816 if (!(dir = g_dir_open(path, 0, NULL))) | |
817 return NULL; | |
818 | |
819 while ((dir_entry = g_dir_read_name(dir))) { | |
820 gchar *filename; | |
821 | |
822 if (file_is_hidden(dir_entry)) | |
823 continue; | |
824 | |
825 filename = g_build_filename(path, dir_entry, NULL); | |
826 | |
827 if (g_file_test(filename, G_FILE_TEST_IS_DIR)) { | |
828 GList *sub; | |
829 sub = playlist_dir_find_files(filename, background, htab); | |
830 g_free(filename); | |
831 list = g_list_concat(list, sub); | |
832 } | |
833 else if (cfg.playlist_detect == TRUE) | |
834 list = g_list_prepend(list, filename); | |
835 else if (input_check_file(filename, TRUE)) | |
836 list = g_list_prepend(list, filename); | |
837 else | |
838 g_free(filename); | |
839 | |
840 while (background && gtk_events_pending()) | |
841 gtk_main_iteration(); | |
842 } | |
843 g_dir_close(dir); | |
844 | |
845 return list; | |
846 } | |
847 | |
848 gboolean | |
849 playlist_add(Playlist * playlist, const gchar * filename) | |
850 { | |
851 return playlist_ins(playlist, filename, -1); | |
852 } | |
853 | |
854 guint | |
855 playlist_add_dir(Playlist * playlist, const gchar * directory) | |
856 { | |
857 return playlist_ins_dir(playlist, directory, -1, TRUE); | |
858 } | |
859 | |
860 guint | |
861 playlist_add_url(Playlist * playlist, const gchar * url) | |
862 { | |
863 return playlist_ins_url(playlist, url, -1); | |
864 } | |
865 | |
866 guint | |
867 playlist_ins_dir(Playlist * playlist, const gchar * path, | |
868 gint pos, | |
869 gboolean background) | |
870 { | |
871 guint entries = 0; | |
872 GList *list, *node; | |
873 GHashTable *htab; | |
874 | |
875 htab = g_hash_table_new(devino_hash, devino_compare); | |
876 | |
877 list = playlist_dir_find_files(path, background, htab); | |
878 list = g_list_sort(list, (GCompareFunc) path_compare); | |
879 | |
880 g_hash_table_foreach_remove(htab, devino_destroy, NULL); | |
881 | |
882 for (node = list; node; node = g_list_next(node)) { | |
883 __playlist_ins(playlist, node->data, pos, NULL); | |
884 g_free(node->data); | |
885 entries++; | |
886 if (pos >= 0) | |
887 pos++; | |
888 } | |
889 | |
890 g_list_free(list); | |
891 | |
892 playlist_recalc_total_time(playlist); | |
893 playlist_generate_shuffle_list(playlist); | |
894 playlistwin_update_list(playlist); | |
895 playlist_manager_update(); | |
896 return entries; | |
897 } | |
898 | |
899 guint | |
900 playlist_ins_url(Playlist * playlist, const gchar * string, | |
901 gint pos) | |
902 { | |
903 gchar *tmp; | |
904 gint i = 1, entries = 0; | |
905 gboolean first = TRUE; | |
906 guint firstpos = 0; | |
907 gboolean success = FALSE; | |
908 gchar *decoded = NULL; | |
909 | |
910 g_return_val_if_fail(playlist != NULL, 0); | |
911 g_return_val_if_fail(string != NULL, 0); | |
912 | |
913 playlistwin_update_list(playlist); | |
914 | |
915 while (*string) { | |
916 GList *node; | |
917 tmp = strchr(string, '\n'); | |
918 if (tmp) { | |
919 if (*(tmp - 1) == '\r') | |
920 *(tmp - 1) = '\0'; | |
921 *tmp = '\0'; | |
922 } | |
923 | |
924 decoded = g_strdup(string); | |
925 | |
926 if (g_file_test(decoded, G_FILE_TEST_IS_DIR)) { | |
927 i = playlist_ins_dir(playlist, decoded, pos, FALSE); | |
928 } | |
929 else { | |
930 if (is_playlist_name(decoded)) { | |
931 i = playlist_load_ins(playlist, decoded, pos); | |
932 } | |
933 else { | |
934 success = playlist_ins(playlist, decoded, pos); | |
935 i = 1; | |
936 } | |
937 } | |
938 | |
939 g_free(decoded); | |
940 | |
941 PLAYLIST_LOCK(playlist->mutex); | |
942 node = g_list_nth(playlist->entries, pos); | |
943 PLAYLIST_UNLOCK(playlist->mutex); | |
944 | |
945 entries += i; | |
946 | |
947 if (first) { | |
948 first = FALSE; | |
949 firstpos = pos; | |
950 } | |
951 | |
952 if (pos >= 0) | |
953 pos += i; | |
954 if (!tmp) | |
955 break; | |
956 | |
957 string = tmp + 1; | |
958 } | |
959 | |
960 playlist_recalc_total_time(playlist); | |
961 playlist_generate_shuffle_list(playlist); | |
962 playlistwin_update_list(playlist); | |
963 | |
964 playlist_manager_update(); | |
965 | |
966 return entries; | |
967 } | |
968 | |
969 void | |
970 playlist_set_info_old_abi(const gchar * title, gint length, gint rate, | |
971 gint freq, gint nch) | |
972 { | |
973 Playlist *playlist = playlist_get_active(); | |
974 | |
975 PLAYLIST_LOCK(playlist->mutex); | |
976 | |
977 g_return_if_fail(playlist != NULL); | |
978 | |
979 if (playlist->position) { | |
980 g_free(playlist->position->title); | |
981 playlist->position->title = g_strdup(title); | |
982 playlist->position->length = length; | |
2488
c5075a79f1aa
[svn] make input->set_info overwrite tuple->track_name. it allows input
yaz
parents:
2480
diff
changeset
|
983 |
c5075a79f1aa
[svn] make input->set_info overwrite tuple->track_name. it allows input
yaz
parents:
2480
diff
changeset
|
984 // 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
|
985 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
|
986 if(playlist->position->tuple->track_name){ |
c5075a79f1aa
[svn] make input->set_info overwrite tuple->track_name. it allows input
yaz
parents:
2480
diff
changeset
|
987 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
|
988 } |
c5075a79f1aa
[svn] make input->set_info overwrite tuple->track_name. it allows input
yaz
parents:
2480
diff
changeset
|
989 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
|
990 } |
2313 | 991 } |
992 | |
993 PLAYLIST_UNLOCK(playlist->mutex); | |
994 | |
995 playlist_recalc_total_time(playlist); | |
996 | |
997 mainwin_set_song_info(rate, freq, nch); | |
2460 | 998 |
999 if ( playlist->position ) | |
1000 hook_call( "playlist set info" , playlist->position ); | |
2313 | 1001 } |
1002 | |
1003 void | |
1004 playlist_set_info(Playlist * playlist, const gchar * title, gint length, gint rate, | |
1005 gint freq, gint nch) | |
1006 { | |
1007 PLAYLIST_LOCK(playlist->mutex); | |
1008 | |
1009 g_return_if_fail(playlist != NULL); | |
1010 | |
1011 if (playlist->position) { | |
1012 g_free(playlist->position->title); | |
1013 playlist->position->title = g_strdup(title); | |
1014 playlist->position->length = length; | |
1015 } | |
1016 | |
1017 PLAYLIST_UNLOCK(playlist->mutex); | |
1018 | |
1019 playlist_recalc_total_time(playlist); | |
1020 | |
1021 mainwin_set_song_info(rate, freq, nch); | |
2460 | 1022 |
1023 if ( playlist->position ) | |
1024 hook_call( "playlist set info" , playlist->position ); | |
2313 | 1025 } |
1026 | |
1027 void | |
1028 playlist_check_pos_current(Playlist *playlist) | |
1029 { | |
1030 gint pos, row, bottom; | |
1031 | |
1032 if (!playlist) | |
1033 return; | |
1034 | |
1035 PLAYLIST_LOCK(playlist->mutex); | |
1036 if (!playlist->position || !playlistwin_list) { | |
1037 PLAYLIST_UNLOCK(playlist->mutex); | |
1038 return; | |
1039 } | |
1040 | |
1041 pos = g_list_index(playlist->entries, playlist->position); | |
1042 | |
1043 if (playlistwin_item_visible(pos)) { | |
1044 PLAYLIST_UNLOCK(playlist->mutex); | |
1045 return; | |
1046 } | |
1047 | |
1048 bottom = MAX(0, playlist_get_length_nolock(playlist) - | |
1049 playlistwin_list->pl_num_visible); | |
1050 row = CLAMP(pos - playlistwin_list->pl_num_visible / 2, 0, bottom); | |
1051 PLAYLIST_UNLOCK(playlist->mutex); | |
1052 playlistwin_set_toprow(row); | |
1053 g_cond_signal(cond_scan); | |
1054 } | |
1055 | |
1056 void | |
1057 playlist_next(Playlist *playlist) | |
1058 { | |
1059 GList *plist_pos_list; | |
1060 gboolean restart_playing = FALSE; | |
2480
bb2f191895ce
[svn] - fixed crash when skipping to next song with an empty playlist
marvin
parents:
2460
diff
changeset
|
1061 if (!playlist_get_length(playlist)) |
2313 | 1062 return; |
1063 | |
1064 PLAYLIST_LOCK(playlist->mutex); | |
1065 | |
1066 if ((playlist_position_before_jump != NULL) && playlist->queue == NULL) | |
1067 { | |
1068 playlist->position = playlist_position_before_jump; | |
1069 playlist_position_before_jump = NULL; | |
1070 } | |
1071 | |
1072 plist_pos_list = find_playlist_position_list(playlist); | |
1073 | |
1074 if (!cfg.repeat && !g_list_next(plist_pos_list) && playlist->queue == NULL) { | |
1075 PLAYLIST_UNLOCK(playlist->mutex); | |
1076 return; | |
1077 } | |
1078 | |
1079 if (playback_get_playing()) { | |
1080 /* We need to stop before changing playlist_position */ | |
1081 PLAYLIST_UNLOCK(playlist->mutex); | |
1082 ip_data.stop = TRUE; | |
1083 playback_stop(); | |
1084 ip_data.stop = FALSE; | |
1085 PLAYLIST_LOCK(playlist->mutex); | |
1086 restart_playing = TRUE; | |
1087 } | |
1088 | |
1089 plist_pos_list = find_playlist_position_list(playlist); | |
1090 if (playlist->queue != NULL) | |
1091 play_queued(playlist); | |
1092 else if (g_list_next(plist_pos_list)) | |
1093 playlist->position = g_list_next(plist_pos_list)->data; | |
1094 else if (cfg.repeat) { | |
1095 playlist->position = NULL; | |
1096 playlist_generate_shuffle_list_nolock(playlist); | |
1097 if (cfg.shuffle) | |
1098 playlist->position = playlist->shuffle->data; | |
1099 else | |
1100 playlist->position = playlist->entries->data; | |
1101 } | |
1102 PLAYLIST_UNLOCK(playlist->mutex); | |
1103 playlist_check_pos_current(playlist); | |
1104 | |
1105 if (restart_playing) | |
1106 playback_initiate(); | |
1107 else { | |
1108 mainwin_set_info_text(); | |
1109 playlistwin_update_list(playlist); | |
1110 } | |
1111 } | |
1112 | |
1113 void | |
1114 playlist_prev(Playlist *playlist) | |
1115 { | |
1116 GList *plist_pos_list; | |
1117 gboolean restart_playing = FALSE; | |
1118 | |
2480
bb2f191895ce
[svn] - fixed crash when skipping to next song with an empty playlist
marvin
parents:
2460
diff
changeset
|
1119 if (!playlist_get_length(playlist)) |
2313 | 1120 return; |
1121 | |
1122 PLAYLIST_LOCK(playlist->mutex); | |
1123 | |
1124 if ((playlist_position_before_jump != NULL) && playlist->queue == NULL) | |
1125 { | |
1126 playlist->position = playlist_position_before_jump; | |
1127 playlist_position_before_jump = NULL; | |
1128 } | |
1129 | |
1130 plist_pos_list = find_playlist_position_list(playlist); | |
1131 | |
1132 if (!cfg.repeat && !g_list_previous(plist_pos_list)) { | |
1133 PLAYLIST_UNLOCK(playlist->mutex); | |
1134 return; | |
1135 } | |
1136 | |
1137 if (playback_get_playing()) { | |
1138 /* We need to stop before changing playlist_position */ | |
1139 PLAYLIST_UNLOCK(playlist->mutex); | |
1140 ip_data.stop = TRUE; | |
1141 playback_stop(); | |
1142 ip_data.stop = FALSE; | |
1143 PLAYLIST_LOCK(playlist->mutex); | |
1144 restart_playing = TRUE; | |
1145 } | |
1146 | |
1147 plist_pos_list = find_playlist_position_list(playlist); | |
1148 if (g_list_previous(plist_pos_list)) { | |
1149 playlist->position = g_list_previous(plist_pos_list)->data; | |
1150 } | |
1151 else if (cfg.repeat) { | |
1152 GList *node; | |
1153 playlist->position = NULL; | |
1154 playlist_generate_shuffle_list_nolock(playlist); | |
1155 if (cfg.shuffle) | |
1156 node = g_list_last(playlist->shuffle); | |
1157 else | |
1158 node = g_list_last(playlist->entries); | |
1159 if (node) | |
1160 playlist->position = node->data; | |
1161 } | |
1162 | |
1163 PLAYLIST_UNLOCK(playlist->mutex); | |
1164 | |
1165 playlist_check_pos_current(playlist); | |
1166 | |
1167 if (restart_playing) | |
1168 playback_initiate(); | |
1169 else { | |
1170 mainwin_set_info_text(); | |
1171 playlistwin_update_list(playlist); | |
1172 } | |
1173 } | |
1174 | |
1175 void | |
1176 playlist_queue(Playlist *playlist) | |
1177 { | |
1178 GList *list = playlist_get_selected(playlist); | |
1179 GList *it = list; | |
1180 | |
1181 PLAYLIST_LOCK(playlist->mutex); | |
1182 | |
1183 if ((cfg.shuffle) && (playlist_position_before_jump == NULL)) | |
1184 { | |
1185 /* Shuffling and this is our first manual jump. */ | |
1186 playlist_position_before_jump = playlist->position; | |
1187 } | |
1188 | |
1189 while (it) { | |
1190 GList *next = g_list_next(it); | |
1191 GList *tmp; | |
1192 | |
1193 /* XXX: WTF? --nenolod */ | |
1194 it->data = g_list_nth_data(playlist->entries, GPOINTER_TO_INT(it->data)); | |
1195 if ((tmp = g_list_find(playlist->queue, it->data))) { | |
1196 playlist->queue = g_list_remove_link(playlist->queue, tmp); | |
1197 g_list_free_1(tmp); | |
1198 list = g_list_remove_link(list, it); | |
1199 g_list_free_1(it); | |
1200 } | |
1201 | |
1202 it = next; | |
1203 } | |
1204 | |
1205 playlist->queue = g_list_concat(playlist->queue, list); | |
1206 | |
1207 PLAYLIST_UNLOCK(playlist->mutex); | |
1208 | |
1209 playlist_recalc_total_time(playlist); | |
1210 playlistwin_update_list(playlist); | |
1211 } | |
1212 | |
1213 void | |
1214 playlist_queue_position(Playlist *playlist, guint pos) | |
1215 { | |
1216 GList *tmp; | |
1217 PlaylistEntry *entry; | |
1218 | |
1219 PLAYLIST_LOCK(playlist->mutex); | |
1220 | |
1221 if ((cfg.shuffle) && (playlist_position_before_jump == NULL)) | |
1222 { | |
1223 /* Shuffling and this is our first manual jump. */ | |
1224 playlist_position_before_jump = playlist->position; | |
1225 } | |
1226 | |
1227 entry = g_list_nth_data(playlist->entries, pos); | |
1228 if ((tmp = g_list_find(playlist->queue, entry))) { | |
1229 playlist->queue = g_list_remove_link(playlist->queue, tmp); | |
1230 g_list_free_1(tmp); | |
1231 } | |
1232 else | |
1233 playlist->queue = g_list_append(playlist->queue, entry); | |
1234 PLAYLIST_UNLOCK(playlist->mutex); | |
1235 | |
1236 playlist_recalc_total_time(playlist); | |
1237 playlistwin_update_list(playlist); | |
1238 } | |
1239 | |
1240 gboolean | |
1241 playlist_is_position_queued(Playlist *playlist, guint pos) | |
1242 { | |
1243 PlaylistEntry *entry; | |
1244 GList *tmp; | |
1245 | |
1246 PLAYLIST_LOCK(playlist->mutex); | |
1247 entry = g_list_nth_data(playlist->entries, pos); | |
1248 tmp = g_list_find(playlist->queue, entry); | |
1249 PLAYLIST_UNLOCK(playlist->mutex); | |
1250 | |
1251 return tmp != NULL; | |
1252 } | |
1253 | |
1254 gint | |
1255 playlist_get_queue_position_number(Playlist *playlist, guint pos) | |
1256 { | |
1257 PlaylistEntry *entry; | |
1258 gint tmp; | |
1259 | |
1260 PLAYLIST_LOCK(playlist->mutex); | |
1261 entry = g_list_nth_data(playlist->entries, pos); | |
1262 tmp = g_list_index(playlist->queue, entry); | |
1263 PLAYLIST_UNLOCK(playlist->mutex); | |
1264 | |
1265 return tmp; | |
1266 } | |
1267 | |
1268 gint | |
1269 playlist_get_queue_qposition_number(Playlist *playlist, guint pos) | |
1270 { | |
1271 PlaylistEntry *entry; | |
1272 gint tmp; | |
1273 | |
1274 PLAYLIST_LOCK(playlist->mutex); | |
1275 entry = g_list_nth_data(playlist->queue, pos); | |
1276 tmp = g_list_index(playlist->entries, entry); | |
1277 PLAYLIST_UNLOCK(playlist->mutex); | |
1278 | |
1279 return tmp; | |
1280 } | |
1281 | |
1282 void | |
1283 playlist_clear_queue(Playlist *playlist) | |
1284 { | |
1285 PLAYLIST_LOCK(playlist->mutex); | |
1286 g_list_free(playlist->queue); | |
1287 playlist->queue = NULL; | |
1288 PLAYLIST_UNLOCK(playlist->mutex); | |
1289 | |
1290 playlist_recalc_total_time(playlist); | |
1291 playlistwin_update_list(playlist); | |
1292 } | |
1293 | |
1294 void | |
1295 playlist_queue_remove(Playlist *playlist, guint pos) | |
1296 { | |
1297 void *entry; | |
1298 | |
1299 PLAYLIST_LOCK(playlist->mutex); | |
1300 entry = g_list_nth_data(playlist->entries, pos); | |
1301 playlist->queue = g_list_remove(playlist->queue, entry); | |
1302 PLAYLIST_UNLOCK(playlist->mutex); | |
1303 | |
1304 playlistwin_update_list(playlist); | |
1305 } | |
1306 | |
1307 gint | |
1308 playlist_get_queue_position(Playlist *playlist, PlaylistEntry * entry) | |
1309 { | |
1310 return g_list_index(playlist->queue, entry); | |
1311 } | |
1312 | |
1313 void | |
1314 playlist_set_position(Playlist *playlist, guint pos) | |
1315 { | |
1316 GList *node; | |
1317 gboolean restart_playing = FALSE; | |
1318 | |
1319 if (!playlist) | |
1320 return; | |
1321 | |
1322 PLAYLIST_LOCK(playlist->mutex); | |
1323 | |
1324 node = g_list_nth(playlist->entries, pos); | |
1325 if (!node) { | |
1326 PLAYLIST_UNLOCK(playlist->mutex); | |
1327 return; | |
1328 } | |
1329 | |
1330 if (playback_get_playing()) { | |
1331 /* We need to stop before changing playlist_position */ | |
1332 PLAYLIST_UNLOCK(playlist->mutex); | |
1333 ip_data.stop = TRUE; | |
1334 playback_stop(); | |
1335 ip_data.stop = FALSE; | |
1336 PLAYLIST_LOCK(playlist->mutex); | |
1337 restart_playing = TRUE; | |
1338 } | |
1339 | |
1340 if ((cfg.shuffle) && (playlist_position_before_jump == NULL)) | |
1341 { | |
1342 /* Shuffling and this is our first manual jump. */ | |
1343 playlist_position_before_jump = playlist->position; | |
1344 } | |
1345 | |
1346 playlist->position = node->data; | |
1347 PLAYLIST_UNLOCK(playlist->mutex); | |
1348 playlist_check_pos_current(playlist); | |
1349 | |
1350 if (restart_playing) | |
1351 playback_initiate(); | |
1352 else { | |
1353 mainwin_set_info_text(); | |
1354 playlistwin_update_list(playlist); | |
1355 } | |
1356 } | |
1357 | |
1358 void | |
1359 playlist_eof_reached(Playlist *playlist) | |
1360 { | |
1361 GList *plist_pos_list; | |
1362 | |
1363 if ((cfg.no_playlist_advance && !cfg.repeat) || cfg.stopaftersong) | |
1364 ip_data.stop = TRUE; | |
1365 playback_stop(); | |
1366 if ((cfg.no_playlist_advance && !cfg.repeat) || cfg.stopaftersong) | |
1367 ip_data.stop = FALSE; | |
1368 | |
2408
b380e84148bb
[svn] - rename some hooks so that they are more logical
nenolod
parents:
2407
diff
changeset
|
1369 hook_call("playback end", playlist->position); |
2407
1dc1d36d0347
[svn] - add hooks: playback begin, playback end, playlist reached end
nenolod
parents:
2380
diff
changeset
|
1370 |
2313 | 1371 PLAYLIST_LOCK(playlist->mutex); |
1372 | |
1373 if ((playlist_position_before_jump != NULL) && playlist->queue == NULL) | |
1374 { | |
1375 playlist->position = playlist_position_before_jump; | |
1376 playlist_position_before_jump = NULL; | |
1377 } | |
1378 | |
1379 plist_pos_list = find_playlist_position_list(playlist); | |
1380 | |
1381 if (cfg.no_playlist_advance) { | |
1382 PLAYLIST_UNLOCK(playlist->mutex); | |
1383 mainwin_clear_song_info(); | |
1384 if (cfg.repeat) | |
1385 playback_initiate(); | |
1386 return; | |
1387 } | |
1388 | |
1389 if (cfg.stopaftersong) { | |
1390 PLAYLIST_UNLOCK(playlist->mutex); | |
1391 mainwin_clear_song_info(); | |
1392 mainwin_set_stopaftersong(FALSE); | |
1393 return; | |
1394 } | |
1395 | |
1396 if (playlist->queue != NULL) { | |
1397 play_queued(playlist); | |
1398 } | |
1399 else if (!g_list_next(plist_pos_list)) { | |
1400 if (cfg.shuffle) { | |
1401 playlist->position = NULL; | |
1402 playlist_generate_shuffle_list_nolock(playlist); | |
1403 } | |
2380 | 1404 else if (playlist->entries != NULL) |
2313 | 1405 playlist->position = playlist->entries->data; |
1406 | |
1407 if (!cfg.repeat) { | |
1408 PLAYLIST_UNLOCK(playlist->mutex); | |
2408
b380e84148bb
[svn] - rename some hooks so that they are more logical
nenolod
parents:
2407
diff
changeset
|
1409 hook_call("playlist end reached", playlist->position); |
2313 | 1410 mainwin_clear_song_info(); |
1411 mainwin_set_info_text(); | |
1412 return; | |
1413 } | |
1414 } | |
1415 else | |
1416 playlist->position = g_list_next(plist_pos_list)->data; | |
1417 | |
1418 PLAYLIST_UNLOCK(playlist->mutex); | |
1419 | |
1420 playlist_check_pos_current(playlist); | |
1421 playback_initiate(); | |
1422 mainwin_set_info_text(); | |
1423 playlistwin_update_list(playlist); | |
1424 } | |
1425 | |
1426 gint | |
1427 playlist_get_length(Playlist *playlist) | |
1428 { | |
1429 gint retval; | |
1430 | |
1431 PLAYLIST_LOCK(playlist->mutex); | |
1432 retval = playlist_get_length_nolock(playlist); | |
1433 PLAYLIST_UNLOCK(playlist->mutex); | |
1434 | |
1435 return retval; | |
1436 } | |
1437 | |
1438 gint | |
1439 playlist_queue_get_length(Playlist *playlist) | |
1440 { | |
1441 gint length; | |
1442 | |
1443 PLAYLIST_LOCK(playlist->mutex); | |
1444 length = g_list_length(playlist->queue); | |
1445 PLAYLIST_UNLOCK(playlist->mutex); | |
1446 | |
1447 return length; | |
1448 } | |
1449 | |
1450 gint | |
1451 playlist_get_length_nolock(Playlist *playlist) | |
1452 { | |
1453 return g_list_length(playlist->entries); | |
1454 } | |
1455 | |
1456 gchar * | |
1457 playlist_get_info_text(Playlist *playlist) | |
1458 { | |
1459 gchar *text, *title, *numbers, *length; | |
1460 | |
1461 g_return_val_if_fail(playlist != NULL, NULL); | |
1462 | |
1463 PLAYLIST_LOCK(playlist->mutex); | |
1464 if (!playlist->position) { | |
1465 PLAYLIST_UNLOCK(playlist->mutex); | |
1466 return NULL; | |
1467 } | |
1468 | |
1469 /* FIXME: there should not be a need to do additional conversion, | |
1470 * if playlist is properly maintained */ | |
1471 if (playlist->position->title) { | |
1472 title = str_to_utf8(playlist->position->title); | |
1473 } | |
1474 else { | |
1475 gchar *basename = g_path_get_basename(playlist->position->filename); | |
1476 title = filename_to_utf8(basename); | |
1477 g_free(basename); | |
1478 } | |
1479 | |
1480 /* | |
1481 * If the user don't want numbers in the playlist, don't | |
1482 * display them in other parts of XMMS | |
1483 */ | |
1484 | |
1485 if (cfg.show_numbers_in_pl) | |
1486 numbers = g_strdup_printf("%d. ", playlist_get_position_nolock(playlist) + 1); | |
1487 else | |
1488 numbers = g_strdup(""); | |
1489 | |
1490 if (playlist->position->length != -1) | |
1491 length = g_strdup_printf(" (%d:%-2.2d)", | |
1492 playlist->position->length / 60000, | |
1493 (playlist->position->length / 1000) % 60); | |
1494 else | |
1495 length = g_strdup(""); | |
1496 | |
1497 PLAYLIST_UNLOCK(playlist->mutex); | |
1498 | |
1499 text = convert_title_text(g_strconcat(numbers, title, length, NULL)); | |
1500 | |
1501 g_free(numbers); | |
1502 g_free(title); | |
1503 g_free(length); | |
1504 | |
1505 return text; | |
1506 } | |
1507 | |
1508 gint | |
1509 playlist_get_current_length(Playlist * playlist) | |
1510 { | |
1511 gint len = 0; | |
1512 | |
1513 if (!playlist) | |
1514 return 0; | |
1515 | |
1516 PLAYLIST_LOCK(playlist->mutex); | |
1517 if (playlist->position) | |
1518 len = playlist->position->length; | |
1519 PLAYLIST_UNLOCK(playlist->mutex); | |
1520 | |
1521 return len; | |
1522 } | |
1523 | |
1524 gboolean | |
1525 playlist_save(Playlist * playlist, const gchar * filename) | |
1526 { | |
1527 PlaylistContainer *plc = NULL; | |
1528 gchar *ext; | |
1529 | |
1530 g_return_val_if_fail(playlist != NULL, FALSE); | |
1531 g_return_val_if_fail(filename != NULL, FALSE); | |
1532 | |
1533 ext = strrchr(filename, '.') + 1; | |
1534 | |
1535 playlist_set_current_name(playlist, filename); | |
1536 | |
1537 if ((plc = playlist_container_find(ext)) == NULL) | |
1538 return FALSE; | |
1539 | |
1540 if (plc->plc_write == NULL) | |
1541 return FALSE; | |
1542 | |
1543 plc->plc_write(filename, 0); | |
1544 | |
1545 return TRUE; | |
1546 } | |
1547 | |
1548 gboolean | |
1549 playlist_load(Playlist * playlist, const gchar * filename) | |
1550 { | |
1551 gboolean ret = FALSE; | |
1552 g_return_val_if_fail(playlist != NULL, FALSE); | |
1553 | |
1554 playlist->loading_playlist = TRUE; | |
1555 ret = playlist_load_ins(playlist, filename, -1); | |
1556 playlist->loading_playlist = FALSE; | |
1557 | |
1558 return ret; | |
1559 } | |
1560 | |
1561 void | |
1562 playlist_load_ins_file(Playlist *playlist, | |
1563 const gchar * filename_p, | |
1564 const gchar * playlist_name, gint pos, | |
1565 const gchar * title, gint len) | |
1566 { | |
1567 gchar *filename; | |
1568 gchar *tmp, *path; | |
1569 InputPlugin *dec; /* for decoder cache */ | |
1570 | |
1571 g_return_if_fail(filename_p != NULL); | |
1572 g_return_if_fail(playlist != NULL); | |
1573 g_return_if_fail(playlist_name != NULL); | |
1574 | |
1575 filename = g_strchug(g_strdup(filename_p)); | |
1576 | |
1577 if(cfg.convert_slash) | |
1578 while ((tmp = strchr(filename, '\\')) != NULL) | |
1579 *tmp = '/'; | |
1580 | |
1581 if (filename[0] != '/' && !strstr(filename, "://")) { | |
1582 path = g_strdup(playlist_name); | |
1583 if ((tmp = strrchr(path, '/'))) | |
1584 *tmp = '\0'; | |
1585 else { | |
1586 if (playlist->loading_playlist != TRUE || cfg.playlist_detect == FALSE) | |
1587 dec = input_check_file(filename, FALSE); | |
1588 else | |
1589 dec = NULL; | |
1590 | |
1591 __playlist_ins_with_info(playlist, filename, pos, title, len, dec); | |
1592 return; | |
1593 } | |
1594 tmp = g_build_filename(path, filename, NULL); | |
1595 | |
1596 if (playlist->loading_playlist != TRUE && cfg.playlist_detect != TRUE) | |
1597 dec = input_check_file(tmp, FALSE); | |
1598 else | |
1599 dec = NULL; | |
1600 | |
1601 __playlist_ins_with_info(playlist, tmp, pos, title, len, dec); | |
1602 g_free(tmp); | |
1603 g_free(path); | |
1604 } | |
1605 else | |
1606 { | |
1607 if (playlist->loading_playlist != TRUE && cfg.playlist_detect != TRUE) | |
1608 dec = input_check_file(filename, FALSE); | |
1609 else | |
1610 dec = NULL; | |
1611 | |
1612 __playlist_ins_with_info(playlist, filename, pos, title, len, dec); | |
1613 } | |
1614 | |
1615 g_free(filename); | |
1616 } | |
1617 | |
1618 void | |
1619 playlist_load_ins_file_tuple(Playlist * playlist, | |
1620 const gchar * filename_p, | |
1621 const gchar * playlist_name, | |
1622 gint pos, | |
1623 TitleInput *tuple) | |
1624 { | |
1625 gchar *filename; | |
1626 gchar *tmp, *path; | |
1627 InputPlugin *dec; /* for decoder cache */ | |
1628 | |
1629 g_return_if_fail(filename_p != NULL); | |
1630 g_return_if_fail(playlist_name != NULL); | |
1631 g_return_if_fail(playlist != NULL); | |
1632 | |
1633 filename = g_strchug(g_strdup(filename_p)); | |
1634 | |
1635 while ((tmp = strchr(filename, '\\')) != NULL) | |
1636 *tmp = '/'; | |
1637 | |
1638 if (filename[0] != '/' && !strstr(filename, "://")) { | |
1639 path = g_strdup(playlist_name); | |
1640 if ((tmp = strrchr(path, '/'))) | |
1641 *tmp = '\0'; | |
1642 else { | |
1643 if (playlist->loading_playlist != TRUE || cfg.playlist_detect == FALSE) | |
1644 dec = input_check_file(filename, FALSE); | |
1645 else | |
1646 dec = NULL; | |
1647 | |
1648 __playlist_ins_with_info_tuple(playlist, filename, pos, tuple, dec); | |
1649 return; | |
1650 } | |
1651 tmp = g_build_filename(path, filename, NULL); | |
1652 | |
1653 if (playlist->loading_playlist != TRUE && cfg.playlist_detect != TRUE) | |
1654 dec = input_check_file(tmp, FALSE); | |
1655 else | |
1656 dec = NULL; | |
1657 | |
1658 __playlist_ins_with_info_tuple(playlist, tmp, pos, tuple, dec); | |
1659 g_free(tmp); | |
1660 g_free(path); | |
1661 } | |
1662 else | |
1663 { | |
1664 if (playlist->loading_playlist != TRUE && cfg.playlist_detect != TRUE) | |
1665 dec = input_check_file(filename, FALSE); | |
1666 else | |
1667 dec = NULL; | |
1668 | |
1669 __playlist_ins_with_info_tuple(playlist, filename, pos, tuple, dec); | |
1670 } | |
1671 | |
1672 g_free(filename); | |
1673 } | |
1674 | |
1675 static guint | |
1676 playlist_load_ins(Playlist * playlist, const gchar * filename, gint pos) | |
1677 { | |
1678 PlaylistContainer *plc; | |
1679 gchar *ext; | |
1680 | |
1681 g_return_val_if_fail(playlist != NULL, 0); | |
1682 g_return_val_if_fail(filename != NULL, 0); | |
1683 | |
1684 ext = strrchr(filename, '.') + 1; | |
1685 plc = playlist_container_find(ext); | |
1686 | |
1687 g_return_val_if_fail(plc != NULL, 0); | |
1688 g_return_val_if_fail(plc->plc_read != NULL, 0); | |
1689 | |
1690 plc->plc_read(filename, pos); | |
1691 | |
1692 playlist_generate_shuffle_list(playlist); | |
1693 playlistwin_update_list(playlist); | |
1694 | |
1695 return 1; | |
1696 } | |
1697 | |
1698 GList * | |
1699 get_playlist_nth(Playlist *playlist, guint nth) | |
1700 { | |
1701 g_warning("deprecated function get_playlist_nth() was called"); | |
1702 REQUIRE_LOCK(playlist->mutex); | |
1703 return g_list_nth(playlist->entries, nth); | |
1704 } | |
1705 | |
1706 gint | |
1707 playlist_get_position_nolock(Playlist *playlist) | |
1708 { | |
1709 if (playlist && playlist->position) | |
1710 return g_list_index(playlist->entries, playlist->position); | |
1711 return 0; | |
1712 } | |
1713 | |
1714 gint | |
1715 playlist_get_position(Playlist *playlist) | |
1716 { | |
1717 gint pos; | |
1718 | |
1719 PLAYLIST_LOCK(playlist->mutex); | |
1720 pos = playlist_get_position_nolock(playlist); | |
1721 PLAYLIST_UNLOCK(playlist->mutex); | |
1722 | |
1723 return pos; | |
1724 } | |
1725 | |
1726 gchar * | |
1727 playlist_get_filename(Playlist *playlist, guint pos) | |
1728 { | |
1729 gchar *filename; | |
1730 PlaylistEntry *entry; | |
1731 GList *node; | |
1732 | |
1733 if (!playlist) | |
1734 return NULL; | |
1735 | |
1736 PLAYLIST_LOCK(playlist->mutex); | |
1737 node = g_list_nth(playlist->entries, pos); | |
1738 if (!node) { | |
1739 PLAYLIST_UNLOCK(playlist->mutex); | |
1740 return NULL; | |
1741 } | |
1742 entry = node->data; | |
1743 | |
1744 filename = g_strdup(entry->filename); | |
1745 PLAYLIST_UNLOCK(playlist->mutex); | |
1746 | |
1747 return filename; | |
1748 } | |
1749 | |
1750 gchar * | |
1751 playlist_get_songtitle(Playlist *playlist, guint pos) | |
1752 { | |
1753 gchar *title = NULL; | |
1754 PlaylistEntry *entry; | |
1755 GList *node; | |
1756 | |
1757 if (!playlist) | |
1758 return NULL; | |
1759 | |
1760 PLAYLIST_LOCK(playlist->mutex); | |
1761 | |
1762 if (!(node = g_list_nth(playlist->entries, pos))) { | |
1763 PLAYLIST_UNLOCK(playlist->mutex); | |
1764 return NULL; | |
1765 } | |
1766 | |
1767 entry = node->data; | |
1768 | |
1769 /* FIXME: simplify this logic */ | |
1770 if ((entry->title == NULL && entry->length == -1) || | |
1771 (entry->tuple && entry->tuple->mtime != 0 && (entry->tuple->mtime == -1 || entry->tuple->mtime != playlist_get_mtime(entry->filename)))) | |
1772 { | |
1773 if (playlist_entry_get_info(entry)) | |
1774 title = entry->title; | |
1775 } | |
1776 else { | |
1777 title = entry->title; | |
1778 } | |
1779 | |
1780 PLAYLIST_UNLOCK(playlist->mutex); | |
1781 | |
1782 if (!title) { | |
1783 title = g_path_get_basename(entry->filename); | |
1784 return str_replace(title, filename_to_utf8(title)); | |
1785 } | |
1786 | |
1787 return str_to_utf8(title); | |
1788 } | |
1789 | |
1790 TitleInput * | |
1791 playlist_get_tuple(Playlist *playlist, guint pos) | |
1792 { | |
1793 PlaylistEntry *entry; | |
1794 TitleInput *tuple = NULL; | |
1795 GList *node; | |
1796 | |
1797 if (!playlist) | |
1798 return NULL; | |
1799 | |
1800 PLAYLIST_LOCK(playlist->mutex); | |
1801 | |
1802 if (!(node = g_list_nth(playlist->entries, pos))) { | |
1803 PLAYLIST_UNLOCK(playlist->mutex); | |
1804 return NULL; | |
1805 } | |
1806 | |
1807 entry = (PlaylistEntry *) node->data; | |
1808 | |
1809 tuple = entry->tuple; | |
1810 | |
1811 // if no tuple or tuple with old mtime, get new one. | |
1812 if (tuple == NULL || | |
1813 (entry->tuple && entry->tuple->mtime != 0 && (entry->tuple->mtime == -1 || entry->tuple->mtime != playlist_get_mtime(entry->filename)))) | |
1814 { | |
1815 playlist_entry_get_info(entry); | |
1816 tuple = entry->tuple; | |
1817 } | |
1818 | |
1819 PLAYLIST_UNLOCK(playlist->mutex); | |
1820 | |
1821 return tuple; | |
1822 } | |
1823 | |
1824 gint | |
1825 playlist_get_songtime(Playlist *playlist, guint pos) | |
1826 { | |
1827 gint song_time = -1; | |
1828 PlaylistEntry *entry; | |
1829 GList *node; | |
1830 | |
1831 if (!playlist) | |
1832 return -1; | |
1833 | |
1834 PLAYLIST_LOCK(playlist->mutex); | |
1835 | |
1836 if (!(node = g_list_nth(playlist->entries, pos))) { | |
1837 PLAYLIST_UNLOCK(playlist->mutex); | |
1838 return -1; | |
1839 } | |
1840 | |
1841 entry = node->data; | |
1842 if (entry->tuple == NULL || | |
1843 (entry->tuple->mtime != 0 && (entry->tuple->mtime == -1 || entry->tuple->mtime != playlist_get_mtime(entry->filename)))) { | |
1844 | |
1845 if (playlist_entry_get_info(entry)) | |
1846 song_time = entry->length; | |
1847 | |
1848 PLAYLIST_UNLOCK(playlist->mutex); | |
1849 } | |
1850 else { | |
1851 song_time = entry->length; | |
1852 PLAYLIST_UNLOCK(playlist->mutex); | |
1853 } | |
1854 | |
1855 return song_time; | |
1856 } | |
1857 | |
1858 static gint | |
1859 playlist_compare_track(PlaylistEntry * a, | |
1860 PlaylistEntry * b) | |
1861 { | |
1862 g_return_val_if_fail(a != NULL, 0); | |
1863 g_return_val_if_fail(b != NULL, 0); | |
1864 | |
1865 g_return_val_if_fail(a->tuple != NULL, 0); | |
1866 g_return_val_if_fail(b->tuple != NULL, 0); | |
1867 | |
1868 return (a->tuple->track_number - b->tuple->track_number); | |
1869 } | |
1870 | |
1871 static gint | |
1872 playlist_compare_playlist(PlaylistEntry * a, | |
1873 PlaylistEntry * b) | |
1874 { | |
1875 const gchar *a_title = NULL, *b_title = NULL; | |
1876 | |
1877 g_return_val_if_fail(a != NULL, 0); | |
1878 g_return_val_if_fail(b != NULL, 0); | |
1879 | |
1880 if (a->title != NULL) | |
1881 a_title = a->title; | |
1882 else { | |
1883 if (strrchr(a->filename, '/')) | |
1884 a_title = strrchr(a->filename, '/') + 1; | |
1885 else | |
1886 a_title = a->filename; | |
1887 } | |
1888 | |
1889 if (b->title != NULL) | |
1890 b_title = b->title; | |
1891 else { | |
1892 if (strrchr(a->filename, '/')) | |
1893 b_title = strrchr(b->filename, '/') + 1; | |
1894 else | |
1895 b_title = b->filename; | |
1896 } | |
1897 | |
1898 return strcasecmp(a_title, b_title); | |
1899 } | |
1900 | |
1901 static gint | |
1902 playlist_compare_title(PlaylistEntry * a, | |
1903 PlaylistEntry * b) | |
1904 { | |
1905 const gchar *a_title = NULL, *b_title = NULL; | |
1906 | |
1907 g_return_val_if_fail(a != NULL, 0); | |
1908 g_return_val_if_fail(b != NULL, 0); | |
1909 | |
1910 if (a->tuple != NULL && a->tuple->track_name != NULL) | |
1911 a_title = a->tuple->track_name; | |
1912 if (b->tuple != NULL && b->tuple->track_name != NULL) | |
1913 b_title = b->tuple->track_name; | |
1914 | |
1915 if (a_title != NULL && b_title != NULL) | |
1916 return strcasecmp(a_title, b_title); | |
1917 | |
1918 if (a->title != NULL) | |
1919 a_title = a->title; | |
1920 else { | |
1921 if (strrchr(a->filename, '/')) | |
1922 a_title = strrchr(a->filename, '/') + 1; | |
1923 else | |
1924 a_title = a->filename; | |
1925 } | |
1926 | |
1927 if (b->title != NULL) | |
1928 b_title = b->title; | |
1929 else { | |
1930 if (strrchr(a->filename, '/')) | |
1931 b_title = strrchr(b->filename, '/') + 1; | |
1932 else | |
1933 b_title = b->filename; | |
1934 } | |
1935 | |
1936 return strcasecmp(a_title, b_title); | |
1937 } | |
1938 | |
1939 static gint | |
1940 playlist_compare_artist(PlaylistEntry * a, | |
1941 PlaylistEntry * b) | |
1942 { | |
1943 const gchar *a_artist = NULL, *b_artist = NULL; | |
1944 | |
1945 g_return_val_if_fail(a != NULL, 0); | |
1946 g_return_val_if_fail(b != NULL, 0); | |
1947 | |
1948 if (a->tuple != NULL) | |
1949 playlist_entry_get_info(a); | |
1950 | |
1951 if (b->tuple != NULL) | |
1952 playlist_entry_get_info(b); | |
1953 | |
1954 if (a->tuple != NULL && a->tuple->performer != NULL) | |
1955 a_artist = a->tuple->performer; | |
1956 if (b->tuple != NULL && b->tuple->performer != NULL) | |
1957 b_artist = b->tuple->performer; | |
1958 | |
1959 if (a_artist != NULL && b_artist != NULL) | |
1960 return strcasecmp(a_artist, b_artist); | |
1961 | |
1962 return 0; | |
1963 } | |
1964 | |
1965 static gint | |
1966 playlist_compare_filename(PlaylistEntry * a, | |
1967 PlaylistEntry * b) | |
1968 { | |
1969 gchar *a_filename, *b_filename; | |
1970 | |
1971 g_return_val_if_fail(a != NULL, 0); | |
1972 g_return_val_if_fail(b != NULL, 0); | |
1973 | |
1974 if (strrchr(a->filename, '/')) | |
1975 a_filename = strrchr(a->filename, '/') + 1; | |
1976 else | |
1977 a_filename = a->filename; | |
1978 | |
1979 if (strrchr(b->filename, '/')) | |
1980 b_filename = strrchr(b->filename, '/') + 1; | |
1981 else | |
1982 b_filename = b->filename; | |
1983 | |
1984 | |
1985 return strcasecmp(a_filename, b_filename); | |
1986 } | |
1987 | |
1988 static gint | |
1989 path_compare(const gchar * a, const gchar * b) | |
1990 { | |
1991 gchar *posa, *posb; | |
1992 gint len, ret; | |
1993 | |
1994 posa = strrchr(a, '/'); | |
1995 posb = strrchr(b, '/'); | |
1996 | |
1997 /* | |
1998 * Sort directories before files | |
1999 */ | |
2000 if (posa && posb && (posa - a != posb - b)) { | |
2001 if (posa - a > posb - b) { | |
2002 len = posb - b; | |
2003 ret = -1; | |
2004 } | |
2005 else { | |
2006 len = posa - a; | |
2007 ret = 1; | |
2008 } | |
2009 if (!strncasecmp(a, b, len)) | |
2010 return ret; | |
2011 } | |
2012 return strcasecmp(a, b); | |
2013 } | |
2014 | |
2015 static gint | |
2016 playlist_compare_path(PlaylistEntry * a, | |
2017 PlaylistEntry * b) | |
2018 { | |
2019 return path_compare(a->filename, b->filename); | |
2020 } | |
2021 | |
2022 | |
2023 static time_t | |
2024 playlist_get_mtime(const gchar *filename) | |
2025 { | |
2026 struct stat buf; | |
2027 gint rv; | |
2028 | |
2029 rv = stat(filename, &buf); | |
2030 | |
2031 if (rv == 0) { | |
2032 return buf.st_mtime; | |
2033 } else { | |
2034 return 0; //error | |
2035 } | |
2036 } | |
2037 | |
2038 | |
2039 static gint | |
2040 playlist_compare_date(PlaylistEntry * a, | |
2041 PlaylistEntry * b) | |
2042 { | |
2043 struct stat buf; | |
2044 time_t modtime; | |
2045 | |
2046 gint rv; | |
2047 | |
2048 | |
2049 rv = stat(a->filename, &buf); | |
2050 | |
2051 if (rv == 0) { | |
2052 modtime = buf.st_mtime; | |
2053 rv = stat(b->filename, &buf); | |
2054 | |
2055 if (stat(b->filename, &buf) == 0) { | |
2056 if (buf.st_mtime == modtime) | |
2057 return 0; | |
2058 else | |
2059 return (buf.st_mtime - modtime) > 0 ? -1 : 1; | |
2060 } | |
2061 else | |
2062 return -1; | |
2063 } | |
2064 else if (!lstat(b->filename, &buf)) | |
2065 return 1; | |
2066 else | |
2067 return playlist_compare_filename(a, b); | |
2068 } | |
2069 | |
2070 | |
2071 void | |
2072 playlist_sort(Playlist *playlist, PlaylistSortType type) | |
2073 { | |
2074 playlist_remove_dead_files(playlist); | |
2075 PLAYLIST_LOCK(playlist->mutex); | |
2076 playlist->entries = | |
2077 g_list_sort(playlist->entries, | |
2078 (GCompareFunc) playlist_compare_func_table[type]); | |
2079 PLAYLIST_UNLOCK(playlist->mutex); | |
2080 } | |
2081 | |
2082 static GList * | |
2083 playlist_sort_selected_generic(GList * list, GCompareFunc cmpfunc) | |
2084 { | |
2085 GList *list1, *list2; | |
2086 GList *tmp_list = NULL; | |
2087 GList *index_list = NULL; | |
2088 | |
2089 /* | |
2090 * We take all the selected entries out of the playlist, | |
2091 * sorts them, and then put them back in again. | |
2092 */ | |
2093 | |
2094 list1 = g_list_last(list); | |
2095 | |
2096 while (list1) { | |
2097 list2 = g_list_previous(list1); | |
2098 if (PLAYLIST_ENTRY(list1->data)->selected) { | |
2099 gpointer idx; | |
2100 idx = GINT_TO_POINTER(g_list_position(list, list1)); | |
2101 index_list = g_list_prepend(index_list, idx); | |
2102 list = g_list_remove_link(list, list1); | |
2103 tmp_list = g_list_concat(list1, tmp_list); | |
2104 } | |
2105 list1 = list2; | |
2106 } | |
2107 | |
2108 tmp_list = g_list_sort(tmp_list, cmpfunc); | |
2109 list1 = tmp_list; | |
2110 list2 = index_list; | |
2111 | |
2112 while (list2) { | |
2113 if (!list1) { | |
2114 g_critical(G_STRLOC ": Error during list sorting. " | |
2115 "Possibly dropped some playlist-entries."); | |
2116 break; | |
2117 } | |
2118 | |
2119 list = g_list_insert(list, list1->data, GPOINTER_TO_INT(list2->data)); | |
2120 | |
2121 list2 = g_list_next(list2); | |
2122 list1 = g_list_next(list1); | |
2123 } | |
2124 | |
2125 g_list_free(index_list); | |
2126 g_list_free(tmp_list); | |
2127 | |
2128 return list; | |
2129 } | |
2130 | |
2131 void | |
2132 playlist_sort_selected(Playlist *playlist, PlaylistSortType type) | |
2133 { | |
2134 PLAYLIST_LOCK(playlist->mutex); | |
2135 playlist->entries = playlist_sort_selected_generic(playlist->entries, (GCompareFunc) | |
2136 playlist_compare_func_table | |
2137 [type]); | |
2138 PLAYLIST_UNLOCK(playlist->mutex); | |
2139 } | |
2140 | |
2141 void | |
2142 playlist_reverse(Playlist *playlist) | |
2143 { | |
2144 PLAYLIST_LOCK(playlist->mutex); | |
2145 playlist->entries = g_list_reverse(playlist->entries); | |
2146 PLAYLIST_UNLOCK(playlist->mutex); | |
2147 } | |
2148 | |
2149 static GList * | |
2150 playlist_shuffle_list(Playlist *playlist, GList * list) | |
2151 { | |
2152 /* | |
2153 * Note that this doesn't make a copy of the original list. | |
2154 * The pointer to the original list is not valid after this | |
2155 * fuction is run. | |
2156 */ | |
2157 gint len = g_list_length(list); | |
2158 gint i, j; | |
2159 GList *node, **ptrs; | |
2160 | |
2161 if (!playlist) | |
2162 return NULL; | |
2163 | |
2164 REQUIRE_LOCK(playlist->mutex); | |
2165 | |
2166 if (!len) | |
2167 return NULL; | |
2168 | |
2169 ptrs = g_new(GList *, len); | |
2170 | |
2171 for (node = list, i = 0; i < len; node = g_list_next(node), i++) | |
2172 ptrs[i] = node; | |
2173 | |
2174 j = g_random_int_range(0, len); | |
2175 list = ptrs[j]; | |
2176 ptrs[j]->next = NULL; | |
2177 ptrs[j] = ptrs[0]; | |
2178 | |
2179 for (i = 1; i < len; i++) { | |
2180 j = g_random_int_range(0, len - i); | |
2181 list->prev = ptrs[i + j]; | |
2182 ptrs[i + j]->next = list; | |
2183 list = ptrs[i + j]; | |
2184 ptrs[i + j] = ptrs[i]; | |
2185 } | |
2186 list->prev = NULL; | |
2187 | |
2188 g_free(ptrs); | |
2189 | |
2190 return list; | |
2191 } | |
2192 | |
2193 void | |
2194 playlist_random(Playlist *playlist) | |
2195 { | |
2196 PLAYLIST_LOCK(playlist->mutex); | |
2197 playlist->entries = playlist_shuffle_list(playlist, playlist->entries); | |
2198 PLAYLIST_UNLOCK(playlist->mutex); | |
2199 } | |
2200 | |
2201 GList * | |
2202 playlist_get_selected(Playlist *playlist) | |
2203 { | |
2204 GList *node, *list = NULL; | |
2205 gint i = 0; | |
2206 | |
2207 PLAYLIST_LOCK(playlist->mutex); | |
2208 for (node = playlist->entries; node; node = g_list_next(node), i++) { | |
2209 PlaylistEntry *entry = node->data; | |
2210 if (entry->selected) | |
2211 list = g_list_prepend(list, GINT_TO_POINTER(i)); | |
2212 } | |
2213 PLAYLIST_UNLOCK(playlist->mutex); | |
2214 return g_list_reverse(list); | |
2215 } | |
2216 | |
2217 void | |
2218 playlist_clear_selected(Playlist *playlist) | |
2219 { | |
2220 GList *node = NULL; | |
2221 gint i = 0; | |
2222 | |
2223 PLAYLIST_LOCK(playlist->mutex); | |
2224 for (node = playlist->entries; node; node = g_list_next(node), i++) { | |
2225 PLAYLIST_ENTRY(node->data)->selected = FALSE; | |
2226 } | |
2227 PLAYLIST_UNLOCK(playlist->mutex); | |
2228 playlist_recalc_total_time(playlist); | |
2229 playlist_manager_update(); | |
2230 } | |
2231 | |
2232 gint | |
2233 playlist_get_num_selected(Playlist *playlist) | |
2234 { | |
2235 GList *node; | |
2236 gint num = 0; | |
2237 | |
2238 PLAYLIST_LOCK(playlist->mutex); | |
2239 for (node = playlist->entries; node; node = g_list_next(node)) { | |
2240 PlaylistEntry *entry = node->data; | |
2241 if (entry->selected) | |
2242 num++; | |
2243 } | |
2244 PLAYLIST_UNLOCK(playlist->mutex); | |
2245 return num; | |
2246 } | |
2247 | |
2248 | |
2249 static void | |
2250 playlist_generate_shuffle_list(Playlist *playlist) | |
2251 { | |
2252 PLAYLIST_LOCK(playlist->mutex); | |
2253 playlist_generate_shuffle_list_nolock(playlist); | |
2254 PLAYLIST_UNLOCK(playlist->mutex); | |
2255 } | |
2256 | |
2257 static void | |
2258 playlist_generate_shuffle_list_nolock(Playlist *playlist) | |
2259 { | |
2260 GList *node; | |
2261 gint numsongs; | |
2262 | |
2263 if (!cfg.shuffle || !playlist) | |
2264 return; | |
2265 | |
2266 REQUIRE_LOCK(playlist->mutex); | |
2267 | |
2268 if (playlist->shuffle) { | |
2269 g_list_free(playlist->shuffle); | |
2270 playlist->shuffle = NULL; | |
2271 } | |
2272 | |
2273 playlist->shuffle = playlist_shuffle_list(playlist, g_list_copy(playlist->entries)); | |
2274 numsongs = g_list_length(playlist->shuffle); | |
2275 | |
2276 if (playlist->position) { | |
2277 gint i = g_list_index(playlist->shuffle, playlist->position); | |
2278 node = g_list_nth(playlist->shuffle, i); | |
2279 playlist->shuffle = g_list_remove_link(playlist->shuffle, node); | |
2280 playlist->shuffle = g_list_prepend(playlist->shuffle, node->data); | |
2281 } | |
2282 } | |
2283 | |
2284 void | |
2285 playlist_fileinfo(Playlist *playlist, guint pos) | |
2286 { | |
2287 gchar *path = NULL; | |
2288 GList *node; | |
2289 PlaylistEntry *entry = NULL; | |
2290 TitleInput *tuple = NULL; | |
2291 | |
2292 PLAYLIST_LOCK(playlist->mutex); | |
2293 | |
2294 if ((node = g_list_nth(playlist->entries, pos))) | |
2295 { | |
2296 entry = node->data; | |
2297 tuple = entry->tuple; | |
2298 path = g_strdup(entry->filename); | |
2299 } | |
2300 | |
2301 PLAYLIST_UNLOCK(playlist->mutex); | |
2302 | |
2303 /* No tuple? Try to set this entry up properly. --nenolod */ | |
2304 if (entry->tuple == NULL || entry->tuple->mtime == -1 || | |
2305 entry->tuple->mtime == 0 || entry->tuple->mtime != playlist_get_mtime(entry->filename)) | |
2306 { | |
2307 playlist_entry_get_info(entry); | |
2308 tuple = entry->tuple; | |
2309 } | |
2310 | |
2311 if (tuple != NULL) | |
2312 { | |
2313 if (entry->decoder == NULL) | |
2314 entry->decoder = input_check_file(entry->filename, FALSE); /* try to find a decoder */ | |
2315 | |
2316 if (entry->decoder != NULL && entry->decoder->file_info_box == NULL) | |
2317 fileinfo_show_for_tuple(tuple); | |
2318 else if (entry->decoder != NULL && entry->decoder->file_info_box != NULL) | |
2319 entry->decoder->file_info_box(path); | |
2320 else | |
2321 fileinfo_show_for_path(path); | |
2322 g_free(path); | |
2323 } | |
2324 else if (path != NULL) | |
2325 { | |
2326 if (entry != NULL && entry->decoder != NULL && entry->decoder->file_info_box != NULL) | |
2327 entry->decoder->file_info_box(path); | |
2328 else | |
2329 fileinfo_show_for_path(path); | |
2330 g_free(path); | |
2331 } | |
2332 } | |
2333 | |
2334 void | |
2335 playlist_fileinfo_current(Playlist *playlist) | |
2336 { | |
2337 gchar *path = NULL; | |
2338 TitleInput *tuple = NULL; | |
2339 | |
2340 PLAYLIST_LOCK(playlist->mutex); | |
2341 | |
2342 if (playlist->entries && playlist->position) | |
2343 { | |
2344 path = g_strdup(playlist->position->filename); | |
2345 if (( playlist->position->tuple == NULL ) || ( playlist->position->decoder == NULL )) | |
2346 playlist_entry_get_info(playlist->position); | |
2347 tuple = playlist->position->tuple; | |
2348 } | |
2349 | |
2350 PLAYLIST_UNLOCK(playlist->mutex); | |
2351 | |
2352 if (tuple != NULL) | |
2353 { | |
2354 if (playlist->position->decoder != NULL && playlist->position->decoder->file_info_box == NULL) | |
2355 fileinfo_show_for_tuple(tuple); | |
2356 else if (playlist->position->decoder != NULL && playlist->position->decoder->file_info_box != NULL) | |
2357 playlist->position->decoder->file_info_box(path); | |
2358 else | |
2359 fileinfo_show_for_path(path); | |
2360 g_free(path); | |
2361 } | |
2362 else if (path != NULL) | |
2363 { | |
2364 if (playlist->position != NULL && playlist->position->decoder != NULL && playlist->position->decoder->file_info_box != NULL) | |
2365 playlist->position->decoder->file_info_box(path); | |
2366 else | |
2367 fileinfo_show_for_path(path); | |
2368 g_free(path); | |
2369 } | |
2370 } | |
2371 | |
2372 | |
2373 static gboolean | |
2374 playlist_get_info_is_going(void) | |
2375 { | |
2376 gboolean result; | |
2377 | |
2378 G_LOCK(playlist_get_info_going); | |
2379 result = playlist_get_info_going; | |
2380 G_UNLOCK(playlist_get_info_going); | |
2381 | |
2382 return result; | |
2383 } | |
2384 | |
2385 static gpointer | |
2386 playlist_get_info_func(gpointer arg) | |
2387 { | |
2388 GList *node; | |
2389 gboolean update_playlistwin = FALSE; | |
2390 gboolean update_mainwin = FALSE; | |
2391 | |
2392 while (playlist_get_info_is_going()) { | |
2393 PlaylistEntry *entry; | |
2394 Playlist *playlist = playlist_get_active(); | |
2395 | |
2396 // on_load | |
2397 if (cfg.use_pl_metadata && | |
2398 cfg.get_info_on_load && | |
2399 playlist_get_info_scan_active) { | |
2400 | |
2401 PLAYLIST_LOCK(playlist->mutex); | |
2402 for (node = playlist->entries; node; node = g_list_next(node)) { | |
2403 entry = node->data; | |
2404 | |
2405 if(entry->tuple && (entry->tuple->length > -1)) { | |
2406 update_playlistwin = TRUE; | |
2407 continue; | |
2408 } | |
2409 | |
2410 if (!playlist_entry_get_info(entry)) { | |
2411 if (g_list_index(playlist->entries, entry) == -1) | |
2412 /* Entry disappeared while we looked it up. | |
2413 Restart. */ | |
2414 node = playlist->entries; | |
2415 } | |
2416 else if ((entry->tuple != NULL || entry->title != NULL) && entry->length != -1) { | |
2417 update_playlistwin = TRUE; | |
2418 if (entry == playlist->position) | |
2419 update_mainwin = TRUE; | |
2420 break; | |
2421 } | |
2422 } | |
2423 PLAYLIST_UNLOCK(playlist->mutex); | |
2424 | |
2425 if (!node) { | |
2426 g_mutex_lock(mutex_scan); | |
2427 playlist_get_info_scan_active = FALSE; | |
2428 g_mutex_unlock(mutex_scan); | |
2429 } | |
2430 } // on_load | |
2431 | |
2432 // on_demand | |
2433 else if (!cfg.get_info_on_load && | |
2434 cfg.get_info_on_demand && | |
2435 cfg.playlist_visible && | |
2436 !cfg.playlist_shaded && | |
2437 cfg.use_pl_metadata) { | |
2438 | |
2439 g_mutex_lock(mutex_scan); | |
2440 playlist_get_info_scan_active = FALSE; | |
2441 g_mutex_unlock(mutex_scan); | |
2442 | |
2443 PLAYLIST_LOCK(playlist->mutex); | |
2444 | |
2445 if (!playlist->entries) { | |
2446 PLAYLIST_UNLOCK(playlist->mutex); | |
2447 } | |
2448 else { | |
2449 for (node = g_list_nth(playlist->entries, playlistwin_get_toprow()); | |
2450 node && playlistwin_item_visible(g_list_position(playlist->entries, node)); | |
2451 node = g_list_next(node)) { | |
2452 | |
2453 entry = node->data; | |
2454 | |
2455 if(entry->tuple && (entry->tuple->length > -1)) { | |
2456 update_playlistwin = TRUE; | |
2457 continue; | |
2458 } | |
2459 | |
2460 if (!playlist_entry_get_info(entry)) { | |
2461 if (g_list_index(playlist->entries, entry) == -1) | |
2462 /* Entry disapeared while we | |
2463 looked it up. Restart. */ | |
2464 node = | |
2465 g_list_nth(playlist->entries, | |
2466 playlistwin_get_toprow()); | |
2467 } | |
2468 else if ((entry->tuple != NULL || entry->title != NULL) && entry->length != -1) { | |
2469 update_playlistwin = TRUE; | |
2470 if (entry == playlist->position) | |
2471 update_mainwin = TRUE; | |
2545
610d85b8a22b
[svn] - on loading a playlist with tuple, invoke the scanner thread only if mtime is -1.
yaz
parents:
2504
diff
changeset
|
2472 // no need for break here since this iteration is very short. |
2313 | 2473 } |
2474 } | |
2475 PLAYLIST_UNLOCK(playlist->mutex); | |
2476 } | |
2477 } // on_demand | |
2478 else if (cfg.get_info_on_demand && | |
2479 (!cfg.playlist_visible || cfg.playlist_shaded | |
2480 || !cfg.use_pl_metadata)) | |
2481 { | |
2482 g_mutex_lock(mutex_scan); | |
2483 playlist_get_info_scan_active = FALSE; | |
2484 g_mutex_unlock(mutex_scan); | |
2485 } | |
2486 else /* not on_demand and not on_load... | |
2487 NOTE: this shouldn't happen anymore, sanity check in bmp_config_load now */ | |
2488 { | |
2489 g_mutex_lock(mutex_scan); | |
2490 playlist_get_info_scan_active = FALSE; | |
2491 g_mutex_unlock(mutex_scan); | |
2492 } | |
2493 | |
2494 if (update_playlistwin) { | |
2495 playlistwin_update_list(playlist); | |
2496 update_playlistwin = FALSE; | |
2497 } | |
2498 | |
2499 if (update_mainwin) { | |
2500 mainwin_set_info_text(); | |
2501 update_mainwin = FALSE; | |
2502 } | |
2503 | |
2504 if (playlist_get_info_scan_active) { | |
2505 continue; | |
2506 } | |
2507 | |
2508 g_mutex_lock(mutex_scan); | |
2509 g_cond_wait(cond_scan, mutex_scan); | |
2510 g_mutex_unlock(mutex_scan); | |
2511 | |
2512 } // while | |
2513 | |
2514 g_thread_exit(NULL); | |
2515 return NULL; | |
2516 } | |
2517 | |
2518 void | |
2519 playlist_start_get_info_thread(void) | |
2520 { | |
2521 G_LOCK(playlist_get_info_going); | |
2522 playlist_get_info_going = TRUE; | |
2523 G_UNLOCK(playlist_get_info_going); | |
2524 | |
2525 playlist_get_info_thread = g_thread_create(playlist_get_info_func, | |
2526 NULL, TRUE, NULL); | |
2527 } | |
2528 | |
2529 void | |
2530 playlist_stop_get_info_thread(void) | |
2531 { | |
2532 G_LOCK(playlist_get_info_going); | |
2533 playlist_get_info_going = FALSE; | |
2534 G_UNLOCK(playlist_get_info_going); | |
2535 | |
2536 g_cond_broadcast(cond_scan); | |
2537 g_thread_join(playlist_get_info_thread); | |
2538 } | |
2539 | |
2540 void | |
2541 playlist_start_get_info_scan(void) | |
2542 { | |
2543 g_mutex_lock(mutex_scan); | |
2544 playlist_get_info_scan_active = TRUE; | |
2545 g_mutex_unlock(mutex_scan); | |
2546 g_cond_signal(cond_scan); | |
2547 } | |
2548 | |
2549 void | |
2550 playlist_remove_dead_files(Playlist *playlist) | |
2551 { | |
2552 GList *node, *next_node; | |
2553 | |
2554 PLAYLIST_LOCK(playlist->mutex); | |
2555 | |
2556 for (node = playlist->entries; node; node = next_node) { | |
2557 PlaylistEntry *entry = PLAYLIST_ENTRY(node->data); | |
2558 next_node = g_list_next(node); | |
2559 | |
2560 if (!entry || !entry->filename) { | |
2561 g_message(G_STRLOC ": Playlist entry is invalid!"); | |
2562 continue; | |
2563 } | |
2564 | |
2565 /* FIXME: What about 'file:///'? */ | |
2566 /* Don't kill URLs */ | |
2567 if (strstr(entry->filename, "://")) | |
2568 continue; | |
2569 | |
2570 /* FIXME: Should test for readability */ | |
2571 if (vfs_file_test(entry->filename, G_FILE_TEST_EXISTS)) | |
2572 continue; | |
2573 | |
2574 if (entry == playlist->position) { | |
2575 /* Don't remove the currently playing song */ | |
2576 if (playback_get_playing()) | |
2577 continue; | |
2578 | |
2579 if (next_node) | |
2580 playlist->position = PLAYLIST_ENTRY(next_node->data); | |
2581 else | |
2582 playlist->position = NULL; | |
2583 } | |
2584 | |
2585 playlist_entry_free(entry); | |
2586 playlist->entries = g_list_delete_link(playlist->entries, node); | |
2587 } | |
2588 | |
2589 PLAYLIST_UNLOCK(playlist->mutex); | |
2590 | |
2591 playlist_generate_shuffle_list(playlist); | |
2592 playlistwin_update_list(playlist); | |
2593 playlist_recalc_total_time(playlist); | |
2594 playlist_manager_update(); | |
2595 } | |
2596 | |
2597 | |
2598 static gint | |
2599 playlist_dupscmp_title(PlaylistEntry * a, | |
2600 PlaylistEntry * b) | |
2601 { | |
2602 const gchar *a_title, *b_title; | |
2603 | |
2604 g_return_val_if_fail(a != NULL, 0); | |
2605 g_return_val_if_fail(b != NULL, 0); | |
2606 | |
2607 if (a->title) | |
2608 a_title = a->title; | |
2609 else { | |
2610 if (strrchr(a->filename, '/')) | |
2611 a_title = strrchr(a->filename, '/') + 1; | |
2612 else | |
2613 a_title = a->filename; | |
2614 } | |
2615 | |
2616 if (b->title) | |
2617 b_title = b->title; | |
2618 else { | |
2619 if (strrchr(a->filename, '/')) | |
2620 b_title = strrchr(b->filename, '/') + 1; | |
2621 else | |
2622 b_title = b->filename; | |
2623 } | |
2624 | |
2625 return strcmp(a_title, b_title); | |
2626 } | |
2627 | |
2628 static gint | |
2629 playlist_dupscmp_filename(PlaylistEntry * a, | |
2630 PlaylistEntry * b ) | |
2631 { | |
2632 gchar *a_filename, *b_filename; | |
2633 | |
2634 g_return_val_if_fail(a != NULL, 0); | |
2635 g_return_val_if_fail(b != NULL, 0); | |
2636 | |
2637 if (strrchr(a->filename, '/')) | |
2638 a_filename = strrchr(a->filename, '/') + 1; | |
2639 else | |
2640 a_filename = a->filename; | |
2641 | |
2642 if (strrchr(b->filename, '/')) | |
2643 b_filename = strrchr(b->filename, '/') + 1; | |
2644 else | |
2645 b_filename = b->filename; | |
2646 | |
2647 return strcmp(a_filename, b_filename); | |
2648 } | |
2649 | |
2650 static gint | |
2651 playlist_dupscmp_path(PlaylistEntry * a, | |
2652 PlaylistEntry * b) | |
2653 { | |
2654 /* simply compare the entire filename string */ | |
2655 return strcmp(a->filename, b->filename); | |
2656 } | |
2657 | |
2658 void | |
2659 playlist_remove_duplicates(Playlist *playlist, PlaylistDupsType type) | |
2660 { | |
2661 GList *node, *next_node; | |
2662 GList *node_cmp, *next_node_cmp; | |
2663 gint (*dups_compare_func)(PlaylistEntry * , PlaylistEntry *); | |
2664 | |
2665 switch ( type ) | |
2666 { | |
2667 case PLAYLIST_DUPS_TITLE: | |
2668 dups_compare_func = playlist_dupscmp_title; | |
2669 break; | |
2670 case PLAYLIST_DUPS_PATH: | |
2671 dups_compare_func = playlist_dupscmp_path; | |
2672 break; | |
2673 case PLAYLIST_DUPS_FILENAME: | |
2674 default: | |
2675 dups_compare_func = playlist_dupscmp_filename; | |
2676 break; | |
2677 } | |
2678 | |
2679 PLAYLIST_LOCK(playlist->mutex); | |
2680 | |
2681 for (node = playlist->entries; node; node = next_node) { | |
2682 PlaylistEntry *entry = PLAYLIST_ENTRY(node->data); | |
2683 next_node = g_list_next(node); | |
2684 | |
2685 if (!entry || !entry->filename) { | |
2686 g_message(G_STRLOC ": Playlist entry is invalid!"); | |
2687 continue; | |
2688 } | |
2689 | |
2690 for (node_cmp = next_node; node_cmp; node_cmp = next_node_cmp) { | |
2691 PlaylistEntry *entry_cmp = PLAYLIST_ENTRY(node_cmp->data); | |
2692 next_node_cmp = g_list_next(node_cmp); | |
2693 | |
2694 if (!entry_cmp || !entry_cmp->filename) { | |
2695 g_message(G_STRLOC ": Playlist entry is invalid!"); | |
2696 continue; | |
2697 } | |
2698 | |
2699 /* compare using the chosen dups_compare_func */ | |
2700 if ( !dups_compare_func( entry , entry_cmp ) ) { | |
2701 | |
2702 if (entry_cmp == playlist->position) { | |
2703 /* Don't remove the currently playing song */ | |
2704 if (playback_get_playing()) | |
2705 continue; | |
2706 | |
2707 if (next_node_cmp) | |
2708 playlist->position = PLAYLIST_ENTRY(next_node_cmp->data); | |
2709 else | |
2710 playlist->position = NULL; | |
2711 } | |
2712 | |
2713 /* check if this was the next item of the external | |
2714 loop; if true, replace it with the next of the next*/ | |
2715 if ( node_cmp == next_node ) | |
2716 next_node = g_list_next(next_node); | |
2717 | |
2718 playlist_entry_free(entry_cmp); | |
2719 playlist->entries = g_list_delete_link(playlist->entries, node_cmp); | |
2720 } | |
2721 } | |
2722 } | |
2723 | |
2724 PLAYLIST_UNLOCK(playlist->mutex); | |
2725 | |
2726 playlistwin_update_list(playlist); | |
2727 playlist_recalc_total_time(playlist); | |
2728 | |
2729 playlist_manager_update(); | |
2730 } | |
2731 | |
2732 void | |
2733 playlist_get_total_time(Playlist * playlist, | |
2734 gulong * total_time, | |
2735 gulong * selection_time, | |
2736 gboolean * total_more, | |
2737 gboolean * selection_more) | |
2738 { | |
2739 PLAYLIST_LOCK(playlist->mutex); | |
2740 *total_time = playlist->pl_total_time; | |
2741 *selection_time = playlist->pl_selection_time; | |
2742 *total_more = playlist->pl_total_more; | |
2743 *selection_more = playlist->pl_selection_more; | |
2744 PLAYLIST_UNLOCK(playlist->mutex); | |
2745 } | |
2746 | |
2747 | |
2748 static void | |
2749 playlist_recalc_total_time_nolock(Playlist *playlist) | |
2750 { | |
2751 GList *list; | |
2752 PlaylistEntry *entry; | |
2753 | |
2754 REQUIRE_LOCK(playlist->mutex); | |
2755 | |
2756 playlist->pl_total_time = 0; | |
2757 playlist->pl_selection_time = 0; | |
2758 playlist->pl_total_more = FALSE; | |
2759 playlist->pl_selection_more = FALSE; | |
2760 | |
2761 for (list = playlist->entries; list; list = g_list_next(list)) { | |
2762 entry = list->data; | |
2763 | |
2764 if (entry->length != -1) | |
2765 playlist->pl_total_time += entry->length / 1000; | |
2766 else | |
2767 playlist->pl_total_more = TRUE; | |
2768 | |
2769 if (entry->selected) { | |
2770 if (entry->length != -1) | |
2771 playlist->pl_selection_time += entry->length / 1000; | |
2772 else | |
2773 playlist->pl_selection_more = TRUE; | |
2774 } | |
2775 } | |
2776 } | |
2777 | |
2778 static void | |
2779 playlist_recalc_total_time(Playlist *playlist) | |
2780 { | |
2781 PLAYLIST_LOCK(playlist->mutex); | |
2782 playlist_recalc_total_time_nolock(playlist); | |
2783 PLAYLIST_UNLOCK(playlist->mutex); | |
2784 } | |
2785 | |
2786 gint | |
2787 playlist_select_search( Playlist *playlist , TitleInput *tuple , gint action ) | |
2788 { | |
2789 GList *entry_list = NULL, *found_list = NULL, *sel_list = NULL; | |
2790 gboolean is_first_search = TRUE; | |
2791 gint num_of_entries_found = 0; | |
2792 | |
2793 #if defined(USE_REGEX_ONIGURUMA) | |
2794 /* set encoding for Oniguruma regex to UTF-8 */ | |
2795 reg_set_encoding( REG_POSIX_ENCODING_UTF8 ); | |
2796 onig_set_default_syntax( ONIG_SYNTAX_POSIX_BASIC ); | |
2797 #endif | |
2798 | |
2799 PLAYLIST_LOCK(playlist->mutex); | |
2800 | |
2801 if ( tuple->track_name != NULL ) | |
2802 { | |
2803 /* match by track_name */ | |
2804 const gchar *regex_pattern = tuple->track_name; | |
2805 regex_t regex; | |
2806 #if defined(USE_REGEX_PCRE) | |
2807 if ( regcomp( ®ex , regex_pattern , REG_NOSUB | REG_ICASE | REG_UTF8 ) == 0 ) | |
2808 #else | |
2809 if ( regcomp( ®ex , regex_pattern , REG_NOSUB | REG_ICASE ) == 0 ) | |
2810 #endif | |
2811 { | |
2812 GList *tfound_list = NULL; | |
2813 if ( is_first_search == TRUE ) entry_list = playlist->entries; | |
2814 else entry_list = found_list; /* use found_list */ | |
2815 for ( ; entry_list ; entry_list = g_list_next(entry_list) ) | |
2816 { | |
2817 PlaylistEntry *entry = entry_list->data; | |
2818 if ( ( entry->tuple != NULL ) && ( entry->tuple->track_name != NULL ) && | |
2819 ( regexec( ®ex , entry->tuple->track_name , 0 , NULL , 0 ) == 0 ) ) | |
2820 { | |
2821 tfound_list = g_list_append( tfound_list , entry ); | |
2822 } | |
2823 } | |
2824 g_list_free( found_list ); /* wipe old found_list */ | |
2825 found_list = tfound_list; /* move tfound_list in found_list */ | |
2826 regfree( ®ex ); | |
2827 } | |
2828 is_first_search = FALSE; | |
2829 } | |
2830 | |
2831 if ( tuple->album_name != NULL ) | |
2832 { | |
2833 /* match by album_name */ | |
2834 const gchar *regex_pattern = tuple->album_name; | |
2835 regex_t regex; | |
2836 #if defined(USE_REGEX_PCRE) | |
2837 if ( regcomp( ®ex , regex_pattern , REG_NOSUB | REG_ICASE | REG_UTF8 ) == 0 ) | |
2838 #else | |
2839 if ( regcomp( ®ex , regex_pattern , REG_NOSUB | REG_ICASE ) == 0 ) | |
2840 #endif | |
2841 { | |
2842 GList *tfound_list = NULL; | |
2843 if ( is_first_search == TRUE ) entry_list = playlist->entries; | |
2844 else entry_list = found_list; /* use found_list */ | |
2845 for ( ; entry_list ; entry_list = g_list_next(entry_list) ) | |
2846 { | |
2847 PlaylistEntry *entry = entry_list->data; | |
2848 if ( ( entry->tuple != NULL ) && ( entry->tuple->album_name != NULL ) && | |
2849 ( regexec( ®ex , entry->tuple->album_name , 0 , NULL , 0 ) == 0 ) ) | |
2850 { | |
2851 tfound_list = g_list_append( tfound_list , entry ); | |
2852 } | |
2853 } | |
2854 g_list_free( found_list ); /* wipe old found_list */ | |
2855 found_list = tfound_list; /* move tfound_list in found_list */ | |
2856 regfree( ®ex ); | |
2857 } | |
2858 is_first_search = FALSE; | |
2859 } | |
2860 | |
2861 if ( tuple->performer != NULL ) | |
2862 { | |
2863 /* match by performer */ | |
2864 const gchar *regex_pattern = tuple->performer; | |
2865 regex_t regex; | |
2866 #if defined(USE_REGEX_PCRE) | |
2867 if ( regcomp( ®ex , regex_pattern , REG_NOSUB | REG_ICASE | REG_UTF8 ) == 0 ) | |
2868 #else | |
2869 if ( regcomp( ®ex , regex_pattern , REG_NOSUB | REG_ICASE ) == 0 ) | |
2870 #endif | |
2871 { | |
2872 GList *tfound_list = NULL; | |
2873 if ( is_first_search == TRUE ) entry_list = playlist->entries; | |
2874 else entry_list = found_list; /* use found_list */ | |
2875 for ( ; entry_list ; entry_list = g_list_next(entry_list) ) | |
2876 { | |
2877 PlaylistEntry *entry = entry_list->data; | |
2878 if ( ( entry->tuple != NULL ) && ( entry->tuple->performer != NULL ) && | |
2879 ( regexec( ®ex , entry->tuple->performer , 0 , NULL , 0 ) == 0 ) ) | |
2880 { | |
2881 tfound_list = g_list_append( tfound_list , entry ); | |
2882 } | |
2883 } | |
2884 g_list_free( found_list ); /* wipe old found_list */ | |
2885 found_list = tfound_list; /* move tfound_list in found_list */ | |
2886 regfree( ®ex ); | |
2887 } | |
2888 is_first_search = FALSE; | |
2889 } | |
2890 | |
2891 if ( tuple->file_name != NULL ) | |
2892 { | |
2893 /* match by file_name */ | |
2894 const gchar *regex_pattern = tuple->file_name; | |
2895 regex_t regex; | |
2896 #if defined(USE_REGEX_PCRE) | |
2897 if ( regcomp( ®ex , regex_pattern , REG_NOSUB | REG_ICASE | REG_UTF8 ) == 0 ) | |
2898 #else | |
2899 if ( regcomp( ®ex , regex_pattern , REG_NOSUB | REG_ICASE ) == 0 ) | |
2900 #endif | |
2901 { | |
2902 GList *tfound_list = NULL; | |
2903 if ( is_first_search == TRUE ) entry_list = playlist->entries; | |
2904 else entry_list = found_list; /* use found_list */ | |
2905 for ( ; entry_list ; entry_list = g_list_next(entry_list) ) | |
2906 { | |
2907 PlaylistEntry *entry = entry_list->data; | |
2908 if ( ( entry->tuple != NULL ) && ( entry->tuple->file_name != NULL ) && | |
2909 ( regexec( ®ex , entry->tuple->file_name , 0 , NULL , 0 ) == 0 ) ) | |
2910 { | |
2911 tfound_list = g_list_append( tfound_list , entry ); | |
2912 } | |
2913 } | |
2914 g_list_free( found_list ); /* wipe old found_list */ | |
2915 found_list = tfound_list; /* move tfound_list in found_list */ | |
2916 regfree( ®ex ); | |
2917 } | |
2918 is_first_search = FALSE; | |
2919 } | |
2920 | |
2921 /* NOTE: action = 0 -> default behaviour, select all matching entries */ | |
2922 /* if some entries are still in found_list, those | |
2923 are what the user is searching for; select them */ | |
2924 for ( sel_list = found_list ; sel_list ; sel_list = g_list_next(sel_list) ) | |
2925 { | |
2926 PlaylistEntry *entry = sel_list->data; | |
2927 entry->selected = TRUE; | |
2928 num_of_entries_found++; | |
2929 } | |
2930 | |
2931 g_list_free( found_list ); | |
2932 | |
2933 PLAYLIST_UNLOCK(playlist->mutex); | |
2934 playlist_recalc_total_time(playlist); | |
2935 | |
2936 return num_of_entries_found; | |
2937 } | |
2938 | |
2939 void | |
2940 playlist_select_all(Playlist *playlist, gboolean set) | |
2941 { | |
2942 GList *list; | |
2943 | |
2944 PLAYLIST_LOCK(playlist->mutex); | |
2945 | |
2946 for (list = playlist->entries; list; list = g_list_next(list)) { | |
2947 PlaylistEntry *entry = list->data; | |
2948 entry->selected = set; | |
2949 } | |
2950 | |
2951 PLAYLIST_UNLOCK(playlist->mutex); | |
2952 playlist_recalc_total_time(playlist); | |
2953 } | |
2954 | |
2955 void | |
2956 playlist_select_invert_all(Playlist *playlist) | |
2957 { | |
2958 GList *list; | |
2959 | |
2960 PLAYLIST_LOCK(playlist->mutex); | |
2961 | |
2962 for (list = playlist->entries; list; list = g_list_next(list)) { | |
2963 PlaylistEntry *entry = list->data; | |
2964 entry->selected = !entry->selected; | |
2965 } | |
2966 | |
2967 PLAYLIST_UNLOCK(playlist->mutex); | |
2968 playlist_recalc_total_time(playlist); | |
2969 } | |
2970 | |
2971 gboolean | |
2972 playlist_select_invert(Playlist *playlist, guint pos) | |
2973 { | |
2974 GList *list; | |
2975 gboolean invert_ok = FALSE; | |
2976 | |
2977 PLAYLIST_LOCK(playlist->mutex); | |
2978 | |
2979 if ((list = g_list_nth(playlist->entries, pos))) { | |
2980 PlaylistEntry *entry = list->data; | |
2981 entry->selected = !entry->selected; | |
2982 invert_ok = TRUE; | |
2983 } | |
2984 | |
2985 PLAYLIST_UNLOCK(playlist->mutex); | |
2986 playlist_recalc_total_time(playlist); | |
2987 | |
2988 return invert_ok; | |
2989 } | |
2990 | |
2991 | |
2992 void | |
2993 playlist_select_range(Playlist *playlist, gint min_pos, gint max_pos, gboolean select) | |
2994 { | |
2995 GList *list; | |
2996 gint i; | |
2997 | |
2998 if (min_pos > max_pos) | |
2999 SWAP(min_pos, max_pos); | |
3000 | |
3001 PLAYLIST_LOCK(playlist->mutex); | |
3002 | |
3003 list = g_list_nth(playlist->entries, min_pos); | |
3004 for (i = min_pos; i <= max_pos && list; i++) { | |
3005 PlaylistEntry *entry = list->data; | |
3006 entry->selected = select; | |
3007 list = g_list_next(list); | |
3008 } | |
3009 | |
3010 PLAYLIST_UNLOCK(playlist->mutex); | |
3011 | |
3012 playlist_recalc_total_time(playlist); | |
3013 } | |
3014 | |
3015 gboolean | |
3016 playlist_read_info_selection(Playlist *playlist) | |
3017 { | |
3018 GList *node; | |
3019 gboolean retval = FALSE; | |
3020 | |
3021 PLAYLIST_LOCK(playlist->mutex); | |
3022 | |
3023 for (node = playlist->entries; node; node = g_list_next(node)) { | |
3024 PlaylistEntry *entry = node->data; | |
3025 if (!entry->selected) | |
3026 continue; | |
3027 | |
3028 retval = TRUE; | |
3029 | |
3030 str_replace_in(&entry->title, NULL); | |
3031 entry->length = -1; | |
3032 | |
3033 /* invalidate mtime to reread */ | |
3034 if (entry->tuple != NULL) | |
3035 entry->tuple->mtime = -1; /* -1 denotes "non-initialized". now 0 is for stream etc. yaz */ | |
3036 | |
3037 if (!playlist_entry_get_info(entry)) { | |
3038 if (g_list_index(playlist->entries, entry) == -1) | |
3039 /* Entry disappeared while we looked it up. Restart. */ | |
3040 node = playlist->entries; | |
3041 } | |
3042 } | |
3043 | |
3044 PLAYLIST_UNLOCK(playlist->mutex); | |
3045 | |
3046 playlistwin_update_list(playlist); | |
3047 playlist_recalc_total_time(playlist); | |
3048 | |
3049 return retval; | |
3050 } | |
3051 | |
3052 void | |
3053 playlist_read_info(Playlist *playlist, guint pos) | |
3054 { | |
3055 GList *node; | |
3056 | |
3057 PLAYLIST_LOCK(playlist->mutex); | |
3058 | |
3059 if ((node = g_list_nth(playlist->entries, pos))) { | |
3060 PlaylistEntry *entry = node->data; | |
3061 str_replace_in(&entry->title, NULL); | |
3062 entry->length = -1; | |
3063 playlist_entry_get_info(entry); | |
3064 } | |
3065 | |
3066 PLAYLIST_UNLOCK(playlist->mutex); | |
3067 | |
3068 playlistwin_update_list(playlist); | |
3069 playlist_recalc_total_time(playlist); | |
3070 } | |
3071 | |
3072 Playlist * | |
3073 playlist_get_active(void) | |
3074 { | |
3075 if (playlists_iter != NULL) | |
3076 return (Playlist *) playlists_iter->data; | |
3077 | |
3078 return (Playlist *) playlists->data; | |
3079 } | |
3080 | |
3081 void | |
3082 playlist_set_shuffle(gboolean shuffle) | |
3083 { | |
3084 Playlist *playlist = playlist_get_active(); | |
3085 if (!playlist) | |
3086 return; | |
3087 | |
3088 PLAYLIST_LOCK(playlist->mutex); | |
3089 | |
3090 playlist_position_before_jump = NULL; | |
3091 | |
3092 cfg.shuffle = shuffle; | |
3093 playlist_generate_shuffle_list_nolock(playlist); | |
3094 | |
3095 PLAYLIST_UNLOCK(playlist->mutex); | |
3096 } | |
3097 | |
3098 Playlist * | |
3099 playlist_new(void) | |
3100 { | |
3101 Playlist *playlist = g_new0(Playlist, 1); | |
3102 playlist->mutex = g_mutex_new(); | |
3103 playlist->loading_playlist = FALSE; | |
3104 | |
3105 playlist_set_current_name(playlist, NULL); | |
3106 playlist_clear(playlist); | |
3107 | |
3108 return playlist; | |
3109 } | |
3110 | |
3111 void | |
3112 playlist_free(Playlist *playlist) | |
3113 { | |
3114 g_mutex_free( playlist->mutex ); | |
3115 g_free( playlist ); | |
3116 return; | |
3117 } | |
3118 | |
3119 Playlist * | |
3120 playlist_new_from_selected(void) | |
3121 { | |
3122 Playlist *newpl = playlist_new(); | |
3123 Playlist *playlist = playlist_get_active(); | |
3124 GList *list = playlist_get_selected(playlist); | |
3125 | |
3126 playlist_add_playlist( newpl ); | |
3127 | |
3128 PLAYLIST_LOCK(playlist->mutex); | |
3129 | |
3130 while ( list != NULL ) | |
3131 { | |
3132 PlaylistEntry *entry = g_list_nth_data(playlist->entries, GPOINTER_TO_INT(list->data)); | |
3133 if ( entry->filename != NULL ) /* paranoid? oh well... */ | |
3134 playlist_add( newpl , entry->filename ); | |
3135 list = g_list_next(list); | |
3136 } | |
3137 | |
3138 PLAYLIST_UNLOCK(playlist->mutex); | |
3139 | |
3140 playlist_recalc_total_time(newpl); | |
3141 playlistwin_update_list(playlist); | |
3142 | |
3143 return newpl; | |
3144 } | |
3145 | |
3146 const gchar * | |
3147 playlist_get_filename_to_play(Playlist *playlist) | |
3148 { | |
3149 const gchar *filename = NULL; | |
3150 | |
3151 if (!playlist) | |
3152 return NULL; | |
3153 | |
3154 PLAYLIST_LOCK(playlist->mutex); | |
3155 | |
3156 if (!playlist->position) { | |
3157 if (cfg.shuffle) | |
3158 playlist->position = playlist->shuffle->data; | |
3159 else | |
3160 playlist->position = playlist->entries->data; | |
3161 } | |
3162 | |
3163 filename = playlist->position->filename; | |
3164 | |
3165 PLAYLIST_UNLOCK(playlist->mutex); | |
3166 | |
3167 return filename; | |
3168 } | |
3169 | |
3170 PlaylistEntry * | |
3171 playlist_get_entry_to_play(Playlist *playlist) | |
3172 { | |
3173 if (!playlist) | |
3174 return NULL; | |
3175 | |
3176 PLAYLIST_LOCK(playlist->mutex); | |
3177 | |
3178 if (!playlist->position) { | |
3179 if (cfg.shuffle) | |
3180 playlist->position = playlist->shuffle->data; | |
3181 else | |
3182 playlist->position = playlist->entries->data; | |
3183 } | |
3184 | |
3185 PLAYLIST_UNLOCK(playlist->mutex); | |
3186 | |
3187 return playlist->position; | |
3188 } |