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