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