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